Class TextUndoManager

All Implemented Interfaces:
Serializable, EventListener, UndoableEditListener, UndoableEdit

public class TextUndoManager extends UndoManager
To use this, simply drop this as an UndoableEditListener into your document, and then create actions to call undo/redo as needed (checking can undo/redo first, of course).
See Also:
  • Constructor Details

    • TextUndoManager

      public TextUndoManager()
      Creates a new instance of TextUndoManager.
  • Method Details

    • setRecording

      public void setRecording(boolean recording)
      Toggle recording of undoable edits. Used to suppress capture of programmatic style changes (e.g. a theme switch re-parsing the document) that shouldn't be reachable via user-initiated Undo.
      Since:
      6.0.0
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener pcl)
      Registers a listener for undo/redo state changes.
      Parameters:
      pcl - the listener to add
    • die

      public void die()
      Specified by:
      die in interface UndoableEdit
      Overrides:
      die in class CompoundEdit
    • discardAllEdits

      public void discardAllEdits()
      Overrides:
      discardAllEdits in class UndoManager
    • firePropertyChangeEvent

      protected void firePropertyChangeEvent(String name, boolean oldValue, boolean newValue)
      Fires an undo-state property change event.
      Parameters:
      name - the property name
      oldValue - the previous value
      newValue - the new value
    • hasChanged

      public boolean hasChanged()
      Indicates whether the document differs from the last reset point.
      Returns:
      true if undo history contains unreset edits
    • redo

      public void redo() throws CannotRedoException
      Specified by:
      redo in interface UndoableEdit
      Overrides:
      redo in class UndoManager
      Throws:
      CannotRedoException
    • redoTo

      protected void redoTo(UndoableEdit edit)
      Overrides:
      redoTo in class UndoManager
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener pcl)
      Removes a listener for undo/redo state changes.
      Parameters:
      pcl - the listener to remove
    • reset

      public void reset()
      Marks the current undo position as the unmodified state.
    • trimEdits

      protected void trimEdits(int from, int to)
      Overrides:
      trimEdits in class UndoManager
    • undo

      public void undo() throws CannotUndoException
      Specified by:
      undo in interface UndoableEdit
      Overrides:
      undo in class UndoManager
      Throws:
      CannotUndoException
    • undoableEditHappened

      public void undoableEditHappened(UndoableEditEvent uee)
      Specified by:
      undoableEditHappened in interface UndoableEditListener
      Overrides:
      undoableEditHappened in class UndoManager