source: AE/installer2/src/net/oni2/aeinstaller/gui/HTMLLinkLabel.java@ 708

Last change on this file since 708 was 636, checked in by alloc, 12 years ago

AEI2 0.93:

  • Primarily another bunch of refactorings
File size: 2.0 KB
Line 
1package net.oni2.aeinstaller.gui;
2
3import java.awt.Color;
4import java.awt.Desktop;
5import java.awt.Font;
6import java.io.IOException;
7import java.net.URISyntaxException;
8
9import javax.swing.JEditorPane;
10import javax.swing.JFrame;
11import javax.swing.JLabel;
12import javax.swing.UIDefaults;
13import javax.swing.event.HyperlinkEvent;
14import javax.swing.event.HyperlinkListener;
15import javax.swing.text.DefaultCaret;
16
17import net.oni2.aeinstaller.backend.ColorCopy;
18
19/**
20 * @author Christian Illy
21 */
22public class HTMLLinkLabel extends JEditorPane {
23 private static final long serialVersionUID = 2416829757362043910L;
24
25 private String prefix;
26 private String suffix;
27
28 /**
29 * Create a new HTMLLinkLabel
30 */
31 public HTMLLinkLabel() {
32 super();
33
34 ((DefaultCaret) this.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
35
36 setContentType("text/html");
37
38 JLabel label = new JLabel();
39 Font font = label.getFont();
40
41 StringBuffer style = new StringBuffer("font-family:" + font.getFamily()
42 + ";");
43 style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";");
44 style.append("font-size:" + font.getSize() + "pt;");
45
46 prefix = "<html><body style=\"" + style + "\">";
47 suffix = "</body></html>";
48
49 addHyperlinkListener(new HyperlinkListener() {
50
51 @Override
52 public void hyperlinkUpdate(HyperlinkEvent e) {
53 if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
54 try {
55 Desktop.getDesktop().browse(e.getURL().toURI());
56 } catch (IOException e1) {
57 e1.printStackTrace();
58 } catch (URISyntaxException e1) {
59 e1.printStackTrace();
60 }
61 }
62 });
63 setEditable(false);
64
65 Color bgColor = ColorCopy.copyColor(new JFrame().getBackground());
66 UIDefaults defaults = new UIDefaults();
67 defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
68 putClientProperty("Nimbus.Overrides", defaults);
69 putClientProperty("Nimbus.Overrides.InheritDefaults", true);
70 setBackground(bgColor);
71 }
72
73 @Override
74 public void setText(String t) {
75 super.setText(prefix + t + suffix);
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.