Package net.sf.gridarta.model.mapgrid
Class MapGrid
- java.lang.Object
-
- net.sf.gridarta.model.mapgrid.MapGrid
-
public class MapGrid extends java.lang.Object2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors. This class provides methods to modify these flags. Normally a map cursor is used to access them. Selection flags are not changed directly. First pre-selection flags have to be set withpreSelect(Point, Point), thenselectArea(Point, Point, SelectionMode)will change the selection flags according toSelectionMode. This allows visualisation of the dragging process when selecting an area.Every change of the grid size or flags fires a
MapGridEventand informs all registeredMapGridListeners.
-
-
Field Summary
Fields Modifier and Type Field Description static intGRID_FLAG_CONNECTIONFlag to highlight as part of a connection group.static intGRID_FLAG_CURSORFlag to highlight cursor position.static intGRID_FLAG_ERRORFlag to highlight as error.static intGRID_FLAG_FATALFlag to highlight as fatal.static intGRID_FLAG_INFORMATIONFlag to highlight as information.static intGRID_FLAG_SELECTINGPre-selection - used to preselect squares.static intGRID_FLAG_SELECTIONSelection - marks all selected squares.static intGRID_FLAG_SELECTION_EASTSelection - is set for squares at the east edge of the selected area.static intGRID_FLAG_SELECTION_NORTHSelection - is set for squares at the north edge of the selected area.static intGRID_FLAG_SELECTION_SOUTHSelection - is set for squares at the south edge of the selected area.static intGRID_FLAG_SELECTION_WESTSelection - is set for squares at the west edge of the selected area.static intGRID_FLAG_WARNINGFlag to highlight as warning.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMapGridListener(@NotNull MapGridListener listener)Registers a MapGridListener.voidbeginTransaction()Starts a new transaction.voidclearErrors()Clears all error flags.voidendTransaction()Ends a transaction.intgetFlags(int x, int y)Returns the flags of a square.intgetFlags(@NotNull java.awt.Point p)Returns the flags of a square.@NotNull Size2DgetGridSize()Returns aSize2Dwith the dimension of this grid.@NotNull java.awt.RectanglegetRecChange()Returns a rectangle where the grid was changed.@Nullable java.awt.RectanglegetSelectedRec()Returns the smallest rectangle containing selection.@NotNull java.awt.Point @NotNull []getSelection()Returns the selection.@NotNull Size2DgetSize()Returns size of grid.booleanhasError(@NotNull java.awt.Point p)Checks if a square has the error flag set.voidinvertSelection()Inverts all selected squares.voidpreSelect(@NotNull java.awt.Point start, @NotNull java.awt.Point end)Rectangle defined by two points gets preselected.voidremoveMapGridListener(@NotNull MapGridListener listener)Removes a MapGridListener.voidresize(@NotNull Size2D newSize)Resizes the MapGrid.voidselect(@NotNull java.awt.Point pos, @NotNull SelectionMode selectionMode)Selects or deselects a single square.voidselectAll()Marks all squares as selected.voidselectArea(@NotNull java.awt.Point pos1, @NotNull java.awt.Point pos2, @NotNull SelectionMode selectionMode)Selects or deselects all squares in an area.voidsetCursor(@NotNull java.awt.Point pos)Highlights the given cursor position.voidsetError(int x, int y)Sets the error flag at given coordinates.voidunPreSelect(@NotNull java.awt.Point start, @NotNull java.awt.Point end)Pre-selection of rectangle defined by points gets deleted.voidunSelect()Clears all selection and pre-selection flags from the grid.voidunSetCursor(@NotNull java.awt.Point pos)Un-highlights the given cursor position.voidupdatePreSelect(@NotNull java.awt.Point start, @NotNull java.awt.Point oldEnd, @NotNull java.awt.Point newEnd)Update the pre-selection rectangle.
-
-
-
Field Detail
-
GRID_FLAG_SELECTION
public static final int GRID_FLAG_SELECTION
Selection - marks all selected squares.- See Also:
- Constant Field Values
-
GRID_FLAG_SELECTING
public static final int GRID_FLAG_SELECTING
Pre-selection - used to preselect squares.- See Also:
- Constant Field Values
-
GRID_FLAG_INFORMATION
public static final int GRID_FLAG_INFORMATION
Flag to highlight as information. RFU.- See Also:
- Constant Field Values
-
GRID_FLAG_WARNING
public static final int GRID_FLAG_WARNING
Flag to highlight as warning. RFU.- See Also:
- Constant Field Values
-
GRID_FLAG_ERROR
public static final int GRID_FLAG_ERROR
Flag to highlight as error.- See Also:
- Constant Field Values
-
GRID_FLAG_FATAL
public static final int GRID_FLAG_FATAL
Flag to highlight as fatal. RFU.- See Also:
- Constant Field Values
-
GRID_FLAG_CONNECTION
public static final int GRID_FLAG_CONNECTION
Flag to highlight as part of a connection group. RFU.- See Also:
- Constant Field Values
-
GRID_FLAG_CURSOR
public static final int GRID_FLAG_CURSOR
Flag to highlight cursor position. Normally there will only be up to one square that has this flag set.- See Also:
- Constant Field Values
-
GRID_FLAG_SELECTION_NORTH
public static final int GRID_FLAG_SELECTION_NORTH
Selection - is set for squares at the north edge of the selected area.- See Also:
- Constant Field Values
-
GRID_FLAG_SELECTION_EAST
public static final int GRID_FLAG_SELECTION_EAST
Selection - is set for squares at the east edge of the selected area.- See Also:
- Constant Field Values
-
GRID_FLAG_SELECTION_SOUTH
public static final int GRID_FLAG_SELECTION_SOUTH
Selection - is set for squares at the south edge of the selected area.- See Also:
- Constant Field Values
-
GRID_FLAG_SELECTION_WEST
public static final int GRID_FLAG_SELECTION_WEST
Selection - is set for squares at the west edge of the selected area.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MapGrid
public MapGrid(@NotNull @NotNull Size2D gridSize)Creates a new instance.- Parameters:
gridSize- the size of the grid
-
-
Method Detail
-
addMapGridListener
public void addMapGridListener(@NotNull @NotNull MapGridListener listener)Registers a MapGridListener.- Parameters:
listener- the listener to register
-
removeMapGridListener
public void removeMapGridListener(@NotNull @NotNull MapGridListener listener)Removes a MapGridListener.- Parameters:
listener- the listener to remove
-
getGridSize
@NotNull public @NotNull Size2D getGridSize()
Returns aSize2Dwith the dimension of this grid.- Returns:
- a size 2D with the dimension of this grid
-
resize
public void resize(@NotNull @NotNull Size2D newSize)Resizes the MapGrid. Old flags will be copied to the new grid.- Parameters:
newSize- the new grid size
-
unSelect
public void unSelect()
Clears all selection and pre-selection flags from the grid.
-
unSetCursor
public void unSetCursor(@NotNull @NotNull java.awt.Point pos)Un-highlights the given cursor position.- Parameters:
pos- the map coordinates of square to un-highlight
-
setCursor
public void setCursor(@NotNull @NotNull java.awt.Point pos)Highlights the given cursor position.- Parameters:
pos- the map coordinates of square to highlight
-
preSelect
public void preSelect(@NotNull @NotNull java.awt.Point start, @NotNull @NotNull java.awt.Point end)Rectangle defined by two points gets preselected. The points can be on any corner as long as they are opposite to each other.- Parameters:
start- any point on a corner of the rectangleend- the point on the opposite corner- See Also:
unPreSelect(Point, Point)
-
updatePreSelect
public void updatePreSelect(@NotNull @NotNull java.awt.Point start, @NotNull @NotNull java.awt.Point oldEnd, @NotNull @NotNull java.awt.Point newEnd)Update the pre-selection rectangle. The effect is identical to callingunPreSelect(start, oldEnd); preSelect(start, newEnd);except that smaller change events are generated.- Parameters:
start- the coordinate of the common first pointoldEnd- the coordinate of the end point for selection deletionnewEnd- the coordinate of the end point for selection addition- Note:
- This function assumes that all of (start-oldEnd) has set GRID_FLAG_SELECTING but no other square has set GRID_FLAG_SELECTING; if this precondition does not hold, it does not correctly update the flags
-
unPreSelect
public void unPreSelect(@NotNull @NotNull java.awt.Point start, @NotNull @NotNull java.awt.Point end)Pre-selection of rectangle defined by points gets deleted.- Parameters:
start- the coordinates of the first cornerend- the coordinates of the opposite corner- See Also:
preSelect(Point, Point)
-
select
public void select(@NotNull @NotNull java.awt.Point pos, @NotNull @NotNull SelectionMode selectionMode)Selects or deselects a single square.- Parameters:
pos- the squareselectionMode- the selection mode
-
selectArea
public void selectArea(@NotNull @NotNull java.awt.Point pos1, @NotNull @NotNull java.awt.Point pos2, @NotNull @NotNull SelectionMode selectionMode)Selects or deselects all squares in an area.- Parameters:
pos1- the first corner of rectanglepos2- the opposite corner of rectangleselectionMode- the selection mode
-
hasError
public boolean hasError(@NotNull @NotNull java.awt.Point p)Checks if a square has the error flag set.- Parameters:
p- the point to check- Returns:
trueifGRID_FLAG_ERRORis set
-
getFlags
public int getFlags(int x, int y)Returns the flags of a square.- Parameters:
x- the x-coordinate of the squarey- the y-coordinate of the square- Returns:
- the grid flags
-
getFlags
public int getFlags(@NotNull @NotNull java.awt.Point p)Returns the flags of a square.- Parameters:
p- the coordinates of the square- Returns:
- the grid flags
-
getRecChange
@NotNull public @NotNull java.awt.Rectangle getRecChange()
Returns a rectangle where the grid was changed. Width and height is 0 for single squares.- Returns:
- the changed rectangle
-
getSize
@NotNull public @NotNull Size2D getSize()
Returns size of grid.- Returns:
- the size of gri
-
getSelectedRec
@Nullable public @Nullable java.awt.Rectangle getSelectedRec()
Returns the smallest rectangle containing selection.- Returns:
- the rectangle containing selection or
nullif nothing is selected
-
selectAll
public void selectAll()
Marks all squares as selected.
-
invertSelection
public void invertSelection()
Inverts all selected squares.
-
setError
public void setError(int x, int y)Sets the error flag at given coordinates.- Parameters:
x- the x coordinatey- the y coordinate
-
clearErrors
public void clearErrors()
Clears all error flags.
-
beginTransaction
public void beginTransaction()
Starts 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 void endTransaction()
Ends a transaction. Invoking this method will reduce the transaction depth by 1.If the last transaction is ended, the changes are committed.
-
getSelection
@NotNull public @NotNull java.awt.Point @NotNull [] getSelection()
Returns the selection.- Returns:
- the selection
-
-