Class JJazzUndoManager

All Implemented Interfaces:
Serializable, EventListener, UndoableEditListener, UndoableEdit, org.openide.awt.UndoRedo

public class JJazzUndoManager extends UndoManager implements org.openide.awt.UndoRedo
This is a copy of UndoRedo.Manager with a few convenience methods added to work with CompoundEdits.
See Also:
  • Constructor Details

    • JJazzUndoManager

      public JJazzUndoManager()
    • JJazzUndoManager

      public JJazzUndoManager(String name)
      Parameters:
      name - Used for debug purpose, returned by toString()
  • Method Details

    • isUndoRedoInProgress

      public boolean isUndoRedoInProgress()
    • addUserEditListener

      public void addUserEditListener(JJazzUndoManager.UserEditListener l)
    • removeUserEditListener

      public void removeUserEditListener(JJazzUndoManager.UserEditListener l)
    • startCEdit

      public void startCEdit(String editName)
      Start a JJazzLab high-level compound edit with a null source object.
      Parameters:
      editName - Name of the edit
    • startCEdit

      public void startCEdit(Object source, String editName)
      Start a JJazzLab high-level compound edit.
      Parameters:
      source - The associated source object. Can be null.
      editName - Name of the edit. Can't be null.
    • getCurrentCEditName

      public String getCurrentCEditName()
      The name of the current compound edit.
      Returns:
      Can be null if not current edit
      See Also:
    • endCEdit

      public boolean endCEdit(String editName)
      End a JJazzLab high-level compound edit.

      Notify the UserEditListeners.

      Returns:
      true if the compound edit was non empty.
    • addEdit

      public boolean addEdit(UndoableEdit anEdit)
      Overridden for enabled state management.
      Specified by:
      addEdit in interface UndoableEdit
      Overrides:
      addEdit in class UndoManager
    • isEnabled

      public boolean isEnabled()
      Check if this instance is enabled.
      Returns:
      True by default
      See Also:
    • setEnabled

      public void setEnabled(boolean enabled)
      Enable or disable this instance.

      If disabled no new edit can be added (either via addEdit() or undoableEditHappened()).

      NOTE: Model must NOT be changed while the associated JJazzUndoManager is disabled.

      Parameters:
      enabled -
      Throws:
      IllegalStateException - If an undo is in progress
      See Also:
    • undoableEditHappened

      public void undoableEditHappened(UndoableEditEvent ue)
      Consume an undoable edit (if the instance is enabled).

      Delegates to superclass and notifies listeners.

      Specified by:
      undoableEditHappened in interface UndoableEditListener
      Overrides:
      undoableEditHappened in class UndoManager
      Parameters:
      ue - the edit
    • discardAllEdits

      public void discardAllEdits()
      Discard all the existing edits from the undomanager.
      Overrides:
      discardAllEdits in class UndoManager
    • undo

      public void undo() throws CannotUndoException
      Description copied from interface: org.openide.awt.UndoRedo
      Undo an edit.
      Specified by:
      undo in interface UndoableEdit
      Specified by:
      undo in interface org.openide.awt.UndoRedo
      Overrides:
      undo in class UndoManager
      Throws:
      CannotUndoException - if it fails
    • redo

      public void redo() throws CannotRedoException
      Description copied from interface: org.openide.awt.UndoRedo
      Redo a previously undone edit.
      Specified by:
      redo in interface UndoableEdit
      Specified by:
      redo in interface org.openide.awt.UndoRedo
      Overrides:
      redo in class UndoManager
      Throws:
      CannotRedoException - if it fails
    • undoOrRedo

      public void undoOrRedo() throws CannotRedoException, CannotUndoException
      Overrides:
      undoOrRedo in class UndoManager
      Throws:
      CannotRedoException
      CannotUndoException
    • killNextEditToBeRedone

      public void killNextEditToBeRedone()
      Call die on next edit to be redone (if there is one).
    • abortCEdit

      public void abortCEdit(String cEditName, String errMsg)
      Abort a compound edit started with startCEdit() in the middle: some SimpleEdits have been done but not all of them (endCEdit() was not called).

      The method will :
      0/ Possibly show a dialog to notify user with errMsg.
      1/ Call endCEdit() on cEditName to terminate properly the compound edit.
      Because an exception might have occured some SimpleEdits may be missing in the CEdit (compared to normal).

      If compound edit is not empty:
      2/ Call undo()
      This will roll back the CEdit eEditName, ie undo each of the collected simple edits before the exception occured.

      3/ Remove CEdit cEditName from the undomanager, so that it can't be redone.

      Parameters:
      cEditName - The aborted edit name used with startCEdit()
      errMsg - Error message to notify user. If null user is not notified.
    • fireChange

      public void fireChange()
      Notify listeners of a state change.
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      Description copied from interface: org.openide.awt.UndoRedo
      Add a change listener. The listener will be notified every time the undo/redo ability of this object changes.
      Specified by:
      addChangeListener in interface org.openide.awt.UndoRedo
      Parameters:
      l - the listener to add
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Description copied from interface: org.openide.awt.UndoRedo
      Remove a change listener.
      Specified by:
      removeChangeListener in interface org.openide.awt.UndoRedo
      Parameters:
      l - the listener to remove
      See Also:
      • UndoRedo.addChangeListener(javax.swing.event.ChangeListener)
    • getUndoPresentationName

      public String getUndoPresentationName()
      Description copied from interface: org.openide.awt.UndoRedo
      Get a human-presentable name describing the undo operation.
      Specified by:
      getUndoPresentationName in interface UndoableEdit
      Specified by:
      getUndoPresentationName in interface org.openide.awt.UndoRedo
      Overrides:
      getUndoPresentationName in class UndoManager
      Returns:
      the name
    • getRedoPresentationName

      public String getRedoPresentationName()
      Description copied from interface: org.openide.awt.UndoRedo
      Get a human-presentable name describing the redo operation.
      Specified by:
      getRedoPresentationName in interface UndoableEdit
      Specified by:
      getRedoPresentationName in interface org.openide.awt.UndoRedo
      Overrides:
      getRedoPresentationName in class UndoManager
      Returns:
      the name
    • toString

      public String toString()
      Overrides:
      toString in class UndoManager