Package ptolemy.gui
Class UndoListener
- java.lang.Object
-
- ptolemy.gui.UndoListener
-
- All Implemented Interfaces:
java.util.EventListener
,javax.swing.event.UndoableEditListener
public class UndoListener extends java.lang.Object implements javax.swing.event.UndoableEditListener
An Undo/Redo listener for use with a JTextComponent.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
- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Ben Leinfelder, ben leinfelder
- Pt.AcceptedRating:
- Red (cx)
- Pt.ProposedRating:
- Yellow (cxh)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
UndoListener.RedoAction
Perform the redo action.protected class
UndoListener.UndoAction
Perform the undo action.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description UndoListener()
Construct an undo listener.UndoListener(javax.swing.text.JTextComponent textArea)
Construct an undo listener with default key mappings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
_redoAction
protected UndoListener.RedoAction _redoAction
The redo action.
-
_compoundEdit
protected javax.swing.undo.CompoundEdit _compoundEdit
A compound undo edit, or null if none is progress.
-
_undoAction
protected UndoListener.UndoAction _undoAction
The undo action.
-
_undo
protected javax.swing.undo.UndoManager _undo
The undo manager.
-
-
Constructor Detail
-
UndoListener
public UndoListener()
Construct an undo listener.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.)
-
UndoListener
public UndoListener(javax.swing.text.JTextComponent textArea)
Construct an undo listener with default key mappings. The default key mappings invoke the undo and redo actions on textArea .A typical usage pattern would be:
JTextArea textArea = new JTextArea("testing"); textArea.getDocument().addUndoableEditListener(new UndoListener(textArea));
- Parameters:
textArea
- the text component that is being listened to and upon which undo/redo actions will be performed
-
-
Method Detail
-
endCompoundEdit
public void endCompoundEdit()
End a compound edit.
-
redo
public void redo() throws javax.swing.undo.CannotUndoException
Perform a redo.- Throws:
javax.swing.undo.CannotUndoException
- Thrown if the redo cannot be done.
-
startCompoundEdit
public void startCompoundEdit()
Start a compound undo edit.
-
undo
public void undo() throws javax.swing.undo.CannotUndoException
Perform an undo.- Throws:
javax.swing.undo.CannotUndoException
- Thrown if the redo cannot be done.
-
undoableEditHappened
public void undoableEditHappened(javax.swing.event.UndoableEditEvent event)
Remember the edit and update the action state.- Specified by:
undoableEditHappened
in interfacejavax.swing.event.UndoableEditListener
- Parameters:
event
- The event that occurred.
-
-