29
29
30
30
package org .scijava .ui .swing .widget ;
31
31
32
- import javax .swing .JLabel ;
32
+ import java .io .IOException ;
33
+
34
+ import javax .swing .JEditorPane ;
33
35
import javax .swing .JPanel ;
36
+ import javax .swing .event .HyperlinkEvent ;
37
+ import javax .swing .event .HyperlinkListener ;
34
38
35
39
import org .scijava .Priority ;
40
+ import org .scijava .log .LogService ;
41
+ import org .scijava .platform .PlatformService ;
42
+ import org .scijava .plugin .Parameter ;
36
43
import org .scijava .plugin .Plugin ;
37
44
import org .scijava .widget .InputWidget ;
38
45
import org .scijava .widget .MessageWidget ;
47
54
public class SwingMessageWidget extends SwingInputWidget <String > implements
48
55
MessageWidget <JPanel >
49
56
{
57
+ @ Parameter
58
+ private PlatformService platformService ;
59
+
60
+ @ Parameter
61
+ private LogService logService ;
50
62
51
- private JLabel label ;
63
+ private JEditorPane pane ;
52
64
53
65
// -- InputWidget methods --
54
66
@@ -76,8 +88,28 @@ public void set(final WidgetModel model) {
76
88
77
89
final String text = model .getText ();
78
90
79
- label = new JLabel (text );
80
- getComponent ().add (label );
91
+ pane = new JEditorPane ("text/html" , text );
92
+
93
+ // NB: use format (font etc.) from parent component
94
+ pane .putClientProperty (JEditorPane .HONOR_DISPLAY_PROPERTIES , Boolean .TRUE );
95
+
96
+ pane .setEditable (false );
97
+ pane .setOpaque (false );
98
+ pane .addHyperlinkListener (new HyperlinkListener () {
99
+
100
+ @ Override
101
+ public void hyperlinkUpdate (HyperlinkEvent hle ) {
102
+ if (HyperlinkEvent .EventType .ACTIVATED .equals (hle .getEventType ())) {
103
+ try {
104
+ platformService .open (hle .getURL ());
105
+ }
106
+ catch (IOException exc ) {
107
+ logService .error ("Error while opening " + hle .getURL (), exc );
108
+ }
109
+ }
110
+ }
111
+ });
112
+ getComponent ().add (pane );
81
113
}
82
114
83
115
// -- Typed methods --
@@ -92,6 +124,6 @@ public boolean supports(final WidgetModel model) {
92
124
@ Override
93
125
public void doRefresh () {
94
126
// maybe dialog owner changed message content
95
- label .setText (get ().getText ());
127
+ pane .setText (get ().getText ());
96
128
}
97
129
}
0 commit comments