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.
Silvio Bierman - 19 Jun 2007 09:35 GMT
> I'm completely confused and lost by undo/redo. It seems that I need
> to create a separate "Edit" (extends AbstractUndoableEdit) classes for
[quoted text clipped - 7 lines]
>
> 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