Confused by Undo/Redo

J

Jason Cavett

I'm completely confused and lost by undo/redo. It seems that I need
to create a separate "Edit" (extends AbstractUndoableEdit) classes for
every single component (non-text) that exists in my GUI. This makes
no sense, though (lots of repeated code, etc). Does anybody have a
good tutorial or explanation of a better way to implement undo/redo?
I've searched all over the net and only text components show up
because they have built in undo support. (I'm trying JCheckBoxes,
JTree, etc, etc. I assume it would be the same across all components,
though.)

Thanks.
 
S

Silvio Bierman

Jason Cavett said:
I'm completely confused and lost by undo/redo. It seems that I need
to create a separate "Edit" (extends AbstractUndoableEdit) classes for
every single component (non-text) that exists in my GUI. This makes
no sense, though (lots of repeated code, etc). Does anybody have a
good tutorial or explanation of a better way to implement undo/redo?
I've searched all over the net and only text components show up
because they have built in undo support. (I'm trying JCheckBoxes,
JTree, etc, etc. I assume it would be the same across all components,
though.)

Thanks.

There are two possible approaches.

One is to maintain an undo-stack and a redo-stack of action object that have
undo and redo methods. This usually results in very tedious internal
application structure/logic but is sometimes the only affordable way to do
this (in terms of resources/time required).

The simpler more brute force approach is simply maintaining an undo and a
redo stack of complete document (whatever the document may be) states. This
may involve lots of copying etc. but is far more simple to do. Hence the
numerous applications with limited undo-depths.

Silvio Bierman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top