org.jurvis.swing.actions
Class JvLongAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.jurvis.swing.actions.JvLongAction
All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action

public abstract class JvLongAction
extends AbstractAction

An abstract Action for actions that take a long time. Long actions shouldn't block the event queue because it makes the application appear hung (e.g. the screen won't repaint).

Subclasses implement the execute(java.awt.event.ActionEvent) method with the code to perform the long action. If some setup that must execute on the event thread is necessary (e.g. prompt the user), subclasses can override the preExecute(java.awt.event.ActionEvent) method. If, after executing the long action, some operations must be performed on the event thread (e.g. update models), subclasses can override the postExecute(java.awt.event.ActionEvent, java.lang.Object) method.

Author:
Neil W. Weber
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
JvLongAction()
          Construct a LongAction.
JvLongAction(String name)
          Construct a LongAction with the given name.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Method called when the user invokes this action.
abstract  Object execute(ActionEvent e)
          Execute the long running action.
 void postExecute(ActionEvent e, Object object)
          Perform any operations that must be executed after executing the long action.
 boolean preExecute(ActionEvent e)
          Perform any operations that must be executed before actually executing the long action.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JvLongAction

public JvLongAction()
Construct a LongAction.


JvLongAction

public JvLongAction(String name)
Construct a LongAction with the given name.

Parameters:
name - the name of the action
Method Detail

actionPerformed

public void actionPerformed(ActionEvent event)
Method called when the user invokes this action.

Parameters:
event - the invocation event

preExecute

public boolean preExecute(ActionEvent e)
Perform any operations that must be executed before actually executing the long action. This method will be executed on the event thread.

Parameters:
e - the invocation event
Returns:
true if the execute should be invoked.

execute

public abstract Object execute(ActionEvent e)
Execute the long running action. This method will not be executed on the event thread.

Parameters:
e - the invocation event
Returns:
the result of the action

postExecute

public void postExecute(ActionEvent e,
                        Object object)
Perform any operations that must be executed after executing the long action. This method will be executed on the event thread, so this method would be a good place to update any Swing models.

Parameters:
e - the invocation event
object - the object returned by execute


Copyright © 1999-2004 Neil W. Weber. All Rights Reserved.