UndoableEdit (Java SE 15 & JDK 15) (original) (raw)

All Known Implementing Classes:

[AbstractDocument.DefaultDocumentEvent](../text/AbstractDocument.DefaultDocumentEvent.html "class in javax.swing.text"), [AbstractDocument.ElementEdit](../text/AbstractDocument.ElementEdit.html "class in javax.swing.text"), [AbstractUndoableEdit](AbstractUndoableEdit.html "class in javax.swing.undo"), [CompoundEdit](CompoundEdit.html "class in javax.swing.undo"), [DefaultStyledDocument.AttributeUndoableEdit](../text/DefaultStyledDocument.AttributeUndoableEdit.html "class in javax.swing.text"), [StateEdit](StateEdit.html "class in javax.swing.undo"), [UndoManager](UndoManager.html "class in javax.swing.undo")


public interface UndoableEdit

An UndoableEdit represents an edit. The edit may be undone, or if already undone the edit may be redone.

UndoableEdit is designed to be used with theUndoManager. As UndoableEdits are generated by an UndoableEditListener they are typically added to the UndoManager. When an UndoableEdit is added to an UndoManager the following occurs (assumingend has not been called on the UndoManager):

  1. If the UndoManager contains edits it will calladdEdit on the current edit passing in the new edit as the argument. If addEdit returns 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 addEdit as a way for smaller edits to be incorporated into a larger edit and treated as a single edit.
  2. If addEdit returns false replaceEdit is 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.

The UndoManager makes use ofisSignificant to determine how many edits should be undone or redone. The UndoManager will undo or redo all insignificant edits (isSignificant returns false) between the current edit and the last or next significant edit. addEdit andreplaceEdit can be used to treat multiple edits as a single edit, returning false from isSignificant allows for treating can be used to have many smaller edits undone or redone at once. Similar functionality can also be done using the addEdit method.

Modifier and Type Method Description
boolean addEdit​(UndoableEdit anEdit) Adds an UndoableEdit to this UndoableEdit.
boolean canRedo() Returns true if this edit may be redone.
boolean canUndo() Returns true if this edit may be undone.
void die() Informs the edit that it should no longer be used.
String getPresentationName() Returns a localized, human-readable description of this edit, suitable for use in a change log, for example.
String getRedoPresentationName() Returns a localized, human-readable description of the redoable form of this edit, suitable for use as a Redo menu item, for example.
String getUndoPresentationName() Returns a localized, human-readable description of the undoable form of this edit, suitable for use as an Undo menu item, for example.
boolean isSignificant() Returns true if this edit is considered significant.
void redo() Re-applies the edit.
boolean replaceEdit​(UndoableEdit anEdit) Returns true if this UndoableEdit should replaceanEdit.
void undo() Undo the edit.