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-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.Point;
23 import java.awt.event.MouseAdapter;
24 import java.awt.event.MouseEvent;
25 import java.util.Iterator;
26 import javax.swing.JPanel;
34 import org.jetbrains.annotations.NotNull;
35 
40 public abstract class Control<K, G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
41 
45  @NotNull
46  private final View<K, G, A, R> view;
47 
52  protected Control(@NotNull final View<K, G, A, R> view) {
53  this.view = view;
54 
56 
57  //noinspection RefusedBequest
58  view.addListMouseListener(new MouseAdapter() {
59 
60  @Override
61  public void mousePressed(final MouseEvent e) {
63  if (e.getClickCount() == 2) {
64  final Iterator<Connection<K>> it = view.getSelectedConnections().iterator();
65  if (it.hasNext()) {
66  doubleClick(it.next());
67  }
68  }
69  }
70  });
71  }
72 
77  protected abstract void doubleClick(@NotNull Connection<K> connection);
78 
83  @NotNull
84  public JPanel getView() {
85  return view;
86  }
87 
91  private void highlightSelectedEntries() {
92  final MapView<G, A, R> mapView = view.getMapView();
93  if (mapView == null) {
94  return;
95  }
96 
97  final MapGrid mapGrid = mapView.getMapGrid();
98  mapGrid.unSelect();
99 
100  final Point point = new Point();
101 
102  final Iterable<Connection<K>> connections = view.getSelectedConnections();
103  for (final Iterable<GameObject<?, ?, ?>> connection : connections) {
104  for (final GameObject<?, ?, ?> object : connection) {
105  final BaseObject<?, ?, ?, ?> topObject = object.getTopContainer();
106  point.setLocation(topObject.getMapX(), topObject.getMapY());
107  mapGrid.select(point, SelectionMode.ADD);
108  }
109  }
110  }
111 
112 }
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.map.mapview.MapView.getMapGrid
MapGrid getMapGrid()
Returns the MapGrid of this view.
net.sf.gridarta.gui.panel.connectionview.View< K, G, A, R >
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
Base package of all Gridarta classes.
net.sf.gridarta.model.baseobject.BaseObject.getMapX
int getMapX()
Returns the X coordinate of this GameObject on its map.
net.sf
net.sf.gridarta.gui.panel.connectionview.Control.doubleClick
abstract void doubleClick(@NotNull Connection< K > connection)
Called if an entry is double-clicked.
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.panel.connectionview.Control.Control
Control(@NotNull final View< K, G, A, R > view)
Creates a new instance.
Definition: Control.java:52
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
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.Control.highlightSelectedEntries
void highlightSelectedEntries()
Sets the map selection to the currently selected entries.
Definition: Control.java:91
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.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.model.mapgrid.SelectionMode
Modes that describe how squares get selected.
Definition: SelectionMode.java:26
net.sf.gridarta.model.mapgrid.MapGrid.select
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
Definition: MapGrid.java:408
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.mapgrid.MapGrid
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Definition: MapGrid.java:46
net.sf.gridarta.model.mapgrid.SelectionMode.ADD
ADD
All squares that are preselected get selected.
Definition: SelectionMode.java:31
net.sf.gridarta.model.mapgrid
Definition: MapGrid.java:20
net.sf.gridarta.model.baseobject.BaseObject.getMapY
int getMapY()
Returns the Y coordinate of this GameObject on its map.
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.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.Control
Abstract controller base class for map view controls.
Definition: Control.java:40
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.gui.panel.connectionview.Control.getView
JPanel getView()
Returns the view for this controller.
Definition: Control.java:84
net.sf.gridarta.gui.panel.connectionview.Connection
Stores GameObjects related to key values.
Definition: Connection.java:34
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
net.sf.gridarta.var.crossfire.model.gameobject.GameObject<?, ?, ?>
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.mapgrid.MapGrid.unSelect
void unSelect()
Clears all selection and pre-selection flags from the grid.
Definition: MapGrid.java:263
it
This document describes some hints and requirements for general development on the CrossfireEditor If you plan to make changes to the editor code or setup please read the following and keep it in derived from a basic editor application called Gridder by Pasi Ker�nen so please communicate with best through the cf devel mailing before considering any fundamental changes About code DO NOT USE TABS No matter what Java development platform you are please configure insert indent Tabs are displayed totally different in every editor and there are millions of different editors out there The insertion of tabs in the source code is messing up the syntax formatting in a way that is UNREPAIRABLE Apart from please keep code indentation accurate This is not just good it helps to keep code readable and in that way dramatically decreases the chance for overlooked bugs Everyone is welcomed to correct indentation errors wherever they are spotted Before you start to do this please double check that your editor is really configured to insert spaces Line feeds may be checked in either in windows or in unix linux style All reasonable text and java editors can deal with both linefeed formats Converting line feeds is but in this case please make sure that only linefeed characters are changed and nothing else is affected Due to the platform independent nature of the editor has the potential to run on almost any given operating system the build process differs greatly between systems as well as java environments In the several people have attempted to add build scripts along with structural changes to optimize the setup on one particular system environment which has led to conflict Please do *not *attempt to change the structure or any directories for the mere purpose of improving a build process or performance in a java environment Build scripts may be placed in the root it would be especially fine if it is just one or two files but the latter is not required Please excuse me for placing such restriction I and many users of the editor greatly appreciate build scripts We just had some real troubles over this issue in the past and I don t want to have them repeated the editor has relatively high performance requirements I ve spent a lot of extra work to keep everything as fast and memory efficient as possible when you add new data fields or calculations in the archetype please make sure they are as efficient as possible and worth both the time and space they consume Now don t be afraid too much No development would be possible without adding calculations and data at all Just bear in mind unlike for many other open source performance does make a difference for the CrossfireEditor The for as many systems as possible In case you are unexperienced with java and note that the graphics look different on every and with every font They also have different sizes proportions and behave different A seemingly trivial and effectless change can wreck havoc for the same GUI run on another system please don t be totally afraid of it
Definition: Developer_README.txt:76
net.sf.gridarta.gui.panel.connectionview.Control.view
final View< K, G, A, R > view
The view of this controller.
Definition: Control.java:46