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

au.com.forward.undoRedo
Class UndoRedoEdit

java.lang.Object
  extended by javax.swing.undo.AbstractUndoableEdit
      extended by au.com.forward.undoRedo.UndoRedoEdit
All Implemented Interfaces:
ICanBeRolledBack, IHaveDescription, java.io.Serializable, javax.swing.undo.UndoableEdit

public abstract class UndoRedoEdit
extends javax.swing.undo.AbstractUndoableEdit
implements ICanBeRolledBack, IHaveDescription

See Also:
Serialized Form

Field Summary
protected  java.lang.String description
           
 
Fields inherited from class javax.swing.undo.AbstractUndoableEdit
RedoName, UndoName
 
Constructor Summary
UndoRedoEdit()
          Creates a new instance of UndoRedoEdit
 
Method Summary
 void cancelGetDescription()
          Cancels getDescription
This is called when the undo/redo tree selection changes to cancel the previous getDescription.
 void getDescription(IDisplayText textDisplay)
          Gets the Description of the UndoableEdit.
 java.lang.Long getFrameMarker()
          Returns the last frameMarker set
Because the frameMarker is set for the original edit and every subsequent undo/redo of it, the frameMarker needs to be saved with the task preforming the operation.
 void setFrameMarker(java.lang.Long marker)
          Called by the UndoRedoManager to set the frame marker for future roll back.
 void setUndoState(boolean undoState)
          Sets the undo or redo state.
 
Methods inherited from class javax.swing.undo.AbstractUndoableEdit
addEdit, canRedo, canUndo, die, getPresentationName, getRedoPresentationName, getUndoPresentationName, isSignificant, redo, replaceEdit, toString, undo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface au.com.forward.undoRedo.IHaveDescription
getDescription
 

Field Detail

description

protected java.lang.String description
Constructor Detail

UndoRedoEdit

public UndoRedoEdit()
Creates a new instance of UndoRedoEdit

Method Detail

getDescription

public void getDescription(IDisplayText textDisplay)
Gets the Description of the UndoableEdit.
If getting the description will take some time, such as generating a diff for example. Then display a short message and start a thread to call back to the textDisplay.setText() when the description is ready.
If the selection has changed before textDisplay.setText() is called, then the text is discarded.
cancelGetDescription() is called when the selection changes and the text is no longer needed.


cancelGetDescription

public void cancelGetDescription()
Cancels getDescription
This is called when the undo/redo tree selection changes to cancel the previous getDescription.

Specified by:
cancelGetDescription in interface IHaveDescription

setFrameMarker

public void setFrameMarker(java.lang.Long marker)
Called by the UndoRedoManager to set the frame marker for future roll back.
This method is called when the UndoableEdit is registered with the UndoRedoManager and each time an undo or redo operation is performed so it needs to be saved with the task performing the operation.

Specified by:
setFrameMarker in interface ICanBeRolledBack
Parameters:
marker - the frameMarker associated with this operation

getFrameMarker

public java.lang.Long getFrameMarker()
Returns the last frameMarker set
Because the frameMarker is set for the original edit and every subsequent undo/redo of it, the frameMarker needs to be saved with the task preforming the operation.

This implementation nulls the frameMarker when it is returned. This means this method can only be called once for each marker set. Nulling the frameMarker here allows it to be garbaged collected from the UndoRedoManager when there are not other references.

Specified by:
getFrameMarker in interface ICanBeRolledBack
Returns:
the last frameMarker set.

setUndoState

public void setUndoState(boolean undoState)
Sets the undo or redo state.
Called multiple times by the UndoRedoManager when rolling back to reset the UndoableEdit to its initial state.

This method should also do any other clean up necessary in the UndoableEdit to return it to its previous state.

This method is only called to toggle the state. That is if the current state is canRedo() the only call will be setUndoRedoState(true);

Specified by:
setUndoState in interface ICanBeRolledBack
Parameters:
undoState - true to return UndoableEdit to undo state, false to return it to a redo state.

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