Class UndoManager

java.lang.Object
org.pepsoft.util.undo.UndoManager

public class UndoManager extends Object
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 Details

    • UndoManager

      public UndoManager()
    • UndoManager

      public UndoManager(int maxFrames)
    • UndoManager

      public UndoManager(Action undoAction, Action redoAction)
    • UndoManager

      public UndoManager(Action undoAction, Action redoAction, int maxFrames)
  • Method Details

    • registerActions

      public void registerActions(Action undoAction, Action redoAction)
    • 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

      public Snapshot 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:
      true if 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:
      true if 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:
      true if 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

      public <T> void addBuffer(BufferKey<T> key, T buffer)
    • addBuffer

      public <T> void addBuffer(BufferKey<T> key, T buffer, UndoListener listener)
    • removeBuffer

      public void removeBuffer(BufferKey<?> key)
    • getBuffer

      public <T> T getBuffer(BufferKey<T> key)
    • getBufferForEditing

      public <T> T getBufferForEditing(BufferKey<T> key)
    • addListener

      public void addListener(UndoListener listener)
    • removeListener

      public void removeListener(UndoListener listener)
    • getStopAtClasses

      public Class<?>[] getStopAtClasses()
    • setStopAtClasses

      public void setStopAtClasses(Class<?>... stopAt)
    • getDataSize

      public long getDataSize()