javax.swing.undo
Class CompoundEdit

java.lang.Object
  extended by javax.swing.undo.AbstractUndoableEdit
      extended by javax.swing.undo.CompoundEdit
All Implemented Interfaces:
Serializable, UndoableEdit
Direct Known Subclasses:
AbstractDocument.DefaultDocumentEvent, UndoManager

public class CompoundEdit
extends AbstractUndoableEdit

An editing action that consists of multiple UndoableEdits.

The use of a CompoundEdit is divided in two separate phases.

  1. In the first phase, the CompoundEdit is initialized. After a new instance of CompoundEdit has been created, addEdit(UndoableEdit) is called for each element of the compound. To terminate the initialization phase, call end().
  2. In the second phase, the the CompoundEdit can be used, typically by invoking undo() and redo().

See Also:
Serialized Form

Field Summary
protected  Vector<UndoableEdit> edits
          The UndoableEdits being combined into a compound editing action.
 
Fields inherited from class javax.swing.undo.AbstractUndoableEdit
RedoName, UndoName
 
Constructor Summary
CompoundEdit()
          Constructs a new CompoundEdit.
 
Method Summary
 boolean addEdit(UndoableEdit edit)
          Incorporates another editing action into this one, thus forming a combined edit.
 boolean canRedo()
          Determines whether it would be possible to redo this editing action.
 boolean canUndo()
          Determines whether it would be possible to undo this editing action.
 void die()
          Informs this edit action, and all compound edits, that they will no longer be used.
 void end()
          Informs this CompoundEdit that its construction phase has been completed.
 String getPresentationName()
          Returns a human-readable, localized name that describes this editing action and can be displayed to the user.
 String getRedoPresentationName()
          Calculates a localized message text for presenting the redo action to the user.
 String getUndoPresentationName()
          Calculates a localized message text for presenting the undo action to the user.
 boolean isInProgress()
          Determines whether the initial construction phase of this CompoundEdit is still in progress.
 boolean isSignificant()
          Determines whether this editing action is significant enough for being seperately undoable by the user.
protected  UndoableEdit lastEdit()
          Returns the the UndoableEdit that was last added to this compound.
 void redo()
          Redoes all edits that are part of of this CompoundEdit.
 String toString()
          Calculates a string that may be useful for debugging.
 void undo()
          Undoes all edits that are part of of this CompoundEdit.
 
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
 

Field Detail

edits

protected Vector<UndoableEdit> edits
The UndoableEdits being combined into a compound editing action.

Constructor Detail

CompoundEdit

public CompoundEdit()
Constructs a new CompoundEdit.

Method Detail

undo

public void undo()
          throws CannotUndoException
Undoes all edits that are part of of this CompoundEdit. The compound elements will receive the undo message in the reverse order of addition.

Specified by:
undo in interface UndoableEdit
Overrides:
undo in class AbstractUndoableEdit
Throws:
CannotUndoException - if canUndo() returns false. This can happen if end() has not been called on this CompoundEdit, or if this edit has already been undone.
See Also:
canUndo(), redo()

redo

public void redo()
          throws CannotRedoException
Redoes all edits that are part of of this CompoundEdit. The compound elements will receive the undo message in the same order as they were added.

Specified by:
redo in interface UndoableEdit
Overrides:
redo in class AbstractUndoableEdit
Throws:
CannotRedoException - if canRedo() returns false. This can happen if end() has not been called on this CompoundEdit, or if this edit has already been redone.
See Also:
canRedo(), undo()

lastEdit

protected UndoableEdit lastEdit()
Returns the the UndoableEdit that was last added to this compound.


die

public void die()
Informs this edit action, and all compound edits, that they will no longer be used. Some actions might use this information to release resources such as open files. Called by UndoManager before this action is removed from the edit queue.

The compound elements will receive the die message in the reverse order of addition.

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

addEdit

public boolean addEdit(UndoableEdit edit)
Incorporates another editing action into this one, thus forming a combined edit.

If this edit’s end() method has been called before, false is returned immediately. Otherwise, the last added edit is given the opportunity to incorporate edit. If this fails, edit is given the opportunity to replace the last added edit. If this fails as well, edit gets added as a new compound to edits.

Specified by:
addEdit in interface UndoableEdit
Overrides:
addEdit in class AbstractUndoableEdit
Parameters:
edit - the editing action being added.
Returns:
true if edit could somehow be incorporated; false if edit has not been incorporated because end() was called before.

end

public void end()
Informs this CompoundEdit that its construction phase has been completed. After this method has been called, undo() and redo() may be called, isInProgress() will return false, and all attempts to add further edits will fail.


canUndo

public boolean canUndo()
Determines whether it would be possible to undo this editing action. The result will be true if end() has been called on this CompoundEdit, die() has not yet been called, and the edit has not been undone already.

Specified by:
canUndo in interface UndoableEdit
Overrides:
canUndo in class AbstractUndoableEdit
Returns:
true to indicate that this action can be undone; false otherwise.
See Also:
undo(), canRedo()

canRedo

public boolean canRedo()
Determines whether it would be possible to redo this editing action. The result will be true if end() has been called on this CompoundEdit, die() has not yet been called, and the edit has not been redone already.

Specified by:
canRedo in interface UndoableEdit
Overrides:
canRedo in class AbstractUndoableEdit
Returns:
true to indicate that this action can be redone; false otherwise.
See Also:
redo(), canUndo()

isInProgress

public boolean isInProgress()
Determines whether the initial construction phase of this CompoundEdit is still in progress. During this phase, edits may be added. After initialization has been terminated by calling end(), undo() and redo() can be used.

Returns:
true if the initialization phase is still in progress; false if end() has been called.
See Also:
end()

isSignificant

public boolean isSignificant()
Determines whether this editing action is significant enough for being seperately undoable by the user. A typical significant action would be the resizing of an object. However, changing the selection in a text document would usually not be considered significant.

A CompoundEdit is significant if any of its elements are significant.

Specified by:
isSignificant in interface UndoableEdit
Overrides:
isSignificant in class AbstractUndoableEdit
Returns:
true to indicate that the action is significant enough for being separately undoable, or false otherwise.

getPresentationName

public String getPresentationName()
Returns a human-readable, localized name that describes this editing action and can be displayed to the user.

The implementation delegates the call to the last added edit action. If no edit has been added yet, the inherited implementation will be invoked, which always returns an empty string.

Specified by:
getPresentationName in interface UndoableEdit
Overrides:
getPresentationName in class AbstractUndoableEdit
Returns:
The presentation name.

getUndoPresentationName

public String getUndoPresentationName()
Calculates a localized message text for presenting the undo action to the user.

The implementation delegates the call to the last added edit action. If no edit has been added yet, the inherited implementation will be invoked.

Specified by:
getUndoPresentationName in interface UndoableEdit
Overrides:
getUndoPresentationName in class AbstractUndoableEdit
Returns:
The undo presentation name.

getRedoPresentationName

public String getRedoPresentationName()
Calculates a localized message text for presenting the redo action to the user.

The implementation delegates the call to the last added edit action. If no edit has been added yet, the inherited implementation will be invoked.

Specified by:
getRedoPresentationName in interface UndoableEdit
Overrides:
getRedoPresentationName in class AbstractUndoableEdit
Returns:
The redo presentation name.

toString

public String toString()
Calculates a string that may be useful for debugging.

Overrides:
toString in class AbstractUndoableEdit
Returns:
the String representing this Object, which may be null
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)