 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.map.mapview;
22 import java.awt.Dimension;
23 import java.awt.Point;
24 import java.awt.Rectangle;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.List;
29 import javax.swing.JScrollPane;
42 import org.jetbrains.annotations.NotNull;
43 import org.jetbrains.annotations.Nullable;
77 public void mapSizeChanged(@NotNull
final Size2D newSize) {
87 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
97 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
102 public void modifiedChanged() {
131 final List<MapSquare<G, A, R>> selection =
new ArrayList<>();
132 for (
final Point pos : selectedMapSquares) {
142 final List<G> objects =
new ArrayList<>();
143 for (
final Iterable<G> mapSquare : selectedMapSquares) {
145 objects.add(gameObject.getHead());
156 final int objectSize = objects.size();
157 return objectSize == 0 ? null : objects.get(objectSize == 1 ? 0 :
RandomUtils.
RND.nextInt(objects.size()));
175 if (point.x >= mapSize.
getWidth()) {
177 }
else if (point.x < 0) {
182 }
else if (point.y < 0) {
192 final Dimension extentSize = scrollPane.getViewport().getExtentSize();
193 final Point centerPoint =
new Point(Math.max(0, squareBounds.x + squareBounds.width / 2 - extentSize.width / 2), Math.max(0, squareBounds.y + squareBounds.height / 2 - extentSize.height / 2));
194 scrollPane.getViewport().setViewPosition(centerPoint);
int getWidth()
Returns the width of the area.
final MapGrid mapGrid
The MapGrid of this map view.
A MapModel reflects the data of a map.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
final MapModel< G, A, R > mapModel
The MapModel of this map view.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
Base package of all Gridarta classes.
List< MapSquare< G, A, R > > getSelectedSquares()
Reflects a game object (object on a map).
MapRenderer getRenderer()
Returns the MapRenderer for this view.
MapCursor< G, A, R > getMapCursor()
void centerMapView(@NotNull final Point centerSquare)
GameObjects are the objects based on Archetypes found on maps.
int getHeight()
Returns the height of the area.
G getSelectedGameObject()
static final Random RND
Global random number generator.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
Interface for MapArchObjects.
An interface for classes that collect errors.
Point getLocation()
Get position of cursor.
A map view consists of a map grid and a map cursor, and is attached to a map control.
This package contains the framework for validating maps.
MapCursor provides methods to move and drag on map.
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
void setLocation(@NotNull final Point p)
Move cursor to a new location.
Point[] getSelection()
Returns the selection.
The location of a map file with a map directory.
Interface for listeners listening on MapModel events.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
Rectangle getSquareBounds(@NotNull Point p)
Returns coordinates, length and width of map square.
final MapModelListener< G, A, R > mapModelListener
The MapModelListener used to detect changes in the map model that should be reflected in the window t...
void resize(@NotNull final Size2D newSize)
Resizes the MapGrid.
void prependMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener and call it before all other listeners.
Abstract base class for MapView implementations.
AbstractMapView(@NotNull final MapModel< G, A, R > mapModel, @NotNull final MapGrid mapGrid, @NotNull final MapCursor< G, A, R > mapCursor)
Creates a new instance.
MapModel< G, A, R > getMapModel()
Returns the map model.
List< G > getSelectedGameObjects()
The class Size2D represents a 2d rectangular area.
List< G > getAllGameObjects()
Returns all game objects.
final MapCursor< G, A, R > mapCursor
The MapCursor of this map view.
void setCursorLocation(@NotNull final Point point)