|
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 edu.rice.cs.drjava.DrJava; |
|
40 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
41 |
| import edu.rice.cs.drjava.config.OptionEvent; |
|
42 |
| import edu.rice.cs.drjava.config.OptionListener; |
|
43 |
| import edu.rice.cs.drjava.model.OpenDefinitionsDocument; |
|
44 |
| import edu.rice.cs.drjava.model.SingleDisplayModel; |
|
45 |
| import edu.rice.cs.drjava.model.DJError; |
|
46 |
| import edu.rice.cs.drjava.model.compiler.CompilerErrorModel; |
|
47 |
| import edu.rice.cs.drjava.model.ClipboardHistoryModel; |
|
48 |
| import edu.rice.cs.util.UnexpectedException; |
|
49 |
| import edu.rice.cs.util.swing.HighlightManager; |
|
50 |
| import edu.rice.cs.util.swing.BorderlessScrollPane; |
|
51 |
| import edu.rice.cs.util.text.SwingDocument; |
|
52 |
| import edu.rice.cs.drjava.model.print.DrJavaBook; |
|
53 |
| |
|
54 |
| import edu.rice.cs.util.swing.RightClickMouseAdapter; |
|
55 |
| |
|
56 |
| import java.util.HashMap; |
|
57 |
| import java.util.Vector; |
|
58 |
| |
|
59 |
| import javax.swing.*; |
|
60 |
| import javax.swing.text.*; |
|
61 |
| import javax.swing.text.SimpleAttributeSet; |
|
62 |
| import javax.swing.border.EmptyBorder; |
|
63 |
| import java.awt.datatransfer.*; |
|
64 |
| import java.awt.*; |
|
65 |
| import java.awt.event.MouseAdapter; |
|
66 |
| import java.awt.event.MouseEvent; |
|
67 |
| import java.awt.event.ItemListener; |
|
68 |
| import java.awt.event.ItemEvent; |
|
69 |
| import java.awt.event.ActionListener; |
|
70 |
| import java.awt.event.ActionEvent; |
|
71 |
| import java.awt.print.*; |
|
72 |
| import java.io.IOException; |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| public abstract class ErrorPanel extends TabbedPanel implements OptionConstants { |
|
79 |
| |
|
80 |
| protected static final SimpleAttributeSet NORMAL_ATTRIBUTES = _getNormalAttributes(); |
|
81 |
| protected static final SimpleAttributeSet BOLD_ATTRIBUTES = _getBoldAttributes(); |
|
82 |
| |
|
83 |
| |
|
84 |
| protected volatile int _numErrors; |
|
85 |
| protected volatile JCheckBox _showHighlightsCheckBox; |
|
86 |
| |
|
87 |
| protected volatile SingleDisplayModel _model; |
|
88 |
| |
|
89 |
| private volatile JScrollPane _scroller; |
|
90 |
| |
|
91 |
| |
|
92 |
| private volatile JPanel _leftPanel; |
|
93 |
| |
|
94 |
| |
|
95 |
| private volatile JPanel _rightPanel; |
|
96 |
| |
|
97 |
| private volatile JPanel _errorNavPanel; |
|
98 |
| |
|
99 |
| private volatile JPanel _errorNavButtonsPanel; |
|
100 |
| |
|
101 |
| |
|
102 |
| protected volatile JPanel customPanel; |
|
103 |
| |
|
104 |
| private volatile JButton _nextErrorButton; |
|
105 |
| private volatile JButton _prevErrorButton; |
|
106 |
| |
|
107 |
| |
|
108 |
| protected volatile JPopupMenu _popupMenu = null; |
|
109 |
| protected volatile RightClickMouseAdapter _popupMenuListener = null; |
|
110 |
| |
|
111 |
| |
|
112 |
| static volatile ReverseHighlighter.DrJavaHighlightPainter _listHighlightPainter = |
|
113 |
| new ReverseHighlighter.DrJavaHighlightPainter(DrJava.getConfig().getSetting(COMPILER_ERROR_COLOR)); |
|
114 |
| |
|
115 |
6
| protected static final SimpleAttributeSet _getBoldAttributes() {
|
|
116 |
6
| SimpleAttributeSet s = new SimpleAttributeSet();
|
|
117 |
6
| StyleConstants.setBold(s, true);
|
|
118 |
6
| return s;
|
|
119 |
| } |
|
120 |
| |
|
121 |
6
| protected static final SimpleAttributeSet _getNormalAttributes() {
|
|
122 |
6
| SimpleAttributeSet s = new SimpleAttributeSet();
|
|
123 |
6
| return s;
|
|
124 |
| } |
|
125 |
| |
|
126 |
114
| public ErrorPanel(SingleDisplayModel model, MainFrame frame, String tabString, String labelString) {
|
|
127 |
114
| super(frame, tabString);
|
|
128 |
114
| _model = model;
|
|
129 |
| |
|
130 |
114
| _mainPanel.setLayout(new BorderLayout());
|
|
131 |
| |
|
132 |
114
| _leftPanel = new JPanel(new BorderLayout());
|
|
133 |
| |
|
134 |
114
| _errorNavPanel = new JPanel(new GridBagLayout());
|
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
114
| _errorNavButtonsPanel = new JPanel(new BorderLayout());
|
|
139 |
| |
|
140 |
114
| _nextErrorButton = new JButton(MainFrame.getIcon("Down16.gif"));
|
|
141 |
114
| _prevErrorButton = new JButton(MainFrame.getIcon("Up16.gif"));
|
|
142 |
| |
|
143 |
114
| _nextErrorButton.setMargin(new Insets(0, 0, 0, 0));
|
|
144 |
114
| _nextErrorButton.setToolTipText("Go to the next error");
|
|
145 |
114
| _prevErrorButton.setMargin(new Insets(0, 0, 0, 0));
|
|
146 |
114
| _prevErrorButton.setToolTipText("Go to the previous error");
|
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
114
| _errorNavButtonsPanel.add(_prevErrorButton, BorderLayout.NORTH);
|
|
155 |
114
| _errorNavButtonsPanel.add(_nextErrorButton, BorderLayout.SOUTH);
|
|
156 |
114
| _errorNavButtonsPanel.setBorder(new EmptyBorder(18, 5, 18, 5));
|
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
114
| _errorNavPanel.add(_errorNavButtonsPanel);
|
|
162 |
114
| _showHighlightsCheckBox = new JCheckBox( "Highlight source", true);
|
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
114
| _scroller = new BorderlessScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
|
|
169 |
| JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
|
170 |
| |
|
171 |
114
| _leftPanel.add(_scroller, BorderLayout.CENTER);
|
|
172 |
114
| _leftPanel.add(_errorNavPanel, BorderLayout.EAST);
|
|
173 |
| |
|
174 |
114
| customPanel = new JPanel(new BorderLayout());
|
|
175 |
114
| _rightPanel = new JPanel(new BorderLayout());
|
|
176 |
114
| _rightPanel.setBorder(new EmptyBorder(0,5,0,5));
|
|
177 |
| |
|
178 |
114
| _rightPanel.add(new JLabel(labelString, SwingConstants.LEFT), BorderLayout.NORTH);
|
|
179 |
114
| _rightPanel.add(customPanel, BorderLayout.CENTER);
|
|
180 |
114
| _rightPanel.add(_showHighlightsCheckBox, BorderLayout.SOUTH);
|
|
181 |
| |
|
182 |
114
| _mainPanel.add(_leftPanel, BorderLayout.CENTER);
|
|
183 |
114
| _mainPanel.add(_rightPanel, BorderLayout.EAST);
|
|
184 |
| |
|
185 |
| |
|
186 |
114
| final Action copyAction = new AbstractAction("Copy Contents to Clipboard", MainFrame.getIcon("Copy16.gif")) {
|
|
187 |
0
| public void actionPerformed(ActionEvent e) {
|
|
188 |
0
| getErrorListPane().selectAll();
|
|
189 |
0
| String t = getErrorListPane().getSelectedText();
|
|
190 |
0
| if (t != null) {
|
|
191 |
0
| if (t.length() != 0) {
|
|
192 |
0
| StringSelection stringSelection = new StringSelection(t);
|
|
193 |
0
| Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
|
194 |
0
| clipboard.setContents(stringSelection, getErrorListPane());
|
|
195 |
0
| ClipboardHistoryModel.singleton().put(t);
|
|
196 |
| } |
|
197 |
| } |
|
198 |
| } |
|
199 |
| }; |
|
200 |
114
| addPopupMenu(copyAction);
|
|
201 |
114
| getPopupMenu().add(new AbstractAction("Save Copy of Contents...", MainFrame.getIcon("Save16.gif")) {
|
|
202 |
0
| public void actionPerformed(ActionEvent e) {
|
|
203 |
0
| _frame._saveDocumentCopy(getErrorListPane().getErrorDocument());
|
|
204 |
| } |
|
205 |
| }); |
|
206 |
114
| getPopupMenu().addSeparator();
|
|
207 |
114
| getPopupMenu().add(new AbstractAction("Print...", MainFrame.getIcon("Print16.gif")) {
|
|
208 |
0
| public void actionPerformed(ActionEvent e) {
|
|
209 |
0
| getErrorListPane().getErrorDocument().print();
|
|
210 |
| } |
|
211 |
| }); |
|
212 |
114
| getPopupMenu().add(new AbstractAction("Print Preview...", MainFrame.getIcon("PrintPreview16.gif")) {
|
|
213 |
0
| public void actionPerformed(ActionEvent e) {
|
|
214 |
0
| getErrorListPane().getErrorDocument().preparePrintJob();
|
|
215 |
0
| new PreviewErrorFrame();
|
|
216 |
| } |
|
217 |
| }); |
|
218 |
| } |
|
219 |
| |
|
220 |
114
| protected void setErrorListPane(final ErrorListPane elp) {
|
|
221 |
114
| if (_popupMenuListener!=null) {
|
|
222 |
114
| if ((_scroller!=null) &&
|
|
223 |
| (_scroller.getViewport()!=null) && |
|
224 |
| (_scroller.getViewport().getView()!=null)) { |
|
225 |
0
| _scroller.getViewport().getView().removeMouseListener(_popupMenuListener);
|
|
226 |
| } |
|
227 |
| } |
|
228 |
| |
|
229 |
114
| _scroller.setViewportView(elp);
|
|
230 |
| |
|
231 |
114
| if (_popupMenuListener!=null) {
|
|
232 |
114
| _scroller.getViewport().getView().addMouseListener(_popupMenuListener);
|
|
233 |
| } |
|
234 |
| |
|
235 |
114
| _nextErrorButton.setEnabled(false);
|
|
236 |
114
| _nextErrorButton.addActionListener(new ActionListener() {
|
|
237 |
0
| public void actionPerformed(ActionEvent e) {
|
|
238 |
0
| elp.nextError();
|
|
239 |
| |
|
240 |
| |
|
241 |
| } |
|
242 |
| }); |
|
243 |
114
| _prevErrorButton.setEnabled(false);
|
|
244 |
114
| _prevErrorButton.addActionListener(new ActionListener() {
|
|
245 |
0
| public void actionPerformed(ActionEvent e) {
|
|
246 |
0
| elp.prevError();
|
|
247 |
| |
|
248 |
| |
|
249 |
| } |
|
250 |
| }); |
|
251 |
| } |
|
252 |
| |
|
253 |
| |
|
254 |
114
| public void setListFont(Font f) {
|
|
255 |
114
| SimpleAttributeSet set = new SimpleAttributeSet();
|
|
256 |
114
| StyleConstants.setFontFamily(set, f.getFamily());
|
|
257 |
114
| StyleConstants.setFontSize(set, f.getSize());
|
|
258 |
114
| StyleConstants.setBold(set, f.isBold());
|
|
259 |
114
| StyleConstants.setItalic(set, f.isItalic());
|
|
260 |
| |
|
261 |
114
| _updateStyles(set);
|
|
262 |
| |
|
263 |
114
| getErrorListPane().setFont(f);
|
|
264 |
| |
|
265 |
114
| ErrorDocument doc = getErrorListPane().getErrorDocument();
|
|
266 |
114
| doc.setCharacterAttributes(0, doc.getLength() + 1, set, false);
|
|
267 |
| } |
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
| |
|
272 |
114
| protected void _updateStyles(AttributeSet newSet) {
|
|
273 |
114
| NORMAL_ATTRIBUTES.addAttributes(newSet);
|
|
274 |
114
| BOLD_ATTRIBUTES.addAttributes(newSet);
|
|
275 |
114
| StyleConstants.setBold(BOLD_ATTRIBUTES, true);
|
|
276 |
| } |
|
277 |
| |
|
278 |
| abstract protected ErrorListPane getErrorListPane(); |
|
279 |
| |
|
280 |
317
| protected SingleDisplayModel getModel() { return _model; }
|
|
281 |
| |
|
282 |
| |
|
283 |
| abstract protected CompilerErrorModel getErrorModel(); |
|
284 |
| |
|
285 |
| |
|
286 |
| public abstract class ErrorListPane extends JEditorPane implements ClipboardOwner { |
|
287 |
| |
|
288 |
| protected volatile Keymap _keymap; |
|
289 |
| |
|
290 |
| |
|
291 |
| private volatile int _selectedIndex; |
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| protected volatile Position[] _errorListPositions; |
|
299 |
| |
|
300 |
| |
|
301 |
| protected final HashMap<Position, DJError> _errorTable = new HashMap<Position, DJError>(); |
|
302 |
| |
|
303 |
| |
|
304 |
| private volatile HighlightManager.HighlightInfo _listHighlightTag = null; |
|
305 |
| |
|
306 |
| private volatile HighlightManager _highlightManager = new HighlightManager(this); |
|
307 |
| |
|
308 |
| |
|
309 |
| volatile Action cutAction = new DefaultEditorKit.CutAction() { |
|
310 |
0
| public void actionPerformed(ActionEvent e) {
|
|
311 |
0
| if (getSelectedText() != null) {
|
|
312 |
0
| super.actionPerformed(e);
|
|
313 |
0
| String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(ErrorListPane.this);
|
|
314 |
0
| if ((s != null) && (s.length() != 0)) { ClipboardHistoryModel.singleton().put(s); }
|
|
315 |
| } |
|
316 |
| } |
|
317 |
| }; |
|
318 |
| |
|
319 |
| |
|
320 |
| volatile Action copyAction = new DefaultEditorKit.CopyAction() { |
|
321 |
0
| public void actionPerformed(ActionEvent e) {
|
|
322 |
0
| if (getSelectedText() != null) {
|
|
323 |
0
| super.actionPerformed(e);
|
|
324 |
0
| String s = edu.rice.cs.util.swing.Utilities.getClipboardSelection(ErrorListPane.this);
|
|
325 |
0
| if (s != null && s.length() != 0) { ClipboardHistoryModel.singleton().put(s); }
|
|
326 |
| } |
|
327 |
| } |
|
328 |
| }; |
|
329 |
| |
|
330 |
| |
|
331 |
| volatile Action pasteAction = new DefaultEditorKit.PasteAction() { |
|
332 |
0
| public void actionPerformed(ActionEvent e) { }
|
|
333 |
| }; |
|
334 |
| |
|
335 |
| protected MouseAdapter defaultMouseListener = new MouseAdapter() { |
|
336 |
0
| public void mousePressed(MouseEvent e) { selectNothing(); }
|
|
337 |
0
| public void mouseReleased(MouseEvent e) {
|
|
338 |
0
| DJError error = _errorAtPoint(e.getPoint());
|
|
339 |
| |
|
340 |
0
| if (_isEmptySelection() && error != null) getErrorListPane().switchToError(error);
|
|
341 |
0
| else selectNothing();
|
|
342 |
| } |
|
343 |
| }; |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
114
| public ErrorListPane() {
|
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
114
| setContentType("text/rtf");
|
|
355 |
114
| setDocument(new ErrorDocument(getErrorDocumentTitle()));
|
|
356 |
114
| setHighlighter(new ReverseHighlighter());
|
|
357 |
| |
|
358 |
114
| addMouseListener(defaultMouseListener);
|
|
359 |
| |
|
360 |
114
| _selectedIndex = 0;
|
|
361 |
114
| _errorListPositions = new Position[0];
|
|
362 |
| |
|
363 |
114
| this.setFont(new Font("Courier", 0, 20));
|
|
364 |
| |
|
365 |
| |
|
366 |
| |
|
367 |
| |
|
368 |
| |
|
369 |
| |
|
370 |
114
| setEditable(false);
|
|
371 |
| |
|
372 |
114
| DrJava.getConfig().addOptionListener(COMPILER_ERROR_COLOR, new CompilerErrorColorOptionListener());
|
|
373 |
| |
|
374 |
| |
|
375 |
114
| StyleConstants.setForeground(NORMAL_ATTRIBUTES, DrJava.getConfig().getSetting(DEFINITIONS_NORMAL_COLOR));
|
|
376 |
114
| StyleConstants.setForeground(BOLD_ATTRIBUTES, DrJava.getConfig().getSetting(DEFINITIONS_NORMAL_COLOR));
|
|
377 |
114
| setBackground(DrJava.getConfig().getSetting(DEFINITIONS_BACKGROUND_COLOR));
|
|
378 |
| |
|
379 |
| |
|
380 |
114
| DrJava.getConfig().addOptionListener(DEFINITIONS_NORMAL_COLOR, new ForegroundColorListener());
|
|
381 |
114
| DrJava.getConfig().addOptionListener(DEFINITIONS_BACKGROUND_COLOR, new BackgroundColorListener());
|
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
114
| _showHighlightsCheckBox.addItemListener(new ItemListener() {
|
|
387 |
0
| public void itemStateChanged(ItemEvent e) {
|
|
388 |
0
| DefinitionsPane lastDefPane = _frame.getCurrentDefPane();
|
|
389 |
| |
|
390 |
0
| if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
391 |
0
| lastDefPane.removeErrorHighlight();
|
|
392 |
| } |
|
393 |
| |
|
394 |
0
| else if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
395 |
0
| getErrorListPane().switchToError(getSelectedIndex());
|
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
| } |
|
401 |
| } |
|
402 |
| }); |
|
403 |
| |
|
404 |
114
| _keymap = addKeymap("ERRORLIST_KEYMAP", getKeymap());
|
|
405 |
| |
|
406 |
114
| addActionForKeyStroke(DrJava.getConfig().getSetting(OptionConstants.KEY_CUT), cutAction);
|
|
407 |
114
| addActionForKeyStroke(DrJava.getConfig().getSetting(OptionConstants.KEY_COPY), copyAction);
|
|
408 |
114
| addActionForKeyStroke(DrJava.getConfig().getSetting(OptionConstants.KEY_PASTE_FROM_HISTORY), pasteAction);
|
|
409 |
114
| DrJava.getConfig().addOptionListener(OptionConstants.KEY_CUT, new OptionListener<Vector<KeyStroke>>() {
|
|
410 |
0
| public void optionChanged(OptionEvent<Vector<KeyStroke>> oe) {
|
|
411 |
0
| addActionForKeyStroke(DrJava.getConfig().getSetting(OptionConstants.KEY_CUT), cutAction);
|
|
412 |
| } |
|
413 |
| }); |
|
414 |
114
| DrJava.getConfig().addOptionListener(OptionConstants.KEY_COPY, new OptionListener<Vector<KeyStroke>>() {
|
|
415 |
0
| public void optionChanged(OptionEvent<Vector<KeyStroke>> oe) {
|
|
416 |
0
| addActionForKeyStroke(DrJava.getConfig().getSetting(OptionConstants.KEY_COPY), copyAction);
|
|
417 |
| } |
|
418 |
| }); |
|
419 |
114
| DrJava.getConfig().addOptionListener(OptionConstants.KEY_PASTE_FROM_HISTORY, new OptionListener<Vector<KeyStroke>>() {
|
|
420 |
0
| public void optionChanged(OptionEvent<Vector<KeyStroke>> oe) {
|
|
421 |
0
| addActionForKeyStroke(DrJava.getConfig().getSetting(OptionConstants.KEY_PASTE_FROM_HISTORY), pasteAction);
|
|
422 |
| } |
|
423 |
| }); |
|
424 |
| } |
|
425 |
| |
|
426 |
| |
|
427 |
| |
|
428 |
| |
|
429 |
| |
|
430 |
| |
|
431 |
| |
|
432 |
156
| public ErrorDocument getErrorDocument() { return (ErrorDocument) getDocument(); }
|
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
342
| public void addActionForKeyStroke(Vector<KeyStroke> stroke, Action action) {
|
|
439 |
| |
|
440 |
342
| KeyStroke[] keys = _keymap.getKeyStrokesForAction(action);
|
|
441 |
342
| if (keys != null) {
|
|
442 |
0
| for (int i = 0; i < keys.length; i++) {
|
|
443 |
0
| _keymap.removeKeyStrokeBinding(keys[i]);
|
|
444 |
| } |
|
445 |
| } |
|
446 |
342
| for (KeyStroke ks: stroke) {
|
|
447 |
342
| _keymap.addActionForKeyStroke(ks, action);
|
|
448 |
| } |
|
449 |
342
| setKeymap(_keymap);
|
|
450 |
| } |
|
451 |
| |
|
452 |
| |
|
453 |
0
| public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
|
454 |
| |
|
455 |
| } |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
4
| public boolean shouldShowHighlightsInSource() { return _showHighlightsCheckBox.isSelected(); }
|
|
462 |
| |
|
463 |
| |
|
464 |
84
| public int getSelectedIndex() { return _selectedIndex; }
|
|
465 |
| |
|
466 |
| |
|
467 |
0
| protected DJError _errorAtPoint(Point p) {
|
|
468 |
0
| int modelPos = viewToModel(p);
|
|
469 |
| |
|
470 |
0
| if (modelPos == -1) return null;
|
|
471 |
| |
|
472 |
| |
|
473 |
0
| int errorNum = -1;
|
|
474 |
0
| for (int i = 0; i < _errorListPositions.length; i++) {
|
|
475 |
0
| if (_errorListPositions[i].getOffset() <= modelPos) errorNum = i;
|
|
476 |
0
| else break;
|
|
477 |
| } |
|
478 |
| |
|
479 |
0
| if (errorNum >= 0) return _errorTable.get(_errorListPositions[errorNum]);
|
|
480 |
0
| return null;
|
|
481 |
| } |
|
482 |
| |
|
483 |
| |
|
484 |
5
| private int _getIndexForError(DJError error) {
|
|
485 |
| |
|
486 |
0
| if (error == null) throw new IllegalArgumentException("Couldn't find index for null error");
|
|
487 |
| |
|
488 |
5
| for (int i = 0; i < _errorListPositions.length; i++) {
|
|
489 |
5
| DJError e= _errorTable.get(_errorListPositions[i]);
|
|
490 |
5
| if (error.equals(e)) return i;
|
|
491 |
| } |
|
492 |
| |
|
493 |
0
| throw new IllegalArgumentException("Couldn't find index for error " + error);
|
|
494 |
| } |
|
495 |
| |
|
496 |
| |
|
497 |
0
| protected boolean _isEmptySelection() { return getSelectionStart() == getSelectionEnd(); }
|
|
498 |
| |
|
499 |
| |
|
500 |
127
| protected void updateListPane(boolean done) {
|
|
501 |
127
| try {
|
|
502 |
127
| _errorListPositions = new Position[_numErrors];
|
|
503 |
127
| _errorTable.clear();
|
|
504 |
| |
|
505 |
126
| if (_numErrors == 0) _updateNoErrors(done);
|
|
506 |
1
| else _updateWithErrors();
|
|
507 |
| } |
|
508 |
0
| catch (BadLocationException e) { throw new UnexpectedException(e); }
|
|
509 |
| |
|
510 |
| |
|
511 |
127
| repaint();
|
|
512 |
| } |
|
513 |
| |
|
514 |
| abstract protected void _updateNoErrors(boolean done) throws BadLocationException; |
|
515 |
| |
|
516 |
| abstract protected void _updateWithErrors() throws BadLocationException; |
|
517 |
| |
|
518 |
| |
|
519 |
1
| protected String _getNumErrorsMessage(String failureName, String failureMeaning) {
|
|
520 |
1
| StringBuilder numErrMsg;
|
|
521 |
| |
|
522 |
| |
|
523 |
1
| int numCompErrs = getErrorModel().getNumCompErrors();
|
|
524 |
1
| int numWarnings = getErrorModel().getNumWarnings();
|
|
525 |
| |
|
526 |
1
| if (!getErrorModel().hasOnlyWarnings()) {
|
|
527 |
| |
|
528 |
1
| numErrMsg = new StringBuilder(numCompErrs + " " + failureName);
|
|
529 |
0
| if (numCompErrs > 1) numErrMsg.append("s");
|
|
530 |
0
| if (numWarnings > 0) numErrMsg.append(" and " + numWarnings + " warning");
|
|
531 |
| } |
|
532 |
| |
|
533 |
0
| else numErrMsg = new StringBuilder(numWarnings + " warning");
|
|
534 |
| |
|
535 |
0
| if (numWarnings > 1) numErrMsg.append("s");
|
|
536 |
| |
|
537 |
1
| numErrMsg.append(" " + failureMeaning + ":\n");
|
|
538 |
1
| return numErrMsg.toString();
|
|
539 |
| } |
|
540 |
| |
|
541 |
| |
|
542 |
1
| protected String _getErrorTitle() {
|
|
543 |
1
| CompilerErrorModel cem = getErrorModel();
|
|
544 |
0
| if (cem.getNumCompErrors() > 1) return "--------------\n*** Errors ***\n--------------\n";
|
|
545 |
1
| if (cem.getNumCompErrors() > 0) return "-------------\n*** Error ***\n-------------\n";
|
|
546 |
0
| return "";
|
|
547 |
| } |
|
548 |
| |
|
549 |
| |
|
550 |
1
| protected String _getWarningTitle() {
|
|
551 |
1
| CompilerErrorModel cem = getErrorModel();
|
|
552 |
0
| if (cem.getNumWarnings() > 1) return "--------------\n** Warnings **\n--------------\n";
|
|
553 |
0
| if (cem.getNumWarnings() > 0) return "-------------\n** Warning **\n-------------\n";
|
|
554 |
1
| return "";
|
|
555 |
| } |
|
556 |
| |
|
557 |
| |
|
558 |
1
| protected void _updateWithErrors(String failureName, String failureMeaning, ErrorDocument doc)
|
|
559 |
| throws BadLocationException { |
|
560 |
| |
|
561 |
1
| String numErrsMsg = _getNumErrorsMessage(failureName, failureMeaning);
|
|
562 |
1
| doc.append(numErrsMsg, BOLD_ATTRIBUTES);
|
|
563 |
| |
|
564 |
1
| _insertErrors(doc);
|
|
565 |
1
| setDocument(doc);
|
|
566 |
| |
|
567 |
| |
|
568 |
1
| if (!getErrorModel().hasOnlyWarnings())
|
|
569 |
1
| getErrorListPane().switchToError(0);
|
|
570 |
| } |
|
571 |
| |
|
572 |
| |
|
573 |
42
| public boolean hasNextError() { return this.getSelectedIndex() + 1 < _numErrors; }
|
|
574 |
| |
|
575 |
| |
|
576 |
42
| public boolean hasPrevError() { return this.getSelectedIndex() > 0; }
|
|
577 |
| |
|
578 |
| |
|
579 |
0
| public void nextError() {
|
|
580 |
| |
|
581 |
0
| if (hasNextError()) {
|
|
582 |
0
| this._selectedIndex += 1;
|
|
583 |
| |
|
584 |
0
| getErrorListPane().switchToError(this.getSelectedIndex());
|
|
585 |
| } |
|
586 |
| } |
|
587 |
| |
|
588 |
| |
|
589 |
0
| public void prevError() {
|
|
590 |
| |
|
591 |
0
| if (hasPrevError()) {
|
|
592 |
0
| this._selectedIndex -= 1;
|
|
593 |
0
| getErrorListPane().switchToError(this.getSelectedIndex());
|
|
594 |
| } |
|
595 |
| } |
|
596 |
| |
|
597 |
| |
|
598 |
| |
|
599 |
| |
|
600 |
1
| protected void _insertErrors(ErrorDocument doc) throws BadLocationException {
|
|
601 |
1
| CompilerErrorModel cem = getErrorModel();
|
|
602 |
1
| int numErrors = cem.getNumErrors();
|
|
603 |
| |
|
604 |
| |
|
605 |
| |
|
606 |
| |
|
607 |
1
| int errorPositionInListOfErrors = 0;
|
|
608 |
| |
|
609 |
| |
|
610 |
1
| String errorTitle = _getErrorTitle();
|
|
611 |
0
| if (cem.getNumWarnings() > 0) doc.append(errorTitle, BOLD_ATTRIBUTES);
|
|
612 |
| |
|
613 |
1
| for (int errorNum = 0; errorNum < numErrors; errorNum++) {
|
|
614 |
1
| int startPos = doc.getLength();
|
|
615 |
1
| DJError err = cem.getError(errorNum);
|
|
616 |
| |
|
617 |
1
| if (!err.isWarning()) {
|
|
618 |
1
| _insertErrorText(err, doc);
|
|
619 |
1
| Position pos = doc.createPosition(startPos);
|
|
620 |
1
| _errorListPositions[errorPositionInListOfErrors] = pos;
|
|
621 |
1
| _errorTable.put(pos, err);
|
|
622 |
1
| errorPositionInListOfErrors++;
|
|
623 |
| } |
|
624 |
| } |
|
625 |
| |
|
626 |
1
| String warningTitle = _getWarningTitle();
|
|
627 |
1
| if (cem.getNumCompErrors() > 0) doc.append(warningTitle, BOLD_ATTRIBUTES);
|
|
628 |
| |
|
629 |
1
| for (int errorNum = 0; errorNum < numErrors; errorNum++) {
|
|
630 |
1
| int startPos = doc.getLength();
|
|
631 |
1
| DJError err = cem.getError(errorNum);
|
|
632 |
| |
|
633 |
1
| if (err.isWarning()) {
|
|
634 |
0
| _insertErrorText(err, doc);
|
|
635 |
0
| Position pos = doc.createPosition(startPos);
|
|
636 |
0
| _errorListPositions[errorPositionInListOfErrors] = pos;
|
|
637 |
0
| _errorTable.put(pos, err);
|
|
638 |
0
| errorPositionInListOfErrors++;
|
|
639 |
| } |
|
640 |
| } |
|
641 |
| } |
|
642 |
| |
|
643 |
| |
|
644 |
| |
|
645 |
| |
|
646 |
| |
|
647 |
1
| protected void _insertErrorText(DJError error, ErrorDocument doc) throws BadLocationException {
|
|
648 |
| |
|
649 |
1
| doc.append("File: ", BOLD_ATTRIBUTES);
|
|
650 |
1
| String fileAndLineNumber = error.getFileMessage() + " [line: " + error.getLineMessage() + "]";
|
|
651 |
1
| doc.append(fileAndLineNumber + "\n", NORMAL_ATTRIBUTES);
|
|
652 |
| |
|
653 |
0
| if (error.isWarning()) doc.append(_getWarningText(), BOLD_ATTRIBUTES);
|
|
654 |
1
| else doc.append(_getErrorText(), BOLD_ATTRIBUTES);
|
|
655 |
| |
|
656 |
1
| doc.append(error.message(), NORMAL_ATTRIBUTES);
|
|
657 |
1
| doc.append("\n", NORMAL_ATTRIBUTES);
|
|
658 |
| } |
|
659 |
| |
|
660 |
| |
|
661 |
0
| protected String _getWarningText() { return "Warning: "; }
|
|
662 |
| |
|
663 |
| |
|
664 |
1
| protected String _getErrorText() { return "Error: "; }
|
|
665 |
| |
|
666 |
| |
|
667 |
139
| protected void _removeListHighlight() {
|
|
668 |
139
| if (_listHighlightTag != null) {
|
|
669 |
5
| _listHighlightTag.remove();
|
|
670 |
5
| _listHighlightTag = null;
|
|
671 |
| } |
|
672 |
| |
|
673 |
| |
|
674 |
| } |
|
675 |
| |
|
676 |
| |
|
677 |
129
| public void selectNothing() {
|
|
678 |
| |
|
679 |
129
| _removeListHighlight();
|
|
680 |
| |
|
681 |
| |
|
682 |
129
| _frame.getCurrentDefPane().removeErrorHighlight();
|
|
683 |
| } |
|
684 |
| |
|
685 |
| |
|
686 |
5
| public void selectItem(DJError error) {
|
|
687 |
| |
|
688 |
5
| try {
|
|
689 |
| |
|
690 |
5
| int i = _getIndexForError(error);
|
|
691 |
| |
|
692 |
5
| _selectedIndex = i;
|
|
693 |
| |
|
694 |
5
| _removeListHighlight();
|
|
695 |
| |
|
696 |
5
| int startPos = _errorListPositions[i].getOffset();
|
|
697 |
| |
|
698 |
| |
|
699 |
| |
|
700 |
| |
|
701 |
| |
|
702 |
5
| int endPos;
|
|
703 |
5
| if (i + 1 >= (_numErrors)) endPos = getDocument().getLength();
|
|
704 |
| else { |
|
705 |
0
| endPos = _errorListPositions[i + 1].getOffset();
|
|
706 |
| |
|
707 |
0
| DJError nextError = _errorTable.get(_errorListPositions[i+1]);
|
|
708 |
| |
|
709 |
0
| if (!error.isWarning() && nextError.isWarning()) endPos = endPos - _getWarningTitle().length();
|
|
710 |
| |
|
711 |
| } |
|
712 |
| |
|
713 |
| |
|
714 |
| |
|
715 |
5
| try {
|
|
716 |
5
| _listHighlightTag = _highlightManager.addHighlight(startPos, endPos, _listHighlightPainter);
|
|
717 |
| |
|
718 |
| |
|
719 |
| |
|
720 |
5
| Rectangle startRect;
|
|
721 |
5
| if (i == 0) startRect = modelToView(0);
|
|
722 |
| |
|
723 |
0
| else startRect = modelToView(startPos);
|
|
724 |
| |
|
725 |
5
| Rectangle endRect = modelToView(endPos - 1);
|
|
726 |
| |
|
727 |
5
| if (startRect != null && endRect != null) {
|
|
728 |
| |
|
729 |
| |
|
730 |
0
| startRect.add(endRect);
|
|
731 |
| |
|
732 |
| |
|
733 |
| |
|
734 |
0
| scrollRectToVisible(startRect);
|
|
735 |
0
| _updateScrollButtons();
|
|
736 |
| } |
|
737 |
| else { |
|
738 |
| |
|
739 |
| |
|
740 |
5
| _removeListHighlight();
|
|
741 |
| } |
|
742 |
| } |
|
743 |
| catch (BadLocationException badBadLocation) { } |
|
744 |
| |
|
745 |
| } |
|
746 |
| catch (IllegalArgumentException iae) { |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
0
| _removeListHighlight();
|
|
751 |
| } |
|
752 |
| } |
|
753 |
| |
|
754 |
42
| protected void _updateScrollButtons() {
|
|
755 |
42
| if (hasNextError()) {
|
|
756 |
0
| _nextErrorButton.setEnabled(true);
|
|
757 |
| } |
|
758 |
| else { |
|
759 |
42
| _nextErrorButton.setEnabled(false);
|
|
760 |
| } |
|
761 |
42
| if (hasPrevError()) {
|
|
762 |
0
| _prevErrorButton.setEnabled(true);
|
|
763 |
| } |
|
764 |
| else { |
|
765 |
42
| _prevErrorButton.setEnabled(false);
|
|
766 |
| } |
|
767 |
| } |
|
768 |
| |
|
769 |
| |
|
770 |
| |
|
771 |
| |
|
772 |
| |
|
773 |
1
| void switchToError(DJError error) {
|
|
774 |
| |
|
775 |
0
| if (error == null) return;
|
|
776 |
| |
|
777 |
1
| final SingleDisplayModel model = getModel();
|
|
778 |
| |
|
779 |
1
| DefinitionsPane prevPane = _frame.getCurrentDefPane();
|
|
780 |
1
| prevPane.removeErrorHighlight();
|
|
781 |
1
| OpenDefinitionsDocument prevDoc = prevPane.getOpenDefDocument();
|
|
782 |
| |
|
783 |
1
| if (error.file() != null) {
|
|
784 |
1
| try {
|
|
785 |
1
| boolean open = false;
|
|
786 |
1
| for(OpenDefinitionsDocument doc : model.getOpenDefinitionsDocuments()) {
|
|
787 |
2
| if((doc.getFile() != null) && (doc.getFile().equals(error.file()))) {
|
|
788 |
1
| open = true;
|
|
789 |
1
| break;
|
|
790 |
| } |
|
791 |
| } |
|
792 |
| |
|
793 |
1
| if(open) {
|
|
794 |
1
| OpenDefinitionsDocument doc = model.getDocumentForFile(error.file());
|
|
795 |
1
| CompilerErrorModel errorModel = getErrorModel();
|
|
796 |
| |
|
797 |
1
| Position pos = errorModel.getPosition(error);
|
|
798 |
| |
|
799 |
| |
|
800 |
| |
|
801 |
| |
|
802 |
1
| if (! prevDoc.equals(doc)) {
|
|
803 |
0
| model.setActiveDocument(doc);
|
|
804 |
0
| EventQueue.invokeLater(new Runnable() {
|
|
805 |
0
| public void run() {
|
|
806 |
0
| model.addToBrowserHistory();
|
|
807 |
| } }); |
|
808 |
| } |
|
809 |
1
| else model.refreshActiveDocument();
|
|
810 |
| |
|
811 |
| |
|
812 |
| |
|
813 |
1
| DefinitionsPane defPane = _frame.getCurrentDefPane();
|
|
814 |
| |
|
815 |
1
| if (pos != null) {
|
|
816 |
1
| int errPos = pos.getOffset();
|
|
817 |
1
| if (errPos >= 0 && errPos <= doc.getLength()) {
|
|
818 |
1
| defPane.centerViewOnOffset(errPos);
|
|
819 |
| |
|
820 |
| |
|
821 |
| |
|
822 |
| |
|
823 |
1
| defPane.getErrorCaretListener().updateHighlight(errPos);
|
|
824 |
| } |
|
825 |
| |
|
826 |
| } |
|
827 |
| |
|
828 |
| |
|
829 |
| |
|
830 |
| |
|
831 |
| |
|
832 |
1
| defPane.requestFocusInWindow();
|
|
833 |
1
| defPane.getCaret().setVisible(true);
|
|
834 |
| } |
|
835 |
| } |
|
836 |
| catch (IOException ioe) { |
|
837 |
| |
|
838 |
| } |
|
839 |
| } |
|
840 |
| |
|
841 |
| |
|
842 |
| |
|
843 |
1
| getErrorListPane().selectItem(error);
|
|
844 |
| } |
|
845 |
| |
|
846 |
| |
|
847 |
| |
|
848 |
| |
|
849 |
| |
|
850 |
1
| void switchToError(int index) {
|
|
851 |
1
| if ((index >= 0) && (index < _errorListPositions.length)) {
|
|
852 |
1
| Position pos = _errorListPositions[index];
|
|
853 |
1
| DJError error= _errorTable.get(pos);
|
|
854 |
1
| switchToError(error);
|
|
855 |
| } |
|
856 |
| } |
|
857 |
| |
|
858 |
| |
|
859 |
| private class CompilerErrorColorOptionListener implements OptionListener<Color> { |
|
860 |
| |
|
861 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
862 |
0
| _listHighlightPainter = new ReverseHighlighter.DrJavaHighlightPainter(oce.value);
|
|
863 |
0
| if (_listHighlightTag != null) {
|
|
864 |
0
| _listHighlightTag.refresh(_listHighlightPainter);
|
|
865 |
| } |
|
866 |
| } |
|
867 |
| } |
|
868 |
| |
|
869 |
| |
|
870 |
| private class ForegroundColorListener implements OptionListener<Color> { |
|
871 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
872 |
0
| StyleConstants.setForeground(NORMAL_ATTRIBUTES, oce.value);
|
|
873 |
0
| StyleConstants.setForeground(BOLD_ATTRIBUTES, oce.value);
|
|
874 |
| |
|
875 |
| |
|
876 |
0
| ErrorDocument doc = getErrorListPane().getErrorDocument();
|
|
877 |
0
| SimpleAttributeSet set = new SimpleAttributeSet();
|
|
878 |
0
| set.addAttribute(StyleConstants.Foreground, oce.value);
|
|
879 |
0
| doc.setCharacterAttributes(0, doc.getLength(), set, false);
|
|
880 |
| } |
|
881 |
| } |
|
882 |
| |
|
883 |
| |
|
884 |
| private class BackgroundColorListener implements OptionListener<Color> { |
|
885 |
0
| public void optionChanged(OptionEvent<Color> oce) {
|
|
886 |
0
| setBackground(oce.value);
|
|
887 |
0
| ErrorListPane.this.repaint();
|
|
888 |
| } |
|
889 |
| } |
|
890 |
0
| public String getErrorDocumentTitle() { return "Errors"; }
|
|
891 |
| } |
|
892 |
| |
|
893 |
| public class ErrorDocument extends SwingDocument { |
|
894 |
| protected volatile DrJavaBook _book; |
|
895 |
| protected final String _title; |
|
896 |
200
| public ErrorDocument(String t) { _title = t; }
|
|
897 |
0
| public Pageable getPageable() throws IllegalStateException { return _book; }
|
|
898 |
0
| public void preparePrintJob() {
|
|
899 |
0
| _book = new DrJavaBook(getDocText(0, getLength()), _title, new PageFormat());
|
|
900 |
| } |
|
901 |
0
| public void print() {
|
|
902 |
0
| preparePrintJob();
|
|
903 |
0
| PrinterJob printJob = PrinterJob.getPrinterJob();
|
|
904 |
0
| printJob.setPageable(_book);
|
|
905 |
0
| try {
|
|
906 |
0
| if (printJob.printDialog()) printJob.print();
|
|
907 |
| } |
|
908 |
| catch(PrinterException e) { |
|
909 |
0
| MainFrameStatics.showError(_frame, e, "Print Error", "An error occured while printing.");
|
|
910 |
| } |
|
911 |
0
| cleanUpPrintJob();
|
|
912 |
| } |
|
913 |
0
| public void cleanUpPrintJob() { _book = null; }
|
|
914 |
| } |
|
915 |
| |
|
916 |
| public class PreviewErrorFrame extends PreviewFrame { |
|
917 |
0
| public PreviewErrorFrame() throws IllegalStateException {
|
|
918 |
0
| super(ErrorPanel.this._model, ErrorPanel.this._frame, false);
|
|
919 |
| } |
|
920 |
0
| protected Pageable setUpDocument(SingleDisplayModel model, boolean interactions) {
|
|
921 |
0
| return getErrorListPane().getErrorDocument().getPageable();
|
|
922 |
| } |
|
923 |
0
| protected void _print() {
|
|
924 |
0
| getErrorListPane().getErrorDocument().print();
|
|
925 |
| } |
|
926 |
| } |
|
927 |
| |
|
928 |
456
| public JPopupMenu getPopupMenu() { return _popupMenu; }
|
|
929 |
| |
|
930 |
114
| public void addPopupMenu(Action... actions) {
|
|
931 |
114
| if (_popupMenu==null) {
|
|
932 |
114
| _popupMenu = new JPopupMenu();
|
|
933 |
| } |
|
934 |
| else { |
|
935 |
0
| _popupMenu.removeAll();
|
|
936 |
0
| removeMouseListener(_popupMenuListener);
|
|
937 |
0
| _scroller.removeMouseListener(_popupMenuListener);
|
|
938 |
0
| _scroller.getViewport().getView().removeMouseListener(_popupMenuListener);
|
|
939 |
| } |
|
940 |
114
| for(Action a: actions) { _popupMenu.add(a); }
|
|
941 |
114
| _popupMenuListener = new RightClickMouseAdapter() {
|
|
942 |
0
| protected void _popupAction(MouseEvent e) {
|
|
943 |
0
| requestFocusInWindow();
|
|
944 |
0
| _popupMenu.show(e.getComponent(), e.getX(), e.getY());
|
|
945 |
| } |
|
946 |
| }; |
|
947 |
114
| addMouseListener(_popupMenuListener);
|
|
948 |
114
| if (_scroller!=null) {
|
|
949 |
114
| _scroller.addMouseListener(_popupMenuListener);
|
|
950 |
114
| if (_scroller.getViewport().getView()!=null) {
|
|
951 |
0
| _scroller.getViewport().getView().addMouseListener(_popupMenuListener);
|
|
952 |
| } |
|
953 |
| } |
|
954 |
| } |
|
955 |
| } |