edu.rice.cs.drjava.model.definitions
Class CompoundUndoManager

java.lang.Object
  extended by javax.swing.undo.AbstractUndoableEdit
      extended by javax.swing.undo.CompoundEdit
          extended by javax.swing.undo.UndoManager
              extended by edu.rice.cs.drjava.model.definitions.CompoundUndoManager
All Implemented Interfaces:
Serializable, EventListener, UndoableEditListener, UndoableEdit

public class CompoundUndoManager
extends UndoManager

Extended UndoManager with increased functionality. Can handle aggregating multiple edits into one for the purposes of undoing and redoing. It exposes editToBeUndone and editToBeRedone (under new names); they are protected methods in UndoManager. The public methods that involve composite state are synchronized, so this manager can be accessed outside of the event thread. The internal data structures _compoundEdits and _keys are not thread safe but they only accessed only by synchronized methods. The synchronization scheme (locking on this) follows UndoManager.

Version:
$Id: CompoundUndoManager.java 4691 2008-12-02 23:33:27Z dlsmith $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.undo.CompoundEdit
edits
 
Fields inherited from class javax.swing.undo.AbstractUndoableEdit
RedoName, UndoName
 
Constructor Summary
CompoundUndoManager(GlobalEventNotifier notifier)
          Standard constructor.
 
Method Summary
 boolean _compoundEditInProgress()
          Returns whether or not a compound edit is in progress.
 boolean addEdit(UndoableEdit e)
          Adds an edit.
 boolean canUndo()
          Returns true when a compound edit is in progress, or when there are valid stored undoable edits
 void documentSaved()
          Informs this undo manager that the document has been saved.
 void endCompoundEdit(int key)
          Ends a compound edit.
 void endLastCompoundEdit()
          Ends the last compound edit that was created.
 CompoundEdit getLastCompoundEdit()
          Gets the last Compound Edit entered into the list.
 UndoableEdit getNextRedo()
          Gets the next redo.
 UndoableEdit getNextUndo()
          Gets the next undo.
 String getUndoPresentationName()
          Returns the presentation name for this undo, or delegates to super if none is available
 boolean isModified()
          Determines if the document is in the same undo state as it was when it was last saved.
 void redo()
          Overrides redo so that any compound edit in progress is ended before the redo is performed.
 int startCompoundEdit()
          Starts a compound edit.
 String toString()
           
 void undo()
          Undoes the last undoable edit, or compound edit created by the user.
 
Methods inherited from class javax.swing.undo.UndoManager
canRedo, canUndoOrRedo, discardAllEdits, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, redoTo, setLimit, trimEdits, trimForLimit, undoableEditHappened, undoOrRedo, 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
 

Constructor Detail

CompoundUndoManager

public CompoundUndoManager(GlobalEventNotifier notifier)
Standard constructor.

Method Detail

startCompoundEdit

public int startCompoundEdit()
Starts a compound edit.

Returns:
the key for the compound edit

endLastCompoundEdit

public void endLastCompoundEdit()
Ends the last compound edit that was created. Used when a compound edit is created by the _undoListener in DefinitionsPane and the key is not known in DefinitionsDocument.


endCompoundEdit

public void endCompoundEdit(int key)
Ends a compound edit.

Parameters:
key - the key that was returned by startCompoundEdit()

getLastCompoundEdit

public CompoundEdit getLastCompoundEdit()
Gets the last Compound Edit entered into the list. Used in making a Compound edit for granular undo.


getNextUndo

public UndoableEdit getNextUndo()
Gets the next undo.

Returns:
the next undo

getNextRedo

public UndoableEdit getNextRedo()
Gets the next redo.

Returns:
the next redo

addEdit

public boolean addEdit(UndoableEdit e)
Adds an edit. Checks whether or not the current edit is a compound edit.

Specified by:
addEdit in interface UndoableEdit
Overrides:
addEdit in class UndoManager
Parameters:
e - the edit to be added
Returns:
true if the add is successful, false otherwise

_compoundEditInProgress

public boolean _compoundEditInProgress()
Returns whether or not a compound edit is in progress.

Returns:
true iff in progress

canUndo

public boolean canUndo()
Returns true when a compound edit is in progress, or when there are valid stored undoable edits

Specified by:
canUndo in interface UndoableEdit
Overrides:
canUndo in class UndoManager
Returns:
true iff undoing is possible

getUndoPresentationName

public String getUndoPresentationName()
Returns the presentation name for this undo, or delegates to super if none is available

Specified by:
getUndoPresentationName in interface UndoableEdit
Overrides:
getUndoPresentationName in class UndoManager
Returns:
the undo's presentation name

undo

public void undo()
Undoes the last undoable edit, or compound edit created by the user.

Specified by:
undo in interface UndoableEdit
Overrides:
undo in class UndoManager

redo

public void redo()
Overrides redo so that any compound edit in progress is ended before the redo is performed.

Specified by:
redo in interface UndoableEdit
Overrides:
redo in class UndoManager

documentSaved

public void documentSaved()
Informs this undo manager that the document has been saved.


isModified

public boolean isModified()
Determines if the document is in the same undo state as it was when it was last saved.

Returns:
true iff all changes have been undone since the last save

toString

public String toString()
Overrides:
toString in class UndoManager