Java Reference
In-Depth Information
Besides being able to directly add editable operations with
addEdit()
, the manager also
serves as an
UndoableEditListener
. When the
UndoableEditEvent
happens, the listener adds
the event's
UndoableEdit
command to the manager with
addEdit()
. In addition, you can clear
the edit queue with public void
discardAllEdits()
. After the manager receives the
end()
method,
the sequence goes back to looking like Figure 21-3, leaving the bottom three states (Undoable,
Redoable, and Done) shown in the chart. The whole sequencing is shown in Figure 21-4.
Figure 21-4.
UndoManager states
Keep in mind that certain
undo()
and
redo()
calls can throw exceptions. In addition, when
you ask the
UndoManager
to undo or redo an edit command, the request undoes (or redoes) all
commands up to the last significant one.
The transformation of the
UndoManager
into a
CompoundEdit
might seem confusing to some
users. This transformation allows you to have a secondary
UndoManager
for certain subopera-
tions that, once completed, become a single
CompoundEdit
to be passed along to the primary
UndoManager
.