Class AbstractToggleCommand
- java.lang.Object
-
- javax.swing.AbstractAction
-
- ca.cgjennings.apps.arkham.commands.AbstractCommand
-
- ca.cgjennings.apps.arkham.commands.AbstractToggleCommand
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
public abstract class AbstractToggleCommand extends AbstractCommand
An abstract base class for commands that toggle a state when selected. Note that whether a toggle command is selected or not is determined by the value of the action'sSELECTED_KEY
key. It is up to the subclass to set this key to an appropriate initial value. (TheisSelected()
method is simply a convenience that reads the value of this key and casts the result to a boolean value.)- Since:
- 3.0
- Author:
- Chris Jennings
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class ca.cgjennings.apps.arkham.commands.AbstractCommand
BUTTON_ID_KEY
-
-
Constructor Summary
Constructors Constructor Description AbstractToggleCommand()
Creates a command with no predefined name or icon.AbstractToggleCommand(java.lang.String nameKey)
Defines a command using a name determined by the specified string key.AbstractToggleCommand(java.lang.String nameKey, java.lang.String iconResource)
Defines a command using a name determined by the specified string key and an icon loaded from the given icon resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isSelected()
Returnstrue
if the command is selected, that is, if the toggle state is currently enabled.void
setSelected(boolean selected)
Sets whether the command is selected.void
toggle()
If the command is enabled, toggles the selected state of the command by generating a fake action event.-
Methods inherited from class ca.cgjennings.apps.arkham.commands.AbstractCommand
getAccelerator, getCommandString, getIcon, getName, setAccelerator, setIcon, setIcon, setName, setNameKey, toString, update
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Constructor Detail
-
AbstractToggleCommand
public AbstractToggleCommand()
Creates a command with no predefined name or icon.
-
AbstractToggleCommand
public AbstractToggleCommand(java.lang.String nameKey)
Defines a command using a name determined by the specified string key.- Parameters:
nameKey
- the localized text key for the command name- See Also:
AbstractCommand.setNameKey(java.lang.String)
-
AbstractToggleCommand
public AbstractToggleCommand(java.lang.String nameKey, java.lang.String iconResource)
Defines a command using a name determined by the specified string key and an icon loaded from the given icon resource.- Parameters:
nameKey
- the localized text key for the command nameiconResource
- the resource file to load an icon from- See Also:
AbstractCommand.setNameKey(java.lang.String)
,AbstractCommand.setIcon(javax.swing.Icon)
-
-
Method Detail
-
isSelected
public final boolean isSelected()
Returnstrue
if the command is selected, that is, if the toggle state is currently enabled.- Returns:
true
if the command is selected
-
setSelected
public final void setSelected(boolean selected)
Sets whether the command is selected. This should be used to set the command's initial state. It does not cause the command to be performed.- Parameters:
selected
- iftrue
, the command will be selected
-
toggle
public final void toggle()
If the command is enabled, toggles the selected state of the command by generating a fake action event.
-
-