vmm3d.actions
Class ToggleAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- vmm3d.actions.AbstractActionVMM
-
- vmm3d.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". ThecreateCheckBox()andcreateCheckBoxMenuItem()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. AgetState()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 itsactionPerformedmethod 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
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidactionPerformed(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.JCheckBoxcreateCheckBox()Return a JCheckBox whose selection state is synchronized with the state of this ToggleAction and with other components returned by this method and bycreateCheckBoxMenuItem().javax.swing.JCheckBoxMenuItemcreateCheckBoxMenuItem()Return a JCheckBoxMenuItem whose selection state is synchronized with the state of this ToggleAction and with other components returned by this method and bycreateCheckBox().javax.swing.JMenuItem[]getMenuItems()Returns an array containing a single JCheckBoxMenuItem.booleangetState()Gets the current state of the ToggleAction.voidsetState(boolean state)Sets the current state of the ToggleAction.
-
-
-
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 bycreateCheckBox().
-
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 bycreateCheckBoxMenuItem().
-
getMenuItems
public javax.swing.JMenuItem[] getMenuItems()
Returns an array containing a single JCheckBoxMenuItem. The menu item is constructed by callingcreateCheckBoxMenuItem().- Specified by:
getMenuItemsin interfaceActionItem- Overrides:
getMenuItemsin classAbstractActionVMM
-
-
DMelt 3.0 © DataMelt by jWork.ORG