Gridarta Editor
MapGrid.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapgrid;
21 
22 import java.awt.Point;
23 import java.awt.Rectangle;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.concurrent.CopyOnWriteArrayList;
28 import net.sf.gridarta.utils.Size2D;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
46 public class MapGrid {
47 
51  private int @NotNull [] @NotNull [] gridFlags;
52 
56  @NotNull
57  private final Point cornerMin = new Point();
58 
62  @NotNull
63  private final Point cornerMax = new Point();
64 
68  @NotNull
69  private Size2D gridSize;
70 
74  @NotNull
75  private final Rectangle recChange = new Rectangle();
76 
80  private boolean cachedSelectedRecValid;
81 
86  @Nullable
87  private Rectangle cachedSelectedRec;
88 
92  @Nullable
93  private Point cachedCursorLoc;
94 
98  public static final int GRID_FLAG_SELECTION = 1;
99 
103  public static final int GRID_FLAG_SELECTING = 1 << 1;
104 
108  public static final int GRID_FLAG_INFORMATION = 1 << 2;
109 
113  public static final int GRID_FLAG_WARNING = 1 << 3;
114 
118  public static final int GRID_FLAG_ERROR = 1 << 4;
119 
123  public static final int GRID_FLAG_FATAL = 1 << 5;
124 
128  public static final int GRID_FLAG_CONNECTION = 1 << 6;
129 
134  public static final int GRID_FLAG_CURSOR = 1 << 7;
135 
139  public static final int GRID_FLAG_SELECTION_NORTH = 1 << 8;
140 
144  public static final int GRID_FLAG_SELECTION_EAST = 1 << 9;
145 
149  public static final int GRID_FLAG_SELECTION_SOUTH = 1 << 10;
150 
154  public static final int GRID_FLAG_SELECTION_WEST = 1 << 11;
155 
159  @NotNull
160  private final Collection<MapGridListener> listenerList = new CopyOnWriteArrayList<>();
161 
168  private int transactionDepth;
169 
174  @Nullable
175  private Thread transactionThread;
176 
181  public MapGrid(@NotNull final Size2D gridSize) {
182  this.gridSize = gridSize;
183  gridFlags = new int[gridSize.getWidth()][gridSize.getHeight()];
184  }
185 
190  public void addMapGridListener(@NotNull final MapGridListener listener) {
191  listenerList.add(listener);
192  }
193 
198  public void removeMapGridListener(@NotNull final MapGridListener listener) {
199  listenerList.remove(listener);
200  }
201 
206  @NotNull
207  public Size2D getGridSize() {
208  return gridSize;
209  }
210 
215  public void resize(@NotNull final Size2D newSize) {
216  if (gridSize.equals(newSize)) {
217  // Nothing to do
218  return;
219  }
220  final int[][] newGridFlags = new int[newSize.getWidth()][newSize.getHeight()];
221  final Point pos = new Point();
222  final Size2D minSize = new Size2D(Math.min(newSize.getWidth(), gridSize.getWidth()), Math.min(newSize.getHeight(), gridSize.getHeight()));
223  if (newSize.getWidth() < gridSize.getWidth()) {
224  unsetFlags(newSize.getWidth(), 0, newSize.getWidth(), minSize.getHeight() - 1, GRID_FLAG_SELECTION);
225  }
226  if (newSize.getHeight() < gridSize.getHeight()) {
227  unsetFlags(0, newSize.getHeight(), minSize.getWidth() - 1, newSize.getHeight(), GRID_FLAG_SELECTION);
228  }
229  for (pos.x = 0; pos.x < minSize.getWidth(); pos.x++) {
230  for (pos.y = 0; pos.y < minSize.getHeight(); pos.y++) {
231  newGridFlags[pos.x][pos.y] = gridFlags[pos.x][pos.y];
232  }
233  }
234  gridFlags = newGridFlags;
235  gridSize = newSize;
236  cachedSelectedRecValid = false;
238  }
239 
243  private void fireMapGridChangedEvent() {
244  final MapGridEvent e = new MapGridEvent(this);
245  for (final MapGridListener listener : listenerList) {
246  listener.mapGridChanged(e);
247  }
248  }
249 
253  private void fireMapGridResizeEvent() {
254  final MapGridEvent e = new MapGridEvent(this);
255  for (final MapGridListener listener : listenerList) {
256  listener.mapGridResized(e);
257  }
258  }
259 
263  public void unSelect() {
265  try {
267  } finally {
268  endTransaction();
269  }
270  }
271 
276  public void unSetCursor(@NotNull final Point pos) {
278  try {
279  try {
280  unsetFlags(pos.x, pos.y, pos.x, pos.y, GRID_FLAG_CURSOR);
281  } catch (final ArrayIndexOutOfBoundsException ignored) {
282  // happens after map resizes if the map cursor was within the cut off area
283  }
284  if (cachedCursorLoc != null && cachedCursorLoc.equals(pos)) {
285  cachedCursorLoc = null;
286  }
287  } finally {
288  endTransaction();
289  }
290  }
291 
296  public void setCursor(@NotNull final Point pos) {
298  try {
299  setFlags(pos.x, pos.y, pos.x, pos.y, GRID_FLAG_CURSOR);
300  cachedCursorLoc = new Point(pos);
301  } finally {
302  endTransaction();
303  }
304  }
305 
313  public void preSelect(@NotNull final Point start, @NotNull final Point end) {
315  try {
316  calculateRec(start, end);
318  } finally {
319  endTransaction();
320  }
321  }
322 
334  public void updatePreSelect(@NotNull final Point start, @NotNull final Point oldEnd, @NotNull final Point newEnd) {
335  final Point old1 = new Point(Math.min(start.x, oldEnd.x), Math.min(start.y, oldEnd.y));
336  final Point old2 = new Point(Math.max(start.x, oldEnd.x), Math.max(start.y, oldEnd.y));
337  final Point new1 = new Point(Math.min(start.x, newEnd.x), Math.min(start.y, newEnd.y));
338  final Point new2 = new Point(Math.max(start.x, newEnd.x), Math.max(start.y, newEnd.y));
340  try {
341  // delete old selection
342  if (old1.x < new1.x) {
343  unsetFlags(old1.x, old1.y, new1.x - 1, old2.y, GRID_FLAG_SELECTING);
344  old1.x = new1.x;
345  }
346  if (new2.x < old2.x) {
347  unsetFlags(new2.x + 1, old1.y, old2.x, old2.y, GRID_FLAG_SELECTING);
348  old2.x = new2.x;
349  }
350  if (old1.y < new1.y) {
351  unsetFlags(old1.x, old1.y, old2.x, new1.y - 1, GRID_FLAG_SELECTING);
352  old1.y = new1.y;
353  }
354  if (new2.y < old2.y) {
355  unsetFlags(old1.x, new2.y + 1, old2.x, old2.y, GRID_FLAG_SELECTING);
356  old2.y = new2.y;
357  }
358 
359  // add new selection
360  if (new1.x < old1.x) {
361  setFlags(new1.x, new1.y, old1.x - 1, new2.y, GRID_FLAG_SELECTING);
362  old1.x = new1.x;
363  }
364  if (old2.x < new2.x) {
365  setFlags(old2.x + 1, new1.y, new2.x, new2.y, GRID_FLAG_SELECTING);
366  old2.x = new2.x;
367  }
368  if (new1.y < old1.y) {
369  setFlags(new1.x, new1.y, new2.x, old1.y - 1, GRID_FLAG_SELECTING);
370  old1.y = new1.y;
371  }
372  if (old2.y < new2.y) {
373  setFlags(new1.x, old2.y + 1, new2.x, new2.y, GRID_FLAG_SELECTING);
374  old2.y = new2.y;
375  }
376 
377  // sanity check
378  assert old1.x == new1.x;
379  assert old2.x == new2.x;
380  assert old1.y == new1.y;
381  assert old2.y == new2.y;
382  } finally {
383  endTransaction();
384  }
385  }
386 
393  public void unPreSelect(@NotNull final Point start, @NotNull final Point end) {
395  try {
396  calculateRec(start, end);
398  } finally {
399  endTransaction();
400  }
401  }
402 
408  public void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode) {
409  selectArea(pos, pos, selectionMode);
410  }
411 
418  public void selectArea(@NotNull final Point pos1, @NotNull final Point pos2, @NotNull final SelectionMode selectionMode) {
420  try {
421  calculateRec(pos1, pos2);
422  switch (selectionMode) {
423  case ADD:
425  break;
426  case SUB:
428  break;
429  case FLIP:
431  break;
432  }
433  } finally {
434  endTransaction();
435  }
436  }
437 
444  private void calculateRec(@NotNull final Point p1, @NotNull final Point p2) {
445  if (p1.x > p2.x) {
446  cornerMin.x = p2.x;
447  cornerMax.x = p1.x;
448  } else {
449  cornerMin.x = p1.x;
450  cornerMax.x = p2.x;
451  }
452  if (p1.y > p2.y) {
453  cornerMin.y = p2.y;
454  cornerMax.y = p1.y;
455  } else {
456  cornerMin.y = p1.y;
457  cornerMax.y = p2.y;
458  }
459  }
460 
466  public boolean hasError(@NotNull final Point p) {
467  return (gridFlags[p.x][p.y] & GRID_FLAG_ERROR) != 0;
468  }
469 
476  public int getFlags(final int x, final int y) {
477  return gridFlags[x][y];
478  }
479 
485  public int getFlags(@NotNull final Point p) {
486  return gridFlags[p.x][p.y];
487  }
488 
494  @NotNull
495  public Rectangle getRecChange() {
496  return new Rectangle(recChange);
497  }
498 
503  @NotNull
504  public Size2D getSize() {
505  return gridSize;
506  }
507 
513  @Nullable
514  public Rectangle getSelectedRec() {
516  if (cachedSelectedRec != null) {
517  return new Rectangle(cachedSelectedRec);
518  }
519  if (cachedCursorLoc != null) {
520  return new Rectangle(cachedCursorLoc.x, cachedCursorLoc.y, 1, 1);
521  }
522  return null;
523  }
524 
528  private void calculateCachedSelectedRec() {
530  return;
531  }
532  cachedSelectedRecValid = true;
533 
534  int x1 = -1;
535  for (int x = 0; x < gridSize.getWidth(); x++) {
536  for (int y = 0; y < gridSize.getHeight(); y++) {
537  if ((gridFlags[x][y] & GRID_FLAG_SELECTION) > 0) {
538  x1 = x;
539  break;
540  }
541  }
542  if (x1 >= 0) {
543  break;
544  }
545  }
546  if (x1 < 0) {
547  cachedSelectedRec = null;
548  return;
549  }
550 
551  int x2 = -1;
552  for (int x = gridSize.getWidth() - 1; x >= x1; x--) {
553  for (int y = 0; y < gridSize.getHeight(); y++) {
554  if ((gridFlags[x][y] & GRID_FLAG_SELECTION) > 0) {
555  x2 = x;
556  break;
557  }
558  }
559  if (x2 >= 0) {
560  break;
561  }
562  }
563  int y1 = -1;
564  for (int y = 0; y < gridSize.getHeight(); y++) {
565  for (int x = 0; x < gridSize.getWidth(); x++) {
566  if ((gridFlags[x][y] & GRID_FLAG_SELECTION) > 0) {
567  y1 = y;
568  break;
569  }
570  }
571  if (y1 >= 0) {
572  break;
573  }
574  }
575  int y2 = -1;
576  for (int y = gridSize.getHeight() - 1; y >= y1; y--) {
577  for (int x = 0; x < gridSize.getWidth(); x++) {
578  if ((gridFlags[x][y] & GRID_FLAG_SELECTION) > 0) {
579  y2 = y;
580  break;
581  }
582  }
583  if (y2 >= 0) {
584  break;
585  }
586  }
587  cachedSelectedRec = new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
588  }
589 
593  public void selectAll() {
595  try {
597  } finally {
598  endTransaction();
599  }
600  }
601 
605  public void invertSelection() {
607  try {
609  } finally {
610  endTransaction();
611  }
612  }
613 
619  public void setError(final int x, final int y) {
621  try {
622  setFlags(x, y, x, y, GRID_FLAG_ERROR);
623  } finally {
624  endTransaction();
625  }
626  }
627 
631  public void clearErrors() {
633  try {
635  } finally {
636  endTransaction();
637  }
638  }
639 
646  private void beginRecChange() {
649  recChange.width = 0;
650  recChange.height = 0;
651  }
652 
658  private void updateRecChange(final int x, final int y) {
659  if (recChange.x > x) {
660  recChange.x = x;
661  }
662  if (recChange.y > y) {
663  recChange.y = y;
664  }
665  if (recChange.width < x) {
666  recChange.width = x;
667  }
668  if (recChange.height < y) {
669  recChange.height = y;
670  }
671  }
672 
678  private boolean endRecChange() {
679  recChange.width = recChange.width - recChange.x + 1;
680  recChange.height = recChange.height - recChange.y + 1;
681  return recChange.width > 0 && recChange.height > 0;
682  }
683 
692  private void setFlags(final int minX, final int minY, final int maxX, final int maxY, final int flags) {
693  for (int x = minX; x <= maxX; x++) {
694  for (int y = minY; y <= maxY; y++) {
695  if ((gridFlags[x][y] & flags) != flags) {
696  if ((flags & GRID_FLAG_SELECTION) != 0 && (gridFlags[x][y] & GRID_FLAG_SELECTION) == 0) {
697  updateSelectionFlag(x, y, true);
698  }
699  gridFlags[x][y] |= flags;
700  updateRecChange(x, y);
701  cachedSelectedRecValid = false;
702  }
703  }
704  }
705  }
706 
715  private void unsetFlags(final int minX, final int minY, final int maxX, final int maxY, final int flags) {
716  for (int x = minX; x <= maxX; x++) {
717  for (int y = minY; y <= maxY; y++) {
718  if ((gridFlags[x][y] & flags) != 0) {
719  if ((flags & GRID_FLAG_SELECTION) != 0 && (gridFlags[x][y] & GRID_FLAG_SELECTION) != 0) {
720  updateSelectionFlag(x, y, false);
721  }
722  gridFlags[x][y] &= ~flags;
723  updateRecChange(x, y);
724  cachedSelectedRecValid = false;
725  }
726  }
727  }
728  }
729 
738  private void toggleFlags(final int minX, final int minY, final int maxX, final int maxY, final int flags) {
739  for (int x = minX; x <= maxX; x++) {
740  for (int y = minY; y <= maxY; y++) {
741  updateSelectionFlag(x, y, (gridFlags[x][y] & flags) == 0);
742  gridFlags[x][y] ^= flags;
743  }
744  }
745  cachedSelectedRecValid = false;
746  updateRecChange(minX, minY);
747  updateRecChange(maxX, maxY);
748  }
749 
756  public void beginTransaction() {
757  if (transactionDepth == 0) {
758  transactionThread = Thread.currentThread();
759  beginRecChange();
760  } else {
761  // == is okay for threads.
762  //noinspection ObjectEquality
763  if (transactionThread != Thread.currentThread()) {
764  throw new IllegalStateException("A transaction must only be used by one thread.");
765  }
766  }
768  }
769 
776  public void endTransaction() {
777  if (transactionDepth <= 0) {
778  throw new IllegalStateException("Tried to end a transaction but no transaction was open.");
779  }
781  assert transactionDepth >= 0;
782  if (transactionDepth == 0) {
783  transactionDepth = 0;
784  transactionThread = null;
785  if (endRecChange()) {
787  }
788  }
789  }
790 
798  private void updateSelectionFlag(final int x, final int y, final boolean newState) {
803  }
804 
816  private void updateSelectionFlag(final int x, final int y, final boolean newState, final int dx, final int dy, final int flag, final int dFlag) {
817  final boolean dState = 0 <= dx && dx < gridSize.getWidth() && 0 <= dy && dy < gridSize.getHeight() && (gridFlags[dx][dy] & GRID_FLAG_SELECTION) != 0;
818  if (newState) {
819  if (dState) {
820  gridFlags[dx][dy] &= ~dFlag;
821  updateRecChange(dx, dy);
822  } else {
823  gridFlags[x][y] |= flag;
824  updateRecChange(x, y);
825  }
826  } else {
827  if (dState) {
828  gridFlags[dx][dy] |= dFlag;
829  updateRecChange(dx, dy);
830  } else {
831  gridFlags[x][y] &= ~flag;
832  updateRecChange(x, y);
833  }
834  }
835  }
836 
841  @NotNull
842  public Point @NotNull [] getSelection() {
844  final Rectangle selectedRec = cachedSelectedRec;
845  final List<Point> selection = new ArrayList<>();
846  if (selectedRec != null) {
847  for (int x = selectedRec.x; x < selectedRec.x + selectedRec.width; x++) {
848  for (int y = selectedRec.y; y < selectedRec.y + selectedRec.height; y++) {
849  if ((gridFlags[x][y] & GRID_FLAG_SELECTION) > 0) {
850  selection.add(new Point(x, y));
851  }
852  }
853  }
854  } else if (cachedCursorLoc != null) {
855  selection.add(new Point(cachedCursorLoc));
856  }
857  return selection.toArray(new Point[0]);
858  }
859 
860 }
net.sf.gridarta.model.mapgrid.MapGrid.addMapGridListener
void addMapGridListener(@NotNull final MapGridListener listener)
Registers a MapGridListener.
Definition: MapGrid.java:190
net.sf.gridarta.utils.Size2D.getWidth
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
net.sf.gridarta.model.mapgrid.MapGrid.toggleFlags
void toggleFlags(final int minX, final int minY, final int maxX, final int maxY, final int flags)
Flips flags in a rectangle and generate a grid change event.
Definition: MapGrid.java:738
net.sf.gridarta.model.mapgrid.MapGrid.getFlags
int getFlags(final int x, final int y)
Returns the flags of a square.
Definition: MapGrid.java:476
net.sf.gridarta.model.mapgrid.MapGrid.endTransaction
void endTransaction()
Ends a transaction.
Definition: MapGrid.java:776
net.sf.gridarta.model.mapgrid.MapGrid.invertSelection
void invertSelection()
Inverts all selected squares.
Definition: MapGrid.java:605
net.sf.gridarta.model.mapgrid.MapGrid.fireMapGridResizeEvent
void fireMapGridResizeEvent()
Informs all registered listeners that the size of MapGrid has changed.
Definition: MapGrid.java:253
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION
static final int GRID_FLAG_SELECTION
Selection - marks all selected squares.
Definition: MapGrid.java:98
net.sf.gridarta.model.mapgrid.MapGrid.listenerList
final Collection< MapGridListener > listenerList
The MapGridListeners to inform of changes.
Definition: MapGrid.java:160
net.sf
net.sf.gridarta.model.mapgrid.MapGrid.updatePreSelect
void updatePreSelect(@NotNull final Point start, @NotNull final Point oldEnd, @NotNull final Point newEnd)
Update the pre-selection rectangle.
Definition: MapGrid.java:334
net.sf.gridarta.model.mapgrid.MapGrid.hasError
boolean hasError(@NotNull final Point p)
Checks if a square has the error flag set.
Definition: MapGrid.java:466
net.sf.gridarta.model.mapgrid.MapGrid.transactionDepth
int transactionDepth
The transaction depth.
Definition: MapGrid.java:168
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_INFORMATION
static final int GRID_FLAG_INFORMATION
Flag to highlight as information.
Definition: MapGrid.java:108
net.sf.gridarta.model.mapgrid.MapGrid.clearErrors
void clearErrors()
Clears all error flags.
Definition: MapGrid.java:631
net.sf.gridarta.model.mapgrid.MapGrid.unsetFlags
void unsetFlags(final int minX, final int minY, final int maxX, final int maxY, final int flags)
Resets flags in a rectangle and generate a grid change event.
Definition: MapGrid.java:715
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_EAST
static final int GRID_FLAG_SELECTION_EAST
Selection - is set for squares at the east edge of the selected area.
Definition: MapGrid.java:144
net.sf.gridarta.model.mapgrid.MapGrid.updateSelectionFlag
void updateSelectionFlag(final int x, final int y, final boolean newState, final int dx, final int dy, final int flag, final int dFlag)
Updates the border selection flags of a square and one adjacent square.
Definition: MapGrid.java:816
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_CONNECTION
static final int GRID_FLAG_CONNECTION
Flag to highlight as part of a connection group.
Definition: MapGrid.java:128
net.sf.gridarta.model.mapgrid.MapGrid.getSelectedRec
Rectangle getSelectedRec()
Returns the smallest rectangle containing selection.
Definition: MapGrid.java:514
net.sf.gridarta.model.mapgrid.MapGrid.unSetCursor
void unSetCursor(@NotNull final Point pos)
Un-highlights the given cursor position.
Definition: MapGrid.java:276
net.sf.gridarta.model.mapgrid.MapGrid.cornerMin
final Point cornerMin
Left upper coordinates of rectangle that is being processed.
Definition: MapGrid.java:57
net.sf.gridarta.model.mapgrid.MapGrid.getRecChange
Rectangle getRecChange()
Returns a rectangle where the grid was changed.
Definition: MapGrid.java:495
net.sf.gridarta.model.mapgrid.MapGrid.updateSelectionFlag
void updateSelectionFlag(final int x, final int y, final boolean newState)
Updates the border selection flags of a square and its adjacent squares.
Definition: MapGrid.java:798
net.sf.gridarta.model.mapgrid.MapGrid.setFlags
void setFlags(final int minX, final int minY, final int maxX, final int maxY, final int flags)
Sets flags in a rectangle and generate a grid change event.
Definition: MapGrid.java:692
net.sf.gridarta.model.mapgrid.MapGrid.beginTransaction
void beginTransaction()
Starts a new transaction.
Definition: MapGrid.java:756
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_SOUTH
static final int GRID_FLAG_SELECTION_SOUTH
Selection - is set for squares at the south edge of the selected area.
Definition: MapGrid.java:149
net.sf.gridarta.model.mapgrid.MapGrid.selectAll
void selectAll()
Marks all squares as selected.
Definition: MapGrid.java:593
net
net.sf.gridarta.utils.Size2D.getHeight
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
net.sf.gridarta.model.mapgrid.MapGrid.cachedSelectedRec
Rectangle cachedSelectedRec
The return value for getSelectedRec().
Definition: MapGrid.java:87
net.sf.gridarta.model.mapgrid.MapGrid.cachedSelectedRecValid
boolean cachedSelectedRecValid
If set, cachedSelectedRec is up-to-date.
Definition: MapGrid.java:80
net.sf.gridarta.model.mapgrid.MapGrid.getSize
Size2D getSize()
Returns size of grid.
Definition: MapGrid.java:504
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_WEST
static final int GRID_FLAG_SELECTION_WEST
Selection - is set for squares at the west edge of the selected area.
Definition: MapGrid.java:154
net.sf.gridarta.model.mapgrid.MapGrid.gridSize
Size2D gridSize
Size of.
Definition: MapGrid.java:69
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_ERROR
static final int GRID_FLAG_ERROR
Flag to highlight as error.
Definition: MapGrid.java:118
net.sf.gridarta.model.mapgrid.MapGrid.beginRecChange
void beginRecChange()
Begins a set of changes.
Definition: MapGrid.java:646
net.sf.gridarta.model.mapgrid.SelectionMode
Modes that describe how squares get selected.
Definition: SelectionMode.java:26
net.sf.gridarta.model.mapgrid.MapGrid.removeMapGridListener
void removeMapGridListener(@NotNull final MapGridListener listener)
Removes a MapGridListener.
Definition: MapGrid.java:198
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_CURSOR
static final int GRID_FLAG_CURSOR
Flag to highlight cursor position.
Definition: MapGrid.java:134
net.sf.gridarta.model.mapgrid.MapGrid.endRecChange
boolean endRecChange()
Ends the set of changes and store the bounding box for all recorded changes in recChange.
Definition: MapGrid.java:678
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_WARNING
static final int GRID_FLAG_WARNING
Flag to highlight as warning.
Definition: MapGrid.java:113
net.sf.gridarta.model.mapgrid.MapGrid.select
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
Definition: MapGrid.java:408
net.sf.gridarta.model.mapgrid.MapGrid.getSelection
Point[] getSelection()
Returns the selection.
Definition: MapGrid.java:842
net.sf.gridarta.model.mapgrid.MapGrid
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Definition: MapGrid.java:46
net.sf.gridarta.model.mapgrid.MapGrid.MapGrid
MapGrid(@NotNull final Size2D gridSize)
Creates a new instance.
Definition: MapGrid.java:181
net.sf.gridarta.utils.Size2D.equals
boolean equals(@Nullable final Object obj)
Definition: Size2D.java:76
net.sf.gridarta.model.mapgrid.MapGrid.calculateCachedSelectedRec
void calculateCachedSelectedRec()
Makes sure the value of cachedSelectedRec if up-to-date.
Definition: MapGrid.java:528
net.sf.gridarta.model.mapgrid.MapGrid.getFlags
int getFlags(@NotNull final Point p)
Returns the flags of a square.
Definition: MapGrid.java:485
net.sf.gridarta.model.mapgrid.MapGrid.getGridSize
Size2D getGridSize()
Returns a Size2D with the dimension of this grid.
Definition: MapGrid.java:207
net.sf.gridarta.model.mapgrid.MapGrid.resize
void resize(@NotNull final Size2D newSize)
Resizes the MapGrid.
Definition: MapGrid.java:215
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTION_NORTH
static final int GRID_FLAG_SELECTION_NORTH
Selection - is set for squares at the north edge of the selected area.
Definition: MapGrid.java:139
net.sf.gridarta.model.mapgrid.MapGrid.updateRecChange
void updateRecChange(final int x, final int y)
Adds a point to the set of changes.
Definition: MapGrid.java:658
net.sf.gridarta.model.mapgrid.MapGridListener
Interface for listeners listening to MapGridEvents.
Definition: MapGridListener.java:29
net.sf.gridarta.model.mapgrid.MapGrid.preSelect
void preSelect(@NotNull final Point start, @NotNull final Point end)
Rectangle defined by two points gets preselected.
Definition: MapGrid.java:313
net.sf.gridarta.model.mapgrid.MapGrid.unPreSelect
void unPreSelect(@NotNull final Point start, @NotNull final Point end)
Pre-selection of rectangle defined by points gets deleted.
Definition: MapGrid.java:393
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_FATAL
static final int GRID_FLAG_FATAL
Flag to highlight as fatal.
Definition: MapGrid.java:123
net.sf.gridarta.model.mapgrid.MapGrid.selectArea
void selectArea(@NotNull final Point pos1, @NotNull final Point pos2, @NotNull final SelectionMode selectionMode)
Selects or deselects all squares in an area.
Definition: MapGrid.java:418
net.sf.gridarta.model.mapgrid.MapGrid.setCursor
void setCursor(@NotNull final Point pos)
Highlights the given cursor position.
Definition: MapGrid.java:296
net.sf.gridarta.model.mapgrid.MapGridEvent
This event is created by MapGrid.
Definition: MapGridEvent.java:29
net.sf.gridarta.model.mapgrid.MapGrid.fireMapGridChangedEvent
void fireMapGridChangedEvent()
Inform all registered listeners that the flags on MapGrid have changed.
Definition: MapGrid.java:243
net.sf.gridarta.model.mapgrid.MapGrid.setError
void setError(final int x, final int y)
Sets the error flag at given coordinates.
Definition: MapGrid.java:619
net.sf.gridarta.model.mapgrid.MapGrid.calculateRec
void calculateRec(@NotNull final Point p1, @NotNull final Point p2)
Definition: MapGrid.java:444
net.sf.gridarta.model.mapgrid.MapGrid.transactionThread
Thread transactionThread
The thread that performs the current transaction.
Definition: MapGrid.java:175
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.model.mapgrid.MapGrid.unSelect
void unSelect()
Clears all selection and pre-selection flags from the grid.
Definition: MapGrid.java:263
net.sf.gridarta.model.mapgrid.MapGrid.cornerMax
final Point cornerMax
Right lower coordinates of rectangle that is being processed.
Definition: MapGrid.java:63
net.sf.gridarta.model.mapgrid.MapGrid.cachedCursorLoc
Point cachedCursorLoc
Cached location of the cursor.
Definition: MapGrid.java:93
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.model.mapgrid.MapGrid.gridFlags
int[][] gridFlags
2D-array to store grid flags.
Definition: MapGrid.java:51
net.sf.gridarta.model.mapgrid.MapGrid.GRID_FLAG_SELECTING
static final int GRID_FLAG_SELECTING
Pre-selection - used to preselect squares.
Definition: MapGrid.java:103
net.sf.gridarta.model.mapgrid.MapGrid.recChange
final Rectangle recChange
Rectangle to store location of last grid change.
Definition: MapGrid.java:75