Class DelayUndoManager

  • All Implemented Interfaces:
    java.io.Serializable, java.util.EventListener, javax.swing.event.UndoableEditListener, javax.swing.undo.UndoableEdit

    public class DelayUndoManager
    extends javax.swing.undo.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:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.swing.Timer _timer  
      • Fields inherited from class javax.swing.undo.CompoundEdit

        edits
      • Fields inherited from class javax.swing.undo.AbstractUndoableEdit

        RedoName, UndoName
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addEdit​(javax.swing.undo.UndoableEdit anEdit)  
      void addEditWithoutCaching()
      Calls super.addEdit without caching.
      boolean canRedo()
      Override to commit the cache before checking redo status.
      boolean canUndo()
      Override to commit the cache before checking undo status.
      void commitCache()
      Commits the cached edit.
      void discardAllEdits()  
      void discardCache()  
      boolean isCacheEmpty()
      Checks if there are pending edits in the DelayUndoManager.
      void redo()
      Override to commit the cache before redo.
      void undo()
      Override to commit the cache before undo.
      • Methods inherited from class javax.swing.undo.UndoManager

        canUndoOrRedo, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, getUndoPresentationName, redoTo, setLimit, toString, trimEdits, trimForLimit, undoableEditHappened, undoOrRedo, undoTo
      • Methods inherited from class javax.swing.undo.CompoundEdit

        die, getPresentationName, isInProgress, isSignificant, lastEdit
      • Methods inherited from class javax.swing.undo.AbstractUndoableEdit

        replaceEdit
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • _timer

        protected javax.swing.Timer _timer
    • Constructor Detail

      • DelayUndoManager

        public DelayUndoManager()
      • DelayUndoManager

        public DelayUndoManager​(int delay)
    • Method Detail

      • 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​(javax.swing.undo.UndoableEdit anEdit)
        Specified by:
        addEdit in interface javax.swing.undo.UndoableEdit
        Overrides:
        addEdit in class javax.swing.undo.UndoManager
      • canUndo

        public boolean canUndo()
        Override to commit the cache before checking undo status.
        Specified by:
        canUndo in interface javax.swing.undo.UndoableEdit
        Overrides:
        canUndo in class javax.swing.undo.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 javax.swing.undo.UndoableEdit
        Overrides:
        canRedo in class javax.swing.undo.UndoManager
        Returns:
        true if an redo operation would be successful now, false otherwise
      • undo

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

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

        public void discardAllEdits()
        Overrides:
        discardAllEdits in class javax.swing.undo.UndoManager