org.pietschy.command.undo
Class UndoController

java.lang.Object
  extended by org.pietschy.command.undo.UndoController
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.UndoableEditListener

public class UndoController
extends java.lang.Object
implements javax.swing.event.UndoableEditListener

The UndoController monitors instances of UndoableEventSource and manages undo and redo via its undo and redo commands. The most notable instance of UndoableEventSource is UndoableActionCommand.

The undo state is managed by an instance of UndoContext and can be changed at any time. This allows undo state to be split into separate contexts, such as for a multi file editor.

Version:
$Revision: 1.7 $
Author:
andrewp
See Also:
UndoableEventSource, UndoableActionCommand

Constructor Summary
UndoController(CommandManager commandManager)
          Creates a new undo controller.
UndoController(CommandManager commandManager, java.lang.String undoCommandId, java.lang.String redoCommandId)
          Create a new controller using the specified ids for the undo and redo commands
UndoController(CommandManager commandManager, UndoContext undoContext)
          Creates a new controller using the specified UndoContext.
UndoController(CommandManager commandManager, UndoContext undoContext, java.lang.String undoCommandId, java.lang.String redoCommandId)
          Create a new controller using the specified UndoContext and ids for the undo and redo commands
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
           
 boolean canRedo()
           
 boolean canUndo()
           
protected  void exportCommands()
           
 CommandManager getCommandManager()
           
 ActionCommand getRedoCommand()
          Gets an ActionCommand that when invoked will redo the last undone UndoableEditEvent.
 ActionCommand getUndoCommand()
          Gets an ActionCommand that when invoked will undo the last registered UndoableEditEvent.
 UndoContext getUndoContext()
          Gets the current UndoContext in use.
protected  void redo()
           
 void registerUndoableCommand(UndoableEventSource command)
          Manually registers an UndoableEventSource with this controller.
 void removeChangeListener(javax.swing.event.ChangeListener l)
           
 void setUndoContext(UndoContext undoContext)
          Configures the controller to use the specified UndoContext.
protected  void undo()
           
 void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
          Notifies the controller that an undoable event has happened.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UndoController

public UndoController(CommandManager commandManager)
Creates a new undo controller. The command id used for the undo command will be "gui-commands.undo" and the id used for the redo command will be "gui-commands.redo"

Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.

UndoController

public UndoController(CommandManager commandManager,
                      UndoContext undoContext)
Creates a new controller using the specified UndoContext. The command id used for the undo command will be "gui-commands.undo" and the id used for the redo command will be "gui-commands.redo"

Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.
undoContext - the UndoContext to use.

UndoController

public UndoController(CommandManager commandManager,
                      java.lang.String undoCommandId,
                      java.lang.String redoCommandId)
Create a new controller using the specified ids for the undo and redo commands

Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.
undoCommandId - the id to use for the undo command.
redoCommandId - the id to use for the redo command.

UndoController

public UndoController(CommandManager commandManager,
                      UndoContext undoContext,
                      java.lang.String undoCommandId,
                      java.lang.String redoCommandId)
Create a new controller using the specified UndoContext and ids for the undo and redo commands

Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.
undoContext - the UndoContext to use.
undoCommandId - the id to use for the undo command.
redoCommandId - the id to use for the redo command.
Method Detail

exportCommands

protected void exportCommands()

getCommandManager

public CommandManager getCommandManager()

registerUndoableCommand

public void registerUndoableCommand(UndoableEventSource command)
Manually registers an UndoableEventSource with this controller.

Parameters:
command - the UndoableEventSource to register.
See Also:
UndoableEventSource, UndoableActionCommand

undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
Notifies the controller that an undoable event has happened. This event will be added to the current UndoContext and the undo and redo commands udpated.

Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener
Parameters:
e - the UndoableEditEvent.

setUndoContext

public void setUndoContext(UndoContext undoContext)
Configures the controller to use the specified UndoContext. The undo and redo commands will update according the the state of the context and all new UndoableEditEvents will be registed with it.

Parameters:
undoContext - the undo context to use.

getUndoContext

public UndoContext getUndoContext()
Gets the current UndoContext in use.

Returns:
the current UndoContext in use by the controller.

undo

protected void undo()

redo

protected void redo()

getUndoCommand

public ActionCommand getUndoCommand()
Gets an ActionCommand that when invoked will undo the last registered UndoableEditEvent.

Returns:
an ActionCommand that will undo the the last registered UndoableEditEvent.

getRedoCommand

public ActionCommand getRedoCommand()
Gets an ActionCommand that when invoked will redo the last undone UndoableEditEvent.

Returns:
an ActionCommand that will undo the the last undone UndoableEditEvent.

canUndo

public boolean canUndo()

canRedo

public boolean canRedo()

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)