Is this necessary? Without a detailed analysis of the Swing library,
we don't know for certain. Sun recommends that all GUI code run in
the event thread (with a very short list of exceptions), but we have
found this practice produces unacceptable startup overhead. An
earlier discpline promulgated by Sun stated that GUI components could
be manipulated outside the event thread until they were "realized" but
this guidance is rather vague. If it means before any GUI component
is realized (which starts the event thread), then it clearly looks OK
but how can a programmer designing a specific GUI class know if any
other GUI component has been realized?. This is a global property of
a program. On the other hand, the more liberal interpretation that
each individual GUI component can be manipulated before it is realized
is clearly too liberal because the manipulation might link this
component into an existing GUI component that has already been
realized and is being accessed by the event thread potentially
traversing the unrealized component in the process. So I think Sun
really intended to mean that a GUI component can be safely manipulated
outside the event thread until it becomes accessible to the event
thread. The tricky issue is determining when a GUI component becomes
accessible to the event thread. The pack() operation is particularly
problematic because it may operate on the component after making it
accessible to the event thread. In contrast, setVisible(true) seems
less threatening because it intuitively involves creating a single
reference to the GUI component (in a data structure recording what is
visible) and nothing more.
If we subsequent study the Swing library (which of course can change
from one release to the next) and determine these concerns are
misplaced (because, for example, the pack method is very carefully
coded not to perform any operations on the packed component after it
has been made known to the GUI, then all of these pack operations can
be moved back to their "parent" threads.
The following files were modified:
M src/edu/rice/cs/drjava/DrJavaTestCase.java
M src/edu/rice/cs/drjava/model/MultiThreadedTestCase.java
M src/edu/rice/cs/drjava/ui/config/KeyStrokeOptionComponent.java
M src/edu/rice/cs/drjava/ui/ProjectMenuTest.java
M src/edu/rice/cs/drjava/ui/MainFrameTest.java