ini.trakem2.utils
Class History

java.lang.Object
  extended by ini.trakem2.utils.History

public class History
extends java.lang.Object

A class to represent a generic undo/redo history. Keeps a list of objects and the current index. When adding, and the index not being at the last slot, the list is cleared from that point onward. All added objects must implement the History.Step interface.


Nested Class Summary
static interface History.Step<T>
           
 
Constructor Summary
History()
          New unlimited history list.
History(int max_size)
           
 
Method Summary
 java.util.List<History.Step<?>> add(History.Step<?> step)
          Append a new step.
 java.util.List<History.Step<?>> append(History.Step<?> step)
          Appends a step at the end of the list, without modifying the current index.
 boolean canRedo()
           
 boolean canUndo()
           
 java.util.List<History.Step<?>> clear()
          Remove all steps from the list and return them.
 java.util.List<History.Step<?>> clip()
          Cut the list after the index, leaving from 0 to index, inclusive, inside.
 History.Step<?> get(int i)
           
 java.util.List<History.Step<?>> getAll()
          Returns a list with all undo steps.
 History.Step<?> getCurrent()
           
 int index()
           
 boolean indexAtEnd()
           
 boolean indexAtStart()
           
 History.Step<?> redoOneStep()
          Returns null if there aren't any more steps to redo.
 java.util.List<?> remove(long id)
          Empty all elements from each Step in the list that match the given id, and return them.
 java.util.List<History.Step<?>> resize(int size)
          Resize to maximum the given size, removing from the beginning.
 int size()
           
 History.Step<?> undoOneStep()
          Returns null if there aren't any more steps to undo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

History

public History()
New unlimited history list.


History

public History(int max_size)
Method Detail

add

public java.util.List<History.Step<?>> add(History.Step<?> step)
Append a new step. If max_size is set, resizes the list if larger than max_size, and returns all removed elements. Otherwise returns an empty list.


append

public java.util.List<History.Step<?>> append(History.Step<?> step)
Appends a step at the end of the list, without modifying the current index. If max_size is set, resizes the list if larger than max_size.


getCurrent

public History.Step<?> getCurrent()

undoOneStep

public History.Step<?> undoOneStep()
Returns null if there aren't any more steps to undo.


redoOneStep

public History.Step<?> redoOneStep()
Returns null if there aren't any more steps to redo.


remove

public java.util.List<?> remove(long id)
Empty all elements from each Step in the list that match the given id, and return them.


resize

public java.util.List<History.Step<?>> resize(int size)
Resize to maximum the given size, removing from the beginning. Returns all removed elements, or an empty list if none.


clear

public java.util.List<History.Step<?>> clear()
Remove all steps from the list and return them.


getAll

public java.util.List<History.Step<?>> getAll()
Returns a list with all undo steps.


get

public History.Step<?> get(int i)

clip

public java.util.List<History.Step<?>> clip()
Cut the list after the index, leaving from 0 to index, inclusive, inside. Returns removed steps.


size

public int size()

index

public int index()

indexAtStart

public boolean indexAtStart()

indexAtEnd

public boolean indexAtEnd()

canUndo

public boolean canUndo()

canRedo

public boolean canRedo()