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

Last change on this file since 598 was 593, checked in by alloc, 12 years ago
File size: 2.1 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 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
80}
Note: See TracBrowser for help on using the repository browser.