com.jaxfront.core.util.undo
Class UndoManagerWrapper

java.lang.Object
  extended by javax.swing.undo.AbstractUndoableEdit
      extended by javax.swing.undo.CompoundEdit
          extended by com.jaxfront.core.util.undo.UndoManagerWrapper
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.UndoableEditListener, javax.swing.undo.UndoableEdit
Direct Known Subclasses:
JAXFrontUndoManager

public class UndoManagerWrapper
extends javax.swing.undo.CompoundEdit
implements javax.swing.event.UndoableEditListener

Concrete subclass of CompoundEdit which can serve as a UndoableEditListener, consolidating the UndoableEditEvents from a variety of sources, and undoing or redoing them one at a time. Unlike AbstractUndoableEdit and CompoundEdit, the public methods of this class are synchronized, and should be safe to call from multiple threads. This should make UndoManager a convenient marshall for sets of undoable JavaBeans.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

Version:
1.33, 01/23/03
Author:
Ray Ryan
See Also:
Serialized Form

Constructor Summary
UndoManagerWrapper()
           
 
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.
 boolean canRedo()
          Overridden to preserve usual semantics: returns true if a redo operation would be successful now, false otherwise
 boolean canUndo()
          Overridden to preserve usual semantics: returns true if an undo operation would be successful now, false otherwise
 boolean canUndoOrRedo()
          Return true if calling undoOrRedo will undo or redo.
 void discardAllEdits()
          Empty the undo manager, sending each edit a die message in the process.
 void end()
          Sending end() to an UndoManager turns it into a plain old (ended) CompoundEdit.
 int getLimit()
          Returns the maximum number of edits this UndoManager will hold.
 java.lang.String getRedoPresentationName()
          If inProgress, returns getRedoPresentationName of the significant edit that will be redone when redo() is invoked.
 java.lang.String getUndoOrRedoPresentationName()
          Return the appropriate name for a command that toggles between undo and redo.
 java.lang.String getUndoPresentationName()
          If isInProgress(), returns getUndoPresentationName of the significant edit that will be undone when undo() is invoked.
 void redo()
          If this UndoManager is inProgress, redoes the last significant UndoableEdit at indexOfNextAdd or after, and all insignificant edits up to it.
 void setLimit(int l)
          Set the maximum number of edits this UndoManager will hold.
 java.lang.String toString()
          Returns a string that displays and identifies this object's properties.
 void undo()
          If this UndoManager is inProgress, undo the last significant UndoableEdit before indexOfNextAdd, and all insignificant edits back to it.
 void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
          Called by the UndoabledEdit sources this UndoManager listens to.
 void undoOrRedo()
          Undo or redo as appropriate.
 
Methods inherited from class javax.swing.undo.CompoundEdit
die, getPresentationName, isInProgress, isSignificant
 
Methods inherited from class javax.swing.undo.AbstractUndoableEdit
replaceEdit
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UndoManagerWrapper

public UndoManagerWrapper()
Method Detail

getLimit

public int getLimit()
Returns the maximum number of edits this UndoManager will hold. Default value is 100.

See Also:
addEdit(javax.swing.undo.UndoableEdit), setLimit(int)

discardAllEdits

public void discardAllEdits()
Empty the undo manager, sending each edit a die message in the process.


setLimit

public void setLimit(int l)
Set the maximum number of edits this UndoManager will hold. If edits need to be discarded to shrink the limit, they will be told to die in the reverse of the order that they were added.

See Also:
addEdit(javax.swing.undo.UndoableEdit), getLimit()

undoOrRedo

public void undoOrRedo()
                throws javax.swing.undo.CannotRedoException,
                       javax.swing.undo.CannotUndoException
Undo or redo as appropriate. Suitable for binding to an action that toggles between these two functions. Only makes sense to send this if limit == 1.

Throws:
javax.swing.undo.CannotRedoException
javax.swing.undo.CannotUndoException
See Also:
canUndoOrRedo(), getUndoOrRedoPresentationName()

canUndoOrRedo

public boolean canUndoOrRedo()
Return true if calling undoOrRedo will undo or redo. Suitable for deciding to enable a command that toggles between the two functions, which only makes sense to use if limit == 1.

See Also:
undoOrRedo()

undo

public void undo()
          throws javax.swing.undo.CannotUndoException
If this UndoManager is inProgress, undo the last significant UndoableEdit before indexOfNextAdd, and all insignificant edits back to it. Updates indexOfNextAdd accordingly.

If not inProgress, indexOfNextAdd is ignored and super's routine is called.

Specified by:
undo in interface javax.swing.undo.UndoableEdit
Overrides:
undo in class javax.swing.undo.CompoundEdit
Throws:
javax.swing.undo.CannotUndoException
See Also:
CompoundEdit.end()

canUndo

public boolean canUndo()
Overridden to preserve usual semantics: returns true if an undo operation would be successful now, false otherwise

Specified by:
canUndo in interface javax.swing.undo.UndoableEdit
Overrides:
canUndo in class javax.swing.undo.CompoundEdit

redo

public void redo()
          throws javax.swing.undo.CannotRedoException
If this UndoManager is inProgress, redoes the last significant UndoableEdit at indexOfNextAdd or after, and all insignificant edits up to it. Updates indexOfNextAdd accordingly.

If not inProgress, indexOfNextAdd is ignored and super's routine is called.

Specified by:
redo in interface javax.swing.undo.UndoableEdit
Overrides:
redo in class javax.swing.undo.CompoundEdit
Throws:
javax.swing.undo.CannotRedoException
See Also:
CompoundEdit.end()

canRedo

public boolean canRedo()
Overridden to preserve usual semantics: returns true if a redo operation would be successful now, false otherwise

Specified by:
canRedo in interface javax.swing.undo.UndoableEdit
Overrides:
canRedo in class javax.swing.undo.CompoundEdit

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.

Specified by:
addEdit in interface javax.swing.undo.UndoableEdit
Overrides:
addEdit in class javax.swing.undo.CompoundEdit
Parameters:
anEdit - the edit to be added
See Also:
CompoundEdit.end(), CompoundEdit.addEdit(javax.swing.undo.UndoableEdit)

end

public void end()
Sending end() to an UndoManager turns it into a plain old (ended) CompoundEdit.

Calls super's end() method (making inProgress false), then sends die() to the unreachable edits at indexOfNextAdd and beyond, in the reverse of the order in which they were added.

Overrides:
end in class javax.swing.undo.CompoundEdit
See Also:
CompoundEdit.end()

getUndoOrRedoPresentationName

public java.lang.String getUndoOrRedoPresentationName()
Return the appropriate name for a command that toggles between undo and redo. Only makes sense to use such a command if limit == 1 and we're not in progress.


getUndoPresentationName

public java.lang.String getUndoPresentationName()
If isInProgress(), returns getUndoPresentationName of the significant edit that will be undone when undo() is invoked. If there is none, returns AbstractUndoableEdit.undoText from the defaults table.

If not inProgress, acts as a CompoundEdit

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

getRedoPresentationName

public java.lang.String getRedoPresentationName()
If inProgress, returns getRedoPresentationName of the significant edit that will be redone when redo() is invoked. If there is none, returns AbstractUndoableEdit.redoText from the defaults table.

If not inProgress, acts as a CompoundEdit

Specified by:
getRedoPresentationName in interface javax.swing.undo.UndoableEdit
Overrides:
getRedoPresentationName in class javax.swing.undo.CompoundEdit
See Also:
redo(), CompoundEdit.getUndoPresentationName()

undoableEditHappened

public void undoableEditHappened(javax.swing.event.UndoableEditEvent e)
Called by the UndoabledEdit sources this UndoManager listens to. Calls addEdit with e.getEdit().

Specified by:
undoableEditHappened in interface javax.swing.event.UndoableEditListener
See Also:
addEdit(javax.swing.undo.UndoableEdit)

toString

public java.lang.String toString()
Returns a string that displays and identifies this object's properties.

Overrides:
toString in class javax.swing.undo.CompoundEdit
Returns:
a String representation of this object