Class UndoModel<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<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.Object
    Maintains the undo state for one map control. The state consists of a linear list of UndoStates. 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 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 use
        gameObjectMatchers - the game object matchers to use
        mapTransactionListener - the map transaction listener to store
    • Method Detail

      • 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:
        true if an "undo" operation is possible, false otherwise
      • canRedo

        public boolean canRedo()
        Return whether a "redo" operation is possible.
        Returns:
        true if a "redo" operation is possible, false otherwise
      • 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.