Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.pietschy.command.Command
org.pietschy.command.ActionCommand
org.pietschy.command.ToggleCommand
public abstract class ToggleCommand
extends ActionCommand
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 | |
| |
| |
| |
|
Method Summary | |
void |
|
protected void |
|
protected void |
|
protected void |
|
AbstractButton |
|
AbstractButton |
|
AbstractButton |
|
AbstractButton |
|
AbstractButton |
|
JMenuItem |
|
protected void |
|
protected abstract void |
|
boolean | |
void |
|
void |
|
void |
|
Methods inherited from class org.pietschy.command.ActionCommand | |
addCommandListener , addInterceptor , areEqual , attach , configureButtonStates , detach , execute , execute , getActionAdapter , getActionAdapter , getActionCommand , getActionEvent , getHint , getHint , getHints , getInvoker , getInvokerWindow , getModifiers , handleExecute , installShortCut , installShortCut , postExecute , preExecute , putHint , putHints , removeCommandListener , removeInterceptor , requestDefautIn , setActionCommand , uninstallShortCut , uninstallShortCut |
public ToggleCommand()
Creates a new anonymous ToggleCommand. Anonymous commands can't must be fully programatically generated and can't be exported to command containers.
public ToggleCommand(String commandId)
Creates a new toggle command with the specified Id that is bound toCommandManager.defaultInstance
.
- Parameters:
commandId
- the id of the command.
public ToggleCommand(CommandManager commandManager)
Creates a new anonymous toggle command bound to the specifiedCommandManager.defaultInstance()
.
public ToggleCommand(CommandManager commandManager, String commandId)
Creates a new toggle command with the specified Id that is bound to the specifiedCommandManager
.
- Parameters:
commandManager
- theCommandManager
to which the command belongs.commandId
- the id of the command.
protected void applySelection(boolean selected)
Applies the selected state to the toggle and updates all its buttons. This method also fires a property change event if the new selection has changed from the previous state. 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.
- Parameters:
selected
- the desired selection state of the command.
protected final void attemptSelection(boolean selected) throws ToggleVetoException
Attempts to set the selected state of the command. This method delegats the selection request tohandleSelection(boolean)
and on return configures all attachements appropriately.
- Parameters:
selected
- the desired selection state of the command.
- Throws:
ToggleVetoException
- if a ToggleVetoException is thrown byhandleSelection(boolean)
.
protected void configureButtonStates(AbstractButton button)
Overrides the defaultCommand.configureButtonStates(AbstractButton)
to include the configuration of the buttonsselected
state.
- Overrides:
- configureButtonStates in interface ActionCommand
- Parameters:
button
- the button to initialize.
public AbstractButton createButton(ButtonFactory factory, String faceId)
Creates a toggle button for this command using the specifiedButtonFactory
andFace
.
- Overrides:
- createButton in interface Command
- Returns:
- a new
JToggleButton
for this command.
public AbstractButton createCheckBox()
Creates a checkbox for this command using the default button factory and the button face.
- Returns:
- a new
JCheckBox
for this command.
public AbstractButton createCheckBox(String faceName)
Creates a checkbox for this command using the default button factory and the specified face.
- Returns:
- a new
JCheckBox
for this command.
public AbstractButton createCheckBox(ButtonFactory factory)
Creates a checkbox for this command using the specifed button factory and the button face.
- Returns:
- a new
JCheckBox
for this command.
public AbstractButton createCheckBox(ButtonFactory factory, String faceId)
Creates a checkbox for this command using the specifiedButtonFactory
andFace
.
- Returns:
- a new
JCheckBox
for this command.
public JMenuItem createMenuItem(MenuFactory factory, String faceId)
Creates a newJCheckBoxMenuItem
that is bound to this command.
- Overrides:
- createMenuItem in interface Command
- Parameters:
factory
-faceId
-
- Returns:
- a new
JCheckBoxMenuItem
for this command.
protected void handleExecute()
This method is called whenever the Command is executed. If this command is a member of and exclusive group, then the selection request is delegated to the group by callingToggleGroupController.handleSelectionRequest(ToggleCommand,boolean)
, otherwisesetSelected(boolean)
is called with the value of !isSelected()
.
- Overrides:
- handleExecute in interface ActionCommand
protected abstract void handleSelection(boolean selected) throws ToggleVetoException
Entry for subclasses to handle the selection process. When a request to change the selection is made, this method will be called. To deny the selection request, subclassed must throw aToggleVetoException
. Please note that the current state ofisSelected()
will not be updated until after this method has been called and so should not be used in this method.
- Parameters:
selected
- the requested selection state.
public boolean isSelected()
public void removeNotify(CommandGroup parent)
- Overrides:
- removeNotify in interface Command
public void requestDefautIn(RootPaneContainer container)
Warning this method does nothing as toggle commands are implmented usingJToggleButton
s and default buttons must be instances ofJButton
.
- Overrides:
- requestDefautIn in interface ActionCommand
public final void setSelected(boolean selected)
Attempts to set the selected state of the command. This method delegats the selection request tohandleSelection(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 byhandleSelection(boolean)
.
- Parameters:
selected
- true if the command is being selected, false if it is being deselected.