vmm.actions
Class ToggleAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by vmm.actions.AbstractActionVMM
          extended by vmm.actions.ToggleAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, ActionItem

public class ToggleAction
extends AbstractActionVMM

A ToggleAction is an Action that has a boolean-valued property named "ToggleState". The createCheckBox() and createCheckBoxMenuItem() methods return components whose state is synchronized with each other and with the state of this ToggleAction. When one of these components generates an ActionEvent, the states of the ToggleAction and of all the synchronized components are changed to match. A getState() method is provided as a convenience to make it possible to determine the current state. (Note that this is a concrete subclass of AbstractAction, but its actionPerformed method is defined to do nothing. It is still possible to override this method if you want to perform some action when the state changes.)

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
ToggleAction()
          Create a ToggleAction with no name or icon and initial state set to false.
ToggleAction(java.lang.String name)
          Create a ToggleAction with a given name but no icon and initial state set to false.
ToggleAction(java.lang.String name, boolean checked)
          Create a ToggleAction with a specified name and initial state, and no icon.
ToggleAction(java.lang.String name, javax.swing.Icon icon)
          Create a ToggleAction with a specified name and icon and with state initially set to false.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          This method implements the abstract method that is inherited from the AbstractAction class, but it is defined to do nothing.
 javax.swing.JCheckBox createCheckBox()
          Return a JCheckBox whose selection state is synchronized with the state of this ToggleAction and with other components returned by this method and by createCheckBoxMenuItem().
 javax.swing.JCheckBoxMenuItem createCheckBoxMenuItem()
          Return a JCheckBoxMenuItem whose selection state is synchronized with the state of this ToggleAction and with other components returned by this method and by createCheckBox().
 javax.swing.JMenuItem[] getMenuItems()
          Returns an array containing a single JCheckBoxMenuItem.
 boolean getState()
          Gets the current state of the ToggleAction.
 void setState(boolean state)
          Sets the current state of the ToggleAction.
 
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

ToggleAction

public ToggleAction()
Create a ToggleAction with no name or icon and initial state set to false.


ToggleAction

public ToggleAction(java.lang.String name)
Create a ToggleAction with a given name but no icon and initial state set to false.

Parameters:
name - If non-null, this string will be set as the Name property of the Action.

ToggleAction

public ToggleAction(java.lang.String name,
                    boolean checked)
Create a ToggleAction with a specified name and initial state, and no icon.

Parameters:
name - If non-null, this string will be set as the Name property of the Action.
checked - The initial value of the "ToggleState" property.

ToggleAction

public ToggleAction(java.lang.String name,
                    javax.swing.Icon icon)
Create a ToggleAction with a specified name and icon and with state initially set to false.

Parameters:
name - If non-null, this string will be set as the Name property of the Action.
icon - If non-null this icon will be set as the Icon property of the Action.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
This method implements the abstract method that is inherited from the AbstractAction class, but it is defined to do nothing. If you want to perform some action when the state of the ToggleAction is changed because of a user action, you can override this method. Note that this method is NOT called when the state is changed programmatically.


getState

public boolean getState()
Gets the current state of the ToggleAction. This is just the boolean value associated with the "ToggleState" property of the Action.


setState

public void setState(boolean state)
Sets the current state of the ToggleAction. The state is just the "ToggleState" property of the Action; this method is just a convenience method that sets that property.


createCheckBoxMenuItem

public javax.swing.JCheckBoxMenuItem createCheckBoxMenuItem()
Return a JCheckBoxMenuItem whose selection state is synchronized with the state of this ToggleAction and with other components returned by this method and by createCheckBox().


createCheckBox

public javax.swing.JCheckBox createCheckBox()
Return a JCheckBox whose selection state is synchronized with the state of this ToggleAction and with other components returned by this method and by createCheckBoxMenuItem().


getMenuItems

public javax.swing.JMenuItem[] getMenuItems()
Returns an array containing a single JCheckBoxMenuItem. The menu item is constructed by calling createCheckBoxMenuItem().

Specified by:
getMenuItems in interface ActionItem
Overrides:
getMenuItems in class AbstractActionVMM