|
|||||||||
| Home >> All >> javax >> swing >> [ undo overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
javax.swing.undo
Class StateEdit

java.lang.Objectjavax.swing.undo.AbstractUndoableEdit
javax.swing.undo.StateEdit
- All Implemented Interfaces:
- java.io.Serializable, UndoableEdit
- public class StateEdit
- extends AbstractUndoableEdit
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.
- When a
StateEditis created, the associated StateEditable gets asked to store its state into a hash table,preState55 . - The application will now perform some changes to the edited object. This typically happens by invoking methods on the edited object.
- The editing phase is terminated by invoking the
end()55 method of theStateEdit. Theend()method does two things.- The edited object receives a second request for storing
its state. This time, it will use a different hash table,
postState55 . - To increase efficiency, the
StateEditnow removes any entries frompreState55 andpostState55 that have the same key, and whose values are equal. Equality is determined by invoking theequalsmethod inherited from java.lang.Object.
- The edited object receives a second request for storing
its state. This time, it will use a different hash table,
- When the user later chooses to undo the
StateEdit, the edited object is asked to restore its state 55 from thepreState55 table. Similarly, when the user chooses to redo theStateEdit, the edited object gets asked to restore its state from thepostState55 .
| Field Summary | |
protected StateEditable |
object
The object which is being edited by this StateEdit. |
protected java.util.Hashtable |
postState
The state of object at the time when end() 55
was called. |
protected java.util.Hashtable |
preState
The state of object at the time of constructing
this StateEdit. |
protected static java.lang.String |
RCSID
The ID of the Java source file in Sun’s Revision Control System (RCS). |
protected java.lang.String |
undoRedoName
A human-readable name for this edit action. |
| Fields inherited from class javax.swing.undo.AbstractUndoableEdit |
RedoName, serialVersionUID, UndoName |
| Constructor Summary | |
StateEdit(StateEditable obj)
Constructs a StateEdit, specifying the object whose
state is being edited. |
|
StateEdit(StateEditable obj,
java.lang.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. |
java.lang.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,
java.lang.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 |
RCSID
protected static final java.lang.String RCSID
- The ID of the Java source file in Sun’s Revision Control
System (RCS). This certainly should not be part of the API
specification. But in order to be API-compatible with
Sun’s reference implementation, GNU Classpath also has to
provide this field and match its value. The value used here has
been in every JDK release at least from 1.2 to 1.5.
- See Also:
- Constant Field Values
object
protected StateEditable object
- The object which is being edited by this
StateEdit.
preState
protected java.util.Hashtable preState
- The state of
objectat the time of constructing thisStateEdit.
postState
protected java.util.Hashtable postState
- The state of
objectat the time whenend()55 was called.
undoRedoName
protected java.lang.String undoRedoName
- A human-readable name for this edit action.
| Constructor Detail |
StateEdit
public StateEdit(StateEditable obj)
- Constructs a
StateEdit, specifying the object whose state is being edited.
StateEdit
public StateEdit(StateEditable obj, java.lang.String name)
- Constructs a
StateEdit, specifying the object whose state is being edited.
| Method Detail |
init
protected void init(StateEditable obj, java.lang.String name)
- Initializes this
StateEdit. The edited object will be asked to store its current state intopreState55 .
end
public void end()
- Informs this
StateEditthat all edits are finished. The edited object will be asked to store its state intopostState55 , and any redundant entries will get removed frompreState55 andpostState55 .
undo
public void undo()
- Undoes this edit operation. The edited object will be asked to
restore its state 55 from
preState55 .- Specified by:
undoin interfaceUndoableEdit- Overrides:
undoin classAbstractUndoableEdit
redo
public void redo()
- Redoes this edit operation. The edited object will be asked to
restore its state 55 from
postState55 .- Specified by:
redoin interfaceUndoableEdit- Overrides:
redoin classAbstractUndoableEdit
getPresentationName
public java.lang.String getPresentationName()
- Returns a human-readable, localized name that describes this
editing action and can be displayed to the user.
- Specified by:
getPresentationNamein interfaceUndoableEdit- Overrides:
getPresentationNamein classAbstractUndoableEdit
removeRedundantState
protected void removeRedundantState()
- Removes all redundant entries from the pre- and post-edit state
hash tables. An entry is considered redundant if it is present
both before and after the edit, and if the two values are equal.
|
|||||||||
| Home >> All >> javax >> swing >> [ undo overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC