Class MyUndoManager

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

    public class MyUndoManager
    extends javax.swing.undo.UndoManager
    An UndoManager that can handle the double undo and redo that is created by a JTextComponent.setText(String) call.
    The double undo is a remove (all) and a insert (all). These are combined by this UndoManager.
    NOTE: The nextUndoIsDouble() method MUST be MANUALLY called before the call to JTextComponent.setText(String)!
    Or the two undos must be executed fast (< 1msec) after each other (and FAST_EDITS_ARE_THE_SAME_EDIT = true).
    Fast like selecting text and then start writing. This is with this UndoManager also only one undo / redo.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean FAST_EDITS_ARE_THE_SAME_EDIT  
      • Fields inherited from class javax.swing.undo.CompoundEdit

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

        RedoName, UndoName
    • Constructor Summary

      Constructors 
      Constructor Description
      MyUndoManager()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addEdit​(javax.swing.undo.UndoableEdit anEdit)  
      static MyUndoManager addUndoToTextComponent​(javax.swing.text.JTextComponent textComponent)  
      void discardAllEdits()  
      void nextUndoIsDouble()  
      void redo()  
      java.lang.String toString()  
      void undo()  
      • Methods inherited from class javax.swing.undo.UndoManager

        canRedo, canUndo, canUndoOrRedo, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, getUndoPresentationName, redoTo, setLimit, 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
    • Method Detail

      • 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
      • undo

        public void undo()
                  throws javax.swing.undo.CannotUndoException
        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
        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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class javax.swing.undo.UndoManager