public class UndoRedoList<T>
extends Object
Modifier and Type | Field and Description |
---|---|
protected int |
currentIndex
the index into the state list telling us which state is the current one.
|
int |
maxUndo
Maximum number of states that are undo-able -- currently set to 10
|
protected ArrayList<T> |
stateList
Each past copy of the graph, in text form, is added to the list, up to
its max
|
Constructor and Description |
---|
UndoRedoList()
Create an empty undo/redo structure
|
UndoRedoList(int max)
Allows user to decide how many undo steps are saved.
|
Modifier and Type | Method and Description |
---|---|
T |
mostRecentState()
Get the state on the top of the stack, but do not pop it!
Does not alter the undo/redo list.
|
T |
popRedo()
Restore a previous state, moving forward with respect to the saved
states.
|
T |
popUndo()
Undo the last editing newState.
|
void |
pushCurrent(T currentState)
Track a regular editing action (other than undo or redo) by pushing it
onto the undo list.
|
boolean |
redoAvailable() |
void |
reset()
Initialize the undo/redo sequences, so that there are no past or future
states.
|
String |
toString()
Generally used for debugging
|
boolean |
undoAvailable() |
public int maxUndo
protected ArrayList<T> stateList
protected int currentIndex
public UndoRedoList()
public UndoRedoList(int max)
public boolean undoAvailable()
popUndo()
public boolean redoAvailable()
popRedo()
public T popUndo()
public T popRedo()
public void pushCurrent(T currentState)
currentState
- The most recent editing action. If null, then there's no change.public void reset()
public String toString()
toString
in class Object
public T mostRecentState()