Java Reference
In-Depth Information
If you were using the Undo Framework outside the Swing text components, the Document
element would be replaced with a receiver specific to your client application. You would need
to create your own UndoableEdit interface implementation to act as the Concrete Command
for the pattern. Instead of implementing the interface directly, you merely need to subclass the
AbstractUndoableEdit class to encapsulate the specific information about your command.
The design pattern is quite powerful. No matter which command class you're using within
the pattern, you can set up capabilities, such as macros for tasks along the lines of automated
testing, because the Invoker can sequence the commands at its leisure.
Undo Framework Components
You've seen the Undo Framework in action with the Swing text components and reviewed the
Command design pattern. Let's now look at the individual pieces of the framework.
UndoableEdit Interface
The first Undo Framework piece is the UndoableEdit interface, which has the following
definition:
public interface UndoableEdit {
// Properties
public String getPresentationName();
public String getRedoPresentationName();
public boolean isSignificant();
public String getUndoPresentationName();
// Other Methods
public boolean addEdit(UndoableEdit anEdit);
public boolean canRedo();
public boolean canUndo();
public void die();
public void redo() throws CannotRedoException;
public boolean replaceEdit(UndoableEdit anEdit);
public void undo() throws CannotUndoException;
}
This interface defines the operations that can be done to an object that should support
undo and redo capabilities. In addition to describing the supported operations, the interface
implicitly defines the three states that an undoable operation can be in, as shown in Figure 21-2.
Search WWH ::




Custom Search