Package net.sf.gridarta.model.mapcursor
Class MapCursor<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
- java.lang.Object
-
- net.sf.gridarta.model.mapcursor.MapCursor<G,A,R>
-
public class MapCursor<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends java.lang.ObjectMapCursor provides methods to move and drag on map. The MapCursor is bound to aMapGridwhich will change it flags depending on MapCursor movement/selection.There are three different states for MapCursor:
- Deactivated
- On the map
- Dragging
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMapCursorListener(@NotNull MapCursorListener<G,A,R> listener)Register a MapCursorListener.voidbeginTransaction()Start a new transaction.voiddeactivate()Cursor gets deactivated.booleandeleteSelectedGameObject(boolean performAction, boolean autoJoin)Deletes the selected game object.voiddragRelease()Leave drag mode and undo pre-selection.voiddragSelect(@NotNull SelectionMode selectionMode, boolean forceSelect)Leave drag mode and select pre-selection using selectionMode.voiddragStart()Set cursor to drag mode when it is active.booleandragTo(@Nullable java.awt.Point p)When in drag mode and the point is on the map cursor is moved to this position.voidendTransaction()End a transaction.@Nullable java.awt.DimensiongetDragOffset()Get offset from start position of dragging.GgetGameObject()Returns the selectedGameObject.@NotNull java.awt.PointgetLocation()Get position of cursor.booleangoTo(boolean performAction, @NotNull Direction dir)Moves the cursor one square relative to current position.booleaninsertGameObject(boolean performAction, @NotNull BaseObject<G,A,R,?> gameObject, boolean insertAtEnd, boolean join)Inserts aGameObjectbefore the selected game object.booleanisDragging()Returns whether the cursor is currently being dragged.booleanisOnGrid(@Nullable java.awt.Point p)Check if point is on grid.voidremoveMapCursorListener(@NotNull MapCursorListener<G,A,R> listener)Remove a MapCursorListener.booleanselectAbove(boolean performAction)Moves the selectedGameObject.booleanselectBelow(boolean performAction)Moves the selectedGameObject.voidsetGameObject(G gameObject)Sets the selectedGameObject.voidsetLocation(@NotNull java.awt.Point p)Move cursor to a new location.booleansetLocationSafe(@Nullable java.awt.Point p)Move cursor to a new location.voidsetMapSquare(@Nullable MapSquare<G,A,R> mapSquare)Sets the selectedMapSquare.
-
-
-
Method Detail
-
getLocation
@NotNull public @NotNull java.awt.Point getLocation()
Get position of cursor.- Returns:
- coordinates of cursor
-
setLocation
public void setLocation(@NotNull @NotNull java.awt.Point p)Move cursor to a new location. If new location is not on map, the nearest valid location is chosen.- Parameters:
p- the new location
-
setLocationSafe
public boolean setLocationSafe(@Nullable @Nullable java.awt.Point p)Move cursor to a new location. If new location is not on map, cursor does not change.- Parameters:
p- the new location; ifp == nullnothing happens- Returns:
trueif cursor position changed
-
dragStart
public void dragStart()
Set cursor to drag mode when it is active.
-
dragTo
public boolean dragTo(@Nullable @Nullable java.awt.Point p)When in drag mode and the point is on the map cursor is moved to this position.MapGridchanges pre-selection accordingly.- Parameters:
p- new coordinates- Returns:
truewhen dragging position changed successfully
-
dragRelease
public void dragRelease()
Leave drag mode and undo pre-selection.
-
dragSelect
public void dragSelect(@NotNull @NotNull SelectionMode selectionMode, boolean forceSelect)Leave drag mode and select pre-selection using selectionMode.- Parameters:
selectionMode- Mode how to change selection stateforceSelect- whether to force selection, regardless of the selected area- See Also:
SelectionMode
-
deactivate
public final void deactivate()
Cursor gets deactivated. All selections get lost.
-
getDragOffset
@Nullable public @Nullable java.awt.Dimension getDragOffset()
Get offset from start position of dragging.- Returns:
- offset or
nullwhen not in drag mode
-
isOnGrid
public boolean isOnGrid(@Nullable @Nullable java.awt.Point p)Check if point is on grid.- Parameters:
p- Coordinates of point- Returns:
trueifp != nulland point is on grid
-
goTo
public boolean goTo(boolean performAction, @NotNull @NotNull Direction dir)Moves the cursor one square relative to current position.- Parameters:
performAction- whether the action should be performeddir- the direction- Returns:
trueif cursor really moved
-
isDragging
public boolean isDragging()
Returns whether the cursor is currently being dragged.- Returns:
trueif dragging is active, otherwisefalse.
-
addMapCursorListener
public void addMapCursorListener(@NotNull @NotNull MapCursorListener<G,A,R> listener)Register a MapCursorListener.- Parameters:
listener- MapCursorListener to register
-
removeMapCursorListener
public void removeMapCursorListener(@NotNull @NotNull MapCursorListener<G,A,R> listener)Remove a MapCursorListener.- Parameters:
listener- MapCursorListener to remove
-
getGameObject
@Nullable public G getGameObject()
Returns the selectedGameObject.- Returns:
- the selected game object or
nullif the map cursor is not active or if the selected map square is empty
-
setGameObject
public void setGameObject(@Nullable G gameObject)Sets the selectedGameObject. If the game object is not on a map or not on the map this cursor is attached to, the cursor is unchanged.- Parameters:
gameObject- the selected game object
-
setMapSquare
public void setMapSquare(@Nullable @Nullable MapSquare<G,A,R> mapSquare)Sets the selectedMapSquare. If the map square does not belong to the map this cursor is attached to, the cursor is unchanged.- Parameters:
mapSquare- the selected map square
-
beginTransaction
public final void beginTransaction()
Start a new transaction. Transactions may be nested. Transactions serve the purpose of firing events to the views when more changes are known to come before the view is really required to update. Each invocation of this function requires its own invocation ofendTransaction().
-
endTransaction
public final void endTransaction()
End a transaction. Invoking this method will reduce the transaction depth by 1.If the last transaction is ended, the changes are committed.
-
selectAbove
public boolean selectAbove(boolean performAction)
Moves the selectedGameObject. Does nothing if no game object is selected.- Parameters:
performAction- whether the action should be performed- Returns:
- whether the action was or can be performed
-
selectBelow
public boolean selectBelow(boolean performAction)
Moves the selectedGameObject. Does nothing if no game object is selected.- Parameters:
performAction- whether the action should be performed- Returns:
- whether the action was or can be performed
-
insertGameObject
public boolean insertGameObject(boolean performAction, @NotNull @NotNull BaseObject<G,A,R,?> gameObject, boolean insertAtEnd, boolean join)Inserts aGameObjectbefore the selected game object. Does nothing if no game object is selected.- Parameters:
performAction- whether the action should be performedgameObject- the game object to insertinsertAtEnd- whether to ignore the selected game object and insert at the endjoin- if set, auto-joining is supported- Returns:
- whether the action was or can be performed
-
deleteSelectedGameObject
public boolean deleteSelectedGameObject(boolean performAction, boolean autoJoin)Deletes the selected game object. Does nothing if no game object is selected.- Parameters:
performAction- whether the action should be performedautoJoin- whether to preform auto-joining- Returns:
- whether the action was or can be performed
-
-