edu.mit.ai.psg.ui.outliner
Class OutlineCommand
java.lang.Object
|
+--edu.mit.ai.psg.ui.outliner.OutlineCommand
- public abstract class OutlineCommand
- extends Object
- implements ActionListener, Runnable
Used for popup menu commands. Provides an ActionListener with
methods that run the command in a separate thread so the AWT
thread can continue to update the screen. Sets the cursor to the
wait cursor while it is running. Derived classes must implement
runCommand() to perform the command in the new thread, and
queue work for the AWT thread to update the UI by calling
SwingUtilities.invokeLater(java.lang.Runnable) or SwingUtilities.invokeAndWait(java.lang.Runnable)
For example:
. void addPopupMenuTitle(final PopupMenu menu, final OutlineNode node,
. final TreePath treePath, final JTree jTree);
. OutlineCommand.installCommand
. (menu, "Compute",
. new OutlineCommand(jTree, "MyProgram-Compute") {
. protected void runCommand() throws InterruptedException {
. compute...
. SwingUtilities.invokeAndWait(new Runnable() {
. public void run() { update display... }); }});
- See Also:
OutlineRenderer.addPopupMenuItems(java.awt.PopupMenu, edu.mit.ai.psg.ui.outliner.OutlineNode, javax.swing.tree.TreePath, javax.swing.JTree)
|
Constructor Summary |
OutlineCommand(JTree jTree,
String threadName)
Initializes command; if this command is invoked,
jTree is the JTree whose cursor becomes the wait
cursor while this command runs in another thread named threadName. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
myJTree
protected final JTree myJTree
myThreadName
protected final String myThreadName
waitCursor
public static Cursor waitCursor
OutlineCommand
public OutlineCommand(JTree jTree,
String threadName)
- Initializes command; if this command is invoked,
jTree is the JTree whose cursor becomes the wait
cursor while this command runs in another thread named threadName.
installCommand
public static void installCommand(Menu menu,
String menuItemString,
ActionListener outlineCommand)
- convenience procedure to install a
MenuItem displayed
with menuItemString that performs
outlineCommand when invoked
installDisabledCommand
public static void installDisabledCommand(Menu menu,
String menuItemString)
actionPerformed
public void actionPerformed(ActionEvent event)
- creates and starts a new thread that calls
run()
- Specified by:
- actionPerformed in interface ActionListener
run
public void run()
- saves old JTree cursor and calls
runCommand() and then
restores old JTree cursor upon exit.
- Specified by:
- run in interface Runnable
runCommand
protected abstract void runCommand()
- implement this method to perform command when invoked. It is run in
its own thread, so accessing any (mutable) part of UI objects, including
OutlineNodes, should be queued for the AWT thread through
SwingUtilities.invokeLater(java.lang.Runnable) or
SwingUtilities.invokeAndWait(java.lang.Runnable).
invokeSwingAndWait
protected void invokeSwingAndWait(Runnable doUpdate)
try { SwingUtilities.invokeAndWait(doUpate); }
catch (InterruptedException e) {}
catch (InvocationException e) { e.printStackTrace(); }