Class DelayUndoManager

All Implemented Interfaces:
Serializable, EventListener, UndoableEditListener, UndoableEdit

public class DelayUndoManager extends UndoManager
An undo manager that aggregates UndoableEdits into one CompoundEdit if they are executed very close to each other. By default, the gap is 500 ms. You can control it by passing in a different number in the constructor.
See Also:
  • Field Details

    • _timer

      protected Timer _timer
  • Constructor Details

    • DelayUndoManager

      public DelayUndoManager()
    • DelayUndoManager

      public DelayUndoManager(int delay)
  • Method Details

    • isCacheEmpty

      public boolean isCacheEmpty()
      Checks if there are pending edits in the DelayUndoManager.
      Returns:
      true if there are pending edits. Otherwise false.
    • commitCache

      public void commitCache()
      Commits the cached edit.
    • addEditWithoutCaching

      public void addEditWithoutCaching()
      Calls super.addEdit without caching.
    • discardCache

      public void discardCache()
    • addEdit

      public boolean addEdit(UndoableEdit anEdit)
      Specified by:
      addEdit in interface UndoableEdit
      Overrides:
      addEdit in class UndoManager
    • canUndo

      public boolean canUndo()
      Override to commit the cache before checking undo status.
      Specified by:
      canUndo in interface UndoableEdit
      Overrides:
      canUndo in class UndoManager
      Returns:
      true if an undo operation would be successful now, false otherwise
    • canRedo

      public boolean canRedo()
      Override to commit the cache before checking redo status.
      Specified by:
      canRedo in interface UndoableEdit
      Overrides:
      canRedo in class UndoManager
      Returns:
      true if an redo operation would be successful now, false otherwise
    • undo

      public void undo() throws CannotUndoException
      Override to commit the cache before undo.
      Specified by:
      undo in interface UndoableEdit
      Overrides:
      undo in class UndoManager
      Throws:
      CannotUndoException
    • redo

      public void redo() throws CannotRedoException
      Override to commit the cache before redo.
      Specified by:
      redo in interface UndoableEdit
      Overrides:
      redo in class UndoManager
      Throws:
      CannotRedoException
    • discardAllEdits

      public void discardAllEdits()
      Overrides:
      discardAllEdits in class UndoManager