|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbe.ugent.caagt.swirl.undoredo.UndoManager
public class UndoManager
Manages a list of changes of type UndoableChange
. Allows changes
of this type to be undone and redone.
Listeners can be registered with
this manager and will be notified whenever a change has been undone or redone.
Changes come in logical groups. A single call to undoLast()
or
redoLast()
always undoes or redoes one group at the time. Groups are
constructed by merging subsequent changes with the leader of the group.
The leader also determines the caption for the undo and redo buttons of the entire
group. If this is not the desired behaviour an extra dummy change (with trivial
undo and redo operations and the desired captions) can be used as a leader.
Additionally the manager can be used to keep track of whether the state of the managed data is dirty, i.e., whether important information would be lost if the application would be aborted without saving. This is done by marking the manager state (i.e., the index of the current change in the list) when a save operation has just completed. If at a later time the current index position is different from the marked index position, the state of the data should be considered dirty. Registered listeners will also be notified whenever the mark changes.
Note: For this simple mark strategy to be valid, you must make sure that every action which changes the managed data is registered with the undo manager and that actions which do not change the data in a significant way, are not.
Constructor Summary | |
---|---|
UndoManager()
Default constructor. |
Method Summary | |
---|---|
void |
add(UndoableChange change,
boolean leader)
Register an undoable change with the manager. |
void |
addUndoListener(UndoListener l)
Register a listener with this object. |
boolean |
canRedo()
Are there currently any changes that can be redone? |
boolean |
canUndo()
Are there currently any changes that can be undone? |
void |
clear()
Clear the list of undoable commands. |
protected void |
fireUndoStateChanged()
Notify all listeners of a change to the undo state. |
java.lang.String |
getRedoCaption()
Return the caption for a redo button. |
java.lang.String |
getUndoCaption()
Return the caption for an undo button. |
boolean |
isDirty()
Check whether the current index position is different from the mark. |
void |
redoLast()
Redo the last group of commands which was previously undone. |
void |
removeUndoListener(UndoListener l)
Unregister a listener with this object. |
void |
setMark()
Put the mark at the current index position. |
void |
undoLast()
Undo te last group of commands. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UndoManager()
Method Detail |
---|
public boolean canUndo()
public boolean canRedo()
public void setMark()
public boolean isDirty()
public void add(UndoableChange change, boolean leader)
leader
- If true, the call
will start a new group of which the
given element becomes the leader.
If false the given undoable change will be appended to the
current group.public void clear()
public void undoLast()
public void redoLast()
public void addUndoListener(UndoListener l)
public java.lang.String getUndoCaption()
public java.lang.String getRedoCaption()
public void removeUndoListener(UndoListener l)
protected void fireUndoStateChanged()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |