Skip to content

Commit f78a3fe

Browse files
committed
EditorPane: Support for functional hyperlinks
If a URL exists in source code commentaries, this allows opening it using ctrl+click
1 parent 0cf932c commit f78a3fe

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/org/scijava/ui/swing/script/EditorPane.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import javax.swing.ToolTipManager;
5555
import javax.swing.event.DocumentEvent;
5656
import javax.swing.event.DocumentListener;
57+
import javax.swing.event.HyperlinkEvent;
58+
import javax.swing.event.HyperlinkListener;
5759
import javax.swing.text.BadLocationException;
5860
import javax.swing.text.DefaultEditorKit;
5961

@@ -71,6 +73,7 @@
7173
import org.fife.ui.rtextarea.RecordableTextAction;
7274
import org.scijava.Context;
7375
import org.scijava.log.LogService;
76+
import org.scijava.platform.PlatformService;
7477
import org.scijava.plugin.Parameter;
7578
import org.scijava.prefs.PrefService;
7679
import org.scijava.script.ScriptHeaderService;
@@ -113,6 +116,8 @@ public class EditorPane extends RSyntaxTextArea implements DocumentListener {
113116
@Parameter
114117
private PrefService prefService;
115118
@Parameter
119+
private PlatformService platformService;
120+
@Parameter
116121
private LogService log;
117122

118123
/**
@@ -129,6 +134,22 @@ public EditorPane() {
129134
setCodeFoldingEnabled(true);
130135
setShowMatchedBracketPopup(true);
131136
setClearWhitespaceLinesEnabled(false); // most folks wont't want this set?
137+
// If a URL exists in commentaries this allows opening it using ctrl+click
138+
setHyperlinksEnabled(true);
139+
addHyperlinkListener(new HyperlinkListener() {
140+
141+
@Override
142+
public void hyperlinkUpdate(final HyperlinkEvent hle) {
143+
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
144+
try {
145+
platformService.open(hle.getURL());
146+
}
147+
catch (final IOException exc) {
148+
//ignored
149+
}
150+
}
151+
}
152+
});
132153

133154
// load preferences
134155
loadPreferences();

0 commit comments

Comments
 (0)