Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Allowing "Undo"s in a SWING GUI  RSS feed

 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone ever created a GUI app that allows users to Undo actions? I've never done one, but am working on an app that will likely need such an architecture. The app basically allows the creation of small data items, editing attributes of the items, re-ordering/rearranging of the items, and deletion of the items... those are the types of activities that will need to be Undo-able.

Obviously I'm not expecting any code samples here, as its sort of a big topic, but can anyone clue me in on what the general approach is for creating an Undo architecture? Or are there any good articles on the subject that anyone knows of?

Thanks!
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,
I have developed an app like yours few years ago, I used the Command Pattern which is great to handle actions and their undos.

You'll find a brief description here and the basic design here

If you google using command pattern you will find a lot of articles, tutorials etc.

I hope this helps!
Giovanni
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Giovanni,

Thanks! And it's good timing, too, since I just finished reading Head First Design Patterns. I'll head off in that direction and see what I come up with.
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

don't forget that Swing has it's own undo managers that you can take advantage of. In fact, any text component can use them.

You didn't specify if you are building some kind of text editor, but if you are I highly recommend that you check out:

http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#undo

You need to do very little in order to get it up and running.

Cheers, Jared.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!