public interface UndoableEdit
UndoableEditrepresents an edit. The edit may be undone, or if already undone the edit may be redone.
UndoableEdit is designed to be used with the
UndoableEdits are generated
UndoableEditListener they are typically added to
UndoManager. When an
is added to an
UndoManager the following occurs (assuming
end has not been called on the
UndoManagercontains edits it will call
addEditon the current edit passing in the new edit as the argument. If
addEditreturns true the new edit is assumed to have been incorporated into the current edit and the new edit will not be added to the list of current edits. Edits can use
addEditas a way for smaller edits to be incorporated into a larger edit and treated as a single edit.
replaceEditis called on the new edit with the current edit passed in as the argument. This is the inverse of
addEdit if the new edit returns true from
replaceEdit, the new edit replaces the current edit.
UndoManagermakes use of
isSignificantto determine how many edits should be undone or redone. The
UndoManagerwill undo or redo all insignificant edits (
isSignificantreturns false) between the current edit and the last or next significant edit.
replaceEditcan be used to treat multiple edits as a single edit, returning false from
isSignificantallows for treating can be used to have many smaller edits undone or redone at once. Similar functionality can also be done using the
|Modifier and Type||Method and Description|
Returns true if this edit may be redone.
Returns true if this edit may be undone.
Informs the edit that it should no longer be used.
Returns a localized, human-readable description of this edit, suitable for use in a change log, for example.
Returns a localized, human-readable description of the redoable form of this edit, suitable for use as a Redo menu item, for example.
Returns a localized, human-readable description of the undoable form of this edit, suitable for use as an Undo menu item, for example.
Returns true if this edit is considered significant.
Re-applies the edit.
Returns true if this
Undo the edit.
void undo() throws CannotUndoException
CannotUndoException- if this edit can not be undone
void redo() throws CannotRedoException
CannotRedoException- if this edit can not be redone
UndoableEdithas been marked as dead it can no longer be undone or redone.
This is a useful hook for cleaning up state no longer
needed once undoing or redoing is impossible--for example,
deleting file resources used by objects that can no longer be
UndoManager calls this before it dequeues edits.
Note that this is a one-way operation. There is no "un-die" method.
boolean addEdit(UndoableEdit anEdit)
UndoableEdit. This method can be used to coalesce smaller edits into a larger compound edit. For example, text editors typically allow undo operations to apply to words or sentences. The text editor may choose to generate edits on each key event, but allow those edits to be coalesced into a more user-friendly unit, such as a word. In this case, the
addEditto return true when the edits may be coalesced.
A return value of true indicates
anEdit was incorporated
into this edit. A return value of false indicates
may not be incorporated into this edit.
Typically the receiver is already in the queue of a
UndoManager (or other
and is being given a chance to incorporate
rather than letting it be added to the queue in turn.
If true is returned, from now on
anEdit must return
and must throw the appropriate exception on
anEdit- the edit to be added
anEditmay be incorporated into this edit
boolean replaceEdit(UndoableEdit anEdit)
anEdit. This method is used by
UndoManager; it is called if
anEditcould not be added to the current edit (
This method provides a way for an edit to replace an existing edit.
This message is the opposite of addEdit--anEdit has typically
already been queued in an
UndoManager (or other
UndoableEditListener), and the receiver is being given a chance
to take its place.
If true is returned, from now on anEdit must return false from canUndo() and canRedo(), and must throw the appropriate exception on undo() or redo().
anEdit- the edit that replaces the current edit
UndoManagerwill undo, or redo, all insignificant edits to the next significant edit.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2018, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.