20 package net.sf.gridarta.model.undo;
22 import java.util.ArrayList;
23 import java.util.List;
31 import org.jetbrains.annotations.NotNull;
65 private final List<UndoState<G, A, R>>
undoStack =
new ArrayList<>();
109 assert undoStackIndex == undoStack.size();
110 undoStack.add(undoState);
111 undoStackIndex = undoStack.size();
119 while (undoStack.size() > maxUndoStates) {
134 return undoStackIndex > 0;
143 return undoStackIndex < undoStack.size();
151 if (undoStackIndex <= 0) {
152 throw new IllegalStateException(
"undo stack is empty");
155 return undoStack.get(undoStackIndex - 1).getName();
163 if (undoStackIndex >= undoStack.size()) {
164 throw new IllegalStateException(
"redo stack is empty");
167 return undoStack.get(undoStackIndex).getName();
177 if (undoStackIndex <= 0) {
178 throw new IllegalStateException(
"undo stack is empty");
194 if (undoStackIndex >= undoStack.size()) {
195 throw new IllegalStateException(
"redo stack is empty");
215 undoStack.set(undoStackIndex, undoState);
220 undoStack.set(undoStackIndex - 1, undoState);
241 index = undoStackIndex - 1;
246 final String name = prevUndoState.
getName();
250 undoStack.set(index, undoState);
258 while (undoStackIndex < undoStack.size()) {
267 assert !undoStack.isEmpty();
268 assert undoStackIndex < undoStack.size();
269 undoStack.remove(undoStack.size() - 1);
276 assert !undoStack.isEmpty();
277 assert undoStackIndex > 0;
final GameObjectMatchers gameObjectMatchers
The GameObjectMatchers to use.
String undoName()
Return the "undo" operation name.
Maintains the undo state for one map control.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
void setSavedSquares(@NotNull final SavedSquares< G, A, R > savedSquares)
Records the affected map squares.
boolean canRedo()
Return whether a "redo" operation is possible.
REDO
A redo operation is executing.
String getName()
Return the name of the operation.
void finish(@NotNull final UndoState< G, A, R > undoState)
Finishes an undo or redo operation.
Holds information to undo/redo one edit operation.
Represents the type of undo recording.
Base package of all Gridarta classes.
NORMAL
Normal operation: appends changes to undo stack.
Interface for listeners listening on map transactions of MapModels.
void discardRedo()
Discard one "redo" information.
Reflects a game object (object on a map).
Abstract factory for creating GameObject instances.
boolean canUndo()
Return whether an "undo" operation is possible.
GameObjects are the objects based on Archetypes found on maps.
MapTransactionListener< G, A, R > getMapTransactionListener()
Returns the MapTransactionListener that was passed to the constructor.
int undoStackIndex
Current index into undoStack.
Maintains GameObjectMatcher instances.
final GameObjectFactory< G, A, R > gameObjectFactory
The GameObjectFactory to use.
UndoState< G, A, R > undo()
Perform an "undo" operation.
final MapTransactionListener< G, A, R > mapTransactionListener
The stored MapTransactionListener.
void discardUndo()
Discard one "undo" information.
String redoName()
Return the "redo" operation name.
void addUndoState(@NotNull final UndoState< G, A, R > undoState)
Add a new undo state to the undo stack.
UndoState< G, A, R > redo()
Perform a "redo" operation.
UNDO
An undo operation is executing.
Records a set of changed map squares.
void finish()
Finishes an undo or redo operation.
void discardAllRedo()
Discard all "redo" information.
final List< UndoState< G, A, R > > undoStack
The undo stack.
A getMapArchObject()
Returns the map arch object before the operation started.
void trimToSize(final int maxUndoStates)
Discard old undo information.
UndoType type
The type for recording undo information.
Interface for MapArchObjects.
UndoModel(@NotNull final GameObjectFactory< G, A, R > gameObjectFactory, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final MapTransactionListener< G, A, R > mapTransactionListener)
Creates a new instance.