public class ZapTextComponentUndoManager extends UndoManager implements PropertyChangeListener
ZapTextComponentUndoManager
manages a list of UndoableEdit
s, providing a way to
undo or redo the appropriate edits with undo and redo actions accessible through KeyStroke
s created with Constant.ACCELERATOR_UNDO
and Constant.ACCELERATOR_REDO
,
respectively.
The default is to maintain a window of 100 undoable edits. When the limit is reached older
undoable edits start to be discarded when new ones are saved. The limit can be changed with the
method setLimit(int)
.
There are three policies that affect if, and when, the undoable edits are saved:
UndoManagerPolicy.DEFAULT
UndoManagerPolicy.ALWAYS_ENABLED
UndoManagerPolicy.ALWAYS_DISABLED
setUndoManagerPolicy
.
The ZapTextComponentUndoManager
listens to changes to the Document
of the
JTextComponent
used with the ZapTextComponentUndoManager
, so there is no need to
do anything if the document is changed.
Modifier and Type | Class and Description |
---|---|
static class |
ZapTextComponentUndoManager.UndoManagerPolicy
There are three policies that affect if, and when, the undoable edits are saved:
UndoManagerPolicy.DEFAULT
UndoManagerPolicy.ALWAYS_ENABLED
UndoManagerPolicy.ALWAYS_DISABLED
|
edits
RedoName, UndoName
Constructor and Description |
---|
ZapTextComponentUndoManager(JTextComponent textComponent)
Creates a new
ZapTextComponentUndoManager with a DEFAULT policy. |
Modifier and Type | Method and Description |
---|---|
void |
propertyChange(PropertyChangeEvent evt) |
void |
setUndoManagerPolicy(ZapTextComponentUndoManager.UndoManagerPolicy policy)
Sets the new policy.
|
addEdit, canRedo, canUndo, canUndoOrRedo, discardAllEdits, editToBeRedone, editToBeUndone, end, getLimit, getRedoPresentationName, getUndoOrRedoPresentationName, getUndoPresentationName, redo, redoTo, setLimit, toString, trimEdits, trimForLimit, undo, undoableEditHappened, undoOrRedo, undoTo
die, getPresentationName, isInProgress, isSignificant, lastEdit
replaceEdit
public ZapTextComponentUndoManager(JTextComponent textComponent)
ZapTextComponentUndoManager
with a DEFAULT
policy.textComponent
- the JTextComponent
that will have undoable edits.NullPointerException
- if textComponent is null
.ZapTextComponentUndoManager.UndoManagerPolicy.DEFAULT
public final void setUndoManagerPolicy(ZapTextComponentUndoManager.UndoManagerPolicy policy) throws NullPointerException
policy
- the new policyNullPointerException
- if policy is null
ZapTextComponentUndoManager.UndoManagerPolicy
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener