javax.swing.undo
Class StateEdit
- Serializable, UndoableEdit
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
StateEdit
is created, the associated
StateEditable
gets asked to store its state into a hash
table, preState
. - 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()
method of the StateEdit
. The end()
method
does two things.
- The edited object receives a second request for storing
its state. This time, it will use a different hash table,
postState
. - To increase efficiency, the
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
. - When the user later chooses to undo the
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
.
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.
|
addEdit , canRedo , canUndo , die , getPresentationName , getRedoPresentationName , getUndoPresentationName , isSignificant , redo , replaceEdit , toString , undo |
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
RCSID
protected static final 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. However, we do not try to match its value.
preState
protected Hashtable preState
The state of object
at the time of constructing
this StateEdit
.
StateEdit
public StateEdit(StateEditable obj)
Constructs a StateEdit
, specifying the object whose
state is being edited.
obj
- the object whose state is being edited by this
StateEdit
.
StateEdit
public StateEdit(StateEditable obj,
String name)
Constructs a 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.
end
public void end()
Informs this
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
.
init
protected void init(StateEditable obj,
String name)
Initializes this
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.
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.
StateEdit.java -- UndoableEdit for StateEditable implementations.
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.