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 | 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 | }
|
---|