javax.swing.undo

Class CompoundEdit

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, {@link #addEdit(UndoableEdit)} is called for each element of the compound. To terminate the initialization phase, call {@link #end()}.
  2. In the second phase, the the CompoundEdit can be used, typically by invoking {@link #undo()} and {@link #redo()}.
Field Summary
protected Vector<UndoableEdit>edits
The UndoableEdits being combined into a compound editing action.
Constructor Summary
CompoundEdit()
Constructs a new CompoundEdit.
Method Summary
booleanaddEdit(UndoableEdit edit)
Incorporates another editing action into this one, thus forming a combined edit.
booleancanRedo()
Determines whether it would be possible to redo this editing action.
booleancanUndo()
Determines whether it would be possible to undo this editing action.
voiddie()
Informs this edit action, and all compound edits, that they will no longer be used.
voidend()
Informs this CompoundEdit that its construction phase has been completed.
StringgetPresentationName()
Returns a human-readable, localized name that describes this editing action and can be displayed to the user.
StringgetRedoPresentationName()
Calculates a localized message text for presenting the redo action to the user.
StringgetUndoPresentationName()
Calculates a localized message text for presenting the undo action to the user.
booleanisInProgress()
Determines whether the initial construction phase of this CompoundEdit is still in progress.
booleanisSignificant()
Determines whether this editing action is significant enough for being seperately undoable by the user.
protected UndoableEditlastEdit()
Returns the the UndoableEdit that was last added to this compound.
voidredo()
Redoes all edits that are part of of this CompoundEdit.
StringtoString()
Calculates a string that may be useful for debugging.
voidundo()
Undoes all edits that are part of of this CompoundEdit.

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

addEdit

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

If this edit’s {@link #end()} method has been called before, false is returned immediately. Otherwise, the {@linkplain #lastEdit() last added edit} is given the opportunity to {@linkplain UndoableEdit#addEdit(UndoableEdit) incorporate} edit. If this fails, edit is given the opportunity to {@linkplain UndoableEdit#replaceEdit(UndoableEdit) replace} the last added edit. If this fails as well, edit gets added as a new compound to {@link #edits}.

Parameters: edit the editing action being added.

Returns: true if edit could somehow be incorporated; false if edit has not been incorporated because {@link #end()} was called before.

canRedo

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

Returns: true to indicate that this action can be redone; false otherwise.

See Also: redo canUndo

canUndo

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

Returns: true to indicate that this action can be undone; false otherwise.

See Also: undo canRedo

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 {@link UndoManager} before this action is removed from the edit queue.

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

end

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

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 {@linkplain #lastEdit() last added edit action}. If no edit has been added yet, the inherited implementation will be invoked, which always returns an empty string.

getRedoPresentationName

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

The implementation delegates the call to the {@linkplain #lastEdit() last added edit action}. If no edit has been added yet, the {@linkplain AbstractUndoableEdit#getRedoPresentationName() inherited implementation} will be invoked.

getUndoPresentationName

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

The implementation delegates the call to the {@linkplain #lastEdit() last added edit action}. If no edit has been added yet, the {@linkplain AbstractUndoableEdit#getUndoPresentationName() inherited implementation} will be invoked.

isInProgress

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

Returns: true if the initialization phase is still in progress; false if {@link #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.

lastEdit

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

redo

public void redo()
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.

Throws: CannotRedoException if {@link #canRedo()} returns false. This can happen if {@link #end()} has not been called on this CompoundEdit, or if this edit has already been redone.

See Also: canRedo undo

toString

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

undo

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

Throws: CannotUndoException if {@link #canUndo()} returns false. This can happen if {@link #end()} has not been called on this CompoundEdit, or if this edit has already been undone.

See Also: canUndo redo