com.autodesk.undo
Class Undo

java.lang.Object
  extended by com.autodesk.undo.Undo

public class Undo
extends java.lang.Object

This class implements an undo/redo stack for the addition and deletion of Undoable objects. This class is NOT thread safe. Undo maintains two stacks. One is the main stack and the other is the current stack. While a user is operating on a widget their actions are saved in the current stack. When they switch to another widget the contents of the current stack are moved into the main stack and saved there as a group. What this means is that while the user is typing in a a widget each key press is saved and can be undone and redone. However when they switch to another widget this collection of key presses is saved to the main stack as a group so that the whole set of key presses is undone and redone as a group.


Constructor Summary
Undo()
           
 
Method Summary
 void addUndoChangeListener(com.autodesk.undo.UndoChangeListener listener)
          Add a UndoChangeListener that will be notified when the text has changed.
 boolean atMark()
          Check if the undo queue is at it's marked position.
 boolean canRedo()
          Determine if any redo's remain.
 boolean canUndo()
          Determine if any undo's remain.
 void clear()
          Clear the Undo stack.
 void commit(boolean group)
          Commit the current stack to the main stack.
 void enable(boolean enable)
          Enable or disable pushing onto the Undo stack.
 void endGroup()
          Mark the end of a group of undo events on the stack.
protected  void fireMarkLeft()
          Notify listeners that the mark has been left.
protected  void fireMarkVisited()
          Notify listeners that the mark has been visited.
 void mark()
          Mark the current position in the undo queue.
 void printUndoStack()
          Print the contents of the Undo stack.
 void push(UndoableChange item)
          Push a new item onto the stack.
 void redo()
          Redo an undone operation.
 void removeUndoChangeListener(com.autodesk.undo.UndoChangeListener listener)
          Remove a UndoChangeListener from this instance.
 void startGroup()
          Mark the start of a group of undo events on the stack.
 void undo()
          Undo an operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Undo

public Undo()
Method Detail

push

public void push(UndoableChange item)
Push a new item onto the stack. If some undo operations have been performed since the last push(), then there will be a number of items at the top of the stack, above the stackPointer, that need to be deleted. They cannot be redone once this push has been done.


commit

public void commit(boolean group)
Commit the current stack to the main stack.

Parameters:
group - if true then whatever is on the current undo stack will be grouped so that they will be undone and redone together, apparently as a single event.

enable

public void enable(boolean enable)
Enable or disable pushing onto the Undo stack. Sometimes it is nice to disable the ability to push things onto the stack without changing a whole lot of code. This method allows pushing to be disabled until such time as it is enabled again.


clear

public void clear()
Clear the Undo stack.


canUndo

public boolean canUndo()
Determine if any undo's remain. If there is anything in the stack that can be undone then true is returned.


canRedo

public boolean canRedo()
Determine if any redo's remain. If there is anything in the stack that can be redone then true is returned.


startGroup

public void startGroup()
Mark the start of a group of undo events on the stack.


endGroup

public void endGroup()
Mark the end of a group of undo events on the stack.


undo

public void undo()
Undo an operation. This method will correct the state of the Undoable object.


redo

public void redo()
Redo an undone operation.


printUndoStack

public void printUndoStack()
Print the contents of the Undo stack. This is only used for debugging.


mark

public void mark()
Mark the current position in the undo queue. If the queue is in the middle of a group, the group is ended and a new group is started.


atMark

public boolean atMark()
Check if the undo queue is at it's marked position.


addUndoChangeListener

public void addUndoChangeListener(com.autodesk.undo.UndoChangeListener listener)
Add a UndoChangeListener that will be notified when the text has changed.

Parameters:
listener - the UndoChangeListener to add. May not be null.

removeUndoChangeListener

public void removeUndoChangeListener(com.autodesk.undo.UndoChangeListener listener)
Remove a UndoChangeListener from this instance.

Parameters:
listener - the UndoChangeListener to remove. May not be null.

fireMarkVisited

protected void fireMarkVisited()
Notify listeners that the mark has been visited.


fireMarkLeft

protected void fireMarkLeft()
Notify listeners that the mark has been left.