|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
Undoable edit events occur when an operation that can be undone occurs on a component. Currently, only text components fire undoable edit events, and then only indirectly. The text component's document fires the events. For text components, undoable operations include inserting characters, deleting characters, and modifying the style of text. Programs typically listen to undoable edit events to assist in the implementation of undo and redo commands.Here is the undoable edit event handling code from an application called
TextComponentDemo.You can find a link to the source file for... //where initialization occurs document.addUndoableEditListener(new MyUndoableEditListener()); ... protected class MyUndoableEditListener implements UndoableEditListener { public void undoableEditHappened(UndoableEditEvent e) { //Remember the edit and update the menus undo.addEdit(e.getEdit()); undoAction.updateUndoState(); redoAction.updateRedoState(); } }TextComponentDemoin the example index for Using Swing Components. For a discussion about the undoable edit listener aspect of the program see Implementing Undo and Redo
The UndoableEditListener Interface
Because
UndoableEditListenerhas only one method, it has no corresponding adapter class.
Method Purpose undoableEditHappened(UndoableEditEvent) Called when an undoable event occurs on the listened-to component.
Method Purpose Object getSource()
(injava.util.EventObject)Return the object that fired the event. UndoableEdit getEdit() Returns an UndoableEditobject that represents the edit that occurred and contains information about and commands for undoing or redoing the edit.
The following table lists the examples that use undoable edit listeners.
Example Where Described Notes TextComponentDemoImplementing Undo and Redo Implements undo and redo on a text pane with help from an undoable edit listener.