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.Collections;
27 import java.util.Iterator;
28 import java.util.List;
29 import javax.swing.JScrollPane;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
57 private final List<MapView<G, A, R>>
mapViews =
new ArrayList<>();
69 listeners.
add(listener);
77 listeners.
remove(listener);
86 return mapViews.isEmpty() ? null : mapViews.get(0);
94 return mapViews.size();
109 mapControl.acquire();
111 final MapView<G, A, R> mapView = mapViewFactory.newMapView(mapControl, viewPosition, ++nextMapViewCounter);
112 mapViews.add(mapView);
113 mapControl.acquire();
115 listener.mapViewCreated(mapView);
117 if (viewPosition == null && centerSquare != null) {
120 final Dimension extentSize = scrollPane.getViewport().getExtentSize();
121 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));
122 scrollPane.getViewport().setViewPosition(centerPoint);
126 mapControl.release();
136 final Point[] result =
new Point[mapViews.size()];
137 for (
int i = 0; i < result.length; i++) {
138 result[i] = mapViews.get(i).getScrollPane().getViewport().getViewPosition();
149 listener.mapViewClosing(mapView);
151 mapView.closeNotify();
152 mapViews.remove(mapView);
153 mapView.getMapControl().release();
160 while (!mapViews.isEmpty()) {
170 assert mapViews.contains(mapView);
171 mapViews.remove(mapView);
172 mapViews.add(0, mapView);
182 return Collections.unmodifiableList(mapViews).iterator();
190 mapView.getRenderer().forceRepaint();
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
Point [] getViewPositions()
Returns the current view positions of all views of a MapControl.
Rectangle getSquareBounds(@NotNull Point p)
Returns coordinates, length and width of map square.
T [] getListeners()
Returns an array of all the listeners.
int nextMapViewCounter
The map view counter for the next created MapView.
int getMapViews()
Returns the number of views of a MapControl.
void repaintAllViews()
Repaints all MapViews.
A list of MapViews for one MapControl instance.
void closeView(@NotNull final MapView< G, A, R > mapView)
Closes a view of a MapControl.
void removeMapViewsListener(@NotNull final MapViewsListener< G, A, R > listener)
Removes a MapViewsListener to be notified of events.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
MapView< G, A, R > newMapView(@NotNull final MapControl< G, A, R > mapControl, @Nullable final Point viewPosition, @Nullable final Point centerSquare, @NotNull final MapViewFactory< G, A, R > mapViewFactory)
Creates a new MapView.
void remove(@NotNull final T listener)
Removes a listener.
void closeAllViews()
Closes all views of a MapControl.
GameObjects are the objects based on Archetypes found on maps.
void add(@NotNull final T listener)
Adds a listener.
MapRenderer getRenderer()
Returns the MapRenderer for this view.
MapView< G, A, R > getMapViewFrame()
Returns the last used view of a MapControl.
final List< MapView< G, A, R > > mapViews
The list contains all views of the map.
void addMapViewsListener(@NotNull final MapViewsListener< G, A, R > listener)
Adds a MapViewsListener to be notified of events.
Type-safe version of EventListenerList.
final EventListenerList2< MapViewsListener< G, A, R > > listeners
The registered MapViewsListeners.
Interface for listeners interested in MapViewsManager related events.
Currently nothing more than a marker interface for unification.
Iterator< MapView< G, A, R > > getMapViewIterator()
Returns an Iterator returning all MapViews.
Interface for MapArchObjects.
void setFocus(@NotNull final MapView< G, A, R > mapView)
Sets a MapView as the main view.