 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.misc;
22 import java.awt.Point;
23 import java.awt.Rectangle;
24 import java.util.Collection;
25 import java.util.LinkedList;
26 import java.util.List;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
159 final Point pos =
new Point();
250 throw new IllegalArgumentException(
"unsupported direction: " + dir);
271 private void shift(
final Point pos,
final int len) {
272 final Point prevPos =
new Point(pos.x +
dx, pos.y +
dy);
273 final Point startPos =
new Point();
276 assert !startSelection;
277 boolean isStart =
true;
278 final Collection<G> startGameObjects =
new LinkedList<>();
279 final List<GameObject<G, A, R>> gameObjectsToDelete =
new LinkedList<>();
280 final Collection<G> gameObjectsToInsert =
new LinkedList<>();
281 for (
int i = 0; i < len; i++) {
286 gameObjectsToInsert.clear();
290 startPos.setLocation(prevPos);
292 assert startGameObjects.isEmpty();
295 startGameObjects.add(gameObject);
296 gameObjectsToDelete.add(gameObject);
303 gameObjectsToInsert.add(gameObject);
304 gameObjectsToDelete.add(gameObject);
313 gameObjectsToInsert.addAll(startGameObjects);
314 startGameObjects.clear();
320 while (!gameObjectsToDelete.isEmpty()) {
321 gameObjectsToDelete.remove(0).remove();
324 prevPos.setLocation(pos);
332 assert startGameObjects.isEmpty();
343 private void insertAllAndClear(@NotNull
final Collection<G> gameObjects, @NotNull
final Point point) {
344 for (
final G gameObject : gameObjects) {
InsertionMode getTopmostInsertionMode()
Returns the "topmost" insertion mode.
int getWidth()
Returns the width of the area.
A MapModel reflects the data of a map.
int getFlags(final int x, final int y)
Returns the flags of a square.
void endTransaction()
Ends a transaction.
MapGrid getMapGrid()
Returns the MapGrid of this view.
G insertBaseObject(@NotNull BaseObject< G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode insertionMode)
Inserts a BaseObject to a map.
final MapViewSettings mapViewSettings
The map view settings instance.
Base package of all Gridarta classes.
void endTransaction()
End a transaction.
static final int GRID_FLAG_SELECTION
Selection - marks all selected squares.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void shift(final Point pos, final int len)
Shifts one row.
SUB
All squares that are preselected get unselected.
Rectangle getSelectedRec()
Returns the smallest rectangle containing selection.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
Graphical User Interface of Gridarta.
final MapModel< G, A, R > mapModel
The map model to operate on.
void beginTransaction()
Starts a new transaction.
final MapView< G, A, R > mapView
The map view to operate on.
int dy
The y offset to shift.
GameObjects are the objects based on Archetypes found on maps.
int getHeight()
Returns the height of the area.
ShiftProcessor(@NotNull final MapViewSettings mapViewSettings, @NotNull final MapView< G, A, R > mapView, @NotNull final MapModel< G, A, R > mapModel, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Creates a new instance.
void shift(@NotNull final Direction dir)
Shifts the map contents by one square.
Size2D getSize()
Returns size of grid.
Interface for MapArchObjects.
boolean isEditType(int editType)
Get information on the current state of edit type.
Rectangle selRec
The selection rectangle to operate on.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Modes that describe how squares get selected.
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
int dx
The x offset to shift.
MapGrid mapGrid
The map grid to operate on.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
ADD
All squares that are preselected get selected.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
Base classes for rendering maps.
Performs a "shift" operation in a map: shift all selected squares into the given direction.
void insertAllAndClear(@NotNull final Collection< G > gameObjects, @NotNull final Point point)
Inserts a collection of GameObjects into the map and clears the list.
boolean canShift(@NotNull final Direction dir)
Checks whether shifting is possible.
The class Size2D represents a 2d rectangular area.