com.nwoods.jgo
Class JGoDocumentChangedEdit

java.lang.Object
  extended bycom.nwoods.jgo.AbstractUndoableEdit
      extended bycom.nwoods.jgo.JGoDocumentChangedEdit
All Implemented Interfaces:
java.io.Serializable, UndoableEdit

public class JGoDocumentChangedEdit
extends AbstractUndoableEdit

JGoDocumentChangedEdit is an UndoableEdit that remembers the document it is associated with, the kind of change it represents, and the before and after state (usually a property value) for that kind of change. This class represents a low-level, detailed change. These are collected together in a CompoundEdit by the JGoUndoManager to represent the potentially many changes caused by a user's single logical gesture such as a moving the current selection.

For both the old and the new values, this remembers both an integer and an Object, which is enough for the vast majority of kinds of changes. There are convenience methods for remembering booleans as an integers, and for remembering floats and doubles as Objects. There are also convenience methods, typically called by changeValue, for getting a value based on whether for undo or for redo. In these methods if the undo parameter is true, it returns the old value, otherwise it returns the new value.

This class calls the copyOldValueForUndo, copyNewValueForRedo, and changeValue methods of JGoDocument and (indirectly) JGoObject. The former two methods are used to remember the before and after states of the document or object for the given hint; the latter method is called in order to actually perform the undo or redo.

See Also:
JGoUndoManager, JGoDocument, JGoDocumentEvent, Serialized Form

Constructor Summary
JGoDocumentChangedEdit(JGoDocumentEvent e, JGoUndoManager mgr, boolean isbefore)
          Construct an UndoableEdit that remembers standard information for undoing and redoing JGoDocument (and JGoObject) changes.
 
Method Summary
 boolean canRedo()
           
 boolean canUndo()
           
 void die()
          Clear out any references held by this edit.
 JGoDocumentChangedEdit findBeforeChangingEdit()
          Return the last BeforeChanging JGoDocumentChangedEdit in the list of UndoableEdits maintained by this Edit's UndoManager.
 JGoDocument getDoc()
          Return the document associated with this edit.
 int getFlags()
          Return the JGoDocumentEvent flags or sub-hint associated with this edit.
 int getHint()
          Return the JGoDocumentEvent hint associated with this edit.
 java.lang.Object getNewValue()
          Return the Object part of the new state information.
 boolean getNewValueBoolean()
          Return the integer part of the new state information as a boolean.
 double getNewValueDouble()
          Return the Object part of the new state information assuming a double.
 int getNewValueInt()
          Return the integer part of the new state information.
 java.lang.Object getObject()
          Return the JGoDocumentEvent Object associated with this edit.
 java.lang.Object getOldValue()
          Return the Object part of the previous state information.
 boolean getOldValueBoolean()
          Return the integer part of the previous state information as a boolean.
 double getOldValueDouble()
          Return the Object part of the previous state information assuming a double.
 int getOldValueInt()
          Return the integer part of the previous state information.
 java.lang.String getPresentationName()
           
 JGoUndoManager getUndoManager()
          Return the JGoUndoManager that this Edit is part of
 java.lang.Object getValue(boolean undo)
          This convenience method returns either getOldValue() if undo is true, or getNewValue() otherwise.
 boolean getValueBoolean(boolean undo)
          This convenience method returns either getOldValueBoolean() if undo is true, or getNewValueBoolean() otherwise.
 double getValueDouble(boolean undo)
          This convenience method returns either getOldValueDouble() if undo is true, or getNewValueDouble() otherwise.
 int getValueInt(boolean undo)
          This convenience method returns either getOldValueInt() if undo is true, or getNewValueInt() otherwise.
 boolean isBeforeChanging()
          Return true if this Edit resulted from a JGoDocumentEvent whose isBeforeChanging() method returned true.
 void redo()
          Implement redo by calling changeValue on the document, unless the edit represents an isBeforeChanging() event.
 void setNewValue(java.lang.Object x)
          Set the Object part of the new state information.
 void setNewValueBoolean(boolean b)
          Set the integer part of the new state information, assuming zero is false.
 void setNewValueDouble(double d)
          Set the Object part of the new state information as a Double.
 void setNewValueInt(int i)
          Set the integer part of the new state information.
 void setOldValue(java.lang.Object x)
          Set the Object part of the previous state information.
 void setOldValueBoolean(boolean b)
          Set the integer part of the previous state information, assuming zero is false.
 void setOldValueDouble(double d)
          Set the Object part of the previous state information as a Double.
 void setOldValueInt(int i)
          Set the integer part of the previous state information.
 java.lang.String toString()
          Produce a somewhat human-readable description of this particular change to a document.
 void undo()
          Implement undo by calling changeValue on the document, unless the edit represents an isBeforeChanging() event.
 
Methods inherited from class com.nwoods.jgo.AbstractUndoableEdit
addEdit, getRedoPresentationName, getUndoPresentationName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JGoDocumentChangedEdit

public JGoDocumentChangedEdit(JGoDocumentEvent e,
                              JGoUndoManager mgr,
                              boolean isbefore)
Construct an UndoableEdit that remembers standard information for undoing and redoing JGoDocument (and JGoObject) changes.

Method Detail

die

public void die()
Clear out any references held by this edit.

Specified by:
die in interface UndoableEdit
Overrides:
die in class AbstractUndoableEdit

toString

public java.lang.String toString()
Produce a somewhat human-readable description of this particular change to a document.


getPresentationName

public java.lang.String getPresentationName()
Specified by:
getPresentationName in interface UndoableEdit
Overrides:
getPresentationName in class AbstractUndoableEdit

canUndo

public boolean canUndo()
Specified by:
canUndo in interface UndoableEdit
Overrides:
canUndo in class AbstractUndoableEdit

canRedo

public boolean canRedo()
Specified by:
canRedo in interface UndoableEdit
Overrides:
canRedo in class AbstractUndoableEdit

undo

public void undo()
          throws CannotUndoException
Implement undo by calling changeValue on the document, unless the edit represents an isBeforeChanging() event.

Specified by:
undo in interface UndoableEdit
Overrides:
undo in class AbstractUndoableEdit
Throws:
CannotUndoException

redo

public void redo()
          throws CannotRedoException
Implement redo by calling changeValue on the document, unless the edit represents an isBeforeChanging() event.

Specified by:
redo in interface UndoableEdit
Overrides:
redo in class AbstractUndoableEdit
Throws:
CannotRedoException

isBeforeChanging

public boolean isBeforeChanging()
Return true if this Edit resulted from a JGoDocumentEvent whose isBeforeChanging() method returned true.


findBeforeChangingEdit

public JGoDocumentChangedEdit findBeforeChangingEdit()
Return the last BeforeChanging JGoDocumentChangedEdit in the list of UndoableEdits maintained by this Edit's UndoManager.

Returns:
a JGoDocumentChangedEdit that isBeforeChanging() for the same document (and object, if any) and hints/flags

getUndoManager

public JGoUndoManager getUndoManager()
Return the JGoUndoManager that this Edit is part of


getDoc

public JGoDocument getDoc()
Return the document associated with this edit.


getHint

public int getHint()
Return the JGoDocumentEvent hint associated with this edit.


getFlags

public int getFlags()
Return the JGoDocumentEvent flags or sub-hint associated with this edit.


getObject

public java.lang.Object getObject()
Return the JGoDocumentEvent Object associated with this edit. This may be null, depending on the hint/sub-hint.


getValueInt

public int getValueInt(boolean undo)
This convenience method returns either getOldValueInt() if undo is true, or getNewValueInt() otherwise.


getValueBoolean

public boolean getValueBoolean(boolean undo)
This convenience method returns either getOldValueBoolean() if undo is true, or getNewValueBoolean() otherwise.


getValue

public java.lang.Object getValue(boolean undo)
This convenience method returns either getOldValue() if undo is true, or getNewValue() otherwise.


getValueDouble

public double getValueDouble(boolean undo)
This convenience method returns either getOldValueDouble() if undo is true, or getNewValueDouble() otherwise.


getOldValueInt

public int getOldValueInt()
Return the integer part of the previous state information.


setOldValueInt

public void setOldValueInt(int i)
Set the integer part of the previous state information.


getOldValueBoolean

public boolean getOldValueBoolean()
Return the integer part of the previous state information as a boolean. (Zero is false, non-zero is true.)


setOldValueBoolean

public void setOldValueBoolean(boolean b)
Set the integer part of the previous state information, assuming zero is false.


getOldValue

public java.lang.Object getOldValue()
Return the Object part of the previous state information.


setOldValue

public void setOldValue(java.lang.Object x)
Set the Object part of the previous state information.


getOldValueDouble

public double getOldValueDouble()
Return the Object part of the previous state information assuming a double.


setOldValueDouble

public void setOldValueDouble(double d)
Set the Object part of the previous state information as a Double.


getNewValueInt

public int getNewValueInt()
Return the integer part of the new state information.


setNewValueInt

public void setNewValueInt(int i)
Set the integer part of the new state information.


getNewValueBoolean

public boolean getNewValueBoolean()
Return the integer part of the new state information as a boolean. (Zero is false, non-zero is true.)


setNewValueBoolean

public void setNewValueBoolean(boolean b)
Set the integer part of the new state information, assuming zero is false.


getNewValue

public java.lang.Object getNewValue()
Return the Object part of the new state information.


setNewValue

public void setNewValue(java.lang.Object x)
Set the Object part of the new state information.


getNewValueDouble

public double getNewValueDouble()
Return the Object part of the new state information assuming a double.


setNewValueDouble

public void setNewValueDouble(double d)
Set the Object part of the new state information as a Double.