Gridarta Editor
net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R > Class Template Reference

Maintains the undo state for one map control. More...

+ Collaboration diagram for net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >:

Public Member Functions

boolean canRedo ()
 Return whether a "redo" operation is possible. More...
 
boolean canUndo ()
 Return whether an "undo" operation is possible. More...
 
void finish (@NotNull final UndoState< G, A, R > undoState)
 Finishes an undo or redo operation. More...
 
void finish ()
 Finishes an undo or redo operation. More...
 
MapTransactionListener< G, A, R > getMapTransactionListener ()
 Returns the MapTransactionListener that was passed to the constructor. More...
 
UndoState< G, A, R > redo ()
 Perform a "redo" operation. More...
 
String redoName ()
 Return the "redo" operation name. More...
 
void trimToSize (final int maxUndoStates)
 Discard old undo information. More...
 
UndoState< G, A, R > undo ()
 Perform an "undo" operation. More...
 
 UndoModel (@NotNull final GameObjectFactory< G, A, R > gameObjectFactory, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final MapTransactionListener< G, A, R > mapTransactionListener)
 Creates a new instance. More...
 
String undoName ()
 Return the "undo" operation name. More...
 

Private Member Functions

void addUndoState (@NotNull final UndoState< G, A, R > undoState)
 Add a new undo state to the undo stack. More...
 
void discardAllRedo ()
 Discard all "redo" information. More...
 
void discardRedo ()
 Discard one "redo" information. More...
 
void discardUndo ()
 Discard one "undo" information. More...
 

Private Attributes

final GameObjectFactory< G, A, R > gameObjectFactory
 The GameObjectFactory to use. More...
 
final GameObjectMatchers gameObjectMatchers
 The GameObjectMatchers to use. More...
 
final MapTransactionListener< G, A, R > mapTransactionListener
 The stored MapTransactionListener. More...
 
UndoType type = UndoType.NORMAL
 The type for recording undo information. More...
 
final List< UndoState< G, A, R > > undoStack = new ArrayList<>()
 The undo stack. More...
 
int undoStackIndex
 Current index into undoStack. More...
 

Detailed Description

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.

Author
Andreas Kirschbaum

Definition at line 40 of file UndoModel.java.

Constructor & Destructor Documentation

◆ UndoModel()

net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.UndoModel ( @NotNull final GameObjectFactory< G, A, R >  gameObjectFactory,
@NotNull final GameObjectMatchers  gameObjectMatchers,
@NotNull final MapTransactionListener< G, A, R >  mapTransactionListener 
)

Member Function Documentation

◆ addUndoState()

void net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.addUndoState ( @NotNull final UndoState< G, A, R >  undoState)
private

Add a new undo state to the undo stack.

This discards the existing "redo" information (if present).

Parameters
undoStatethe undo state to add

Definition at line 106 of file UndoModel.java.

References net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.discardAllRedo().

Referenced by net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.finish().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canRedo()

boolean net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.canRedo ( )

Return whether a "redo" operation is possible.

Returns
true
if a "redo" operation is possible,
false
otherwise

Definition at line 142 of file UndoModel.java.

Referenced by net.sf.gridarta.gui.undo.UndoControl< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.doRedo(), and net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.trimToSize().

+ Here is the caller graph for this function:

◆ canUndo()

boolean net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.canUndo ( )

Return whether an "undo" operation is possible.

Returns
true
if an "undo" operation is possible,
false
otherwise

Definition at line 133 of file UndoModel.java.

Referenced by net.sf.gridarta.gui.undo.UndoControl< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.doUndo().

+ Here is the caller graph for this function:

◆ discardAllRedo()

void net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.discardAllRedo ( )
private

◆ discardRedo()

◆ discardUndo()

void net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.discardUndo ( )
private

Discard one "undo" information.

Definition at line 275 of file UndoModel.java.

Referenced by net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.trimToSize().

+ Here is the caller graph for this function:

◆ finish() [1/2]

void net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.finish ( @NotNull final UndoState< G, A, R >  undoState)

Finishes an undo or redo operation.

Does nothing if none is in progress.

Parameters
undoStatethe changes of the operation

Definition at line 208 of file UndoModel.java.

References net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.addUndoState(), and net.sf.gridarta.model.undo.UndoType.NORMAL.

Referenced by net.sf.gridarta.gui.undo.UndoControl< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.UndoControl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finish() [2/2]

◆ getMapTransactionListener()

MapTransactionListener<G, A, R> net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.getMapTransactionListener ( )

◆ redo()

UndoState<G, A, R> net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.redo ( )

Perform a "redo" operation.

Returns
the undo state to apply; the returned object must not be modified by the caller

Definition at line 193 of file UndoModel.java.

References net.sf.gridarta.model.undo.UndoType.REDO.

◆ redoName()

String net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.redoName ( )

Return the "redo" operation name.

Returns
the "redo" operation name

Definition at line 162 of file UndoModel.java.

Referenced by net.sf.gridarta.gui.undo.UndoControl< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.refreshMenus().

+ Here is the caller graph for this function:

◆ trimToSize()

◆ undo()

UndoState<G, A, R> net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.undo ( )

Perform an "undo" operation.

Returns
the undo state to apply; the returned object must not be modified by the caller

Definition at line 176 of file UndoModel.java.

References net.sf.gridarta.model.undo.UndoType.UNDO.

◆ undoName()

String net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.undoName ( )

Return the "undo" operation name.

Returns
the "undo" operation name

Definition at line 150 of file UndoModel.java.

Referenced by net.sf.gridarta.gui.undo.UndoControl< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.refreshMenus().

+ Here is the caller graph for this function:

Member Data Documentation

◆ gameObjectFactory

◆ gameObjectMatchers

◆ mapTransactionListener

◆ type

UndoType net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.type = UndoType.NORMAL
private

The type for recording undo information.

Definition at line 77 of file UndoModel.java.

◆ undoStack

final List<UndoState<G, A, R> > net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.undoStack = new ArrayList<>()
private

The undo stack.

It consists of recorded UndoStates for the associated net.sf.gridarta.model.mapmodel.MapModel.

Definition at line 65 of file UndoModel.java.

◆ undoStackIndex

int net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.undoStackIndex
private

Current index into undoStack.

If

, "undo" is not possible; if

, "redo" is not possible.

Definition at line 72 of file UndoModel.java.

Referenced by net.sf.gridarta.model.undo.UndoModel< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.finish().


The documentation for this class was generated from the following file: