aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to implment Undo/Redo for a editor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to implment Undo/Redo for a editor" Watch "How to implment Undo/Redo for a editor" New topic
Author

How to implment Undo/Redo for a editor

Dinesh Bang
Ranch Hand

Joined: Jun 15, 2006
Posts: 52
Hi Ranchers,

I am looking to implement the undo/redo functionality for my custom editor. Any idea's how to achieve that ?


SCJP 1.4,SCBCD 1.3, SCWCD 1.5, ???
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Each JTextComponent (including JTextArea and JTextField) have a Document. To this Document you can attach a UndoableEditListener. Combine this with an UndoManager.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dinesh Bang
Ranch Hand

Joined: Jun 15, 2006
Posts: 52
Thanks for quick response

Just to add up, Is there a generic way to handle Undo/Redo for whole perspective.
In my application I will be required to have it on all the views, project explorer ,editors etc.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
Read the secton from the Swing tutorial on "Text Component Features" for a working example.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Dinesh Bang wrote:Just to add up, Is there a generic way to handle Undo/Redo for whole perspective.
In my application I will be required to have it on all the views, project explorer ,editors etc.

You should still use UndoableEdit and UndoManager, but you must handle your own events that will create an UndoableEdit. Hint: extend AbstractUndoableEdit and override undo() and redo():
 
Don't get me started about those stupid light bulbs.
 
subject: How to implment Undo/Redo for a editor