Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages

How to Write an Undoable Edit Listener


Note: This section assumes that you're familiar with the AWT event listener scheme. If you aren't, you can read about it in The 1.1 AWT Event Model(in the Creating a User Interface trail).
Undoable edit events occur when an operation that can be undone occurs on a component. Currently, only text components generate undoable edit events, and then only indirectly. The text component's document generates the events. For text components, undoable operations include inserting characters, deleting characters, and modifying the style of text. [PENDING: verify that only text components generate these events]

Undoable Edit Event Methods

The UndoableEditListener interface has just one method, so it has no corresponding adapter class. Here's the method:
void undoableEditHappened(UndoableEditEvent)
Called when an undoable event occurs on the listened-to component.

Examples of Handling Undoable Edit Events

Programs typically listen to undoable edit events to assist in the implementation of undo and redo commands. Refer to Implementing Undo and Redo for an example.

The UndoableEditEvent Class

The undoableEditHappened method has a single parameter: a UndoableEditEvent(in the API reference documentation) object. To get the document that generated the event, use the getSource method which UndoableEditEvent inherits from EventObject.

The UndoableEditEvent class defines one method which returns an object that contains detailed information about the edit that occurred.

UndoableEdit getEdit()
Returns an UndoableEdit(in the API reference documentation)instance that represents the edit that occurred and contains information about and commands for undoing or redoing the edit.


Previous | Next | Trail Map | Creating a User Interface | Using the JFC/Swing Packages