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.
    • 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
      Specified by:
      undo in interface UndoableEdit
      Specified by:
      undo in interface org.openide.awt.UndoRedo
      Overrides:
      undo in class UndoManager
      Throws:
      CannotUndoException
    • redo

      public void redo() throws CannotRedoException
      Specified by:
      redo in interface UndoableEdit
      Specified by:
      redo in interface org.openide.awt.UndoRedo
      Overrides:
      redo in class UndoManager
      Throws:
      CannotRedoException
    • 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).
    • handleUnsupportedEditException

      public void handleUnsupportedEditException(String cEditName, String errMsg)
      Convenience method : the right way to handle UnsupportedEditException when catched by the highest level caller, ie the one who called startCEdit() and should call endCEdit().

      This method should be called first in the catch section.

      1/ Call endCEdit() on cEditName to terminate properly the compound edit.
      Because exception 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.

      4/ Show a dialog to notify errMsg.

      Parameters:
      cEditName -
      errMsg -
    • fireChange

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

      public void addChangeListener(ChangeListener l)
      Specified by:
      addChangeListener in interface org.openide.awt.UndoRedo
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Specified by:
      removeChangeListener in interface org.openide.awt.UndoRedo
    • getUndoPresentationName

      public String getUndoPresentationName()
      Specified by:
      getUndoPresentationName in interface UndoableEdit
      Specified by:
      getUndoPresentationName in interface org.openide.awt.UndoRedo
      Overrides:
      getUndoPresentationName in class UndoManager
    • getRedoPresentationName

      public String getRedoPresentationName()
      Specified by:
      getRedoPresentationName in interface UndoableEdit
      Specified by:
      getRedoPresentationName in interface org.openide.awt.UndoRedo
      Overrides:
      getRedoPresentationName in class UndoManager
    • toString

      public String toString()
      Overrides:
      toString in class UndoManager