AbstractUndoableEdit (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../../java.base/java/io/Serializable.html "interface in java.io")
, [UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Direct Known Subclasses:
[AbstractDocument.ElementEdit](../text/AbstractDocument.ElementEdit.html "class in javax.swing.text")
, [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")
public class AbstractUndoableEdit extends Object implements UndoableEdit, Serializable
An abstract implementation of UndoableEdit
, implementing simple responses to all boolean methods in that interface.
Field Summary
Fields
Modifier and Type | Field | Description |
---|---|---|
protected static String | RedoName | String returned by getRedoPresentationName; as of Java 2 platform v1.3.1 this field is no longer used. |
protected static String | UndoName | String returned by getUndoPresentationName; as of Java 2 platform v1.3.1 this field is no longer used. |
Constructor Summary
Constructors
Constructor | Description |
---|---|
AbstractUndoableEdit() | Creates an AbstractUndoableEdit which defaultshasBeenDone and alive to true. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
boolean | addEdit(UndoableEdit anEdit) | This default implementation returns false. |
boolean | canRedo() | Returns true if this edit is alive and hasBeenDone is false. |
boolean | canUndo() | Returns true if this edit is alive and hasBeenDone is true. |
void | die() | Sets alive to false. |
String | getPresentationName() | This default implementation returns "". |
String | getRedoPresentationName() | Retreives the value from the defaults table with keyAbstractUndoableEdit.redoText and returns that value followed by a space, followed bygetPresentationName. |
String | getUndoPresentationName() | Retreives the value from the defaults table with keyAbstractUndoableEdit.undoText and returns that value followed by a space, followed bygetPresentationName. |
boolean | isSignificant() | This default implementation returns true. |
void | redo() | Throws CannotRedoException if canRedo returns false. |
boolean | replaceEdit(UndoableEdit anEdit) | This default implementation returns false. |
String | toString() | Returns a string that displays and identifies this object's properties. |
void | undo() | Throws CannotUndoException if canUndo returns false. |
Field Details
UndoName
protected static final String UndoName
String returned bygetUndoPresentationName
; as of Java 2 platform v1.3.1 this field is no longer used. This value is now localized and comes from the defaults table with keyAbstractUndoableEdit.undoText
.
See Also:
UIDefaults, Constant Field ValuesRedoName
protected static final String RedoName
String returned bygetRedoPresentationName
; as of Java 2 platform v1.3.1 this field is no longer used. This value is now localized and comes from the defaults table with keyAbstractUndoableEdit.redoText
.
See Also:
UIDefaults, Constant Field ValuesConstructor Details
AbstractUndoableEdit
public AbstractUndoableEdit()
Creates anAbstractUndoableEdit
which defaultshasBeenDone
andalive
totrue
.Method Details
die
public void die()
Setsalive
to false. Note that this is a one way operation; dead edits cannot be resurrected. Sendingundo
orredo
to a dead edit results in an exception being thrown.
Typically an edit is killed when it is consolidated by another edit'saddEdit
orreplaceEdit
method, or when it is dequeued from anUndoManager
.
Specified by:
[die](UndoableEdit.html#die%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
See Also:
CompoundEdit.die()undo
Throws
CannotUndoException
ifcanUndo
returnsfalse
. SetshasBeenDone
tofalse
. Subclasses should override to undo the operation represented by this edit. Override should begin with a call to super.
Specified by:
[undo](UndoableEdit.html#undo%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Throws:
[CannotUndoException](CannotUndoException.html "class in javax.swing.undo")
- ifcanUndo
returnsfalse
See Also:
canUndo()canUndo
public boolean canUndo()
Returns true if this edit isalive
andhasBeenDone
istrue
.
Specified by:
[canUndo](UndoableEdit.html#canUndo%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Returns:
true if this edit isalive
andhasBeenDone
istrue
See Also:
die(), undo(), redo()redo
Throws
CannotRedoException
ifcanRedo
returns false. SetshasBeenDone
totrue
. Subclasses should override to redo the operation represented by this edit. Override should begin with a call to super.
Specified by:
[redo](UndoableEdit.html#redo%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Throws:
[CannotRedoException](CannotRedoException.html "class in javax.swing.undo")
- ifcanRedo
returnsfalse
See Also:
canRedo()canRedo
public boolean canRedo()
Returnstrue
if this edit isalive
andhasBeenDone
isfalse
.
Specified by:
[canRedo](UndoableEdit.html#canRedo%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Returns:
true
if this edit isalive
andhasBeenDone
isfalse
See Also:
die(), undo(), redo()addEdit
This default implementation returns false.
Specified by:
[addEdit](UndoableEdit.html#addEdit%28javax.swing.undo.UndoableEdit%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Parameters:
anEdit
- the edit to be added
Returns:
false
See Also:
UndoableEdit.addEdit(javax.swing.undo.UndoableEdit)replaceEdit
This default implementation returns false.
Specified by:
[replaceEdit](UndoableEdit.html#replaceEdit%28javax.swing.undo.UndoableEdit%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Parameters:
anEdit
- the edit to replace
Returns:
false
See Also:
UndoableEdit.replaceEdit(javax.swing.undo.UndoableEdit)isSignificant
public boolean isSignificant()
This default implementation returns true.
Specified by:
[isSignificant](UndoableEdit.html#isSignificant%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Returns:
true
See Also:
UndoableEdit.isSignificant()getPresentationName
public String getPresentationName()
This default implementation returns "". Used bygetUndoPresentationName
andgetRedoPresentationName
to construct the strings they return. Subclasses should override to return an appropriate description of the operation this edit represents.
Specified by:
[getPresentationName](UndoableEdit.html#getPresentationName%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Returns:
the empty string ""
See Also:
getUndoPresentationName(), getRedoPresentationName()getUndoPresentationName
public String getUndoPresentationName()
Retreives the value from the defaults table with keyAbstractUndoableEdit.undoText
and returns that value followed by a space, followed bygetPresentationName
. IfgetPresentationName
returns "", then the defaults value is returned alone.
Specified by:
[getUndoPresentationName](UndoableEdit.html#getUndoPresentationName%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Returns:
the value from the defaults table with keyAbstractUndoableEdit.undoText
, followed by a space, followed bygetPresentationName
unlessgetPresentationName
is "" in which case, the defaults value is returned alone.
See Also:
getPresentationName()getRedoPresentationName
public String getRedoPresentationName()
Retreives the value from the defaults table with keyAbstractUndoableEdit.redoText
and returns that value followed by a space, followed bygetPresentationName
. IfgetPresentationName
returns "", then the defaults value is returned alone.
Specified by:
[getRedoPresentationName](UndoableEdit.html#getRedoPresentationName%28%29)
in interface[UndoableEdit](UndoableEdit.html "interface in javax.swing.undo")
Returns:
the value from the defaults table with keyAbstractUndoableEdit.redoText
, followed by a space, followed bygetPresentationName
unlessgetPresentationName
is "" in which case, the defaults value is returned alone.
See Also:
getPresentationName()toString
Returns a string that displays and identifies this object's properties.
Overrides:
[toString](../../../../java.base/java/lang/Object.html#toString%28%29)
in class[Object](../../../../java.base/java/lang/Object.html "class in java.lang")
Returns:
a String representation of this object