Gridarta Editor
View.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.gui.panel.connectionview;
21 
22 import java.awt.BorderLayout;
23 import java.awt.event.MouseListener;
24 import java.util.ArrayList;
25 import java.util.Comparator;
26 import java.util.Map;
27 import java.util.TreeMap;
28 import java.util.Vector;
29 import javax.swing.JList;
30 import javax.swing.JPanel;
31 import javax.swing.JScrollPane;
32 import javax.swing.event.ListSelectionListener;
43 import org.jetbrains.annotations.NotNull;
44 import org.jetbrains.annotations.Nullable;
45 
58 public abstract class View<K, G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JPanel {
59 
63  private static final long serialVersionUID = 1L;
64 
68  @NotNull
69  private final Map<K, Connection<K>> connections;
70 
74  @NotNull
75  private final JList<Connection<K>> connectionList = new JList<>();
76 
80  @Nullable
82 
86  @NotNull
88 
89  @Override
90  public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
91  View.this.mapView = mapView;
93  }
94 
95  @Override
96  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
97  // ignore
98  }
99 
100  @Override
101  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
102  // ignore
103  }
104 
105  };
106 
110  @NotNull
112 
113  @Override
114  public void mapModelChanged(@NotNull final MapModel<G, A, R> mapModel) {
115  if (mapView != null && mapModel == mapView.getMapControl().getMapModel()) {
117  }
118  }
119 
120  };
121 
130  protected View(@NotNull final Comparator<K> keyComparator, @NotNull final CellRenderer<K> cellRenderer, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final DelayedMapModelListenerManager<G, A, R> delayedMapModelListenerManager) {
131  connections = new TreeMap<>(keyComparator);
132  setLayout(new BorderLayout());
133  connectionList.setCellRenderer(cellRenderer);
134  add(new JScrollPane(connectionList));
135  delayedMapModelListenerManager.addDelayedMapModelListener(delayedMapModelListener);
136  mapViewManager.addMapViewManagerListener(mapViewManagerListener);
137  }
138 
143  @Nullable
145  return mapView;
146  }
147 
152  public void addListSelectionListener(@NotNull final ListSelectionListener listener) {
153  connectionList.addListSelectionListener(listener);
154  }
155 
160  public void addListMouseListener(@NotNull final MouseListener listener) {
161  connectionList.addMouseListener(listener);
162  }
163 
167  private void scanMapForConnections() {
168  connections.clear();
169  if (mapView != null) {
171  }
172  connectionList.setListData(new Vector<>(connections.values()));
173  }
174 
179  private void scanMapForConnections(@NotNull final Iterable<MapSquare<G, A, R>> mapModel) {
180  for (final Iterable<G> mapSquare : mapModel) {
181  for (final G gameObject : mapSquare) {
182  scanGameObjectForConnections(gameObject);
183  }
184  }
185  }
186 
191  protected abstract void scanGameObjectForConnections(@NotNull G gameObject);
192 
193  protected void addConnection(@NotNull final K key, @NotNull final GameObject<G, A, R> gameObject) {
194  if (!connections.containsKey(key)) {
195  connections.put(key, new Connection<>(key));
196  }
197  connections.get(key).addGameObject(gameObject);
198  }
199 
204  @NotNull
205  public Iterable<Connection<K>> getSelectedConnections() {
206  return new ArrayList<>(connectionList.getSelectedValuesList());
207  }
208 
209 }
net.sf.gridarta.gui.panel.connectionview.View.scanGameObjectForConnections
abstract void scanGameObjectForConnections(@NotNull G gameObject)
Scans the given game object for connections.
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.gui.panel.connectionview.View.getSelectedConnections
Iterable< Connection< K > > getSelectedConnections()
Returns a list of all selected connections.
Definition: View.java:205
net.sf.gridarta.gui.panel.connectionview.View
Abstract base class for a panel that holds information about connections of the selected key on the s...
Definition: View.java:58
net.sf.gridarta.gui.panel.connectionview.View.getMapView
MapView< G, A, R > getMapView()
Returns the current map view.
Definition: View.java:144
net.sf.gridarta.gui.map.mapview.MapView.getMapControl
MapControl< G, A, R > getMapControl()
Return the controller of this view.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.MapSquare
A single Map Square.
Definition: MapSquare.java:45
net.sf.gridarta.gui.panel.connectionview.View.connections
final Map< K, Connection< K > > connections
The connections.
Definition: View.java:69
net.sf.gridarta.gui.map.mapview.MapViewManager
Maintains all map views.
Definition: MapViewManager.java:38
net.sf
net.sf.gridarta.gui.panel.connectionview.View.View
View(@NotNull final Comparator< K > keyComparator, @NotNull final CellRenderer< K > cellRenderer, @NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final DelayedMapModelListenerManager< G, A, R > delayedMapModelListenerManager)
Creates a new instance.
Definition: View.java:130
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.gui.map.mapview.MapViewManagerListener
Interface for listeners interested in events related to {} instances.
Definition: MapViewManagerListener.java:33
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.panel.connectionview.View.addConnection
void addConnection(@NotNull final K key, @NotNull final GameObject< G, A, R > gameObject)
Definition: View.java:193
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.panel.connectionview.View.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: View.java:63
net.sf.gridarta.gui.panel.connectionview.View.delayedMapModelListener
final DelayedMapModelListener< G, A, R > delayedMapModelListener
The map model listener to detect map changes.
Definition: View.java:111
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.map.mapview
Definition: AbstractMapView.java:20
net.sf.gridarta.gui.panel.connectionview.View.scanMapForConnections
void scanMapForConnections()
Scans the current map (mapView) for the contained connections.
Definition: View.java:167
net.sf.gridarta.gui.map.mapview.MapView
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
net.sf.gridarta.gui.delayedmapmodel
Definition: DelayedMapModelListener.java:20
net.sf.gridarta.gui.panel.connectionview.View.connectionList
final JList< Connection< K > > connectionList
The List with the connections.
Definition: View.java:75
net.sf.gridarta.gui.panel.connectionview.View.addListSelectionListener
void addListSelectionListener(@NotNull final ListSelectionListener listener)
Registers a ListSelectionListener for the connection list.
Definition: View.java:152
net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager
Provides support for delayed notification of MapModel changes.
Definition: DelayedMapModelListenerManager.java:54
net.sf.gridarta.gui.panel.connectionview.View.addListMouseListener
void addListMouseListener(@NotNull final MouseListener listener)
Registers a MouseListener for the connection list.
Definition: View.java:160
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.panel.connectionview.Connection
Stores GameObjects related to key values.
Definition: Connection.java:34
net.sf.gridarta.gui.panel.connectionview.View.mapView
MapView< G, A, R > mapView
Map view corresponding to connectionList.
Definition: View.java:81
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.model.mapcontrol.MapControl.getMapModel
MapModel< G, A, R > getMapModel()
Returns the map model.
net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListener
Interface for listeners interested in delayed map model change events.
Definition: DelayedMapModelListener.java:33
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.panel.connectionview.View.scanMapForConnections
void scanMapForConnections(@NotNull final Iterable< MapSquare< G, A, R >> mapModel)
Scans the given map for the contained connections.
Definition: View.java:179
net.sf.gridarta.gui.panel.connectionview.CellRenderer
A DefaultListCellRenderer for rendering Connection objects in a list.
Definition: CellRenderer.java:36
net.sf.gridarta.gui.panel.connectionview.View.mapViewManagerListener
final MapViewManagerListener< G, A, R > mapViewManagerListener
The map view listener to detect changed active maps.
Definition: View.java:87