Package net.sf.gridarta.model.undo
Class UndoModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
- java.lang.Object
-
- net.sf.gridarta.model.undo.UndoModel<G,A,R>
-
public class UndoModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends java.lang.ObjectMaintains the undo state for one map control. The state consists of a linear list ofUndoStates. Possible operations are "undo" and "redo". If a map is changed after performing one or more "undo" operations, the previously recorded "redo" operations are discarded.
-
-
Constructor Summary
Constructors Constructor Description UndoModel(@NotNull GameObjectFactory<G,A,R> gameObjectFactory, @NotNull GameObjectMatchers gameObjectMatchers, @NotNull MapTransactionListener<G,A,R> mapTransactionListener)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRedo()Return whether a "redo" operation is possible.booleancanUndo()Return whether an "undo" operation is possible.voidfinish()Finishes an undo or redo operation.voidfinish(@NotNull UndoState<G,A,R> undoState)Finishes an undo or redo operation.@NotNull MapTransactionListener<G,A,R>getMapTransactionListener()Returns theMapTransactionListenerthat was passed to the constructor.@NotNull UndoState<G,A,R>redo()Perform a "redo" operation.java.lang.StringredoName()Return the "redo" operation name.voidtrimToSize(int maxUndoStates)Discard old undo information.@NotNull UndoState<G,A,R>undo()Perform an "undo" operation.java.lang.StringundoName()Return the "undo" operation name.
-
-
-
Constructor Detail
-
UndoModel
public UndoModel(@NotNull @NotNull GameObjectFactory<G,A,R> gameObjectFactory, @NotNull @NotNull GameObjectMatchers gameObjectMatchers, @NotNull @NotNull MapTransactionListener<G,A,R> mapTransactionListener)Creates a new instance.- Parameters:
gameObjectFactory- the game object factory to usegameObjectMatchers- the game object matchers to usemapTransactionListener- the map transaction listener to store
-
-
Method Detail
-
getMapTransactionListener
@NotNull public @NotNull MapTransactionListener<G,A,R> getMapTransactionListener()
Returns theMapTransactionListenerthat was passed to the constructor.- Returns:
- the map transaction listener
-
trimToSize
public void trimToSize(int maxUndoStates)
Discard old undo information.- Parameters:
maxUndoStates- the maximum number of undo states to save
-
canUndo
public boolean canUndo()
Return whether an "undo" operation is possible.- Returns:
trueif an "undo" operation is possible,falseotherwise
-
canRedo
public boolean canRedo()
Return whether a "redo" operation is possible.- Returns:
trueif a "redo" operation is possible,falseotherwise
-
undoName
public java.lang.String undoName()
Return the "undo" operation name.- Returns:
- the "undo" operation name
-
redoName
public java.lang.String redoName()
Return the "redo" operation name.- Returns:
- the "redo" operation name
-
undo
@NotNull public @NotNull UndoState<G,A,R> undo()
Perform an "undo" operation.- Returns:
- the undo state to apply; the returned object must not be modified by the caller
-
redo
@NotNull public @NotNull UndoState<G,A,R> redo()
Perform a "redo" operation.- Returns:
- the undo state to apply; the returned object must not be modified by the caller
-
finish
public void finish(@NotNull @NotNull UndoState<G,A,R> undoState)Finishes an undo or redo operation. Does nothing if none is in progress.- Parameters:
undoState- the changes of the operation
-
finish
public void finish()
Finishes an undo or redo operation. Does nothing if none is in progress.
-
-