public class MapGrid
extends java.lang.Object
preSelect(Point,
Point)
, then selectArea(Point, Point, SelectionMode)
will change
the selection flags according to SelectionMode
. 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 registered MapGridListeners
.
Modifier and Type | Field and 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.
|
Constructor and Description |
---|
MapGrid(@NotNull Size2D gridSize)
Creates a new instance.
|
Modifier and Type | Method and 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 a
Size2D 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.
|
public static final int GRID_FLAG_SELECTION
public static final int GRID_FLAG_SELECTING
public static final int GRID_FLAG_INFORMATION
public static final int GRID_FLAG_WARNING
public static final int GRID_FLAG_ERROR
public static final int GRID_FLAG_FATAL
public static final int GRID_FLAG_CONNECTION
public static final int GRID_FLAG_CURSOR
public static final int GRID_FLAG_SELECTION_NORTH
public static final int GRID_FLAG_SELECTION_EAST
public static final int GRID_FLAG_SELECTION_SOUTH
public static final int GRID_FLAG_SELECTION_WEST
public MapGrid(@NotNull @NotNull Size2D gridSize)
gridSize
- the size of the gridpublic void addMapGridListener(@NotNull @NotNull MapGridListener listener)
listener
- the listener to registerpublic void removeMapGridListener(@NotNull @NotNull MapGridListener listener)
listener
- the listener to remove@NotNull public @NotNull Size2D getGridSize()
Size2D
with the dimension of this grid.public void resize(@NotNull @NotNull Size2D newSize)
newSize
- the new grid sizepublic void unSelect()
public void unSetCursor(@NotNull @NotNull java.awt.Point pos)
pos
- the map coordinates of square to un-highlightpublic void setCursor(@NotNull @NotNull java.awt.Point pos)
pos
- the map coordinates of square to highlightpublic void preSelect(@NotNull @NotNull java.awt.Point start, @NotNull @NotNull java.awt.Point end)
start
- any point on a corner of the rectangleend
- the point on the opposite cornerunPreSelect(Point, Point)
public void updatePreSelect(@NotNull @NotNull java.awt.Point start, @NotNull @NotNull java.awt.Point oldEnd, @NotNull @NotNull java.awt.Point newEnd)
unPreSelect(start, oldEnd); preSelect(start, newEnd);
except that
smaller change events are generated.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 additionpublic void unPreSelect(@NotNull @NotNull java.awt.Point start, @NotNull @NotNull java.awt.Point end)
start
- the coordinates of the first cornerend
- the coordinates of the opposite cornerpreSelect(Point, Point)
public void select(@NotNull @NotNull java.awt.Point pos, @NotNull @NotNull SelectionMode selectionMode)
pos
- the squareselectionMode
- the selection modepublic void selectArea(@NotNull @NotNull java.awt.Point pos1, @NotNull @NotNull java.awt.Point pos2, @NotNull @NotNull SelectionMode selectionMode)
pos1
- the first corner of rectanglepos2
- the opposite corner of rectangleselectionMode
- the selection modepublic boolean hasError(@NotNull @NotNull java.awt.Point p)
p
- the point to checktrue
if GRID_FLAG_ERROR
is setpublic int getFlags(int x, int y)
x
- the x-coordinate of the squarey
- the y-coordinate of the squarepublic int getFlags(@NotNull @NotNull java.awt.Point p)
p
- the coordinates of the square@NotNull public @NotNull java.awt.Rectangle getRecChange()
@NotNull public @NotNull Size2D getSize()
@Nullable public @Nullable java.awt.Rectangle getSelectedRec()
null
if nothing is
selectedpublic void selectAll()
public void invertSelection()
public void setError(int x, int y)
x
- the x coordinatey
- the y coordinatepublic void clearErrors()
public void beginTransaction()
endTransaction()
.public void endTransaction()
If the last transaction is ended, the changes are committed.
@NotNull public @NotNull java.awt.Point[] getSelection()