org.pietschy.command.undo
Class UndoableToggleCommand

java.lang.Object
  extended by org.pietschy.command.Command
      extended by org.pietschy.command.ActionCommand
          extended by org.pietschy.command.ToggleCommand
              extended by org.pietschy.command.undo.UndoableToggleCommand
All Implemented Interfaces:
ActionCommandExecutor, UndoableEventSource
Direct Known Subclasses:
SimpleUndoToggle

public abstract class UndoableToggleCommand
extends ToggleCommand
implements UndoableEventSource

UndoableToggleCommands provide a default implementation for toggle commands that can be undone. UndoableToggleCommands implement UndoableEventSource and can be monitored by an UndoController.

Subclasses must implement performEdit(boolean) to handle the selection process.

See Also:
performEdit(boolean), ToggleCommand.applySelection(boolean)

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
  UndoableToggleCommand()
          Creates a new anonymous UndoableToggleCommand.
protected UndoableToggleCommand(CommandManager commandManager, java.lang.String commandId)
          Creates a new command with the specified id that is bound to the specified CommandManager.
  UndoableToggleCommand(java.lang.String commandId)
          Creates a new command with the speicifed Id that is bound to the CommandManager.defaultInstance().
 
Method Summary
 void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
          Adds a new UndoableEditListener to this command.
 javax.swing.event.UndoableEditListener[] getUndoableEditListeners()
          Gets the UndoableEditListeners regstered with this command.
protected  void handleSelection(boolean selected)
          Delegates to performEdit(boolean)
protected abstract  javax.swing.undo.UndoableEdit performEdit(boolean selected)
          Subclasses must override to perform the actual edit.
protected  void postEdit(javax.swing.undo.UndoableEdit e)
          Notifies all the UndoableEditListeners of the undoable event.
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
          Removes an UndoableEditListener from this command.
 
Methods inherited from class org.pietschy.command.ToggleCommand
addNotify, applySelection, attemptSelection, configureButtonStates, createButton, createCheckBox, createCheckBox, createCheckBox, createCheckBox, createMenuItem, handleExecute, isSelected, removeNotify, requestDefautIn, setSelected
 
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 org.pietschy.command.Command
addFace, addHoverListener, addNewFace, addPropertyChangeListener, addPropertyChangeListener, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, export, faceExists, fireHoverEnded, fireHoverStarted, getAccelerator, getAlternativeFaceNames, getButtonFactory, getButtonIn, getCommandManager, getDefaultFace, getDefaultFace, getDescription, getFace, getFace, getIcon, getId, getLongDescription, getMenuFactory, getMnemonic, getMnemonicIndex, getProperty, getProperty, getPropertyNames, getSelectedIcon, getText, getTextPosition, getToolbarFactory, initCommandManager, installFace, isAnonymous, isAttachedTo, isEnabled, isVisible, putProperty, removeHoverListener, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setAccelerator, setButtonFactory, setDescription, setEnabled, setIcon, setLongDescription, setMenuFactory, setMnemonic, setMnemonicIndex, setSelectedIcon, setText, setTextPosition, setToolbarFactory, setVisible, toString
 
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

UndoableToggleCommand

public UndoableToggleCommand()
Creates a new anonymous UndoableToggleCommand. Anonymous commands must be fully programatically generated and can only be added to groups manually by calling groupCommand.installFace(myAnonymousCommand).


UndoableToggleCommand

public UndoableToggleCommand(java.lang.String commandId)
Creates a new command with the speicifed Id that is bound to the CommandManager.defaultInstance().


UndoableToggleCommand

protected UndoableToggleCommand(CommandManager commandManager,
                                java.lang.String commandId)
Creates a new command with the specified id that is bound to the specified CommandManager.

Method Detail

handleSelection

protected final void handleSelection(boolean selected)
                              throws ToggleVetoException
Delegates to performEdit(boolean)

Specified by:
handleSelection in class ToggleCommand
Parameters:
selected - the new desired state of the toggle
Throws:
ToggleVetoException - if the new state can't be fullfilled.

performEdit

protected abstract javax.swing.undo.UndoableEdit performEdit(boolean selected)
                                                      throws ToggleVetoException
Subclasses must override to perform the actual edit. This method behaves similar to ToggleCommand.handleSelection(boolean) in that it can throw a ToggleVetoException to cancel the edit.

Please note that the edit object should call ToggleCommand.applySelection(boolean) to update the state of this command without causing a new UndoableEdit to be created. For example

 class MyToggle.ToggleUndoableEdit extends UndoableEdit
 {
    public void undo()
    {
       // undo any command specific stuff...
       ...
       // and reset our state without causeing any side effects..
       applySelection(oldState);
    }
 }
 

Parameters:
selected - the new selected state of the command.
Returns:
an UndoableEdit object that can undo and redo the commands action.
Throws:
ToggleVetoException - if the toggle action can't proceed.
See Also:
ToggleCommand.applySelection(boolean)

postEdit

protected void postEdit(javax.swing.undo.UndoableEdit e)
Notifies all the UndoableEditListeners of the undoable event.

Parameters:
e - the undoable event.

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
Adds a new UndoableEditListener to this command.

Specified by:
addUndoableEditListener in interface UndoableEventSource
Parameters:
l - the listener to installFace.
See Also:
UndoController

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
Removes an UndoableEditListener from this command.

Specified by:
removeUndoableEditListener in interface UndoableEventSource
Parameters:
l - the listener to remove.
See Also:
UndoController

getUndoableEditListeners

public javax.swing.event.UndoableEditListener[] getUndoableEditListeners()
Gets the UndoableEditListeners regstered with this command.

Specified by:
getUndoableEditListeners in interface UndoableEventSource
See Also:
UndoController