CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.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 ch.randelshofer.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:
1.4 2004-03-25 Support for change listener added.
1.3 2003-03-16 Texts and accelerator keys are now read from a resource bundle.
1.1.2 2003-03-12 Actions use now KeyStroke objects instead of String objects as accelerator keys.
1.1.1 2002-05-10 Method addEdit is now smarter when determining whether an edit is significant.
1.1 2002-04-08 Method hasSignificantEdits/clearChanged added.
1.0 2001-10-09
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
static javax.swing.undo.UndoableEdit DISCARD_ALL_EDITS
          Sending this UndoableEdit event to the UndoRedoManager disables the Undo and Redo functions of the manager.
 
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
 void addChangeListener(javax.swing.event.ChangeListener l)
          Adds a change listener.
 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 discardAllEdits()
          Discards all edits.
protected  void fireStateChanged()
          Notify all listeners that have registered interest for notification on this event type.
 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 removeChangeListener(javax.swing.event.ChangeListener l)
           
 void undo()
          Undoes the last edit event.
 void undoOrRedo()
          Undoes or redoes the last edit event.
 
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

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.

Constructor Detail

UndoRedoManager

public UndoRedoManager()
Creates new UndoRedoManager

Method Detail

discardAllEdits

public void discardAllEdits()
Discards all edits.

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

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.


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

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
Adds a change listener. ChangeListener's get notified, when the state of hasSignificantEdits changes.

See Also:
hasSignificantEdits

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)

fireStateChanged

protected void fireStateChanged()
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.


(c) Werner Randelshofer.
All rights reserved.