com.algosome.common.undoable
Class ChangeManager

java.lang.Object
  extended by com.algosome.common.undoable.ChangeManager
All Implemented Interfaces:
Changeable, ChangeCando, IChangeManager

public class ChangeManager
extends java.lang.Object
implements ChangeCando, Changeable, IChangeManager

Manages a Queue of Changables to perform undo and/or redo operations. Clients can add implementations of the Changeable class to this class, and it will manage undo/redo as a Queue.

Author:
Greg Cope

Constructor Summary
ChangeManager()
          Creates a new ChangeManager object which is initially empty.
ChangeManager(ChangeManager manager)
          Creates a new ChangeManager which is a duplicate of the parameter in both contents and current index.
 
Method Summary
 void addChangeable(Changeable changeable)
          Adds a Changeable to manage.
 void addListener(ChangeManagerListener l)
           
 void backtrackTo(Changeable changeable)
          Backtracks to the parameter changeable, or the start if the parameter does not exists in this list (changeable and elements in the list are compared by the equals method)
 boolean canRedo()
          Determines if a redo can be performed.
 boolean canUndo()
          Determines if an undo can be performed.
 void clear()
          Clears all Changables contained in this manager.
 void forwardTo(Changeable changeable)
          Fastforwards to the parameter changeable, or the end if the parameter does not exists in this list (changeable and elements in the list are compared by the equals method)
 java.util.List<ChangeManagerListener> getListeners()
           
 ChangeManagerModel getModel()
           
 void redo()
          Redoes the Changable at the current index.
 void removeListener(ChangeManagerListener l)
           
static void setMaxSize(int size)
          Sets the max size for this.
 java.lang.String toString()
           
 void undo()
          Undoes the Changeable at the current index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChangeManager

public ChangeManager()
Creates a new ChangeManager object which is initially empty.


ChangeManager

public ChangeManager(ChangeManager manager)
Creates a new ChangeManager which is a duplicate of the parameter in both contents and current index.

Parameters:
manager -
Method Detail

getListeners

public java.util.List<ChangeManagerListener> getListeners()

setMaxSize

public static void setMaxSize(int size)
Sets the max size for this.

Parameters:
size - The max size, or -1 for unlimited.

clear

public void clear()
Clears all Changables contained in this manager.


addChangeable

public void addChangeable(Changeable changeable)
Adds a Changeable to manage.

Parameters:
changeable -

canUndo

public boolean canUndo()
Determines if an undo can be performed.

Specified by:
canUndo in interface ChangeCando
Returns:

canRedo

public boolean canRedo()
Determines if a redo can be performed.

Specified by:
canRedo in interface ChangeCando
Returns:

undo

public void undo()
Undoes the Changeable at the current index.

Specified by:
undo in interface Changeable
Throws:
java.lang.IllegalStateException - if canUndo returns false.

backtrackTo

public void backtrackTo(Changeable changeable)
Backtracks to the parameter changeable, or the start if the parameter does not exists in this list (changeable and elements in the list are compared by the equals method)

Parameters:
changeable -

forwardTo

public void forwardTo(Changeable changeable)
Fastforwards to the parameter changeable, or the end if the parameter does not exists in this list (changeable and elements in the list are compared by the equals method)

Parameters:
changeable -

redo

public void redo()
Redoes the Changable at the current index.

Specified by:
redo in interface Changeable
Throws:
java.lang.IllegalStateException - if canRedo returns false.

addListener

public void addListener(ChangeManagerListener l)
Parameters:
l -

removeListener

public void removeListener(ChangeManagerListener l)
Parameters:
l -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getModel

public ChangeManagerModel getModel()