javax.swing.undo

Class AbstractUndoableEdit

public class AbstractUndoableEdit extends Object implements UndoableEdit, Serializable

A default implementation of UndoableEdit that can be used as a base for implementing editing operations.
Field Summary
protected static StringRedoName
The constant string “Redo”, which was returned by {@link #getRedoPresentationName()} on early versions of the platform.
protected static StringUndoName
The constant string “Undo”, which was returned by {@link #getUndoPresentationName()} on early versions of the platform.
Constructor Summary
AbstractUndoableEdit()
Constructs a new AbstractUndoableEdit.
Method Summary
booleanaddEdit(UndoableEdit edit)
Incorporates another editing action into this one, thus forming a combined action.
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 that it will no longer be used.
StringgetPresentationName()
Returns a human-readable, localized name that describes this editing action and can be displayed to the user.
StringgetRedoPresentationName()
Calculates a localized name for presenting the redo action to the user.
StringgetUndoPresentationName()
Calculates a localized name for presenting the undo action to the user.
booleanisSignificant()
Determines whether this editing action is significant enough for being seperately undoable by the user.
voidredo()
Redoes this editing action.
booleanreplaceEdit(UndoableEdit edit)
Incorporates another editing action into this one, thus forming a combined action that replaces the argument action.
StringtoString()
voidundo()
Undoes this editing action.

Field Detail

RedoName

protected static final String RedoName
The constant string “Redo”, which was returned by {@link #getRedoPresentationName()} on early versions of the platform. However, this field has become obsolete with version 1.3.1. That method now retrieves a localized string from the {@link javax.swing.UIManager}, using the key “AbstractUndoableEdit.redoText”.

UndoName

protected static final String UndoName
The constant string “Undo”, which was returned by {@link #getUndoPresentationName()} on early versions of the platform. However, this field has become obsolete with version 1.3.1. That method now retrieves a localized string from the {@link javax.swing.UIManager}, using the key “AbstractUndoableEdit.undoText”.

Constructor Detail

AbstractUndoableEdit

public AbstractUndoableEdit()
Constructs a new AbstractUndoableEdit. The initial state is that the editing action is alive, and hasBeenDone is true.

Method Detail

addEdit

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

The default implementation always returns false, indicating that the editing action could not be incorporated.

Parameters: edit the editing action to be incorporated.

canRedo

public boolean canRedo()
Determines whether it would be possible to redo this editing action.

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.

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

See Also: undo canRedo

die

public void die()
Informs this edit action that it will no longer be used. Some actions might use this information to release resources, for example open files. Called by {@link UndoManager} before this action is removed from the edit queue.

getPresentationName

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

The default implementation returns an empty string.

getRedoPresentationName

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

The default implementation returns the concatenation of the string “Redo” and the action name, which is determined by calling {@link #getPresentationName()}.

The string “Redo” is retrieved from the {@link javax.swing.UIManager}, using the key “AbstractUndoableEdit.redoText”. This allows the text to be localized.

getUndoPresentationName

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

The default implementation returns the concatenation of the string “Undo” and the action name, which is determined by calling {@link #getPresentationName()}.

The string “Undo” is retrieved from the {@link javax.swing.UIManager}, using the key “AbstractUndoableEdit.undoText”. This allows the text to be localized.

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.

The default implementation returns true.

Returns: true to indicate that the action is significant enough for being separately undoable, or false otherwise.

redo

public void redo()
Redoes this editing action.

Throws: CannotRedoException if {@link #canRedo()} returns false, for example because this action has not yet been undone.

See Also: canRedo undo

replaceEdit

public boolean replaceEdit(UndoableEdit edit)
Incorporates another editing action into this one, thus forming a combined action that replaces the argument action.

The default implementation always returns false, indicating that the argument action should not be replaced.

Parameters: edit the editing action to be replaced.

toString

public String toString()

undo

public void undo()
Undoes this editing action.

Throws: CannotUndoException if {@link #canUndo()} returns false, for example because this action has already been undone.

See Also: canUndo redo