mental_boi Posted August 16, 2007 Share Posted August 16, 2007 how do i implement the undo/redo functions for an image editor? Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted August 18, 2007 Share Posted August 18, 2007 Keep a collection of some kind (maybe a Vector) of things that have been done. Then also keep an index of the current step (i.e. if they've undone something, it would go back in the list until they added/changed something and then it would go to the end again). Link to comment Share on other sites More sharing options...
0 Winston Posted August 19, 2007 Share Posted August 19, 2007 Look into stack's, have a two stack based collections one holding the undo and the other redo. Link to comment Share on other sites More sharing options...
0 solo.man Posted August 23, 2007 Share Posted August 23, 2007 I'd agree with jordan. A vector is your best option. Every time the user modifies the image, add a record to the vector containing a copy of the image at this stage. Once the vector gets over a certain size (the undo limit), then also remove the first record from the vector whenever you add a record so as to keep it at a static size. Then when the user presses undo, you revert to the previous item in the vector. If he presses redo, jump to the next item. Once he starts working on the image again, then you remove any records that come after the currrent record and start adding to the vector again. I could give code if it would be useful. Link to comment Share on other sites More sharing options...
0 tmeg Posted August 25, 2007 Share Posted August 25, 2007 Also consider to use the undo redo framework of Java Swing. All commands have to provide a code path for applying a effect or change, and one for reversing the effect. So in the apply code path you need to save any information that is needed to reverse the change. Link to comment Share on other sites More sharing options...
0 Winston Posted August 25, 2007 Share Posted August 25, 2007 It's the Command design pattern. If you think about it, what you'd do for each task is pass Command objects, that store the values in it, and everytime you perform a task you push make that command, execute the command by passing it to the respective method, and then you push that onto a stack, then when a next action is performed you do the same, to reverse the effect, you pop the undo stack, and grab that command object, process it, then push it onto the redo stack. Link to comment Share on other sites More sharing options...
0 designpattern Posted September 12, 2009 Share Posted September 12, 2009 Implementing Undo/Redo in Java is quite easy when using the UndoManager related classes from the Java framework. I have written a kind of tutorial on Undo/Redo in Java that explains the simple concepts. Don't worry about Vectors or Command patterns - it's all included for free in the Java framework. In the case of an image editor you might want to concentrate on some memory management mechanism that buffers your undo information on disk (as PhotoShop does), because you probably will end upwith a copy of a part or all of your image for every undoable edit step. Cheers, Dominik Link to comment Share on other sites More sharing options...
Question
mental_boi
how do i implement the undo/redo functions for an image editor?
Link to comment
Share on other sites
6 answers to this question
Recommended Posts