|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.undo.AbstractUndoableEdit
javax.swing.undo.StateEdit
public class StateEdit
A helper class, making it easy to support undo and redo.
The following example shows how to use this class.
Foo foo; // class Foo implements StateEditable
StateEdit edit;
edit = new StateEdit(foo, "Name Change");
foo.setName("Jane Doe");
edit.end();
undoManager.addEdit(edit);
If Foo’s implementation of StateEditable considers the name as part of the editable state,
the user can now choose “Undo Name Change” or
“Redo Name Change” from the respective menu. No
further undo support is needed from the application.
The following explains what happens in the example.
StateEdit is created, the associated
StateEditable gets asked to store its state into a hash
table, preState.end()
method of the StateEdit. The end() method
does two things.
postState.StateEdit now removes
any entries from preState and postState that have
the same key, and whose values are equal. Equality is determined
by invoking the equals method inherited from
Object.StateEdit,
the edited object is asked to restore its state from the preState table. Similarly,
when the user chooses to redo the StateEdit,
the edited object gets asked to restore its state from the postState.
| Field Summary | |
|---|---|
protected StateEditable |
object
The object which is being edited by this StateEdit. |
protected Hashtable<Object,Object> |
postState
The state of object at the time when end()
was called. |
protected Hashtable<Object,Object> |
preState
The state of object at the time of constructing
this StateEdit. |
protected static String |
RCSID
The ID of the Java source file in Sun’s Revision Control System (RCS). |
protected String |
undoRedoName
A human-readable name for this edit action. |
| Fields inherited from class javax.swing.undo.AbstractUndoableEdit |
|---|
RedoName, UndoName |
| Constructor Summary | |
|---|---|
StateEdit(StateEditable obj)
Constructs a StateEdit, specifying the object whose
state is being edited. |
|
StateEdit(StateEditable obj,
String name)
Constructs a StateEdit, specifying the object whose
state is being edited. |
|
| Method Summary | |
|---|---|
void |
end()
Informs this StateEdit that all edits are finished. |
String |
getPresentationName()
Returns a human-readable, localized name that describes this editing action and can be displayed to the user. |
protected void |
init(StateEditable obj,
String name)
Initializes this StateEdit. |
void |
redo()
Redoes this edit operation. |
protected void |
removeRedundantState()
Removes all redundant entries from the pre- and post-edit state hash tables. |
void |
undo()
Undoes this edit operation. |
| Methods inherited from class javax.swing.undo.AbstractUndoableEdit |
|---|
addEdit, canRedo, canUndo, die, getRedoPresentationName, getUndoPresentationName, isSignificant, replaceEdit, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final String RCSID
protected StateEditable object
StateEdit.
protected Hashtable<Object,Object> preState
object at the time of constructing
this StateEdit.
protected Hashtable<Object,Object> postState
object at the time when end()
was called.
protected String undoRedoName
| Constructor Detail |
|---|
public StateEdit(StateEditable obj)
StateEdit, specifying the object whose
state is being edited.
obj - the object whose state is being edited by this
StateEdit.
public StateEdit(StateEditable obj,
String name)
StateEdit, specifying the object whose
state is being edited.
obj - the object whose state is being edited by this
StateEdit.name - the human-readable name of the editing action.| Method Detail |
|---|
protected void init(StateEditable obj,
String name)
StateEdit. The edited object will
be asked to store its current state into preState.
obj - the object being edited.name - the human-readable name of the editing action.public void end()
StateEdit that all edits are finished.
The edited object will be asked to store its state into postState, and any redundant entries will get removed from
preState and postState.
public void undo()
preState.
undo in interface UndoableEditundo in class AbstractUndoableEditCannotUndoException - if AbstractUndoableEdit.canUndo() returns
false, for example because this action has already
been undone.AbstractUndoableEdit.canUndo(),
AbstractUndoableEdit.redo()public void redo()
postState.
redo in interface UndoableEditredo in class AbstractUndoableEditCannotRedoException - if AbstractUndoableEdit.canRedo() returns
false, for example because this action has not yet
been undone.AbstractUndoableEdit.canRedo(),
AbstractUndoableEdit.undo()public String getPresentationName()
getPresentationName in interface UndoableEditgetPresentationName in class AbstractUndoableEditnull if no presentation
name is available.protected void removeRedundantState()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||