ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/AE/installer2/src/net/oni2/aeinstaller/gui/HTMLLinkLabel.java
Revision: 592
Committed: Sat Dec 29 16:01:15 2012 UTC (12 years, 9 months ago) by alloc
Content type: text/x-java
File size: 2104 byte(s)
Log Message:
AEI - Current state

File Contents

# Content
1 package net.oni2.aeinstaller.gui;
2
3 import java.awt.Color;
4 import java.awt.Desktop;
5 import java.awt.Font;
6 import java.io.IOException;
7 import java.net.URISyntaxException;
8
9 import javax.swing.JEditorPane;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.UIDefaults;
13 import javax.swing.event.HyperlinkEvent;
14 import javax.swing.event.HyperlinkListener;
15 import javax.swing.text.DefaultCaret;
16
17 import net.oni2.aeinstaller.backend.ColorCopy;
18
19 /**
20 * @author Christian Illy
21 */
22 public class HTMLLinkLabel extends JEditorPane {
23 private static final long serialVersionUID = 2416829757362043910L;
24
25 String prefix;
26 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 // TODO Auto-generated catch block
58 e1.printStackTrace();
59 } catch (URISyntaxException e1) {
60 // TODO Auto-generated catch block
61 e1.printStackTrace();
62 }
63 }
64 });
65 setEditable(false);
66
67 Color bgColor = ColorCopy.copyColor(new JFrame().getBackground());
68 UIDefaults defaults = new UIDefaults();
69 defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
70 putClientProperty("Nimbus.Overrides", defaults);
71 putClientProperty("Nimbus.Overrides.InheritDefaults", true);
72 setBackground(bgColor);
73 }
74
75 @Override
76 public void setText(String t) {
77 super.setText(prefix + t + suffix);
78 }
79 }