UndoRedo V1.2
by Matthew Ford
2005/06/27

au.com.forward.undoRedo
Class UndoRedo

java.lang.Object
  extended by au.com.forward.undoRedo.UndoRedo
All Implemented Interfaces:
java.lang.Cloneable, javax.swing.undo.UndoableEdit
Direct Known Subclasses:
BranchUndoRedo

public class UndoRedo
extends java.lang.Object
implements javax.swing.undo.UndoableEdit, java.lang.Cloneable

Wrapps an UndoableEdit for adding to the UndoRedoManager tree.
Wrapping allows us to reuse the original UndoableEdit when adding Undo nodes generated from redo branches. This avoids the need to clone the original UndoableEdit, which may not be cloneable or may require significant memory.


Field Summary
static java.lang.String ALL_REDONE_PREFIX
          Prefix for all nodes redone.
static java.lang.String DEAD_FORMAT
          Prefix for dead nodes
protected  javax.swing.undo.UndoableEdit edit
          the wrapped edit
static java.lang.String HTML_START
          Prefix for HTML
static java.lang.String INSIGNIFICANT_FORMAT
          Prefix for insignificant nodes
static java.lang.String REDONE_PREFIX
          Prefix for redone nodes
static java.lang.String UNREACHABLE_FORMAT
          Prefix for unreachable nodes
 
Constructor Summary
UndoRedo(javax.swing.undo.UndoableEdit edit)
          Creates a new instance of UndoRedo wrapping an UndoableEdit.
 
Method Summary
 boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
          Does nothing, always returns false.
 boolean canRedo()
          True if it is still possible to redo this operation.
 boolean canUndo()
          True if it is still possible to undo this operation.
 java.lang.Object clone()
          Returns the clone of this UndoRedo.
 void die()
          May be sent to inform an edit that it should no longer be used.
 boolean equalsComplement(java.lang.Object obj)
          Returns true if the obj is the complement of this UndoRedo.
static java.lang.String escapeHTML(java.lang.String input)
           
 UndoRedo getComplement()
          Returns the UndoRedo complement of this object.
 java.lang.String getPresentationName()
          Provides a localized, human readable description of this edit , should be detailed enough to provide a the basis of a meaningful node lable.
 java.lang.String getRedoPresentationName()
          Provides a localized, human readable description of the redoable form of this edit.
 javax.swing.undo.UndoableEdit getUndoableEdit()
          Returns the UndoableEdit wrapped by this UndoRedo
 java.lang.String getUndoPresentationName()
          Provides a localized, human readable description of the undoable form of this edit.
 boolean isDead()
          Is the wrapped UndoableEdit dead
 boolean isSignificant()
          Returns false if this edit is insignificant--for example one that maintains the user's selection, but does not change any model state.
 boolean isUndo()
          Returns true if this is the undo version.
 boolean isUnreachable()
          Returns true if thie undo/redo cannot be reached.
 void redo()
          Re-apply the edit, assuming that it has been undone.
 boolean replaceEdit(javax.swing.undo.UndoableEdit anEdit)
          Does nothing, always returns false.
 void setUnreachable()
          Sets this undo/redo as being un-reached.
 java.lang.String toString()
          Returns a string representation of this UndoRedo object.
 void undo()
          Undo the edit that was made.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

edit

protected javax.swing.undo.UndoableEdit edit
the wrapped edit


HTML_START

public static java.lang.String HTML_START
Prefix for HTML


REDONE_PREFIX

public static java.lang.String REDONE_PREFIX
Prefix for redone nodes


ALL_REDONE_PREFIX

public static java.lang.String ALL_REDONE_PREFIX
Prefix for all nodes redone. Used for branch nodes


DEAD_FORMAT

public static java.lang.String DEAD_FORMAT
Prefix for dead nodes


UNREACHABLE_FORMAT

public static java.lang.String UNREACHABLE_FORMAT
Prefix for unreachable nodes


INSIGNIFICANT_FORMAT

public static java.lang.String INSIGNIFICANT_FORMAT
Prefix for insignificant nodes

Constructor Detail

UndoRedo

public UndoRedo(javax.swing.undo.UndoableEdit edit)
Creates a new instance of UndoRedo wrapping an UndoableEdit. This is always an undo, (ie. undo == true)

Method Detail

getUndoableEdit

public javax.swing.undo.UndoableEdit getUndoableEdit()
Returns the UndoableEdit wrapped by this UndoRedo

Returns:
the UndoableEdit that is wrapped by this UndoRedo

equalsComplement

public boolean equalsComplement(java.lang.Object obj)
Returns true if the obj is the complement of this UndoRedo. UndoRedo complements wrap the same UndoableEdit object but have complementary undo settings

Parameters:
obj - the object to test
Returns:
true if the object is the complement of this UndoRedo

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns the clone of this UndoRedo.
Does not clone the wrapped UndoableEdit.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this UndoRedo, with a reference to the original wrapped edit.
Throws:
java.lang.CloneNotSupportedException

isUndo

public boolean isUndo()
Returns true if this is the undo version.
This setting is independent of the undo/redo setting of the wrapped UndoableEdit.

Returns:
true if Undo, false if Redo

isUnreachable

public boolean isUnreachable()
Returns true if thie undo/redo cannot be reached.
Usually due to an intervening dead node.

Returns:
true if this undo/redo cannot be reached.

setUnreachable

public void setUnreachable()
Sets this undo/redo as being un-reached.
Usually due to an intervening dead node.
Like die(), this setting cannot be undone.


getComplement

public UndoRedo getComplement()
Returns the UndoRedo complement of this object.
Keeps the original reference to wrapped Undoable edit.

Returns:
the UndoRedo complement of this object.

undo

public void undo()
          throws javax.swing.undo.CannotUndoException
Undo the edit that was made.

Specified by:
undo in interface javax.swing.undo.UndoableEdit
Throws:
javax.swing.undo.CannotUndoException - if cannot be undone.

canUndo

public boolean canUndo()
True if it is still possible to undo this operation.

Specified by:
canUndo in interface javax.swing.undo.UndoableEdit
Returns:
true if this is an Undo UndoRedo and the wrapped UndoableEdit can be undone.

redo

public void redo()
          throws javax.swing.undo.CannotRedoException
Re-apply the edit, assuming that it has been undone.

Specified by:
redo in interface javax.swing.undo.UndoableEdit
Throws:
javax.swing.undo.CannotRedoException - if cannot be redone.

canRedo

public boolean canRedo()
True if it is still possible to redo this operation.

Specified by:
canRedo in interface javax.swing.undo.UndoableEdit
Returns:
true if this is a Redo UndoRedo and the wrapped UndoableEdit can be redone. false if either this is and Undo leaf or a Redo leaf wrapping an Undo edit

isDead

public boolean isDead()
Is the wrapped UndoableEdit dead

Returns:
true if the wrapped UndoableEdit is dead, else false.

die

public void die()
May be sent to inform an edit that it should no longer be used. This is a useful hook for cleaning up state no longer needed once undoing or redoing is impossible.
The UndoRedoManager never calls this and the will throw an exception if it encounters a dead UndoRedo.
Note that this is a one-way operation. There is no "un-die" method.

Specified by:
die in interface javax.swing.undo.UndoableEdit

addEdit

public boolean addEdit(javax.swing.undo.UndoableEdit anEdit)
Does nothing, always returns false.

Specified by:
addEdit in interface javax.swing.undo.UndoableEdit
Parameters:
anEdit - the edit to be added
Returns:
always false

replaceEdit

public boolean replaceEdit(javax.swing.undo.UndoableEdit anEdit)
Does nothing, always returns false.

Specified by:
replaceEdit in interface javax.swing.undo.UndoableEdit
Parameters:
anEdit - the edit to be replace this edit
Returns:
always false

isSignificant

public boolean isSignificant()
Returns false if this edit is insignificant--for example one that maintains the user's selection, but does not change any model state. This status can be used by an UndoableEditListener (like UndoManager) when deciding which UndoableEdits to present to the user as Undo/Redo options, and which to perform as side effects of undoing or redoing other events.

UndoRedoManager does not take any notice of this hint.

Specified by:
isSignificant in interface javax.swing.undo.UndoableEdit
Returns:
always false

getPresentationName

public java.lang.String getPresentationName()
Provides a localized, human readable description of this edit , should be detailed enough to provide a the basis of a meaningful node lable.
If name starts with assume rest of string has been escaped already

Specified by:
getPresentationName in interface javax.swing.undo.UndoableEdit
Returns:
the presentation name.

getUndoPresentationName

public java.lang.String getUndoPresentationName()
Provides a localized, human readable description of the undoable form of this edit.
If name starts with assume rest of string has been escaped already

Specified by:
getUndoPresentationName in interface javax.swing.undo.UndoableEdit

getRedoPresentationName

public java.lang.String getRedoPresentationName()
Provides a localized, human readable description of the redoable form of this edit.
If name starts with assume rest of string has been escaped already

Specified by:
getRedoPresentationName in interface javax.swing.undo.UndoableEdit

toString

public java.lang.String toString()
Returns a string representation of this UndoRedo object.
Use by the tree in its node display.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.

escapeHTML

public static java.lang.String escapeHTML(java.lang.String input)

©2005, Forward Computing and Control Pty. Ltd
ACN 003 669 994   NSW Australia
All Rights Reserved.