34
34
import java .awt .Container ;
35
35
import java .awt .Dimension ;
36
36
import java .awt .Font ;
37
- import java .awt .Graphics2D ;
37
+ import java .awt .Toolkit ;
38
38
import java .awt .event .ActionEvent ;
39
+ import java .awt .event .KeyEvent ;
39
40
import java .awt .event .MouseAdapter ;
40
41
import java .awt .event .MouseEvent ;
41
- import java .awt .image .BufferedImage ;
42
42
import java .io .BufferedReader ;
43
43
import java .io .BufferedWriter ;
44
44
import java .io .File ;
55
55
import java .util .regex .Pattern ;
56
56
57
57
import javax .swing .Action ;
58
- import javax .swing .ImageIcon ;
59
58
import javax .swing .JMenu ;
60
59
import javax .swing .JMenuItem ;
61
60
import javax .swing .JOptionPane ;
87
86
import org .fife .ui .rsyntaxtextarea .Style ;
88
87
import org .fife .ui .rsyntaxtextarea .SyntaxScheme ;
89
88
import org .fife .ui .rsyntaxtextarea .Theme ;
89
+ import org .fife .ui .rsyntaxtextarea .parser .TaskTagParser ;
90
90
import org .fife .ui .rtextarea .Gutter ;
91
91
import org .fife .ui .rtextarea .GutterIconInfo ;
92
92
import org .fife .ui .rtextarea .RTextArea ;
95
95
import org .fife .ui .rtextarea .RTextAreaEditorKit .InvertSelectionCaseAction ;
96
96
import org .fife .ui .rtextarea .RTextAreaEditorKit .LineMoveAction ;
97
97
import org .fife .ui .rtextarea .RTextAreaEditorKit .LowerSelectionCaseAction ;
98
+ import org .fife .ui .rtextarea .RTextAreaEditorKit .NextBookmarkAction ;
98
99
import org .fife .ui .rtextarea .RTextAreaEditorKit .TimeDateAction ;
100
+ import org .fife .ui .rtextarea .RTextAreaEditorKit .ToggleBookmarkAction ;
99
101
import org .fife .ui .rtextarea .RTextAreaEditorKit .UpperSelectionCaseAction ;
100
102
import org .fife .ui .rtextarea .RTextScrollPane ;
101
103
import org .fife .ui .rtextarea .RecordableTextAction ;
@@ -184,7 +186,8 @@ public void hyperlinkUpdate(final HyperlinkEvent hle) {
184
186
}
185
187
}
186
188
});
187
-
189
+ // Add support for TODO, FIXME, HACK
190
+ addParser (new TaskTagParser ());
188
191
// load preferences
189
192
loadPreferences ();
190
193
@@ -202,6 +205,11 @@ public void hyperlinkUpdate(final HyperlinkEvent hle) {
202
205
if (getActionMap ().get (RSyntaxTextAreaEditorKit .rstaCopyAsStyledTextAction ) != null )
203
206
getActionMap ().put (RSyntaxTextAreaEditorKit .rstaCopyAsStyledTextAction , new CopyAsStyledTextAction ());
204
207
208
+ // Fix conflicts with historical shortcuts: override defaults
209
+ getActionMap ().put (RTextAreaEditorKit .rtaNextBookmarkAction , new NextBookMarkActionImpl (RTextAreaEditorKit .rtaNextBookmarkAction , true ));
210
+ getActionMap ().put (RTextAreaEditorKit .rtaPrevBookmarkAction , new NextBookMarkActionImpl (RTextAreaEditorKit .rtaPrevBookmarkAction , false ));
211
+ getActionMap ().put (RTextAreaEditorKit .rtaToggleBookmarkAction , new ToggleBookmarkActionImpl ());
212
+
205
213
adjustPopupMenu ();
206
214
207
215
ToolTipManager .sharedInstance ().registerComponent (this );
@@ -300,37 +308,12 @@ public RTextScrollPane wrappedInScrollbars() {
300
308
sp .setIconRowHeaderEnabled (true );
301
309
gutter = sp .getGutter ();
302
310
gutter .setBookmarkingEnabled (true );
303
- updateBookmarkIcon ();
304
311
gutter .setShowCollapsedRegionToolTips (true );
305
312
gutter .setFoldIndicatorEnabled (true );
313
+ GutterUtils .updateIcons (gutter );
306
314
return sp ;
307
315
}
308
316
309
- protected void updateBookmarkIcon () {
310
- // this will clear existing bookmarks, so we'll need restore existing ones
311
- final GutterIconInfo [] stash = gutter .getBookmarks ();
312
- gutter .setBookmarkIcon (createBookmarkIcon ());
313
- try {
314
- for (final GutterIconInfo info : stash )
315
- gutter .toggleBookmark (info .getMarkedOffset ());
316
- } catch (final BadLocationException ignored ) {
317
- JOptionPane .showMessageDialog (this , "Some bookmarks may have been lost." , "Lost Bookmarks" ,
318
- JOptionPane .WARNING_MESSAGE );
319
- }
320
- }
321
-
322
- private ImageIcon createBookmarkIcon () {
323
- final int size = gutter .getLineNumberFont ().getSize ();
324
- final BufferedImage image = new BufferedImage (size , size , BufferedImage .TYPE_INT_ARGB );
325
- final Graphics2D graphics = image .createGraphics ();
326
- graphics .setColor (gutter .getLineNumberColor ());
327
- graphics .fillRect (0 , 0 , size , size );
328
- graphics .setXORMode (getCurrentLineHighlightColor ());
329
- graphics .drawRect (0 , 0 , size - 1 , size - 1 );
330
- image .flush ();
331
- return new ImageIcon (image );
332
- }
333
-
334
317
RecordableTextAction wordMovement (final String id , final int direction , final boolean select ) {
335
318
return new RecordableTextAction (id ) {
336
319
private static final long serialVersionUID = 1L ;
@@ -690,8 +673,8 @@ protected void setLanguage(final ScriptLanguage language,
690
673
}
691
674
692
675
if ("None" .equals (languageName ) ) {
693
- supportStatus = null ; // no need to update console
694
- return ;
676
+ supportStatus = "Active language: None" ;
677
+ return ; // no need to update console any further
695
678
}
696
679
String supportLevel = "SciJava supported" ;
697
680
// try to get language support for current language, may be null.
@@ -829,7 +812,7 @@ public void increaseFontSize(final float factor) {
829
812
if (gutter != null ) {
830
813
final float lnSize = size * 0.8f ;
831
814
gutter .setLineNumberFont (font .deriveFont (lnSize ));
832
- updateBookmarkIcon ( );
815
+ GutterUtils . updateIcons ( gutter );
833
816
}
834
817
Component parent = getParent ();
835
818
if (parent instanceof JViewport ) {
@@ -1033,7 +1016,7 @@ private void applyTheme(final Theme th) throws IllegalArgumentException {
1033
1016
final float existingFontSize = getFontSize ();
1034
1017
th .apply (this );
1035
1018
setFontSize (existingFontSize );
1036
- updateBookmarkIcon (); // update bookmark icon color
1019
+ GutterUtils . updateIcons ( gutter );
1037
1020
}
1038
1021
1039
1022
private static Theme getTheme (final String theme ) throws IllegalArgumentException {
@@ -1198,6 +1181,33 @@ public String getMacroID() {
1198
1181
1199
1182
}
1200
1183
1184
+ /** solves hot-key conflicts with historical shortcuts */
1185
+ static class NextBookMarkActionImpl extends NextBookmarkAction {
1186
+ private static final long serialVersionUID = 1L ;
1187
+
1188
+ public NextBookMarkActionImpl (String name , boolean forward ) {
1189
+ super (name , forward );
1190
+ final KeyStroke keystroke = KeyStroke .getKeyStroke (KeyEvent .VK_F2 , (forward ) ? 0 : ActionEvent .SHIFT_MASK );
1191
+ setAccelerator (keystroke );
1192
+ }
1193
+
1194
+ }
1195
+ /** solves hot-key conflicts with historical shortcuts */
1196
+ class ToggleBookmarkActionImpl extends ToggleBookmarkAction {
1197
+ private static final long serialVersionUID = 1L ;
1198
+
1199
+ public ToggleBookmarkActionImpl () {
1200
+ super ();
1201
+ final KeyStroke keystroke = KeyStroke .getKeyStroke (KeyEvent .VK_F2 , Toolkit .getDefaultToolkit ().getMenuShortcutKeyMask ());
1202
+ setAccelerator (keystroke );
1203
+ }
1204
+
1205
+ @ Override
1206
+ public void actionPerformedImpl (ActionEvent e , RTextArea textArea ) {
1207
+ toggleBookmark ();
1208
+ }
1209
+ }
1210
+
1201
1211
/** Modified from DecreaseIndentAction */
1202
1212
static class IncreaseIndentAction extends RecordableTextAction {
1203
1213
0 commit comments