Undo in graphical application

4

418928

Hi everybody,

I've created a small application that allows the user to draw things
and put things on the screen (polygons, circles, arcs, etc.). Now I
want to implement an undo operation. The question is: does Java offer
any facility for this? Or there is any design pattern that I am
advised to use?

The obvious approach is to store snapshots of previous states of the
application desktop to restore them if necessary. But then I start
thinking about how many undos to support, if I will support redos,
etc. Just wondering if there's something out there on this subject.

Thanks
Sergio.
 
N

niceguy

Hi everybody,

I've created a small application that allows the user to draw things
and put things on the screen (polygons, circles, arcs, etc.). Now I
want to implement an undo operation. The question is: does Java offer
any facility for this? Or there is any design pattern that I am
advised to use?

The obvious approach is to store snapshots of previous states of the
application desktop to restore them if necessary.

That's one way. It's probably not the right way.

But then I start
thinking about how many undos to support, if I will support redos,
etc. Just wondering if there's something out there on this subject.

javax.swing.undo

The 'things' you draw should be stored in some sort of Collection.
This, in combination with the undo functionality will allow you to
draw only thing things you want, when you want. For example, you
could allow the user to show only Rectangles. The painting code would
iterate over this Collection, drawing whatever items meet the users
requirements.


Jim S.
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top