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)
{
}
}
From looking through an example of
StateEditable, it would appear that in yourstoreStatemethod, you need to populate theHashtablethat is passed in. Similarly, you assign state in yourrestoreStatefrom theHashtablethat is passed in. You will need to define a key for the value in theHashtable. With that in mind, I suggest that you addto the top of your file, and then fill out the two methods like so: