3737import edu .rice .cs .drjava .model .DJError ;
3838import edu .rice .cs .drjava .model .compiler .CompilerErrorModel ;
3939import edu .rice .cs .drjava .model .ClipboardHistoryModel ;
40+ import edu .rice .cs .drjava .model .print .DrJavaBook ;
4041import edu .rice .cs .util .UnexpectedException ;
4142import edu .rice .cs .util .swing .HighlightManager ;
4243import edu .rice .cs .util .swing .BorderlessScrollPane ;
44+ import edu .rice .cs .util .swing .Utilities ;
4345import edu .rice .cs .util .text .SwingDocument ;
44- import edu . rice . cs . drjava . model . print . DrJavaBook ;
46+
4547
4648import edu .rice .cs .util .swing .RightClickMouseAdapter ;
4749
@@ -116,6 +118,7 @@ protected static final SimpleAttributeSet _getNormalAttributes() {
116118 return s ;
117119 }
118120
121+ /* Primary constructor for ErrorPanel class */
119122 public ErrorPanel (SingleDisplayModel model , MainFrame frame , String tabString , String labelString ) {
120123 super (frame , tabString );
121124 _model = model ;
@@ -156,11 +159,10 @@ public ErrorPanel(SingleDisplayModel model, MainFrame frame, String tabString, S
156159
157160 // _mainPanel.setMinimumSize(new Dimension(225,60));
158161 // We make the vertical scrollbar always there.
159- // If we don't, when it pops up it cuts away the right edge of the
160- // text. Very bad.
162+ // If we don't, when it pops up it cuts away the right edge of thetext. Very bad.
161163 _scroller = new BorderlessScrollPane (ScrollPaneConstants .VERTICAL_SCROLLBAR_ALWAYS ,
162164 ScrollPaneConstants .HORIZONTAL_SCROLLBAR_NEVER );
163-
165+
164166 _leftPanel .add (_scroller , BorderLayout .CENTER );
165167 _leftPanel .add (_errorNavPanel , BorderLayout .EAST );
166168
@@ -175,9 +177,10 @@ public ErrorPanel(SingleDisplayModel model, MainFrame frame, String tabString, S
175177 _mainPanel .add (_leftPanel , BorderLayout .CENTER );
176178 _mainPanel .add (_rightPanel , BorderLayout .EAST );
177179
178- /** Default copy action. Returns focus to the correct pane. */
180+ /** Default copy action. Returns focus to the correct pane. Executes in dispatch thread. */
179181 final Action copyAction = new AbstractAction ("Copy Contents to Clipboard" , MainFrame .getIcon ("Copy16.gif" )) {
180182 public void actionPerformed (ActionEvent e ) {
183+ assert EventQueue .isDispatchThread ();
181184 getErrorListPane ().selectAll ();
182185 String t = getErrorListPane ().getSelectedText ();
183186 if (t != null ) {
@@ -188,54 +191,68 @@ public void actionPerformed(ActionEvent e) {
188191 ClipboardHistoryModel .singleton ().put (t );
189192 }
190193 }
191- }
194+ };
192195 };
196+
193197 addPopupMenu (copyAction );
198+
194199 getPopupMenu ().add (new AbstractAction ("Save Copy of Contents..." , MainFrame .getIcon ("Save16.gif" )) {
200+ /* Executes in dispatch thread. */
195201 public void actionPerformed (ActionEvent e ) {
202+ assert EventQueue .isDispatchThread ();
196203 _frame ._saveDocumentCopy (getErrorListPane ().getErrorDocument ());
197204 }
198205 });
206+
199207 getPopupMenu ().addSeparator ();
208+
200209 getPopupMenu ().add (new AbstractAction ("Print..." , MainFrame .getIcon ("Print16.gif" )) {
210+ /* Executes in dispatch thread. */
201211 public void actionPerformed (ActionEvent e ) {
212+ assert EventQueue .isDispatchThread ();
202213 getErrorListPane ().getErrorDocument ().print ();
203214 }
204215 });
216+
205217 getPopupMenu ().add (new AbstractAction ("Print Preview..." , MainFrame .getIcon ("PrintPreview16.gif" )) {
218+ /* Executes in dispatch thread. */
206219 public void actionPerformed (ActionEvent e ) {
220+ assert EventQueue .isDispatchThread ();
207221 getErrorListPane ().getErrorDocument ().preparePrintJob ();
208222 new PreviewErrorFrame ();
209223 }
210224 });
211225 }
212-
226+
213227 protected void setErrorListPane (final ErrorListPane elp ) {
214- if (_popupMenuListener !=null ) {
215- if ((_scroller !=null ) && // unnecessary?
216- (_scroller .getViewport ()!=null ) &&
217- (_scroller .getViewport ().getView ()!=null )) {
228+ /* Should this action be performed in the dispatch thread? */
229+ if (_popupMenuListener != null ) {
230+ if ((_scroller .getViewport () != null ) && (_scroller .getViewport ().getView () != null )) {
218231 _scroller .getViewport ().getView ().removeMouseListener (_popupMenuListener );
219232 }
220233 }
221234
222235 _scroller .setViewportView (elp );
223236
224- if (_popupMenuListener !=null ) {
225- _scroller .getViewport ().getView ().addMouseListener (_popupMenuListener );
226- }
237+ if (_popupMenuListener !=null ) { _scroller .getViewport ().getView ().addMouseListener (_popupMenuListener ); }
227238
228239 _nextErrorButton .setEnabled (false );
240+
229241 _nextErrorButton .addActionListener (new ActionListener () {
242+ /* Executes in dispatch thread. */
230243 public void actionPerformed (ActionEvent e ) {
244+ assert EventQueue .isDispatchThread ();
231245 elp .nextError ();
232246 // _prevErrorButton.setEnabled(_errorListPane.hasPrevError());
233247 // _nextErrorButton.setEnabled(_errorListPane.hasNextError());
234248 }
235249 });
250+
236251 _prevErrorButton .setEnabled (false );
237252 _prevErrorButton .addActionListener (new ActionListener () {
253+ /* Executes in dispatch thread. */
238254 public void actionPerformed (ActionEvent e ) {
255+ assert EventQueue .isDispatchThread ();
239256 elp .prevError ();
240257 // _prevErrorButton.setEnabled(_errorListPane.hasPrevError());
241258 // _nextErrorButton.setEnabled(_errorListPane.hasNextError());
@@ -301,28 +318,34 @@ public abstract class ErrorListPane extends JEditorPane implements ClipboardOwne
301318
302319 /** Default cut action. */
303320 volatile Action cutAction = new DefaultEditorKit .CutAction () {
321+
322+ /* Executes in dispatch thread. */
304323 public void actionPerformed (ActionEvent e ) {
324+ assert EventQueue .isDispatchThread ();
305325 if (getSelectedText () != null ) {
306326 super .actionPerformed (e );
307- String s = edu . rice . cs . util . swing . Utilities .getClipboardSelection (ErrorListPane .this );
327+ String s = Utilities .getClipboardSelection (ErrorListPane .this );
308328 if ((s != null ) && (s .length () != 0 )) { ClipboardHistoryModel .singleton ().put (s ); }
309329 }
310330 }
311331 };
312-
332+
313333 /** Default copy action. */
314334 volatile Action copyAction = new DefaultEditorKit .CopyAction () {
335+ /* Executes in dispatch thread. */
315336 public void actionPerformed (ActionEvent e ) {
337+ assert EventQueue .isDispatchThread ();
316338 if (getSelectedText () != null ) {
317339 super .actionPerformed (e );
318- String s = edu . rice . cs . util . swing . Utilities .getClipboardSelection (ErrorListPane .this );
340+ String s = Utilities .getClipboardSelection (ErrorListPane .this );
319341 if (s != null && s .length () != 0 ) { ClipboardHistoryModel .singleton ().put (s ); }
320342 }
321343 }
322344 };
323345
324346 /** No-op paste action. */
325347 volatile Action pasteAction = new DefaultEditorKit .PasteAction () {
348+ /* Executes in any thread. */
326349 public void actionPerformed (ActionEvent e ) { }
327350 };
328351
@@ -498,14 +521,13 @@ private int _getIndexForError(DJError error) {
498521 /** @return true if the text selection interval is empty. */
499522 protected boolean _isEmptySelection () { return getSelectionStart () == getSelectionEnd (); }
500523
501- /** Update the pane which holds the list of errors for the viewer.
502- * @param done boolean
503- */
524+ /** Update the pane which holds the list of errors for the viewer. Only executes in the dispatch thread.
525+ * @param done boolean
526+ */
504527 protected void updateListPane (boolean done ) {
505528 try {
506529 _errorListPositions = new Position [_numErrors ];
507530 _errorTable .clear ();
508-
509531 if (_numErrors == 0 ) _updateNoErrors (done );
510532 else _updateWithErrors ();
511533 }
@@ -818,9 +840,8 @@ void switchToError(DJError error) {
818840 if (! prevDoc .equals (doc )) {
819841 model .setActiveDocument (doc );
820842 EventQueue .invokeLater (new Runnable () {
821- public void run () {
822- model .addToBrowserHistory ();
823- } });
843+ public void run () { model .addToBrowserHistory (); }
844+ });
824845 }
825846 else model .refreshActiveDocument ();
826847
@@ -837,8 +858,7 @@ public void run() {
837858 * is unhighlighted and the new error is not highlighted because the CaretListener does not act because there
838859 * is no change in caret position. (This is the only place where updateHighlight was called from before) */
839860 defPane .getErrorCaretListener ().updateHighlight (errPos );
840- }
841-
861+ }
842862 }
843863 // The following line is a brute force hack that fixed a bug plaguing the DefinitionsPane immediately after a compilation
844864 // with errors. In some cases (which were consistently reproducible), the DefinitionsPane editing functions would break
@@ -961,11 +981,10 @@ protected void _popupAction(MouseEvent e) {
961981 }
962982 };
963983 addMouseListener (_popupMenuListener );
964- if (_scroller !=null ) { // test unnecessary?
965- _scroller .addMouseListener (_popupMenuListener );
966- if (_scroller .getViewport ().getView ()!=null ) {
967- _scroller .getViewport ().getView ().addMouseListener (_popupMenuListener );
968- }
984+
985+ _scroller .addMouseListener (_popupMenuListener );
986+ if (_scroller .getViewport ().getView () != null ) {
987+ _scroller .getViewport ().getView ().addMouseListener (_popupMenuListener );
969988 }
970989 }
971990}
0 commit comments