|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.ActionCommand
com.pietschy.command.toggle.ToggleCommand
public abstract class ToggleCommand
An ActionCommand that models selection. Each invocation of the command toggles the selection state.
Subclasses must override the handleSelection(boolean) method.
ToggleCommands can also be included in ToggleGroups to support the
notion of exclusive selection similar to ButtonGroups.
| Field Summary | |
|---|---|
static java.lang.String |
PROPERTY_SELECTED
|
| Fields inherited from class com.pietschy.command.ActionCommand |
|---|
PARAMETER_ACTION_EVENT, PARAMETER_INVOKER, PARAMETER_INVOKER_WINDOW, PARAMETER_MODIFIERS |
| Fields inherited from class com.pietschy.command.Command |
|---|
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE |
| Constructor Summary | |
|---|---|
ToggleCommand()
Creates a new anonymous instance. |
|
ToggleCommand(java.lang.String commandId)
Creates a new instance with the specified id. |
|
| Method Summary | |
|---|---|
void |
addNotify(CommandGroup parent)
Invoked whenever a command is added to a group. |
protected void |
applySelection(boolean selected)
Applies the selected state to the toggle and updates all its buttons. |
protected void |
attemptSelection(boolean selected)
Attempts to set the selected state of the command. |
protected void |
configureButtonStates(javax.swing.AbstractButton button)
Overrides the default Command.configureButtonStates() to include the configuration of
the buttons selected state. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory,
java.lang.String context)
Creates a toggle button for this command using the specified ButtonFactory and Face. |
javax.swing.AbstractButton |
createCheckBox()
Creates a checkbox for this command using the default button factory and the button face. |
javax.swing.AbstractButton |
createCheckBox(ButtonFactory factory)
Creates a checkbox for this command using the specifed button factory and the button face. |
javax.swing.AbstractButton |
createCheckBox(ButtonFactory factory,
java.lang.String context)
Creates a checkbox for this command using the specified ButtonFactory and Face. |
javax.swing.AbstractButton |
createCheckBox(java.lang.String context)
Creates a checkbox for this command using the default button factory and the specified face. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.lang.String context)
Creates a new JCheckBoxMenuItem that is bound to this command. |
protected void |
handleExecute()
This method is called whenever the Command is executed. |
protected abstract void |
handleSelection(boolean selected)
Entry for subclasses to handle the selection process. |
boolean |
isSelected()
Checks if this command is currently selected. |
void |
removeNotify(CommandGroup parent)
Invoked whenever a command is remvoved from a group. |
void |
requestDefaultIn(javax.swing.RootPaneContainer container)
Warning this method throws an UnsupportedOperationException as toggle commands are
implmented using JToggleButtons and default buttons must be instances of JButton. |
void |
setSelected(boolean selected)
Attempts to set the selected state of the command. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.pietschy.command.ActionCommandExecutor |
|---|
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener |
| Methods inherited from interface com.pietschy.command.Identifiable |
|---|
getId |
| Field Detail |
|---|
public static final java.lang.String PROPERTY_SELECTED
| Constructor Detail |
|---|
public ToggleCommand()
public ToggleCommand(java.lang.String commandId)
commandId - the id of the command.| Method Detail |
|---|
protected void configureButtonStates(javax.swing.AbstractButton button)
Command.configureButtonStates() to include the configuration of
the buttons selected state.
configureButtonStates in class Commandbutton - the button to initialize.public final void setSelected(boolean selected)
handleSelection(boolean) and configures all attachements appropriately
based on the return value.
It isn't guarenteed that the final state of the command will be the value specified. The
actual final state will be determined by handleSelection(boolean).
This property is bound and a property changed event will be fired if the selection state
changes.
selected - true if the command is being selected, false if it is
being deselected.
protected final void attemptSelection(boolean selected)
throws ToggleVetoException
handleSelection(boolean) and on return configures all attachements appropriately.
selected - the desired selection state of the command.
ToggleVetoException - if a ToggleVetoException is thrown by handleSelection(boolean).protected void applySelection(boolean selected)
This method should only be called by subclasses if the wish to by-pass all of the normal behaviour and explicitly set the state of this toggle (such as when reverting state after an undo request). This method completely ignores any exclusive group membership and will not update the state of any other toggles which may share membership with the command.
selected - the desired selection state of the command.public boolean isSelected()
true if the command is selected, false otherwise.protected void handleExecute()
ToggleGroupController.handleSelectionRequest(com.pietschy.command.toggle.ToggleCommand, boolean), otherwise setSelected(boolean) is called with
the value of !isSelected().
handleExecute in class ActionCommand
protected abstract void handleSelection(boolean selected)
throws ToggleVetoException
To deny the selection request, subclassed must throw a ToggleVetoException.
Please note that
the current state of isSelected() will not be updated until after this method
has been called and so should not be used in this method.
selected - the requested selection state.
ToggleVetoException
public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
java.lang.String context)
JCheckBoxMenuItem that is bound to this command.
createMenuItem in class Commandfactory - the factory to use when creating the button.context - the face context to use when creating the button.
JCheckBoxMenuItem for this command.
public javax.swing.AbstractButton createButton(ButtonFactory factory,
java.lang.String context)
ButtonFactory and Face.
createButton in class Commandfactory - the factory to use when creating the button.context - the face context to use when creating the button.
JToggleButton for this command.public javax.swing.AbstractButton createCheckBox()
JCheckBox for this command.public javax.swing.AbstractButton createCheckBox(java.lang.String context)
context - the face context to use when creating the button.
JCheckBox for this command.public javax.swing.AbstractButton createCheckBox(ButtonFactory factory)
factory - the factory to use when creating the button.
JCheckBox for this command.
public javax.swing.AbstractButton createCheckBox(ButtonFactory factory,
java.lang.String context)
ButtonFactory and Face.
factory - the factory to use when creating the button.context - the face context to use when creating the button.
JCheckBox for this command.public void requestDefaultIn(javax.swing.RootPaneContainer container)
UnsupportedOperationException as toggle commands are
implmented using JToggleButtons and default buttons must be instances of JButton.
requestDefaultIn in class ActionCommandcontainer - the root pane container to check.public void addNotify(CommandGroup parent)
Command
addNotify in class Commandparent - the parent group to which the command was added.public void removeNotify(CommandGroup parent)
Command
removeNotify in class Commandparent - the parent from which the command was removed.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||