|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.ui; |
|
38 |
| |
|
39 |
| import javax.swing.*; |
|
40 |
| import javax.swing.undo.*; |
|
41 |
| import javax.swing.event.*; |
|
42 |
| import javax.swing.text.*; |
|
43 |
| import java.awt.*; |
|
44 |
| import java.awt.event.*; |
|
45 |
| import java.util.List; |
|
46 |
| import java.util.LinkedList; |
|
47 |
| |
|
48 |
| import edu.rice.cs.plt.tuple.Pair; |
|
49 |
| import edu.rice.cs.util.UnexpectedException; |
|
50 |
| import edu.rice.cs.util.OperationCanceledException; |
|
51 |
| import edu.rice.cs.util.swing.HighlightManager; |
|
52 |
| import edu.rice.cs.util.swing.RightClickMouseAdapter; |
|
53 |
| import edu.rice.cs.util.text.SwingDocument; |
|
54 |
| import edu.rice.cs.drjava.model.*; |
|
55 |
| import edu.rice.cs.drjava.model.definitions.CompoundUndoManager; |
|
56 |
| import edu.rice.cs.drjava.model.definitions.DefinitionsEditorKit; |
|
57 |
| import edu.rice.cs.drjava.model.definitions.NoSuchDocumentException; |
|
58 |
| import edu.rice.cs.drjava.model.definitions.indent.Indenter; |
|
59 |
| import edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelState; |
|
60 |
| import edu.rice.cs.drjava.config.*; |
|
61 |
| import edu.rice.cs.drjava.DrJava; |
|
62 |
| import edu.rice.cs.drjava.model.debug.Breakpoint; |
|
63 |
| |
|
64 |
| import static edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelStates.*; |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| public class DefinitionsPane extends AbstractDJPane implements Finalizable<DefinitionsPane> { |
|
71 |
| |
|
72 |
| |
|
73 |
| private static DefinitionsEditorKit EDITOR_KIT; |
|
74 |
| |
|
75 |
| |
|
76 |
| private static int INDENT_WARNING_THRESHOLD = 200000; |
|
77 |
| |
|
78 |
| |
|
79 |
| private final MainFrame _mainFrame; |
|
80 |
| |
|
81 |
| private final OpenDefinitionsDocument _doc; |
|
82 |
| |
|
83 |
| private volatile UndoAction _undoAction; |
|
84 |
| private volatile RedoAction _redoAction; |
|
85 |
| |
|
86 |
| private volatile boolean testVariable; |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| private volatile boolean _hasWarnedAboutModified = false; |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| private volatile boolean _isDeleteCompoundEdit; |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| private volatile boolean _isCtrlShiftBracketDown = false; |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| private volatile boolean _antiAliasText = false; |
|
107 |
| |
|
108 |
| |
|
109 |
| private volatile boolean _displayRightMargin = false; |
|
110 |
| |
|
111 |
| |
|
112 |
| private volatile int _numRightMarginColumns = 120; |
|
113 |
| |
|
114 |
| |
|
115 |
| private static volatile int _maxCharWidth = 0; |
|
116 |
| |
|
117 |
| |
|
118 |
| private volatile Color _rightMarginColor = Color.red; |
|
119 |
| |
|
120 |
| |
|
121 |
| private volatile HighlightManager.HighlightInfo _errorHighlightTag = null; |
|
122 |
| |
|
123 |
| |
|
124 |
| static volatile ReverseHighlighter.DefaultUnderlineHighlightPainter BOOKMARK_PAINTER = |
|
125 |
| new ReverseHighlighter.DefaultUnderlineHighlightPainter(DrJava.getConfig().getSetting(BOOKMARK_COLOR), 3); |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| static volatile LayeredHighlighter.LayerPainter[] FIND_RESULTS_PAINTERS; |
|
130 |
| |
|
131 |
| static { |
|
132 |
6
| FIND_RESULTS_PAINTERS = new LayeredHighlighter.LayerPainter[FIND_RESULTS_COLORS.length+1];
|
|
133 |
6
| for(int i = 0; i < FIND_RESULTS_COLORS.length; ++i) {
|
|
134 |
48
| FIND_RESULTS_PAINTERS[i] =
|
|
135 |
| new ReverseHighlighter.DefaultFrameHighlightPainter(DrJava.getConfig().getSetting(FIND_RESULTS_COLORS[i]), 2); |
|
136 |
| } |
|
137 |
6
| FIND_RESULTS_PAINTERS[FIND_RESULTS_COLORS.length] =
|
|
138 |
| new ReverseHighlighter.DefaultUnderlineHighlightPainter(Color.WHITE, 0); |
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| static volatile int[] FIND_RESULTS_PAINTERS_USAGE = new int[FIND_RESULTS_COLORS.length]; |
|
144 |
| |
|
145 |
| |
|
146 |
| static ReverseHighlighter.DrJavaHighlightPainter BREAKPOINT_PAINTER = |
|
147 |
| new ReverseHighlighter.DrJavaHighlightPainter(DrJava.getConfig().getSetting(DEBUG_BREAKPOINT_COLOR)); |
|
148 |
| |
|
149 |
| |
|
150 |
| static volatile ReverseHighlighter.DrJavaHighlightPainter DISABLED_BREAKPOINT_PAINTER = |
|
151 |
| new ReverseHighlighter.DrJavaHighlightPainter(DrJava.getConfig().getSetting(DEBUG_BREAKPOINT_DISABLED_COLOR)); |
|
152 |
| |
|
153 |
| |
|
154 |
| static volatile ReverseHighlighter.DrJavaHighlightPainter THREAD_PAINTER = |
|
155 |
| new ReverseHighlighter.DrJavaHighlightPainter(DrJava.getConfig().getSetting(DEBUG_THREAD_COLOR)); |
|
156 |
| |
|
157 |
| |
|
158 |
| public static final String INDENT_KEYMAP_NAME = "INDENT_KEYMAP"; |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
8
| protected void matchUpdate(int offset, boolean opening) {
|
|
165 |
8
| assert EventQueue.isDispatchThread();
|
|
166 |
8
| assert offset > 0;
|
|
167 |
8
| _doc.setCurrentLocation(offset);
|
|
168 |
8
| _removePreviousHighlight();
|
|
169 |
| |
|
170 |
| |
|
171 |
8
| int caretPos = getCaretPosition();
|
|
172 |
| |
|
173 |
8
| if (opening) {
|
|
174 |
| |
|
175 |
| |
|
176 |
2
| int to = _doc.balanceForward();
|
|
177 |
2
| if (to > -1) {
|
|
178 |
1
| int end = caretPos + to;
|
|
179 |
1
| _addHighlight(caretPos - 1, end);
|
|
180 |
| } |
|
181 |
2
| updateStatusField();
|
|
182 |
| } |
|
183 |
| else { |
|
184 |
| |
|
185 |
| |
|
186 |
6
| int from = _doc.balanceBackward();
|
|
187 |
6
| if (from > -1) {
|
|
188 |
6
| int start = caretPos - from;
|
|
189 |
6
| _addHighlight(start, caretPos);
|
|
190 |
| |
|
191 |
6
| String matchText = _matchText(start);
|
|
192 |
| |
|
193 |
6
| if (matchText != null) _mainFrame.updateStatusField("Bracket matches: " + matchText);
|
|
194 |
0
| else updateStatusField();
|
|
195 |
| } |
|
196 |
| } |
|
197 |
| } |
|
198 |
| |
|
199 |
| |
|
200 |
95
| protected void updateStatusField() { _mainFrame.updateStatusField(); }
|
|
201 |
| |
|
202 |
| |
|
203 |
6
| private String _matchText(int braceIndex) {
|
|
204 |
6
| DJDocument doc = _doc;
|
|
205 |
6
| String docText;
|
|
206 |
6
| docText = doc.getText();
|
|
207 |
| |
|
208 |
6
| char ch = docText.charAt(braceIndex);
|
|
209 |
6
| if ( ch == '{' || ch == '(') {
|
|
210 |
6
| Character charBefore = null;
|
|
211 |
6
| int charBeforeIndex = braceIndex-1;
|
|
212 |
6
| boolean previousLine = false;
|
|
213 |
| |
|
214 |
4
| if (charBeforeIndex != -1) charBefore = docText.charAt(charBeforeIndex);
|
|
215 |
| |
|
216 |
6
| charBeforeIndex--;
|
|
217 |
| |
|
218 |
6
| while (charBeforeIndex >= 0 && (charBefore == '\n' || charBefore == ' ')) {
|
|
219 |
5
| charBefore = docText.charAt(charBeforeIndex);
|
|
220 |
2
| if (!previousLine && charBefore != '\n' && charBefore != ' ') charBeforeIndex = braceIndex-1;
|
|
221 |
1
| if (charBefore == '\n') previousLine = true;
|
|
222 |
5
| charBeforeIndex--;
|
|
223 |
| } |
|
224 |
| |
|
225 |
6
| final StringBuilder returnText = new StringBuilder(docText.substring(0, charBeforeIndex+2));
|
|
226 |
1
| if (previousLine) returnText.append("...");
|
|
227 |
6
| returnText.append(ch);
|
|
228 |
| |
|
229 |
6
| int lastNewlineIndex = returnText.lastIndexOf("\n");
|
|
230 |
6
| return returnText.substring(lastNewlineIndex+1);
|
|
231 |
| } |
|
232 |
| else |
|
233 |
0
| return null;
|
|
234 |
| } |
|
235 |
| |
|
236 |
| |
|
237 |
| private class MatchColorOptionListener implements OptionListener<Color> { |
|
238 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
239 |
0
| MATCH_PAINTER = new ReverseHighlighter.DrJavaHighlightPainter(oce.value);
|
|
240 |
0
| if (_matchHighlight != null) {
|
|
241 |
0
| int start = _matchHighlight.getStartOffset();
|
|
242 |
0
| int end = _matchHighlight.getEndOffset();
|
|
243 |
0
| _matchHighlight.remove();
|
|
244 |
0
| _addHighlight(start, end);
|
|
245 |
| } |
|
246 |
| } |
|
247 |
| } |
|
248 |
| |
|
249 |
| |
|
250 |
| private class ErrorColorOptionListener implements OptionListener<Color> { |
|
251 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
252 |
0
| ERROR_PAINTER = new ReverseHighlighter.DrJavaHighlightPainter(oce.value);
|
|
253 |
0
| if (_errorHighlightTag != null) {
|
|
254 |
0
| int start = _errorHighlightTag.getStartOffset();
|
|
255 |
0
| int end = _errorHighlightTag.getEndOffset();
|
|
256 |
0
| _errorHighlightTag.remove();
|
|
257 |
0
| addErrorHighlight(start, end);
|
|
258 |
| } |
|
259 |
| } |
|
260 |
| } |
|
261 |
| |
|
262 |
| |
|
263 |
| private class BookmarkColorOptionListener implements OptionListener<Color> { |
|
264 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
265 |
0
| BOOKMARK_PAINTER =
|
|
266 |
| new ReverseHighlighter.DefaultUnderlineHighlightPainter(oce.value, BOOKMARK_PAINTER.getThickness()); |
|
267 |
0
| _mainFrame.refreshBookmarkHighlightPainter();
|
|
268 |
| } |
|
269 |
| } |
|
270 |
| |
|
271 |
| |
|
272 |
| private static class FindResultsColorOptionListener implements OptionListener<Color> { |
|
273 |
| private int _index; |
|
274 |
744
| public FindResultsColorOptionListener(int i) { _index = i; }
|
|
275 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
276 |
0
| synchronized(FIND_RESULTS_PAINTERS) {
|
|
277 |
0
| FIND_RESULTS_PAINTERS[_index] = new ReverseHighlighter.DefaultFrameHighlightPainter(oce.value, 2);
|
|
278 |
| } |
|
279 |
| } |
|
280 |
| } |
|
281 |
| |
|
282 |
| |
|
283 |
| private class BreakpointColorOptionListener implements OptionListener<Color> { |
|
284 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
285 |
0
| BREAKPOINT_PAINTER = new ReverseHighlighter.DrJavaHighlightPainter(oce.value);
|
|
286 |
0
| _mainFrame.refreshBreakpointHighlightPainter();
|
|
287 |
| } |
|
288 |
| } |
|
289 |
| |
|
290 |
| |
|
291 |
| private class DisabledBreakpointColorOptionListener implements OptionListener<Color> { |
|
292 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
293 |
0
| DISABLED_BREAKPOINT_PAINTER = new ReverseHighlighter.DrJavaHighlightPainter(oce.value);
|
|
294 |
0
| _mainFrame.refreshBreakpointHighlightPainter();
|
|
295 |
| } |
|
296 |
| } |
|
297 |
| |
|
298 |
| |
|
299 |
| private static class ThreadColorOptionListener implements OptionListener<Color> { |
|
300 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
301 |
0
| THREAD_PAINTER = new ReverseHighlighter.DrJavaHighlightPainter(oce.value);
|
|
302 |
| } |
|
303 |
| } |
|
304 |
| |
|
305 |
| |
|
306 |
| private class AntiAliasOptionListener implements OptionListener<Boolean> { |
|
307 |
0
| public void optionChanged(OptionEvent<Boolean> oce) {
|
|
308 |
0
| _antiAliasText = oce.value.booleanValue();
|
|
309 |
0
| DefinitionsPane.this.repaint();
|
|
310 |
| } |
|
311 |
| } |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
| |
|
318 |
| private final UndoableEditListener _undoListener = new UndoableEditListener() { |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
42
| public void undoableEditHappened(UndoableEditEvent e) {
|
|
324 |
42
| assert EventQueue.isDispatchThread();
|
|
325 |
| |
|
326 |
42
| UndoableEdit undo = e.getEdit();
|
|
327 |
42
| if (! _inCompoundEdit) {
|
|
328 |
19
| CompoundUndoManager undoMan = _doc.getUndoManager();
|
|
329 |
19
| _inCompoundEdit = true;
|
|
330 |
19
| _compoundEditKey = undoMan.startCompoundEdit();
|
|
331 |
19
| getUndoAction().updateUndoState();
|
|
332 |
19
| getRedoAction().updateRedoState();
|
|
333 |
| } |
|
334 |
42
| _doc.getUndoManager().addEdit(undo);
|
|
335 |
42
| getRedoAction().setEnabled(false);
|
|
336 |
| } |
|
337 |
| }; |
|
338 |
| |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| private volatile JPopupMenu _popMenu; |
|
346 |
| |
|
347 |
| |
|
348 |
| private volatile PopupMenuMouseAdapter _popupMenuMA; |
|
349 |
| |
|
350 |
| |
|
351 |
| private volatile ErrorCaretListener _errorListener; |
|
352 |
| |
|
353 |
| private volatile ActionListener _setSizeListener = null; |
|
354 |
| |
|
355 |
| |
|
356 |
| private class IndentKeyActionTab extends AbstractAction { |
|
357 |
| |
|
358 |
| |
|
359 |
0
| public void actionPerformed(ActionEvent e) {
|
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
0
| _mainFrame.hourglassOn();
|
|
364 |
0
| try {
|
|
365 |
0
| indent();
|
|
366 |
| } finally { |
|
367 |
0
| _mainFrame.hourglassOff();
|
|
368 |
| } |
|
369 |
| } |
|
370 |
| } |
|
371 |
| |
|
372 |
| |
|
373 |
| private class IndentKeyAction extends AbstractAction { |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
| @SuppressWarnings("unused") private final String _key; |
|
380 |
| |
|
381 |
| |
|
382 |
| private final Action _defaultAction; |
|
383 |
| |
|
384 |
| |
|
385 |
| private final boolean _indentNonCode; |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| |
|
390 |
279
| IndentKeyAction(String key, Action defaultAction) {
|
|
391 |
279
| this(key, defaultAction, false);
|
|
392 |
| } |
|
393 |
| |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
372
| IndentKeyAction(String key, Action defaultAction, boolean indentNonCode) {
|
|
400 |
372
| _key = key;
|
|
401 |
372
| _defaultAction = defaultAction;
|
|
402 |
372
| _indentNonCode = indentNonCode;
|
|
403 |
| } |
|
404 |
| |
|
405 |
| |
|
406 |
| |
|
407 |
| |
|
408 |
0
| protected Indenter.IndentReason getIndentReason() { return Indenter.IndentReason.OTHER; }
|
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
2
| public void actionPerformed(ActionEvent e) {
|
|
414 |
| |
|
415 |
| |
|
416 |
2
| if (!_isCtrlShiftBracketDown &&
|
|
417 |
| (e != null) && |
|
418 |
| (e.getActionCommand() != null) && |
|
419 |
| (e.getActionCommand().equals("{") || e.getActionCommand().equals("}"))) { |
|
420 |
1
| ActionEvent e2 = new ActionEvent(e.getSource(),
|
|
421 |
| e.getID(), |
|
422 |
| e.getActionCommand(), |
|
423 |
| e.getWhen(), |
|
424 |
| ActionEvent.SHIFT_MASK); |
|
425 |
1
| _defaultAction.actionPerformed(e2);
|
|
426 |
| } |
|
427 |
| else { |
|
428 |
1
| _defaultAction.actionPerformed(e);
|
|
429 |
| } |
|
430 |
| |
|
431 |
| |
|
432 |
| |
|
433 |
2
| updateCurrentLocationInDoc();
|
|
434 |
2
| ReducedModelState state = _doc.getStateAtCurrent();
|
|
435 |
1
| if (state.equals(FREE) || _indentNonCode) indent(getIndentReason());
|
|
436 |
| } |
|
437 |
| } |
|
438 |
| |
|
439 |
| |
|
440 |
87
| public void updateCurrentLocationInDoc() {
|
|
441 |
87
| _doc.setCurrentLocation(getCaretPosition());
|
|
442 |
| } |
|
443 |
| |
|
444 |
| |
|
445 |
| private volatile Action _indentKeyActionTab = new IndentKeyActionTab(); |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
| |
|
450 |
| |
|
451 |
| |
|
452 |
| private final Action _indentKeyActionLine = |
|
453 |
| new IndentKeyAction("\n", (Action) getActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)), |
|
454 |
| true ) { |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
1
| protected Indenter.IndentReason getIndentReason() { return Indenter.IndentReason.ENTER_KEY_PRESS; }
|
|
459 |
| }; |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
| |
|
464 |
| private final Action _indentKeyActionCurly = new IndentKeyAction("}", getKeymap().getDefaultAction()); |
|
465 |
| private final Action _indentKeyActionOpenCurly = new IndentKeyAction("{", getKeymap().getDefaultAction()); |
|
466 |
| private final Action _indentKeyActionColon = new IndentKeyAction(":", getKeymap().getDefaultAction()); |
|
467 |
| |
|
468 |
| |
|
469 |
| |
|
470 |
| |
|
471 |
| public volatile boolean _inCompoundEdit = false; |
|
472 |
| private volatile int _compoundEditKey; |
|
473 |
| |
|
474 |
| |
|
475 |
| final Keymap ourMap; |
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
| |
|
480 |
93
| public DefinitionsPane(MainFrame mf, final OpenDefinitionsDocument doc) {
|
|
481 |
93
| super(new SwingDocument());
|
|
482 |
| |
|
483 |
93
| _mainFrame = mf;
|
|
484 |
| |
|
485 |
93
| addFocusListener(new FocusAdapter() {
|
|
486 |
0
| public void focusGained(FocusEvent e) {
|
|
487 |
0
| _mainFrame.getModel().getDocumentNavigator().requestSelectionUpdate(doc);
|
|
488 |
| } |
|
489 |
| }); |
|
490 |
| |
|
491 |
93
| _doc = doc;
|
|
492 |
| |
|
493 |
| |
|
494 |
| |
|
495 |
93
| _selStart = _doc.getInitialSelectionStart();
|
|
496 |
93
| _selEnd = _doc.getInitialSelectionEnd();
|
|
497 |
93
| _savedVScroll = _doc.getInitialVerticalScroll();
|
|
498 |
93
| _savedHScroll = _doc.getInitialHorizontalScroll();
|
|
499 |
| |
|
500 |
| |
|
501 |
93
| _resetUndo();
|
|
502 |
| |
|
503 |
93
| Font mainFont = DrJava.getConfig().getSetting(FONT_MAIN);
|
|
504 |
93
| setFont(mainFont);
|
|
505 |
| |
|
506 |
93
| setEditable(true);
|
|
507 |
| |
|
508 |
| |
|
509 |
93
| ourMap = addKeymap(INDENT_KEYMAP_NAME, getKeymap());
|
|
510 |
93
| ourMap.addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), _indentKeyActionLine);
|
|
511 |
93
| ourMap.addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), _indentKeyActionTab);
|
|
512 |
93
| ourMap.addActionForKeyStroke(KeyStroke.getKeyStroke('}'), _indentKeyActionCurly);
|
|
513 |
93
| ourMap.addActionForKeyStroke(KeyStroke.getKeyStroke('{'), _indentKeyActionOpenCurly);
|
|
514 |
93
| ourMap.addActionForKeyStroke(KeyStroke.getKeyStroke(':'), _indentKeyActionColon);
|
|
515 |
93
| setKeymap(ourMap);
|
|
516 |
| |
|
517 |
| |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
| |
|
522 |
| |
|
523 |
| |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
93
| _antiAliasText = DrJava.getConfig().getSetting(TEXT_ANTIALIAS);
|
|
532 |
93
| _displayRightMargin = DrJava.getConfig().getSetting(DISPLAY_RIGHT_MARGIN);
|
|
533 |
93
| _numRightMarginColumns = DrJava.getConfig().getSetting(RIGHT_MARGIN_COLUMNS);
|
|
534 |
93
| _rightMarginColor = DrJava.getConfig().getSetting(RIGHT_MARGIN_COLOR);
|
|
535 |
| |
|
536 |
93
| OptionListener<Color> cListener;
|
|
537 |
93
| Pair<Option<Color>, OptionListener<Color>> cPair;
|
|
538 |
| |
|
539 |
| |
|
540 |
| |
|
541 |
93
| cListener = new ForegroundColorListener(this);
|
|
542 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.DEFINITIONS_NORMAL_COLOR, cListener);
|
|
543 |
93
| _colorOptionListeners.add(cPair);
|
|
544 |
| |
|
545 |
93
| cListener = new BackgroundColorListener(this);
|
|
546 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.DEFINITIONS_BACKGROUND_COLOR, cListener);
|
|
547 |
93
| _colorOptionListeners.add(cPair);
|
|
548 |
| |
|
549 |
| |
|
550 |
93
| cListener = new MatchColorOptionListener();
|
|
551 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.DEFINITIONS_MATCH_COLOR, cListener);
|
|
552 |
93
| _colorOptionListeners.add(cPair);
|
|
553 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.DEFINITIONS_MATCH_COLOR, cListener);
|
|
554 |
| |
|
555 |
93
| cListener = new ErrorColorOptionListener();
|
|
556 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.COMPILER_ERROR_COLOR, cListener);
|
|
557 |
93
| _colorOptionListeners.add(cPair);
|
|
558 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.COMPILER_ERROR_COLOR, cListener);
|
|
559 |
| |
|
560 |
93
| cListener = new BookmarkColorOptionListener();
|
|
561 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.BOOKMARK_COLOR, cListener);
|
|
562 |
93
| _colorOptionListeners.add(cPair);
|
|
563 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.BOOKMARK_COLOR, cListener);
|
|
564 |
| |
|
565 |
93
| for (int i = 0; i < FIND_RESULTS_COLORS.length; ++i) {
|
|
566 |
744
| cListener = new FindResultsColorOptionListener(i);
|
|
567 |
744
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.FIND_RESULTS_COLORS[i], cListener);
|
|
568 |
744
| _colorOptionListeners.add(cPair);
|
|
569 |
744
| DrJava.getConfig().addOptionListener(OptionConstants.FIND_RESULTS_COLORS[i], cListener);
|
|
570 |
| } |
|
571 |
| |
|
572 |
93
| cListener = new BreakpointColorOptionListener();
|
|
573 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.DEBUG_BREAKPOINT_COLOR, cListener);
|
|
574 |
93
| _colorOptionListeners.add(cPair);
|
|
575 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.DEBUG_BREAKPOINT_COLOR, cListener);
|
|
576 |
| |
|
577 |
93
| cListener = new DisabledBreakpointColorOptionListener();
|
|
578 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.DEBUG_BREAKPOINT_DISABLED_COLOR, cListener);
|
|
579 |
93
| _colorOptionListeners.add(cPair);
|
|
580 |
93
| DrJava.getConfig().addOptionListener( OptionConstants.DEBUG_BREAKPOINT_DISABLED_COLOR, cListener);
|
|
581 |
| |
|
582 |
93
| cListener = new ThreadColorOptionListener();
|
|
583 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.DEBUG_THREAD_COLOR, cListener);
|
|
584 |
93
| _colorOptionListeners.add(cPair);
|
|
585 |
93
| DrJava.getConfig().addOptionListener( OptionConstants.DEBUG_THREAD_COLOR, cListener);
|
|
586 |
| |
|
587 |
93
| OptionListener<Boolean> bListener = new AntiAliasOptionListener();
|
|
588 |
93
| Pair<Option<Boolean>, OptionListener<Boolean>> bPair =
|
|
589 |
| new Pair<Option<Boolean>, OptionListener<Boolean>>(OptionConstants.TEXT_ANTIALIAS, bListener); |
|
590 |
93
| _booleanOptionListeners.add(bPair);
|
|
591 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.TEXT_ANTIALIAS, bListener);
|
|
592 |
| |
|
593 |
93
| bListener = new OptionListener<Boolean>() {
|
|
594 |
0
| public void optionChanged(OptionEvent<Boolean> oce) {
|
|
595 |
0
| _displayRightMargin = oce.value;
|
|
596 |
0
| DefinitionsPane.this.repaint();
|
|
597 |
| } |
|
598 |
| }; |
|
599 |
93
| bPair = new Pair<Option<Boolean>, OptionListener<Boolean>>(OptionConstants.DISPLAY_RIGHT_MARGIN, bListener);
|
|
600 |
93
| _booleanOptionListeners.add(bPair);
|
|
601 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.DISPLAY_RIGHT_MARGIN, bListener);
|
|
602 |
| |
|
603 |
93
| OptionListener<Integer> iTemp = new OptionListener<Integer>() {
|
|
604 |
0
| public void optionChanged(OptionEvent<Integer> oce) {
|
|
605 |
0
| _numRightMarginColumns = oce.value;
|
|
606 |
0
| DefinitionsPane.this.repaint();
|
|
607 |
| } |
|
608 |
| }; |
|
609 |
93
| Pair<Option<Integer>, OptionListener<Integer>> iPair =
|
|
610 |
| new Pair<Option<Integer>, OptionListener<Integer>>(OptionConstants.RIGHT_MARGIN_COLUMNS, iTemp); |
|
611 |
93
| _integerOptionListeners.add(iPair);
|
|
612 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.RIGHT_MARGIN_COLUMNS, iTemp);
|
|
613 |
| |
|
614 |
93
| cListener = new OptionListener<Color>() {
|
|
615 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
616 |
0
| _rightMarginColor = oce.value;
|
|
617 |
0
| DefinitionsPane.this.repaint();
|
|
618 |
| } |
|
619 |
| }; |
|
620 |
93
| cPair = new Pair<Option<Color>, OptionListener<Color>>(OptionConstants.RIGHT_MARGIN_COLOR, cListener);
|
|
621 |
93
| _colorOptionListeners.add(cPair);
|
|
622 |
93
| DrJava.getConfig().addOptionListener(OptionConstants.RIGHT_MARGIN_COLOR, cListener);
|
|
623 |
| |
|
624 |
93
| createPopupMenu();
|
|
625 |
| |
|
626 |
| |
|
627 |
93
| _popupMenuMA = new PopupMenuMouseAdapter();
|
|
628 |
93
| this.addMouseListener(_popupMenuMA);
|
|
629 |
93
| this.setHighlighter(new ReverseHighlighter());
|
|
630 |
93
| _highlightManager = new HighlightManager(this);
|
|
631 |
| |
|
632 |
93
| int rate = this.getCaret().getBlinkRate();
|
|
633 |
| |
|
634 |
| |
|
635 |
| |
|
636 |
| |
|
637 |
| |
|
638 |
93
| this.getCaret().setBlinkRate(rate);
|
|
639 |
| |
|
640 |
| |
|
641 |
93
| _isDeleteCompoundEdit = true;
|
|
642 |
| } |
|
643 |
| |
|
644 |
| |
|
645 |
15
| public void endCompoundEdit() {
|
|
646 |
15
| if (_inCompoundEdit) {
|
|
647 |
11
| CompoundUndoManager undoMan = _doc.getUndoManager();
|
|
648 |
11
| _inCompoundEdit = false;
|
|
649 |
11
| undoMan.endCompoundEdit(_compoundEditKey);
|
|
650 |
| } |
|
651 |
| } |
|
652 |
| |
|
653 |
| |
|
654 |
| |
|
655 |
| |
|
656 |
| |
|
657 |
| |
|
658 |
37
| public void processKeyEvent(KeyEvent e) {
|
|
659 |
37
| if (_mainFrame.getAllowKeyEvents()) {
|
|
660 |
| |
|
661 |
| |
|
662 |
| |
|
663 |
36
| if (((e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET) || (e.getKeyCode() == KeyEvent.VK_CLOSE_BRACKET)) &&
|
|
664 |
| ((e.getModifiers() & InputEvent.CTRL_MASK) != 0) && |
|
665 |
| ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0)) { |
|
666 |
| |
|
667 |
0
| if (e.getID() == KeyEvent.KEY_PRESSED) {
|
|
668 |
0
| _isCtrlShiftBracketDown = true;
|
|
669 |
| } |
|
670 |
0
| else if (e.getID() == KeyEvent.KEY_RELEASED) {
|
|
671 |
0
| _isCtrlShiftBracketDown = false;
|
|
672 |
| } |
|
673 |
| } |
|
674 |
| |
|
675 |
| |
|
676 |
36
| if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE && _isDeleteCompoundEdit) {
|
|
677 |
2
| endCompoundEdit();
|
|
678 |
2
| _isDeleteCompoundEdit = false;
|
|
679 |
| } |
|
680 |
34
| else if (e.getID()==KeyEvent.KEY_PRESSED && e.getKeyCode() != KeyEvent.VK_BACK_SPACE) {
|
|
681 |
10
| _isDeleteCompoundEdit = true;
|
|
682 |
| } |
|
683 |
| |
|
684 |
36
| KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
|
|
685 |
36
| Action a = KeyBindingManager.ONLY.get(ks);
|
|
686 |
| |
|
687 |
| |
|
688 |
36
| if ((ks != KeyStrokeOption.NULL_KEYSTROKE) && (a != null)) {
|
|
689 |
| |
|
690 |
3
| endCompoundEdit();
|
|
691 |
| |
|
692 |
3
| SwingUtilities.notifyAction(a, ks, e, e.getSource(), e.getModifiers());
|
|
693 |
| |
|
694 |
| |
|
695 |
3
| e.consume();
|
|
696 |
| } |
|
697 |
| else { |
|
698 |
| |
|
699 |
33
| Keymap km = getKeymap();
|
|
700 |
| |
|
701 |
33
| if (km.isLocallyDefined(ks) || km.isLocallyDefined(KeyStroke.getKeyStroke(ks.getKeyChar()))) {
|
|
702 |
| |
|
703 |
1
| if (e.getKeyCode() == KeyEvent.VK_ENTER) endCompoundEdit();
|
|
704 |
| |
|
705 |
| |
|
706 |
| |
|
707 |
| |
|
708 |
4
| super.processKeyEvent(e);
|
|
709 |
| |
|
710 |
| |
|
711 |
4
| endCompoundEdit();
|
|
712 |
| |
|
713 |
| |
|
714 |
| } |
|
715 |
| else { |
|
716 |
| |
|
717 |
| |
|
718 |
| |
|
719 |
| |
|
720 |
29
| if ((e.getModifiers() & InputEvent.META_MASK) != 0
|
|
721 |
| |
|
722 |
| && e.getKeyCode() == KeyEvent.VK_UNDEFINED) { |
|
723 |
| |
|
724 |
1
| return;
|
|
725 |
| } |
|
726 |
| |
|
727 |
| |
|
728 |
| |
|
729 |
| |
|
730 |
28
| if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
|
|
731 |
4
| int newModifiers = e.getModifiers() & ~(InputEvent.SHIFT_MASK);
|
|
732 |
| |
|
733 |
4
| KeyStroke newKs = KeyStroke.getKeyStroke(ks.getKeyCode(), newModifiers, ks.isOnKeyRelease());
|
|
734 |
4
| String name = KeyBindingManager.ONLY.getName(newKs);
|
|
735 |
| |
|
736 |
4
| if (name != null && (name.equals("Delete Previous") || name.equals("Delete Next"))) {
|
|
737 |
0
| endCompoundEdit();
|
|
738 |
| |
|
739 |
| |
|
740 |
0
| SwingUtilities.notifyAction(KeyBindingManager.ONLY.get(newKs), newKs, e, e.getSource(), newModifiers);
|
|
741 |
0
| e.consume();
|
|
742 |
| |
|
743 |
0
| return;
|
|
744 |
| } |
|
745 |
| } |
|
746 |
| |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
28
| if (e.getID() != KeyEvent.KEY_TYPED) {
|
|
751 |
19
| super.processKeyEvent(e);
|
|
752 |
19
| return;
|
|
753 |
| } |
|
754 |
| } |
|
755 |
| |
|
756 |
5
| if ((e.getModifiers() & InputEvent.ALT_MASK) != 0) testVariable = true;
|
|
757 |
8
| else testVariable = false;
|
|
758 |
| |
|
759 |
13
| super.processKeyEvent(e);
|
|
760 |
| } |
|
761 |
| } |
|
762 |
| } |
|
763 |
| |
|
764 |
| |
|
765 |
| |
|
766 |
| |
|
767 |
38
| public static void setEditorKit(DefinitionsEditorKit editorKit) { EDITOR_KIT = editorKit; }
|
|
768 |
| |
|
769 |
| |
|
770 |
| |
|
771 |
38
| public static void updateMaxCharWidth(FontMetrics metrics) {
|
|
772 |
38
| int[] widths = metrics.getWidths();
|
|
773 |
38
| _maxCharWidth = 0;
|
|
774 |
38
| for(int w: widths) {
|
|
775 |
38
| if (w > _maxCharWidth) { _maxCharWidth = w; }
|
|
776 |
| } |
|
777 |
| } |
|
778 |
| |
|
779 |
| |
|
780 |
0
| protected void paintComponent(Graphics g) {
|
|
781 |
0
| if (_antiAliasText && g instanceof Graphics2D) {
|
|
782 |
0
| Graphics2D g2d = (Graphics2D) g;
|
|
783 |
0
| g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
784 |
| } |
|
785 |
0
| super.paintComponent(g);
|
|
786 |
| |
|
787 |
0
| if (_displayRightMargin) {
|
|
788 |
0
| g.setColor(_rightMarginColor);
|
|
789 |
0
| Rectangle view = _scrollPane.getViewport().getViewRect();
|
|
790 |
0
| g.drawLine(2 + _numRightMarginColumns*_maxCharWidth, view.y,
|
|
791 |
| 2 + _numRightMarginColumns*_maxCharWidth, view.y+view.height); |
|
792 |
| } |
|
793 |
| } |
|
794 |
| |
|
795 |
| |
|
796 |
93
| private void createPopupMenu() {
|
|
797 |
| |
|
798 |
93
| _popMenu = new JPopupMenu();
|
|
799 |
| |
|
800 |
93
| _popMenu.add(_mainFrame.cutAction);
|
|
801 |
93
| _popMenu.add(_mainFrame.copyAction);
|
|
802 |
93
| _popMenu.add(_mainFrame.pasteAction);
|
|
803 |
93
| _popMenu.addSeparator();
|
|
804 |
| |
|
805 |
93
| JMenuItem indentItem = new JMenuItem("Indent Line(s)");
|
|
806 |
93
| indentItem.addActionListener(new AbstractAction() {
|
|
807 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
808 |
0
| _mainFrame.hourglassOn();
|
|
809 |
0
| try {
|
|
810 |
0
| indent();
|
|
811 |
| } finally { |
|
812 |
0
| _mainFrame.hourglassOff();
|
|
813 |
| } |
|
814 |
| } |
|
815 |
| }); |
|
816 |
93
| _popMenu.add(indentItem);
|
|
817 |
| |
|
818 |
93
| JMenuItem commentLinesItem = new JMenuItem("Comment Line(s)");
|
|
819 |
93
| commentLinesItem.addActionListener(new AbstractAction() {
|
|
820 |
0
| public void actionPerformed( ActionEvent ae) {
|
|
821 |
0
| _mainFrame.hourglassOn();
|
|
822 |
0
| try{
|
|
823 |
0
| updateCurrentLocationInDoc();
|
|
824 |
0
| _commentLines();
|
|
825 |
| } |
|
826 |
0
| finally{ _mainFrame.hourglassOff(); }
|
|
827 |
| } |
|
828 |
| }); |
|
829 |
93
| _popMenu.add(commentLinesItem);
|
|
830 |
| |
|
831 |
93
| JMenuItem uncommentLinesItem = new JMenuItem("Uncomment Line(s)");
|
|
832 |
93
| uncommentLinesItem.addActionListener ( new AbstractAction() {
|
|
833 |
0
| public void actionPerformed( ActionEvent ae) {
|
|
834 |
0
| updateCurrentLocationInDoc();
|
|
835 |
0
| _uncommentLines();
|
|
836 |
| } |
|
837 |
| }); |
|
838 |
93
| _popMenu.add(uncommentLinesItem);
|
|
839 |
| |
|
840 |
| |
|
841 |
93
| _popMenu.addSeparator();
|
|
842 |
93
| JMenuItem gotoFileUnderCursorItem = new JMenuItem("Go to File Under Cursor");
|
|
843 |
93
| gotoFileUnderCursorItem.addActionListener ( new AbstractAction() {
|
|
844 |
0
| public void actionPerformed( ActionEvent ae) {
|
|
845 |
0
| updateCurrentLocationInDoc();
|
|
846 |
0
| _mainFrame._gotoFileUnderCursor();
|
|
847 |
| } |
|
848 |
| }); |
|
849 |
93
| _popMenu.add(gotoFileUnderCursorItem);
|
|
850 |
| |
|
851 |
| |
|
852 |
93
| JMenuItem toggleBookmarkItem = new JMenuItem("Toggle Bookmark");
|
|
853 |
93
| toggleBookmarkItem.addActionListener ( new AbstractAction() {
|
|
854 |
| |
|
855 |
0
| public void actionPerformed( ActionEvent ae) {
|
|
856 |
| |
|
857 |
0
| _mainFrame.toggleBookmark();
|
|
858 |
| } |
|
859 |
| }); |
|
860 |
93
| _popMenu.add(toggleBookmarkItem);
|
|
861 |
| |
|
862 |
93
| if (_mainFrame.getModel().getDebugger().isAvailable()) {
|
|
863 |
93
| _popMenu.addSeparator();
|
|
864 |
| |
|
865 |
| |
|
866 |
93
| JMenuItem breakpointItem = new JMenuItem("Toggle Breakpoint");
|
|
867 |
93
| breakpointItem.addActionListener( new AbstractAction() {
|
|
868 |
0
| public void actionPerformed( ActionEvent ae ) {
|
|
869 |
| |
|
870 |
0
| setCaretPosition(viewToModel(_popupMenuMA.getLastMouseClick().getPoint()));
|
|
871 |
0
| _mainFrame.debuggerToggleBreakpoint();
|
|
872 |
| } |
|
873 |
| }); |
|
874 |
93
| _popMenu.add(breakpointItem);
|
|
875 |
| } |
|
876 |
| } |
|
877 |
| |
|
878 |
| |
|
879 |
| private class PopupMenuMouseAdapter extends RightClickMouseAdapter { |
|
880 |
| |
|
881 |
| private MouseEvent _lastMouseClick = null; |
|
882 |
| |
|
883 |
0
| public void mousePressed(MouseEvent e) {
|
|
884 |
0
| super.mousePressed(e);
|
|
885 |
| |
|
886 |
0
| _lastMouseClick = e;
|
|
887 |
0
| endCompoundEdit();
|
|
888 |
| |
|
889 |
| |
|
890 |
| |
|
891 |
| |
|
892 |
| |
|
893 |
| |
|
894 |
| |
|
895 |
| } |
|
896 |
| |
|
897 |
0
| protected void _popupAction(MouseEvent e) {
|
|
898 |
0
| requestFocusInWindow();
|
|
899 |
0
| _popMenu.show(e.getComponent(), e.getX(), e.getY());
|
|
900 |
| } |
|
901 |
| |
|
902 |
0
| public MouseEvent getLastMouseClick() { return _lastMouseClick; }
|
|
903 |
| } |
|
904 |
| |
|
905 |
| |
|
906 |
0
| private void _commentLines() {
|
|
907 |
0
| _mainFrame.commentLines();
|
|
908 |
| |
|
909 |
| } |
|
910 |
| |
|
911 |
| |
|
912 |
0
| private void _uncommentLines() {
|
|
913 |
0
| _mainFrame.uncommentLines();
|
|
914 |
| |
|
915 |
| } |
|
916 |
| |
|
917 |
| |
|
918 |
146
| public UndoAction getUndoAction() { return _undoAction; }
|
|
919 |
| |
|
920 |
| |
|
921 |
188
| public RedoAction getRedoAction() { return _redoAction; }
|
|
922 |
| |
|
923 |
| |
|
924 |
26
| public OpenDefinitionsDocument getOpenDefDocument() { return _doc; }
|
|
925 |
| |
|
926 |
| |
|
927 |
| |
|
928 |
| |
|
929 |
105
| public DJDocument getDJDocument() { return _doc; }
|
|
930 |
| |
|
931 |
| |
|
932 |
0
| public HighlightManager getHighlightManager() { return _highlightManager; }
|
|
933 |
| |
|
934 |
| |
|
935 |
| |
|
936 |
| |
|
937 |
| |
|
938 |
0
| public void setPositionAndScroll(int pos) {
|
|
939 |
0
| assert EventQueue.isDispatchThread();
|
|
940 |
0
| try {
|
|
941 |
0
| setCaretPos(pos);
|
|
942 |
0
| scrollRectToVisible(modelToView(pos));
|
|
943 |
| } |
|
944 |
0
| catch (BadLocationException ble) { throw new UnexpectedException(ble); }
|
|
945 |
| } |
|
946 |
| |
|
947 |
| |
|
948 |
| |
|
949 |
| |
|
950 |
186
| public void setDocument(Document d) {
|
|
951 |
186
| if (_doc != null) {
|
|
952 |
0
| if ((d == null) || (!d.equals(_doc))) {
|
|
953 |
0
| throw new IllegalStateException("Cannot set the document of a DefinitionsPane to a different document.");
|
|
954 |
| } |
|
955 |
| } |
|
956 |
186
| super.setDocument(d);
|
|
957 |
| } |
|
958 |
| |
|
959 |
5
| public boolean checkAltKey() {
|
|
960 |
5
| return testVariable;
|
|
961 |
| } |
|
962 |
| |
|
963 |
| |
|
964 |
93
| public void addErrorCaretListener(ErrorCaretListener eListener) {
|
|
965 |
93
| _errorListener = eListener;
|
|
966 |
93
| addCaretListener(eListener);
|
|
967 |
| } |
|
968 |
| |
|
969 |
| |
|
970 |
103
| public ErrorCaretListener getErrorCaretListener() { return _errorListener; }
|
|
971 |
| |
|
972 |
| |
|
973 |
| |
|
974 |
| |
|
975 |
4
| public void addErrorHighlight(int from, int to) {
|
|
976 |
4
| removeErrorHighlight();
|
|
977 |
4
| _errorHighlightTag = _highlightManager.addHighlight(from, to, ERROR_PAINTER);
|
|
978 |
| } |
|
979 |
| |
|
980 |
| |
|
981 |
205
| public void removeErrorHighlight() {
|
|
982 |
205
| if (_errorHighlightTag != null) {
|
|
983 |
3
| _errorHighlightTag.remove();
|
|
984 |
3
| _errorHighlightTag = null;
|
|
985 |
| } |
|
986 |
| } |
|
987 |
| |
|
988 |
0
| public boolean hasWarnedAboutModified() { return _hasWarnedAboutModified; }
|
|
989 |
| |
|
990 |
0
| public void hasWarnedAboutModified( boolean hasWarned) {
|
|
991 |
0
| _hasWarnedAboutModified = hasWarned;
|
|
992 |
| } |
|
993 |
| |
|
994 |
0
| public void addBreakpointHighlight( Breakpoint bp ) { }
|
|
995 |
| |
|
996 |
0
| public void removeBreakpointHighlight( Breakpoint bp) { }
|
|
997 |
| |
|
998 |
| |
|
999 |
| |
|
1000 |
| |
|
1001 |
| private volatile JScrollPane _scrollPane; |
|
1002 |
| |
|
1003 |
93
| public void setScrollPane(JScrollPane s) { _scrollPane = s; }
|
|
1004 |
| |
|
1005 |
| |
|
1006 |
| private volatile int _savedVScroll; |
|
1007 |
| private volatile int _savedHScroll; |
|
1008 |
| private volatile int _position; |
|
1009 |
| private volatile int _selStart; |
|
1010 |
| private volatile int _selEnd; |
|
1011 |
| |
|
1012 |
| |
|
1013 |
| |
|
1014 |
| |
|
1015 |
| |
|
1016 |
| |
|
1017 |
66
| public void notifyInactive() {
|
|
1018 |
| |
|
1019 |
| |
|
1020 |
| |
|
1021 |
| |
|
1022 |
66
| try {
|
|
1023 |
| |
|
1024 |
66
| updateCurrentLocationInDoc();
|
|
1025 |
| |
|
1026 |
| |
|
1027 |
66
| removeErrorHighlight();
|
|
1028 |
| |
|
1029 |
66
| _position = _doc.getCurrentLocation();
|
|
1030 |
66
| _selStart = super.getSelectionStart();
|
|
1031 |
66
| _selEnd = super.getSelectionEnd();
|
|
1032 |
| |
|
1033 |
66
| _savedVScroll = _scrollPane.getVerticalScrollBar().getValue();
|
|
1034 |
66
| _savedHScroll = _scrollPane.getHorizontalScrollBar().getValue();
|
|
1035 |
| |
|
1036 |
66
| super.setDocument(NULL_DOCUMENT);
|
|
1037 |
| } |
|
1038 |
| catch(NoSuchDocumentException e) { |
|
1039 |
| |
|
1040 |
| |
|
1041 |
| |
|
1042 |
| } |
|
1043 |
| } |
|
1044 |
| |
|
1045 |
| |
|
1046 |
| |
|
1047 |
| |
|
1048 |
| |
|
1049 |
104
| public void notifyActive() {
|
|
1050 |
104
| assert ! _mainFrame.isVisible() || EventQueue.isDispatchThread();
|
|
1051 |
104
| super.setDocument(_doc);
|
|
1052 |
88
| if (_doc.getUndoableEditListeners().length == 0) _resetUndo();
|
|
1053 |
| |
|
1054 |
104
| int len = _doc.getLength();
|
|
1055 |
104
| if (len < _position || len < _selEnd) {
|
|
1056 |
| |
|
1057 |
| |
|
1058 |
3
| _position = len;
|
|
1059 |
3
| _selStart = len;
|
|
1060 |
3
| _selEnd = len;
|
|
1061 |
| } |
|
1062 |
104
| if (_position == _selStart) {
|
|
1063 |
104
| setCaretPosition(_selEnd);
|
|
1064 |
104
| moveCaretPosition(_selStart);
|
|
1065 |
104
| _doc.setCurrentLocation(_selStart);
|
|
1066 |
| } |
|
1067 |
| else { |
|
1068 |
0
| setCaretPosition(_selStart);
|
|
1069 |
0
| moveCaretPosition(_selEnd);
|
|
1070 |
0
| _doc.setCurrentLocation(_selEnd);
|
|
1071 |
| } |
|
1072 |
104
| _scrollPane.getVerticalScrollBar().setValue(_savedVScroll);
|
|
1073 |
104
| _scrollPane.getHorizontalScrollBar().setValue(_savedHScroll);
|
|
1074 |
| |
|
1075 |
104
| _scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
|
1076 |
104
| _scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
|
1077 |
| } |
|
1078 |
| |
|
1079 |
| |
|
1080 |
6
| public int getSelectionStart() {
|
|
1081 |
0
| if (getDocument() == NULL_DOCUMENT) return _selStart;
|
|
1082 |
6
| else return super.getSelectionStart();
|
|
1083 |
| } |
|
1084 |
| |
|
1085 |
6
| public int getSelectionEnd() {
|
|
1086 |
0
| if (getDocument() == NULL_DOCUMENT) return _selEnd;
|
|
1087 |
6
| else return super.getSelectionEnd();
|
|
1088 |
| } |
|
1089 |
| |
|
1090 |
3
| public int getVerticalScroll() {
|
|
1091 |
0
| if (getDocument() == NULL_DOCUMENT) return _savedVScroll;
|
|
1092 |
3
| else return _scrollPane.getVerticalScrollBar().getValue();
|
|
1093 |
| } |
|
1094 |
| |
|
1095 |
3
| public int getHorizontalScroll() {
|
|
1096 |
0
| if (getDocument() == NULL_DOCUMENT) return _savedHScroll;
|
|
1097 |
3
| else return _scrollPane.getHorizontalScrollBar().getValue();
|
|
1098 |
| } |
|
1099 |
| |
|
1100 |
| |
|
1101 |
| |
|
1102 |
0
| public int getCurrentLine() { return _doc.getLineOfOffset(getCaretPosition())+1; }
|
|
1103 |
| |
|
1104 |
| |
|
1105 |
| |
|
1106 |
| |
|
1107 |
| |
|
1108 |
| |
|
1109 |
| |
|
1110 |
| |
|
1111 |
| |
|
1112 |
| |
|
1113 |
| |
|
1114 |
| |
|
1115 |
| |
|
1116 |
| |
|
1117 |
0
| public int getCurrentLinefromDoc() { return _doc.getCurrentLine(); }
|
|
1118 |
| |
|
1119 |
0
| public int getCurrentCol() { return _doc.getCurrentCol(); }
|
|
1120 |
| |
|
1121 |
63
| public void setSize(int width, int height) {
|
|
1122 |
63
| super.setSize(width, height);
|
|
1123 |
0
| if (_setSizeListener != null) _setSizeListener.actionPerformed(null);
|
|
1124 |
| } |
|
1125 |
| |
|
1126 |
| |
|
1127 |
| |
|
1128 |
| |
|
1129 |
| |
|
1130 |
1
| public void centerViewOnOffset(int offset) {
|
|
1131 |
1
| assert EventQueue.isDispatchThread();
|
|
1132 |
1
| try {
|
|
1133 |
1
| FontMetrics metrics = getFontMetrics(getFont());
|
|
1134 |
1
| JViewport defViewPort = _mainFrame.getDefViewport();
|
|
1135 |
1
| double viewWidth = defViewPort.getWidth();
|
|
1136 |
1
| double viewHeight = defViewPort.getHeight();
|
|
1137 |
| |
|
1138 |
| |
|
1139 |
1
| Rectangle startRect;
|
|
1140 |
1
| startRect = modelToView(offset);
|
|
1141 |
| |
|
1142 |
1
| if (startRect != null) {
|
|
1143 |
0
| int startRectX = (int) startRect.getX();
|
|
1144 |
0
| int startRectY = (int) startRect.getY();
|
|
1145 |
0
| startRect.setLocation(startRectX - (int)(viewWidth*.5), startRectY - (int)(viewHeight*.5));
|
|
1146 |
0
| Point endPoint = new Point(startRectX + (int)(viewWidth*.5),
|
|
1147 |
| startRectY + (int)(viewHeight*.5) + metrics.getHeight()/2); |
|
1148 |
| |
|
1149 |
| |
|
1150 |
| |
|
1151 |
0
| startRect.add(endPoint);
|
|
1152 |
| |
|
1153 |
0
| scrollRectToVisible(startRect);
|
|
1154 |
| } |
|
1155 |
| |
|
1156 |
| |
|
1157 |
1
| setCaretPos(offset);
|
|
1158 |
| } |
|
1159 |
0
| catch (BadLocationException e) { throw new UnexpectedException(e); }
|
|
1160 |
| } |
|
1161 |
| |
|
1162 |
0
| public void centerViewOnLine(int lineNumber) {
|
|
1163 |
0
| FontMetrics metrics = getFontMetrics(getFont());
|
|
1164 |
0
| Point p = new Point(0, metrics.getHeight() * (lineNumber));
|
|
1165 |
0
| int offset = this.viewToModel(p);
|
|
1166 |
0
| this.centerViewOnOffset(offset);
|
|
1167 |
| } |
|
1168 |
| |
|
1169 |
| |
|
1170 |
| |
|
1171 |
| |
|
1172 |
2
| public void select(int selectionStart, int selectionEnd) {
|
|
1173 |
2
| setCaretPosition(selectionStart);
|
|
1174 |
2
| moveCaretPosition(selectionEnd);
|
|
1175 |
| } |
|
1176 |
| |
|
1177 |
| |
|
1178 |
0
| public void resetUndo() {
|
|
1179 |
0
| _doc.getUndoManager().discardAllEdits();
|
|
1180 |
| |
|
1181 |
0
| _undoAction.updateUndoState();
|
|
1182 |
0
| _redoAction.updateRedoState();
|
|
1183 |
| } |
|
1184 |
| |
|
1185 |
| |
|
1186 |
181
| private void _resetUndo() {
|
|
1187 |
93
| if (_undoAction == null) _undoAction = new UndoAction();
|
|
1188 |
93
| if (_redoAction == null) _redoAction = new RedoAction();
|
|
1189 |
| |
|
1190 |
181
| _doc.resetUndoManager();
|
|
1191 |
| |
|
1192 |
181
| getDocument().addUndoableEditListener(_undoListener);
|
|
1193 |
181
| _undoAction.updateUndoState();
|
|
1194 |
181
| _redoAction.updateRedoState();
|
|
1195 |
| } |
|
1196 |
| |
|
1197 |
| |
|
1198 |
| |
|
1199 |
| |
|
1200 |
| |
|
1201 |
186
| protected EditorKit createDefaultEditorKit() {
|
|
1202 |
| |
|
1203 |
186
| return EDITOR_KIT;
|
|
1204 |
| } |
|
1205 |
| |
|
1206 |
| |
|
1207 |
| |
|
1208 |
| |
|
1209 |
| |
|
1210 |
| |
|
1211 |
1
| protected boolean shouldIndent(int selStart, int selEnd) {
|
|
1212 |
1
| if (selEnd > (selStart + INDENT_WARNING_THRESHOLD)) {
|
|
1213 |
0
| Object[] options = {"Yes", "No"};
|
|
1214 |
0
| int n = JOptionPane.showOptionDialog
|
|
1215 |
| (_mainFrame, |
|
1216 |
| "Re-indenting this block may take a long time. Are you sure?", |
|
1217 |
| "Confirm Re-indent", |
|
1218 |
| JOptionPane.YES_NO_OPTION, |
|
1219 |
| JOptionPane.QUESTION_MESSAGE, |
|
1220 |
| null, |
|
1221 |
| options, |
|
1222 |
| options[1]); |
|
1223 |
0
| switch (n) {
|
|
1224 |
0
| case JOptionPane.CANCEL_OPTION:
|
|
1225 |
0
| case JOptionPane.CLOSED_OPTION:
|
|
1226 |
0
| case JOptionPane.NO_OPTION:
|
|
1227 |
0
| return false;
|
|
1228 |
0
| default:
|
|
1229 |
0
| return true;
|
|
1230 |
| } |
|
1231 |
| } |
|
1232 |
1
| return true;
|
|
1233 |
| } |
|
1234 |
| |
|
1235 |
| |
|
1236 |
| |
|
1237 |
| |
|
1238 |
| |
|
1239 |
| |
|
1240 |
| |
|
1241 |
1
| protected void indentLines(int selStart, int selEnd, Indenter.IndentReason reason, ProgressMonitor pm) {
|
|
1242 |
| |
|
1243 |
| |
|
1244 |
1
| assert EventQueue.isDispatchThread();
|
|
1245 |
1
| try {
|
|
1246 |
1
| _doc.indentLines(selStart, selEnd, reason, pm);
|
|
1247 |
1
| endCompoundEdit();
|
|
1248 |
1
| setCaretPosition(_doc.getCurrentLocation());
|
|
1249 |
| } |
|
1250 |
| catch(OperationCanceledException oce) { |
|
1251 |
| |
|
1252 |
0
| endCompoundEdit();
|
|
1253 |
0
| _doc.getUndoManager().undo();
|
|
1254 |
| |
|
1255 |
0
| throw new UnexpectedException(oce);
|
|
1256 |
| } |
|
1257 |
| } |
|
1258 |
| |
|
1259 |
| |
|
1260 |
| private List<Pair<Option<Color>, OptionListener<Color>>> _colorOptionListeners = |
|
1261 |
| new LinkedList<Pair<Option<Color>, OptionListener<Color>>>(); |
|
1262 |
| |
|
1263 |
| private List<Pair<Option<Boolean>, OptionListener<Boolean>>> _booleanOptionListeners = |
|
1264 |
| new LinkedList<Pair<Option<Boolean>, OptionListener<Boolean>>>(); |
|
1265 |
| |
|
1266 |
| private List<Pair<Option<Integer>, OptionListener<Integer>>> _integerOptionListeners = |
|
1267 |
| new LinkedList<Pair<Option<Integer>, OptionListener<Integer>>>(); |
|
1268 |
| |
|
1269 |
| |
|
1270 |
| |
|
1271 |
| |
|
1272 |
37
| public void close() {
|
|
1273 |
37
| for (Pair<Option<Color>, OptionListener<Color>> p: _colorOptionListeners) {
|
|
1274 |
629
| DrJava.getConfig().removeOptionListener(p.first(), p.second());
|
|
1275 |
| } |
|
1276 |
37
| for (Pair<Option<Boolean>, OptionListener<Boolean>> p: _booleanOptionListeners) {
|
|
1277 |
74
| DrJava.getConfig().removeOptionListener(p.first(), p.second());
|
|
1278 |
| } |
|
1279 |
37
| for (Pair<Option<Integer>, OptionListener<Integer>> p: _integerOptionListeners) {
|
|
1280 |
37
| DrJava.getConfig().removeOptionListener(p.first(), p.second());
|
|
1281 |
| } |
|
1282 |
37
| _colorOptionListeners.clear();
|
|
1283 |
37
| _booleanOptionListeners.clear();
|
|
1284 |
37
| _integerOptionListeners.clear();
|
|
1285 |
| |
|
1286 |
37
| ourMap.removeBindings();
|
|
1287 |
37
| removeKeymap(ourMap.getName());
|
|
1288 |
| |
|
1289 |
37
| _popMenu.removeAll();
|
|
1290 |
| } |
|
1291 |
| |
|
1292 |
| |
|
1293 |
| public class UndoAction extends AbstractAction { |
|
1294 |
| |
|
1295 |
| |
|
1296 |
93
| private UndoAction() {
|
|
1297 |
93
| super("Undo");
|
|
1298 |
93
| setEnabled(false);
|
|
1299 |
| } |
|
1300 |
| |
|
1301 |
| |
|
1302 |
| |
|
1303 |
| |
|
1304 |
1
| public void actionPerformed(ActionEvent e) {
|
|
1305 |
1
| try {
|
|
1306 |
| |
|
1307 |
| |
|
1308 |
| |
|
1309 |
| |
|
1310 |
| |
|
1311 |
| |
|
1312 |
| |
|
1313 |
| |
|
1314 |
| |
|
1315 |
| |
|
1316 |
1
| _doc.getUndoManager().undo();
|
|
1317 |
1
| _doc.updateModifiedSinceSave();
|
|
1318 |
1
| _mainFrame.updateStatusField();
|
|
1319 |
| } |
|
1320 |
| catch (CannotUndoException ex) { |
|
1321 |
0
| throw new UnexpectedException(ex);
|
|
1322 |
| } |
|
1323 |
1
| updateUndoState();
|
|
1324 |
1
| _redoAction.updateRedoState();
|
|
1325 |
| } |
|
1326 |
| |
|
1327 |
| |
|
1328 |
224
| protected void updateUndoState() {
|
|
1329 |
224
| if (_doc.undoManagerCanUndo()) {
|
|
1330 |
31
| setEnabled(true);
|
|
1331 |
31
| putValue(Action.NAME, _doc.getUndoManager().getUndoPresentationName());
|
|
1332 |
| } |
|
1333 |
| else { |
|
1334 |
193
| setEnabled(false);
|
|
1335 |
193
| putValue(Action.NAME, "Undo");
|
|
1336 |
| } |
|
1337 |
| } |
|
1338 |
| } |
|
1339 |
| |
|
1340 |
| |
|
1341 |
| public class RedoAction extends AbstractAction { |
|
1342 |
| |
|
1343 |
| |
|
1344 |
93
| private RedoAction() {
|
|
1345 |
93
| super("Redo");
|
|
1346 |
93
| setEnabled(false);
|
|
1347 |
| } |
|
1348 |
| |
|
1349 |
| |
|
1350 |
| |
|
1351 |
| |
|
1352 |
0
| public void actionPerformed(ActionEvent e) {
|
|
1353 |
0
| try {
|
|
1354 |
| |
|
1355 |
| |
|
1356 |
| |
|
1357 |
| |
|
1358 |
| |
|
1359 |
0
| _doc.getUndoManager().redo();
|
|
1360 |
| |
|
1361 |
| |
|
1362 |
| |
|
1363 |
| |
|
1364 |
| |
|
1365 |
0
| _doc.updateModifiedSinceSave();
|
|
1366 |
0
| _mainFrame.updateStatusField();
|
|
1367 |
| } catch (CannotRedoException ex) { |
|
1368 |
0
| throw new UnexpectedException(ex);
|
|
1369 |
| } |
|
1370 |
0
| updateRedoState();
|
|
1371 |
0
| _undoAction.updateUndoState();
|
|
1372 |
| } |
|
1373 |
| |
|
1374 |
| |
|
1375 |
224
| protected void updateRedoState() {
|
|
1376 |
224
| if (_doc.undoManagerCanRedo()) {
|
|
1377 |
5
| setEnabled(true);
|
|
1378 |
5
| putValue(Action.NAME, _doc.getUndoManager().getRedoPresentationName());
|
|
1379 |
| } |
|
1380 |
| else { |
|
1381 |
219
| setEnabled(false);
|
|
1382 |
219
| putValue(Action.NAME, "Redo");
|
|
1383 |
| } |
|
1384 |
| } |
|
1385 |
| } |
|
1386 |
| |
|
1387 |
| |
|
1388 |
| |
|
1389 |
| |
|
1390 |
| |
|
1391 |
| |
|
1392 |
| |
|
1393 |
| |
|
1394 |
| |
|
1395 |
| |
|
1396 |
| |
|
1397 |
| |
|
1398 |
| |
|
1399 |
| |
|
1400 |
| |
|
1401 |
| |
|
1402 |
| |
|
1403 |
| |
|
1404 |
| |
|
1405 |
| |
|
1406 |
| |
|
1407 |
| |
|
1408 |
| |
|
1409 |
| |
|
1410 |
| |
|
1411 |
| |
|
1412 |
| |
|
1413 |
| |
|
1414 |
| |
|
1415 |
| |
|
1416 |
| |
|
1417 |
| |
|
1418 |
| |
|
1419 |
| |
|
1420 |
| |
|
1421 |
| |
|
1422 |
| |
|
1423 |
| |
|
1424 |
| |
|
1425 |
| |
|
1426 |
| |
|
1427 |
| private List<FinalizationListener<DefinitionsPane>> _finalizationListeners = |
|
1428 |
| new LinkedList<FinalizationListener<DefinitionsPane>>(); |
|
1429 |
| |
|
1430 |
| |
|
1431 |
| |
|
1432 |
| |
|
1433 |
| |
|
1434 |
| |
|
1435 |
6
| public void addFinalizationListener(FinalizationListener<DefinitionsPane> fl) { _finalizationListeners.add(fl); }
|
|
1436 |
| |
|
1437 |
0
| public List<FinalizationListener<DefinitionsPane>> getFinalizationListeners() { return _finalizationListeners; }
|
|
1438 |
| |
|
1439 |
| |
|
1440 |
| |
|
1441 |
| |
|
1442 |
26
| protected void finalize() {
|
|
1443 |
26
| FinalizationEvent<DefinitionsPane> fe = new FinalizationEvent<DefinitionsPane>(this);
|
|
1444 |
6
| for (FinalizationListener<DefinitionsPane> fl: _finalizationListeners) fl.finalized(fe);
|
|
1445 |
| } |
|
1446 |
| } |