Implements an Undo/Redo in MVC

Posted by bnabilos on Stack Overflow See other posts from Stack Overflow or by bnabilos
Published on 2010-05-25T11:51:27Z Indexed on 2010/05/25 12:51 UTC
Read the original article Hit count: 330

Filed under:
|
|

Hello,

I have a Java application and I want to implement an Undo/Redo option. the value that I want to stock and that I want to be able to recover is an integer.

My Class Model implements the interface StateEditable and I have to redefine the 2 functions restoreState(Hashtable<?, ?> state) and storeState(Hashtable<Object, Object> state) but I don't know what to put on them. It will be really great if somebody can help me to do that. These are the first lines of my Model class, the value that I want to do an undo/redo on it is value

public class Model extends Observable implements StateEditable
{
        private int value = 5;

        private UndoManager undoRedo = new UndoManager();

        final UndoableEditListener editListener = new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent evt) {
            undoRedo.addEdit(evt.getEdit());
            }
        };

        @Override
        public void restoreState(Hashtable<?, ?> state)
        {

        }

        @Override
        public void storeState(Hashtable<Object, Object> state)
        {

        }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about mvc