 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.undo;
22 import java.util.IdentityHashMap;
24 import javax.swing.Action;
41 import net.
sf.japi.swing.action.ActionBuilder;
42 import net.
sf.japi.swing.action.ActionBuilderFactory;
43 import net.
sf.japi.swing.action.ActionMethod;
44 import org.jetbrains.annotations.NotNull;
45 import org.jetbrains.annotations.Nullable;
57 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
99 mapModel = mapControl ==
null ? null : mapControl.getMapModel();
104 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
124 public void preBeginTransaction() {
129 public void beginTransaction(@NotNull
final String
name) {
137 assert savedUndoState !=
null;
139 assert savedUndoModel !=
null;
147 savedUndoModel.
finish(savedUndoState);
156 public void postEndTransaction() {
174 assert undoModel !=
null;
179 mapManager.addMapManagerListener(mapManagerListener);
187 final boolean undoEnabled =
doUndo(
false);
188 aUndo.setEnabled(undoEnabled);
191 assert undoModel !=
null;
199 final boolean redoEnabled =
doRedo(
false);
200 aRedo.setEnabled(redoEnabled);
203 assert redoModel !=
null;
256 private boolean doUndo(
final boolean performAction) {
258 if (tmpMapModel ==
null) {
263 if (undoModel ==
null) {
288 private boolean doRedo(
final boolean performAction) {
290 if (tmpMapModel ==
null) {
295 if (undoModel ==
null) {
316 public void setAction(@NotNull
final Action action, @NotNull
final String
name) {
317 if (
name.equals(
"undo")) {
319 }
else if (
name.equals(
"redo")) {
322 throw new IllegalArgumentException(
"unsupported action name: " +
name);
MapModel< G, A, R > mapModel
Map model for the current map.
A MapModel reflects the data of a map.
Abstract factory for creating GameObject instances.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
A MapManager manages all opened maps.
void undo()
"Undo" was selected.
boolean doRedo(final boolean performAction)
Performs the "redo" action.
A getMapArchObject()
Returns the map arch object before the operation started.
Base package of all Gridarta classes.
void setSavedSquares(@NotNull final SavedSquares< G, A, R > savedSquares)
Records the affected map squares.
Interface for listeners listening on map transactions of MapModels.
Interface for listeners listening to MapManager changes.
Implements the controller for undo/redo actions.
void refreshMenus()
Enables/disables menu entries based on the current state.
Action aRedo
Action for "redo" function.
UndoControl(@NotNull final MapManager< G, A, R > mapManager, @NotNull final GameObjectFactory< G, A, R > gameObjectFactory, @NotNull final GameObjectMatchers gameObjectMatchers)
Creates a new instance.
static< G extends GameObject< G, A, R > A extends R extends Archetype< G, A, R > void undo(@NotNull final UndoModel< G, A, R > undoModel, @NotNull final MapModel< G, A, R > mapModel)
Reflects a game object (object on a map).
boolean doUndo(final boolean performAction)
Performs the "undo" action.
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
void setMaxUndoStates(final int maxUndoStates)
Sets the maximum number of undo states saved for each map.
Implementation of Undo / Redo for Gridarta.
Records a set of changed map squares.
GameObjects are the objects based on Archetypes found on maps.
Utility class implementing undo and redo actions.
final Map< MapModel< G, A, R >, UndoModel< G, A, R > > undoModels
Contains an UndoModel for each known MapModel.
Classes related to matching {GameObjects}, so called { net.sf.gridarta.model.match....
static< G extends GameObject< G, A, R > A extends R extends Archetype< G, A, R > void redo(@NotNull final UndoModel< G, A, R > undoModel, @NotNull final MapModel< G, A, R > mapModel)
Interface for MapArchObjects.
Maintains GameObjectMatcher instances.
boolean canUndo()
Return whether an "undo" operation is possible.
void removeEmptySquares(@NotNull final Size2D size)
Removes empty squares outside a given area.
String undoName()
Return the "undo" operation name.
SavedSquares< G, A, R > cloneAndClear()
Creates a new instance having the same contents as this instance, then forgets all saves squares in t...
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Holds information to undo/redo one edit operation.
void addMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Registers a map transaction listener.
int maxUndoStates
The maximum number of undo states saved for each map.
void redo()
"Redo" was selected.
String redoName()
Return the "redo" operation name.
Currently nothing more than a marker interface for unification.
Utility class for ActionBuilder related functions.
MapTransactionListener< G, A, R > getMapTransactionListener()
Returns the MapTransactionListener that was passed to the constructor.
void trimToSize(final int maxUndoStates)
Discard old undo information.
Maintains the undo state for one map control.
int getMaxUndoStates()
Returns the maximum number of undo states saved for each map.
Action aUndo
Action for "undo" function.
void finish(@NotNull final UndoState< G, A, R > undoState)
Finishes an undo or redo operation.
boolean canRedo()
Return whether a "redo" operation is possible.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.