Package org.pepsoft.util.undo
Class UndoManager
java.lang.Object
org.pepsoft.util.undo.UndoManager
A data buffer oriented (rather than edit list or operations oriented) manager
of undo and redo data. Uses a copy on write mechanism to maintain a list of
historical versions of a set of data buffers, copying them automatically when
needed after a save point has been executed, and notifying clients when
buffers need to be updated because an undo or redo has been performed.
-
Constructor Summary
ConstructorsConstructorDescriptionUndoManager(int maxFrames) UndoManager(Action undoAction, Action redoAction) UndoManager(Action undoAction, Action redoAction, int maxFrames) -
Method Summary
Modifier and TypeMethodDescription<T> void<T> voidaddBuffer(BufferKey<T> key, T buffer, UndoListener listener) voidaddListener(UndoListener listener) voidArm a save point.voidclear()Throw away all undo and redo information.voidThrow away all redo information<T> T<T> TgetBufferForEditing(BufferKey<T> key) longintGet a read-only snapshot of the current state of the buffers.Class<?>[]booleanisDirty()Indicates whether the current history frame is dirty (meaning that buffers have been checked out for editing from it).booleanredo()Rolls forward all buffers to the next save point, if there is one available, and no edits have been performed since the last undo.voidregisterActions(Action undoAction, Action redoAction) voidremoveBuffer(BufferKey<?> key) voidremoveListener(UndoListener listener) voidSave the current state of all buffers as an undo point.voidsetStopAtClasses(Class<?>... stopAt) booleanundo()Rolls back all buffers to the previous save point, if there is one still available.void
-
Constructor Details
-
UndoManager
public UndoManager() -
UndoManager
public UndoManager(int maxFrames) -
UndoManager
-
UndoManager
-
-
Method Details
-
registerActions
-
unregisterActions
public void unregisterActions() -
getMaxFrames
public int getMaxFrames() -
armSavePoint
public void armSavePoint()Arm a save point. It will be executed the next time a buffer is requested for editing. Arming a save point instead of executing it immediately allows a redo to be performed instead.Will do nothing if a save point is already armed, or if the current frame is the last one and it is not dirty.
-
savePoint
public void savePoint()Save the current state of all buffers as an undo point. -
getSnapshot
Get a read-only snapshot of the current state of the buffers. If you want the state to be a static snapshot that will not reflect later changes, you should execute a save point after getting the snapshot. The snapshot will remain valid until the corresponding undo history frame disappears, after which it will throw an exception if you try to use it.- Returns:
- A snapshot of the current undo history frame.
-
isDirty
public boolean isDirty()Indicates whether the current history frame is dirty (meaning that buffers have been checked out for editing from it).- Returns:
trueif the current history frame is dirty.
-
undo
public boolean undo()Rolls back all buffers to the previous save point, if there is one still available.- Returns:
trueif the undo was succesful.
-
redo
public boolean redo()Rolls forward all buffers to the next save point, if there is one available, and no edits have been performed since the last undo.- Returns:
trueif the redo was succesful.
-
clear
public void clear()Throw away all undo and redo information. -
clearRedo
public void clearRedo()Throw away all redo information -
addBuffer
-
addBuffer
-
removeBuffer
-
getBuffer
-
getBufferForEditing
-
addListener
-
removeListener
-
getStopAtClasses
-
setStopAtClasses
-
getDataSize
public long getDataSize()
-