Package net.sf.gridarta.model.mapgrid
Class MapGrid
- java.lang.Object
-
- net.sf.gridarta.model.mapgrid.MapGrid
-
public class MapGrid extends java.lang.Object
2D-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
MapGridEvent
and informs all registeredMapGridListeners
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
GRID_FLAG_CONNECTION
Flag to highlight as part of a connection group.static int
GRID_FLAG_CURSOR
Flag to highlight cursor position.static int
GRID_FLAG_ERROR
Flag to highlight as error.static int
GRID_FLAG_FATAL
Flag to highlight as fatal.static int
GRID_FLAG_INFORMATION
Flag to highlight as information.static int
GRID_FLAG_SELECTING
Pre-selection - used to preselect squares.static int
GRID_FLAG_SELECTION
Selection - marks all selected squares.static int
GRID_FLAG_SELECTION_EAST
Selection - is set for squares at the east edge of the selected area.static int
GRID_FLAG_SELECTION_NORTH
Selection - is set for squares at the north edge of the selected area.static int
GRID_FLAG_SELECTION_SOUTH
Selection - is set for squares at the south edge of the selected area.static int
GRID_FLAG_SELECTION_WEST
Selection - is set for squares at the west edge of the selected area.static int
GRID_FLAG_WARNING
Flag to highlight as warning.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMapGridListener(@NotNull MapGridListener listener)
Registers a MapGridListener.void
beginTransaction()
Starts a new transaction.void
clearErrors()
Clears all error flags.void
endTransaction()
Ends a transaction.int
getFlags(int x, int y)
Returns the flags of a square.int
getFlags(@NotNull java.awt.Point p)
Returns the flags of a square.@NotNull Size2D
getGridSize()
Returns aSize2D
with the dimension of this grid.@NotNull java.awt.Rectangle
getRecChange()
Returns a rectangle where the grid was changed.@Nullable java.awt.Rectangle
getSelectedRec()
Returns the smallest rectangle containing selection.@NotNull java.awt.Point[]
getSelection()
Returns the selection.@NotNull Size2D
getSize()
Returns size of grid.boolean
hasError(@NotNull java.awt.Point p)
Checks if a square has the error flag set.void
invertSelection()
Inverts all selected squares.void
preSelect(@NotNull java.awt.Point start, @NotNull java.awt.Point end)
Rectangle defined by two points gets preselected.void
removeMapGridListener(@NotNull MapGridListener listener)
Removes a MapGridListener.void
resize(@NotNull Size2D newSize)
Resizes the MapGrid.void
select(@NotNull java.awt.Point pos, @NotNull SelectionMode selectionMode)
Selects or deselects a single square.void
selectAll()
Marks all squares as selected.void
selectArea(@NotNull java.awt.Point pos1, @NotNull java.awt.Point pos2, @NotNull SelectionMode selectionMode)
Selects or deselects all squares in an area.void
setCursor(@NotNull java.awt.Point pos)
Highlights the given cursor position.void
setError(int x, int y)
Sets the error flag at given coordinates.void
unPreSelect(@NotNull java.awt.Point start, @NotNull java.awt.Point end)
Pre-selection of rectangle defined by points gets deleted.void
unSelect()
Clears all selection and pre-selection flags from the grid.void
unSetCursor(@NotNull java.awt.Point pos)
Un-highlights the given cursor position.void
updatePreSelect(@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 aSize2D
with 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:
true
ifGRID_FLAG_ERROR
is 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
null
if 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[] getSelection()
Returns the selection.- Returns:
- the selection
-
-