org.bs.mdi
Class UndoManager

java.lang.Object
  extended byorg.bs.mdi.UndoManager

public class UndoManager
extends Object

Allows to undo or redo Actions. The UndoManager keeps track of Actions which were previously applied to the document and allows to undo or redo these Actions.


Nested Class Summary
 class UndoManager.UndoException
           
 
Field Summary
static int DEFAULT_NUM_ACTIONS
           
 
Constructor Summary
UndoManager(Document document)
          Creates a new UndoManager.
UndoManager(Document document, int limit)
          Creates a new UndoManager.
 
Method Summary
 void add(Action action, Data data)
          Tells the UndoManager that an action has occurred.
 int countAppliedActions()
          Gets the number of elements in the queue of applied actions.
 int countUndoneActions()
          Gets the number of elements in the queue of undone actions.
 void flushLogs()
          Flushes undo and redo logs.
 void flushRedoLog()
          Clears the redo log.
 void flushUndoLog()
          Clears the undo log.
 Action getLastAction()
          Returns the last action which has been applied.
 Action getLastUndoneAction()
          Returns the last action which has been undone.
 int getLimit()
          Gets the current action number limit, i.e. the maximum number of action which this UndoManager will remember.
 boolean isRedoPossible()
          Returns true if the last undone action can be redone.
 boolean isUndoPossible()
          Returns true if the last action can be undone.
 Action redo()
          Performs a redo operation.
 void removeLastAppliedAction()
          Removes the last (i.e. most recent) action in the queue of applied actions.
 void setLimit(int limit)
          Sets the current action number limit.
 Action undo()
          Performs an undo operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NUM_ACTIONS

public static int DEFAULT_NUM_ACTIONS
Constructor Detail

UndoManager

public UndoManager(Document document)
Creates a new UndoManager. This UndoManager will remember the last 64 occurred actions.

Parameters:
document - the document to be associated with this UndoManager

UndoManager

public UndoManager(Document document,
                   int limit)
Creates a new UndoManager. The UndoManager keeps track of all Actions which occur while editing a document and know how to undo/redo an action.

Parameters:
document - the document to be associated with this UndoManager
limit - the maximum number of actions to remember
Method Detail

getLimit

public int getLimit()
Gets the current action number limit, i.e. the maximum number of action which this UndoManager will remember.

Returns:
the action number limit

setLimit

public void setLimit(int limit)
Sets the current action number limit.

Parameters:
limit - the action number limit

add

public void add(Action action,
                Data data)
Tells the UndoManager that an action has occurred. The UndoManager will keep track of that action and allow it to be undone or redone, unless the action number limit is exceeded.

Parameters:
action - the action which has just occurred
data - the corresponding data object

countAppliedActions

public int countAppliedActions()
Gets the number of elements in the queue of applied actions. Usually, this number increases with every call to the add(org.bs.mdi.Action, org.bs.mdi.Data) method, except when the actions limit is exceeded.

Returns:
the number of applied actions

countUndoneActions

public int countUndoneActions()
Gets the number of elements in the queue of undone actions. Usually, this number increases with every call to the undo() method, and is set to zero when add(org.bs.mdi.Action, org.bs.mdi.Data) is called.

Returns:
the number of undone actions

removeLastAppliedAction

public void removeLastAppliedAction()
Removes the last (i.e. most recent) action in the queue of applied actions.


getLastAction

public Action getLastAction()
Returns the last action which has been applied.

Returns:
the last action that has been applied to the document

getLastUndoneAction

public Action getLastUndoneAction()
Returns the last action which has been undone.

Returns:
the last action that has been undone to the document

undo

public Action undo()
            throws UndoManager.UndoException
Performs an undo operation.

Returns:
the action which has been undone
Throws:
UndoManager.UndoException

redo

public Action redo()
            throws UndoManager.UndoException
Performs a redo operation.

Returns:
the action which has been redone.
Throws:
UndoManager.UndoException

flushUndoLog

public void flushUndoLog()
Clears the undo log. Deletes the list of actions which have been applied to the document until now. These actions cannot be undone any more.


flushRedoLog

public void flushRedoLog()
Clears the redo log. Deletes the list of actions which have been undone until now. These actions cannot be redone any more.


flushLogs

public void flushLogs()
Flushes undo and redo logs. See flushUndoLog() and flushRedoLog().


isUndoPossible

public boolean isUndoPossible()
Returns true if the last action can be undone.

Returns:
true if an undo is possible

isRedoPossible

public boolean isRedoPossible()
Returns true if the last undone action can be redone.

Returns:
true if a redo is possible