edu.neu.ccs.gui
Class SimpleThreadedAction

java.lang.Object
  extended byjavax.swing.AbstractAction
      extended byedu.neu.ccs.gui.SimpleThreadedAction
All Implemented Interfaces:
Action, ActionListener, ChangeListener, Cloneable, EventListener, PropertyChangeListener, Serializable

public abstract class SimpleThreadedAction
extends AbstractAction
implements ChangeListener, PropertyChangeListener

SimpleThreadedAction is an abstract class that is a simple extension of the Java AbstractAction class. It is used to simplify the programming interface for an object representing a GUI action that requires no parameters and that must be performed in a new separate thread each time the action is executed.

In a manner parallel to SimpleAction, to implement a SimpleThreadedAction, one must extend the abstract class and define the following method with no parameters:

    public void perform()

The SimpleThreadedAction class has a predefined method

    public void performThreaded()

that will execute the perform() in a separate thread each time that it is invoked. The action of the class is performed by calling the method performThreaded() rather than the method perform(). In particular, if a button is constructed from a SimpleThreadedAction, its behavior will automatically run in a separate threaded.

For convenience, this class also implements ChangeListener and PropertyChangeListener

This class is inspired by the class ThreadedAction but is programmed directly without use of that class.

Version:
2.6
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.AbstractAction
 
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
SimpleThreadedAction()
          Constructs a simple threaded action with no name or icon.
SimpleThreadedAction(String name)
          Constructs a simple threaded action with the given name but no icon.
SimpleThreadedAction(String name, Icon icon)
          Constructs a simple threaded action with the given name and icon.
 
Method Summary
 void actionPerformed(ActionEvent evt)
          Performs this action by calling the performThreaded method which executes the simplified perform method in a separate thread
abstract  void perform()
          Performs the tasks encapsulated by this action.
 void performThreaded()
          Executes the perform method in a separate thread.
 void propertyChange(PropertyChangeEvent evt)
          Performs this property change action by calling the performThreaded method which executes the simplified perform method in a separate thread
 void stateChanged(ChangeEvent evt)
          Performs this state change action by calling the performThreaded method which executes the simplified perform method in a separate thread
 
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

SimpleThreadedAction

public SimpleThreadedAction()
Constructs a simple threaded action with no name or icon.


SimpleThreadedAction

public SimpleThreadedAction(String name)
Constructs a simple threaded action with the given name but no icon.

Parameters:
name - the name for this action

SimpleThreadedAction

public SimpleThreadedAction(String name,
                            Icon icon)
Constructs a simple threaded action with the given name and icon.

Parameters:
name - the name for this action
icon - the icon for this action
Method Detail

actionPerformed

public final void actionPerformed(ActionEvent evt)
Performs this action by calling the performThreaded method which executes the simplified perform method in a separate thread

Specified by:
actionPerformed in interface ActionListener
Parameters:
evt - an object encapsulating an event that triggered this action this parameter is ignored

stateChanged

public final void stateChanged(ChangeEvent evt)
Performs this state change action by calling the performThreaded method which executes the simplified perform method in a separate thread

Specified by:
stateChanged in interface ChangeListener
Parameters:
evt - an object encapsulating an event that triggered this action this parameter is ignored

propertyChange

public final void propertyChange(PropertyChangeEvent evt)
Performs this property change action by calling the performThreaded method which executes the simplified perform method in a separate thread

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
evt - an object encapsulating an event that triggered this action this parameter is ignored

perform

public abstract void perform()

Performs the tasks encapsulated by this action.

Subclasses should override this method to provide tasks this action performs.

If this method is called directly, the tasks will be executed in the same thread. To cause the tasks to be performed in a separate thread, call the method performThreaded.


performThreaded

public final void performThreaded()

Executes the perform method in a separate thread.

To utilize this action algorithmically, this method should be called rather than the perform method.