Skip to content

Commit 772ccdb

Browse files
committed
Yet more "bullet-proofing" in an attempt to fix the progress bar bug. It apparently occurs much less frequently now. Converted many volatile variables in GUI code to final.
Moved some GUI code segments to the dispatch thread. Changes to be committed: modified: ErrorPanel.java modified: GenerateCustomDrJavaJarFrame.java modified: JUnitPanel.java modified: NewJavaClassDialog.java
1 parent 12a07e0 commit 772ccdb

File tree

4 files changed

+60
-50
lines changed

4 files changed

+60
-50
lines changed

drjava/src/edu/rice/cs/drjava/ui/ErrorPanel.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,33 @@ public abstract class ErrorPanel extends TabbedPanel implements OptionConstants
7474

7575
/** The total number of errors in the list */
7676
protected volatile int _numErrors;
77-
protected volatile JCheckBox _showHighlightsCheckBox;
77+
protected final JCheckBox _showHighlightsCheckBox;
7878

79-
protected volatile SingleDisplayModel _model;
79+
protected final SingleDisplayModel _model;
8080

81-
private volatile JScrollPane _scroller;
81+
private final JScrollPane _scroller;
8282

8383
/** This contains the _scroller and the _errorNavPanel. */
84-
private volatile JPanel _leftPanel;
84+
private final JPanel _leftPanel;
8585

8686
/** This contains the label, showHighlightsCheckBox, and the customPanel. */
87-
private volatile JPanel _rightPanel;
87+
private final JPanel _rightPanel;
8888

89-
private volatile JPanel _errorNavPanel;
89+
private final JPanel _errorNavPanel;
9090

91-
private volatile JPanel _errorNavButtonsPanel;
91+
private final JPanel _errorNavButtonsPanel;
9292

9393
/** This JPanel contains each child panel's specific UI components. **/
94-
protected volatile JPanel customPanel;
94+
protected final JPanel customPanel;
9595

96-
private volatile JButton _nextErrorButton;
97-
private volatile JButton _prevErrorButton;
96+
private final JButton _nextErrorButton;
97+
private final JButton _prevErrorButton;
9898

9999
/** _popupMenu and _popupMenuListener are either both null or both non-null. */
100100
protected volatile JPopupMenu _popupMenu = null;
101101
protected volatile RightClickMouseAdapter _popupMenuListener = null;
102102

103-
/** Highlight painter for selected list items. */
103+
/** Highlight painter for selected list items. Not final because it is rebound in CompilerErrorColorOptionListener */
104104
static volatile ReverseHighlighter.DrJavaHighlightPainter _listHighlightPainter =
105105
new ReverseHighlighter.DrJavaHighlightPainter(DrJava.getConfig().getSetting(COMPILER_ERROR_COLOR));
106106

@@ -211,7 +211,7 @@ public void actionPerformed(ActionEvent e) {
211211

212212
protected void setErrorListPane(final ErrorListPane elp) {
213213
if (_popupMenuListener!=null) {
214-
if ((_scroller!=null) &&
214+
if ((_scroller!=null) && // unnecessary?
215215
(_scroller.getViewport()!=null) &&
216216
(_scroller.getViewport().getView()!=null)) {
217217
_scroller.getViewport().getView().removeMouseListener(_popupMenuListener);
@@ -960,7 +960,7 @@ protected void _popupAction(MouseEvent e) {
960960
}
961961
};
962962
addMouseListener(_popupMenuListener);
963-
if (_scroller!=null) {
963+
if (_scroller!=null) { // test unnecessary?
964964
_scroller.addMouseListener(_popupMenuListener);
965965
if (_scroller.getViewport().getView()!=null) {
966966
_scroller.getViewport().getView().addMouseListener(_popupMenuListener);

drjava/src/edu/rice/cs/drjava/ui/GenerateCustomDrJavaJarFrame.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ public class GenerateCustomDrJavaJarFrame extends SwingFrame {
6565
private final JButton _generateButton;
6666
private final JButton _checkButton;
6767
private final JButton _closeButton;
68-
private JPanel _mainPanel;
68+
private final JPanel _mainPanel;
6969

7070
/** The file with the current DrJava executable. */
7171
private final File _drjavaFile = FileOps.getDrJavaFile();
7272

73-
/** File selector for the jar output file. */
74-
private FileSelectorComponent _jarFileSelector;
73+
/** File selector for the jar output file. Not final because it is rebound in _makeJarFileSelector(). */
74+
private volatile FileSelectorComponent _jarFileSelector;
7575

7676
/** List with additional sources. */
77-
private VectorFileOptionComponent _sourcesList;
77+
private volatile VectorFileOptionComponent _sourcesList;
7878

7979
/** Constructs a frame to generate a custom drjava.jar.
8080
* @param mf reference to the main frame
@@ -83,7 +83,7 @@ public GenerateCustomDrJavaJarFrame(MainFrame mf) {
8383
super("Generate Custom drjava.jar File");
8484

8585
_mainFrame = mf;
86-
_mainPanel= new JPanel();
86+
_mainPanel = new JPanel();
8787

8888
Action generateAction = new AbstractAction("Generate") {
8989
public void actionPerformed(ActionEvent e) { generate(); }

drjava/src/edu/rice/cs/drjava/ui/JUnitPanel.java

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import edu.rice.cs.util.UnexpectedException;
3636
import edu.rice.cs.util.swing.BorderlessScrollPane;
3737
import edu.rice.cs.util.swing.RightClickMouseAdapter;
38+
import edu.rice.cs.util.swing.Utilities;
3839

3940
import javax.swing.*;
4041
import javax.swing.border.EmptyBorder;
@@ -101,7 +102,7 @@ public void actionPerformed(ActionEvent ae) {
101102
/** The currently selected error. */
102103
private volatile JUnitError _error = null;
103104
private volatile Window _stackFrame = null;
104-
private volatile JTextArea _stackTextArea;
105+
private volatile JTextArea _stackTextArea; // not final because it is rebound in _setupStackTraceFrame()
105106
private final JLabel _errorLabel = new JLabel();
106107
private final JLabel _testLabel = new JLabel();
107108
private final JLabel _fileLabel = new JLabel();
@@ -261,28 +262,33 @@ public void testStarted(String name) {
261262
String fullName = className + "." + testName;
262263
if (fullName.equals(JUNIT_WARNING)) return;
263264
ErrorDocument doc = getErrorDocument();
264-
// TODO: convert this GUI operatoin to a Runnable and use invokeLater
265-
try {
266-
int len = doc.getLength();
267-
// Insert the classname if it has changed
268-
if (! className.equals(_runningTestName)) {
269-
_runningTestName = className;
270-
doc.insertString(len, " " + className + "\n", NORMAL_ATTRIBUTES);
271-
len = doc.getLength();
265+
266+
// Converted this GUI operation to a Runnable and use invokeLater
267+
Utilities.invokeLater(new Runnable() {
268+
public void run() {
269+
try {
270+
int len = doc.getLength();
271+
// Insert the classname if it has changed
272+
if (! className.equals(_runningTestName)) {
273+
_runningTestName = className;
274+
doc.insertString(len, " " + className + "\n", NORMAL_ATTRIBUTES);
275+
len = doc.getLength();
276+
}
277+
278+
// Insert the test name, remembering its position
279+
doc.insertString(len, " ", NORMAL_ATTRIBUTES);
280+
len = doc.getLength();
281+
doc.insertString(len, testName + "\n", NORMAL_ATTRIBUTES);
282+
Position pos = doc.createPosition(len);
283+
_runningTestNamePositions.put(fullName, pos);
284+
setCaretPosition(len);
285+
}
286+
catch (BadLocationException ble) {
287+
// Inserting at end, shouldn't happen
288+
throw new UnexpectedException(ble);
289+
}
272290
}
273-
274-
// Insert the test name, remembering its position
275-
doc.insertString(len, " ", NORMAL_ATTRIBUTES);
276-
len = doc.getLength();
277-
doc.insertString(len, testName + "\n", NORMAL_ATTRIBUTES);
278-
Position pos = doc.createPosition(len);
279-
_runningTestNamePositions.put(fullName, pos);
280-
setCaretPosition(len);
281-
}
282-
catch (BadLocationException ble) {
283-
// Inserting at end, shouldn't happen
284-
throw new UnexpectedException(ble);
285-
}
291+
});
286292
}
287293

288294
/** Displays the results of a test that has finished in the JUnitPanel.
@@ -299,15 +305,19 @@ public void testEnded(String name, boolean wasSuccessful, boolean causedError) {
299305
if (fullName.equals(JUNIT_WARNING)) return;
300306
// TODO: convert this GUI operation to a Runnable and use invokeLater
301307
ErrorDocument doc = getErrorDocument();
302-
Position namePos = _runningTestNamePositions.get(fullName);
303-
AttributeSet set;
304-
if (! wasSuccessful || causedError) set = TEST_FAIL_ATTRIBUTES;
305-
else set = TEST_PASS_ATTRIBUTES;
306-
if (namePos != null) {
307-
int index = namePos.getOffset();
308-
int length = testName.length();
309-
doc.setCharacterAttributes(index, length, set, false);
310-
}
308+
Utilities.invokeLater(new Runnable() {
309+
public void run() {
310+
Position namePos = _runningTestNamePositions.get(fullName);
311+
AttributeSet set;
312+
if (! wasSuccessful || causedError) set = TEST_FAIL_ATTRIBUTES;
313+
else set = TEST_PASS_ATTRIBUTES;
314+
if (namePos != null) {
315+
int index = namePos.getOffset();
316+
int length = testName.length();
317+
doc.setCharacterAttributes(index, length, set, false);
318+
}
319+
}
320+
});
311321
}
312322

313323
/** Puts the error pane into "junit in progress" state. Only runs in event thread. */

drjava/src/edu/rice/cs/drjava/ui/NewJavaClassDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class NewJavaClassDialog extends SwingFrame {
6767

6868
private final JButton _okButton;
6969
private final JButton _cancelButton;
70-
private JPanel _mainPanel;
70+
private final JPanel _mainPanel;
7171
private final JTextField _className = new JTextField();
7272
private final JTextField _interfaces = new JTextField();
7373
private final JTextField _superClass = new JTextField();

0 commit comments

Comments
 (0)