Gridarta Editor
Control.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 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.Point;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.util.Iterator;
26 import javax.swing.JPanel;
27 import javax.swing.event.ListSelectionEvent;
28 import javax.swing.event.ListSelectionListener;
36 import org.jetbrains.annotations.NotNull;
37 
42 public abstract class Control<K, G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
43 
47  @NotNull
48  private final View<K, G, A, R> view;
49 
54  protected Control(@NotNull final View<K, G, A, R> view) {
55  this.view = view;
56 
57  view.addListSelectionListener(new ListSelectionListener() {
58 
59  @Override
60  public void valueChanged(final ListSelectionEvent e) {
62  }
63  });
64 
65  //noinspection RefusedBequest
66  view.addListMouseListener(new MouseAdapter() {
67 
68  @Override
69  public void mousePressed(final MouseEvent e) {
71  if (e.getClickCount() == 2) {
72  final Iterator<Connection<K>> it = view.getSelectedConnections().iterator();
73  if (it.hasNext()) {
74  doubleClick(it.next());
75  }
76  }
77  }
78  });
79  }
80 
85  protected abstract void doubleClick(@NotNull Connection<K> connection);
86 
91  @NotNull
92  public JPanel getView() {
93  return view;
94  }
95 
99  private void highlightSelectedEntries() {
100  final MapView<G, A, R> mapView = view.getMapView();
101  if (mapView == null) {
102  return;
103  }
104 
105  final MapGrid mapGrid = mapView.getMapGrid();
106  mapGrid.unSelect();
107 
108  final Point point = new Point();
109 
110  final Iterable<Connection<K>> connections = view.getSelectedConnections();
111  for (final Iterable<GameObject<?, ?, ?>> connection : connections) {
112  for (final GameObject<?, ?, ?> object : connection) {
113  final BaseObject<?, ?, ?, ?> topObject = object.getTopContainer();
114  point.setLocation(topObject.getMapX(), topObject.getMapY());
115  mapGrid.select(point, SelectionMode.ADD);
116  }
117  }
118  }
119 
120 }
Abstract controller base class for map view controls.
Definition: Control.java:42
Iterable< Connection< K > > getSelectedConnections()
Return a list of all selected connections.
Definition: View.java:205
Graphical User Interface of Gridarta.
MapGrid getMapGrid()
Returns the MapGrid of this view.
void highlightSelectedEntries()
Sets the map selection to the currently selected entries.
Definition: Control.java:99
Stores GameObjects related to key values.
Definition: Connection.java:34
JPanel getView()
Returns the view for this controller.
Definition: Control.java:92
void unSelect()
Clears all selection and pre-selection flags from the grid.
Definition: MapGrid.java:263
abstract void doubleClick(@NotNull Connection< K > connection)
Called if an entry is double-clicked.
int getMapX()
Returns the X coordinate of this GameObject on its map.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
int getMapY()
Returns the Y coordinate of this GameObject on its map.
GameObjects are the objects based on Archetypes found on maps.
final View< K, G, A, R > view
The view of this controller.
Definition: Control.java:48
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Definition: MapGrid.java:45
Base classes for rendering maps.
MapView< G, A, R > getMapView()
Return the current map view.
Definition: View.java:144
void addListSelectionListener(@NotNull final ListSelectionListener listener)
Register a ListSelectionListener for the connection list.
Definition: View.java:152
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
Definition: MapGrid.java:408
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
ADD
All squares that are preselected get selected.
Control(@NotNull final View< K, G, A, R > view)
Creates a new instance.
Definition: Control.java:54
Modes that describe how squares get selected.