Gridarta Editor
ConnectionView.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.util.Comparator;
30 import org.jetbrains.annotations.NotNull;
31 
38 public class ConnectionView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends View<Integer, G, A, R> {
39 
43  private static final long serialVersionUID = 1L;
44 
51  public ConnectionView(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final DelayedMapModelListenerManager<G, A, R> delayedMapModelListenerManager) {
52  super(new Comparator<Integer>() {
53 
54  @Override
55  public int compare(@NotNull final Integer o1, @NotNull final Integer o2) {
56  if (o1 < o2) {
57  return -1;
58  }
59  if (o1 > o2) {
60  return +1;
61  }
62  return 0;
63  }
64  }, new ConnectionCellRenderer(), mapViewManager, delayedMapModelListenerManager);
65  }
66 
67  @Override
68  protected void scanGameObjectForConnections(@NotNull final G gameObject) {
69  scanGameObject(gameObject);
70  for (final GameObject<G, A, R> invObject : gameObject.recursive()) {
71  scanGameObject(invObject);
72  }
73  }
74 
79  private void scanGameObject(@NotNull final GameObject<G, A, R> gameObject) {
80  final int[] values = Connections.parseConnections(gameObject);
81  if (values == null) {
82  return;
83  }
84 
85  for (final int value : values) {
86  addConnection(value, gameObject);
87  }
88  }
89 
94  private static class ConnectionCellRenderer extends CellRenderer<Integer> {
95 
99  private static final long serialVersionUID = 1L;
100 
101  @NotNull
102  @Override
103  protected String formatKey(@NotNull final Integer key) {
104  return key.toString();
105  }
106 
107  @NotNull
108  @Override
109  protected String formatValue(@NotNull final BaseObject<?, ?, ?, ?> gameObject) {
110  return gameObject.getBestName();
111  }
112 
113  }
114 
115 }
void scanGameObjectForConnections(@NotNull final G gameObject)
static int [] parseConnections(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
Extract the "connected" value(s) from a given game object.
Graphical User Interface of Gridarta.
void scanGameObject(@NotNull final GameObject< G, A, R > gameObject)
Add the given game object as a connection if it has a "connected" field.
Abstract base class for a panel that holds information about connections of the selected key on the s...
Definition: View.java:58
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
static final long serialVersionUID
The serial version UID.
A DefaultListCellRenderer for rendering Connection objects in a list.
GameObjects are the objects based on Archetypes found on maps.
void addConnection( @NotNull final K key, @NotNull final GameObject< G, A, R > gameObject)
Definition: View.java:193
Base classes for rendering maps.
String formatValue(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
Iterable< G > recursive()
Return an object that is a recursive representation.
Utility class to parse "connected" fields in game objects.
ConnectionView(@NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final DelayedMapModelListenerManager< G, A, R > delayedMapModelListenerManager)
Create a ConnectionView.
The view of the connection view control.
Provides support for delayed notification of MapModel changes.