|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.pietschy.command.Command
org.pietschy.command.ActionCommand
org.pietschy.command.ToggleCommand
public abstract class ToggleCommand
The toggle command class implements a command that has a selected state. Each
execution of the command will toggle the selected state of the command. Subclasses
should override the handleSelection(boolean)
method.
Field Summary |
---|
Fields inherited from class org.pietschy.command.ActionCommand |
---|
HINT_ACTION_EVENT, HINT_INVOKER, HINT_INVOKER_WINDOW, HINT_MODIFIERS |
Fields inherited from class org.pietschy.command.Command |
---|
internalLog, listenerList, pcs |
Constructor Summary | |
---|---|
ToggleCommand()
Creates a new anonymous ToggleCommand. |
|
ToggleCommand(CommandManager commandManager)
Creates a new anonymous toggle command bound to the specified CommandManager.defaultInstance() . |
|
ToggleCommand(CommandManager commandManager,
java.lang.String commandId)
Creates a new toggle command with the specified Id that is bound to the specified CommandManager . |
|
ToggleCommand(java.lang.String commandId)
Creates a new toggle command with the specified Id that is bound to CommandManager.defaultInstance . |
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(javax.swing.AbstractButton) to include the configuration of
the buttons selected state. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory,
java.lang.String faceId)
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 faceId)
Creates a checkbox for this command using the specified ButtonFactory and Face . |
javax.swing.AbstractButton |
createCheckBox(java.lang.String faceName)
Creates a checkbox for this command using the default button factory and the specified face. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.lang.String faceId)
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()
|
void |
removeNotify(CommandGroup parent)
Invoked whenever a command is remvoved from a group. |
void |
requestDefautIn(javax.swing.RootPaneContainer container)
Warning this method does nothing as toggle commands are implmented using JToggleButton s 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 org.pietschy.command.ActionCommand |
---|
addCommandListener, addInterceptor, areEqual, attach, detach, execute, execute, getActionAdapter, getActionAdapter, getActionCommand, getActionEvent, getHint, getHint, getHints, getInvoker, getInvokerWindow, getModifiers, installShortCut, installShortCut, postExecute, preExecute, putHint, putHints, removeCommandListener, removeInterceptor, setActionCommand, uninstallShortCut, uninstallShortCut |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.pietschy.command.ActionCommandExecutor |
---|
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener |
Constructor Detail |
---|
public ToggleCommand()
public ToggleCommand(java.lang.String commandId)
CommandManager.defaultInstance
.
commandId
- the id of the command.public ToggleCommand(CommandManager commandManager)
CommandManager.defaultInstance()
.
public ToggleCommand(CommandManager commandManager, java.lang.String commandId)
CommandManager
.
commandManager
- the CommandManager
to which the command belongs.commandId
- the id of the command.Method Detail |
---|
protected void configureButtonStates(javax.swing.AbstractButton button)
Command.configureButtonStates(javax.swing.AbstractButton)
to include the configuration of
the buttons selected
state.
configureButtonStates
in class ActionCommand
button
- 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)
.
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()
protected void handleExecute()
ToggleGroupController.handleSelectionRequest(org.pietschy.command.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 faceId)
JCheckBoxMenuItem
that is bound to this command.
createMenuItem
in class Command
factory
- faceId
-
JCheckBoxMenuItem
for this command.public javax.swing.AbstractButton createButton(ButtonFactory factory, java.lang.String faceId)
ButtonFactory
and Face
.
createButton
in class Command
JToggleButton
for this command.public javax.swing.AbstractButton createCheckBox()
JCheckBox
for this command.public javax.swing.AbstractButton createCheckBox(java.lang.String faceName)
JCheckBox
for this command.public javax.swing.AbstractButton createCheckBox(ButtonFactory factory)
JCheckBox
for this command.public javax.swing.AbstractButton createCheckBox(ButtonFactory factory, java.lang.String faceId)
ButtonFactory
and Face
.
JCheckBox
for this command.public void requestDefautIn(javax.swing.RootPaneContainer container)
JToggleButton
s and default buttons must be instances of JButton
.
requestDefautIn
in class ActionCommand
container
- the root pane container to check.public void addNotify(CommandGroup parent)
Command
addNotify
in class Command
parent
- the parent to which the command was added.public void removeNotify(CommandGroup parent)
Command
removeNotify
in class Command
parent
- the parent from which the command was removed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |