org.jhotdraw.undo
Class UndoRedoManager

java.lang.Object
  extended by javax.swing.undo.AbstractUndoableEdit
      extended by javax.swing.undo.CompoundEdit
          extended by javax.swing.undo.UndoManager
              extended by org.jhotdraw.undo.UndoRedoManager
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.UndoableEditListener, javax.swing.undo.UndoableEdit

public class UndoRedoManager
extends javax.swing.undo.UndoManager

Same as javax.swing.UndoManager but provides actions for undo and redo operations.

Version:
$Id: UndoRedoManager.java 647 2010-01-24 22:52:59Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Nested Class Summary
private  class UndoRedoManager.RedoAction
          Redo Action for use in a menu bar.
private  class UndoRedoManager.UndoAction
          Undo Action for use in a menu bar.
 
Field Summary
private static boolean DEBUG
           
static javax.swing.undo.UndoableEdit DISCARD_ALL_EDITS
          Sending this UndoableEdit event to the UndoRedoManager disables the Undo and Redo functions of the manager.
private  boolean hasSignificantEdits
          This flag is set to true when at least one significant UndoableEdit has been added to the manager since the last call to discardAllEdits.
private static ResourceBundleUtil labels
          The resource bundle used for internationalisation.
protected  java.beans.PropertyChangeSupport propertySupport
           
private  UndoRedoManager.RedoAction redoAction
          The redo action instance.
private  UndoRedoManager.UndoAction undoAction
          The undo action instance.
private  boolean undoOrRedoInProgress
          This flag is set to true when an undo or redo operation is in progress.
 
Fields inherited from class javax.swing.undo.CompoundEdit
edits
 
Fields inherited from class javax.swing.undo.AbstractUndoableEdit
RedoName, UndoName
 
Constructor Summary
UndoRedoManager()
          Creates new UndoRedoManager
 
Method Summary
 boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
          If inProgress, inserts anEdit at indexOfNextAdd, and removes any old edits that were at indexOfNextAdd or later.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
 void discardAllEdits()
          Discards all edits.
protected  void firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
           
protected  void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
           
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
           
static ResourceBundleUtil getLabels()
           
 javax.swing.Action getRedoAction()
          Gets the redo action for use as a Redo menu item.
 javax.swing.Action getUndoAction()
          Gets the undo action for use as an Undo menu item.
 boolean hasSignificantEdits()
          Returns true if at least one significant UndoableEdit has been added since the last call to discardAllEdits.
 void redo()
          Redoes the last undone edit event.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
 void setHasSignificantEdits(boolean newValue)
           
 void setLocale(java.util.Locale l)
           
 void undo()
          Undoes the last edit event.
 void undoOrRedo()
          Undoes or redoes the last edit event.
private  void updateActions()
          Updates the properties of the UndoAction and of the RedoAction.
 
Methods inherited from class javax.swing.undo.UndoManager
canRedo, canUndo, canUndoOrRedo, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, getUndoPresentationName, redoTo, setLimit, toString, trimEdits, trimForLimit, undoableEditHappened, 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

propertySupport

protected java.beans.PropertyChangeSupport propertySupport

DEBUG

private static final boolean DEBUG
See Also:
Constant Field Values

labels

private static ResourceBundleUtil labels
The resource bundle used for internationalisation.


hasSignificantEdits

private boolean hasSignificantEdits
This flag is set to true when at least one significant UndoableEdit has been added to the manager since the last call to discardAllEdits.


undoOrRedoInProgress

private boolean undoOrRedoInProgress
This flag is set to true when an undo or redo operation is in progress. The UndoRedoManager ignores all incoming UndoableEdit events while this flag is true.


DISCARD_ALL_EDITS

public static final javax.swing.undo.UndoableEdit DISCARD_ALL_EDITS
Sending this UndoableEdit event to the UndoRedoManager disables the Undo and Redo functions of the manager.


undoAction

private UndoRedoManager.UndoAction undoAction
The undo action instance.


redoAction

private UndoRedoManager.RedoAction redoAction
The redo action instance.

Constructor Detail

UndoRedoManager

public UndoRedoManager()
Creates new UndoRedoManager

Method Detail

getLabels

public static ResourceBundleUtil getLabels()

setLocale

public void setLocale(java.util.Locale l)

discardAllEdits

public void discardAllEdits()
Discards all edits.

Overrides:
discardAllEdits in class javax.swing.undo.UndoManager

setHasSignificantEdits

public void setHasSignificantEdits(boolean newValue)

hasSignificantEdits

public boolean hasSignificantEdits()
Returns true if at least one significant UndoableEdit has been added since the last call to discardAllEdits.


addEdit

public boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
If inProgress, inserts anEdit at indexOfNextAdd, and removes any old edits that were at indexOfNextAdd or later. The die method is called on each edit that is removed is sent, in the reverse of the order the edits were added. Updates indexOfNextAdd.

If not inProgress, acts as a CompoundEdit

Regardless of inProgress, if undoOrRedoInProgress, calls die on each edit that is sent.

Specified by:
addEdit in interface javax.swing.undo.UndoableEdit
Overrides:
addEdit in class javax.swing.undo.UndoManager
See Also:
CompoundEdit.end(), CompoundEdit.addEdit(javax.swing.undo.UndoableEdit)

getUndoAction

public javax.swing.Action getUndoAction()
Gets the undo action for use as an Undo menu item.


getRedoAction

public javax.swing.Action getRedoAction()
Gets the redo action for use as a Redo menu item.


updateActions

private void updateActions()
Updates the properties of the UndoAction and of the RedoAction.


undo

public void undo()
          throws javax.swing.undo.CannotUndoException
Undoes the last edit event. The UndoRedoManager ignores all incoming UndoableEdit events, while undo is in progress.

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.CannotUndoException
Redoes the last undone edit event. The UndoRedoManager ignores all incoming UndoableEdit events, while redo is in progress.

Specified by:
redo in interface javax.swing.undo.UndoableEdit
Overrides:
redo in class javax.swing.undo.UndoManager
Throws:
javax.swing.undo.CannotUndoException

undoOrRedo

public void undoOrRedo()
                throws javax.swing.undo.CannotUndoException,
                       javax.swing.undo.CannotRedoException
Undoes or redoes the last edit event. The UndoRedoManager ignores all incoming UndoableEdit events, while undo or redo is in progress.

Overrides:
undoOrRedo in class javax.swing.undo.UndoManager
Throws:
javax.swing.undo.CannotUndoException
javax.swing.undo.CannotRedoException

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  boolean oldValue,
                                  boolean newValue)

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  int oldValue,
                                  int newValue)

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)