public class UndoListener
extends java.lang.Object
implements javax.swing.event.UndoableEditListener
A convenience constructor has been provided such that a caller can immediately have default shortcut key mappings for undo/redo actions on the text component
Modifier and Type | Class and Description |
---|---|
protected class |
UndoListener.RedoAction
Perform the redo action.
|
protected class |
UndoListener.UndoAction
Perform the undo action.
|
Modifier and Type | Field and Description |
---|---|
protected javax.swing.undo.CompoundEdit |
_compoundEdit
A compound undo edit, or null if none is progress.
|
protected UndoListener.RedoAction |
_redoAction
The redo action.
|
protected javax.swing.undo.UndoManager |
_undo
The undo manager.
|
protected UndoListener.UndoAction |
_undoAction
The undo action.
|
Constructor and Description |
---|
UndoListener()
Construct an undo listener.
|
UndoListener(javax.swing.text.JTextComponent textArea)
Construct an undo listener with default key mappings.
|
Modifier and Type | Method and Description |
---|---|
void |
endCompoundEdit()
End a compound edit.
|
void |
redo()
Perform a redo.
|
void |
startCompoundEdit()
Start a compound undo edit.
|
void |
undo()
Perform an undo.
|
void |
undoableEditHappened(javax.swing.event.UndoableEditEvent event)
Remember the edit and update the action state.
|
protected UndoListener.RedoAction _redoAction
protected javax.swing.undo.CompoundEdit _compoundEdit
protected UndoListener.UndoAction _undoAction
protected javax.swing.undo.UndoManager _undo
public UndoListener()
This constructor allows simple usage without setting up key mapping automatically (it is then the responsibilty of the caller to provide a mechanism for invoking the undo and redo actions.)
public UndoListener(javax.swing.text.JTextComponent textArea)
A typical usage pattern would be:
JTextArea textArea = new JTextArea("testing");
textArea.getDocument().addUndoableEditListener(new UndoListener(textArea));
textArea
- the text component that is being listened to
and upon which undo/redo actions will be performedpublic void endCompoundEdit()
public void redo() throws javax.swing.undo.CannotUndoException
javax.swing.undo.CannotUndoException
- Thrown if the redo
cannot be done.public void startCompoundEdit()
public void undo() throws javax.swing.undo.CannotUndoException
javax.swing.undo.CannotUndoException
- Thrown if the redo
cannot be done.public void undoableEditHappened(javax.swing.event.UndoableEditEvent event)
undoableEditHappened
in interface javax.swing.event.UndoableEditListener
event
- The event that occurred.