javax.swing.undo
Class AbstractUndoableEdit

java.lang.Object
  extended by javax.swing.undo.AbstractUndoableEdit
All Implemented Interfaces:
Serializable, UndoableEdit
Direct Known Subclasses:
AbstractDocument.ElementEdit, CompoundEdit, DefaultStyledDocument.AttributeUndoableEdit, StateEdit

public class AbstractUndoableEdit
extends Object
implements UndoableEdit, Serializable

A default implementation of UndoableEdit that can be used as a base for implementing editing operations.

See Also:
Serialized Form

Field Summary
protected static String RedoName
          The constant string “Redo”, which was returned by getRedoPresentationName() on early versions of the platform.
protected static String UndoName
          The constant string “Undo”, which was returned by getUndoPresentationName() on early versions of the platform.
 
Constructor Summary
AbstractUndoableEdit()
          Constructs a new AbstractUndoableEdit.
 
Method Summary
 boolean addEdit(UndoableEdit edit)
          Incorporates another editing action into this one, thus forming a combined action.
 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 that it will no longer be used.
 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 name for presenting the redo action to the user.
 String getUndoPresentationName()
          Calculates a localized name for presenting the undo action to the user.
 boolean isSignificant()
          Determines whether this editing action is significant enough for being seperately undoable by the user.
 void redo()
          Redoes this editing action.
 boolean replaceEdit(UndoableEdit edit)
          Incorporates another editing action into this one, thus forming a combined action that replaces the argument action.
 String toString()
          Convert this Object to a human-readable String.
 void undo()
          Undoes this editing action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UndoName

protected static final String UndoName
The constant string “Undo”, which was returned by 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 UIManager, using the key “AbstractUndoableEdit.undoText”.

See Also:
Constant Field Values

RedoName

protected static final String RedoName
The constant string “Redo”, which was returned by 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 UIManager, using the key “AbstractUndoableEdit.redoText”.

See Also:
Constant Field Values
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

undo

public void undo()
          throws CannotUndoException
Undoes this editing action.

Specified by:
undo in interface UndoableEdit
Throws:
CannotUndoException - if canUndo() returns false, for example because this action has already been undone.
See Also:
canUndo(), redo()

canUndo

public boolean canUndo()
Determines whether it would be possible to undo this editing action.

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

redo

public void redo()
          throws CannotRedoException
Redoes this editing action.

Specified by:
redo in interface UndoableEdit
Throws:
CannotRedoException - if canRedo() returns false, for example because this action has not yet been undone.
See Also:
canRedo(), undo()

canRedo

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

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

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

Specified by:
die in interface UndoableEdit

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.

Specified by:
addEdit in interface UndoableEdit
Parameters:
edit - the editing action to be incorporated.
Returns:
true if the edit was combined successfully, and false if it could not be combined.

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.

Specified by:
replaceEdit in interface UndoableEdit
Parameters:
edit - the editing action to be replaced.
Returns:
true if the edit is successfully replaced, and false otherwise.

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.

Specified by:
isSignificant in interface UndoableEdit
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 default implementation returns an empty string.

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

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 getPresentationName().

The string “Undo” is retrieved from the UIManager, using the key “AbstractUndoableEdit.undoText”. This allows the text to be localized.

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

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 getPresentationName().

The string “Redo” is retrieved from the UIManager, using the key “AbstractUndoableEdit.redoText”. This allows the text to be localized.

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

toString

public String toString()
Description copied from class: Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() and such.

It is typical, but not required, to ensure that this method never completes abruptly with a RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).

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