Gridarta Editor
CellRenderer.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.Component;
23 import java.util.Collection;
24 import java.util.TreeSet;
25 import javax.swing.DefaultListCellRenderer;
26 import javax.swing.JList;
28 import org.jetbrains.annotations.NotNull;
29 
36 public abstract class CellRenderer<K> extends DefaultListCellRenderer {
37 
41  private static final long serialVersionUID = 1L;
42 
46  private final StringBuilder sbForFormat = new StringBuilder();
47 
51  private final Collection<String> names = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
52 
56  protected CellRenderer() {
57  }
58 
59  @Override
60  public Component getListCellRendererComponent(final JList<?> list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
61  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
62 
63  //DefaultListCellRenderer does not use type parameters
64  @SuppressWarnings("unchecked") final Connection<K> connection = (Connection<K>) value;
65 
66  sbForFormat.setLength(0);
67  sbForFormat.append(formatKey(connection.getKey()));
68  sbForFormat.append(":");
69 
70  names.clear();
71  for (final BaseObject<?, ?, ?, ?> gameObject : connection) {
72  names.add(formatValue(gameObject));
73  }
74  for (final String name : names) {
75  sbForFormat.append(" ");
76  sbForFormat.append(name);
77  }
78  setText(sbForFormat.toString());
79 
80  return this;
81  }
82 
88  @NotNull
89  protected abstract String formatKey(@NotNull K key);
90 
96  @NotNull
97  protected abstract String formatValue(@NotNull BaseObject<?, ?, ?, ?> gameObject);
98 
99 }
net.sf.gridarta.gui.panel.connectionview.CellRenderer.names
final Collection< String > names
Used for sorting game object names.
Definition: CellRenderer.java:51
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.gui.panel.connectionview.CellRenderer.sbForFormat
final StringBuilder sbForFormat
The StringBuilder used to format entries.
Definition: CellRenderer.java:46
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net
list
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 list
Definition: Developer_README.txt:13
net.sf.gridarta.gui.panel.connectionview.CellRenderer.formatValue
abstract String formatValue(@NotNull BaseObject<?, ?, ?, ?> gameObject)
Returns a string representation for a value.
net.sf.gridarta.gui.panel.connectionview.CellRenderer.getListCellRendererComponent
Component getListCellRendererComponent(final JList<?> list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus)
Definition: CellRenderer.java:60
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.gui.panel.connectionview.Connection.getKey
K getKey()
Returns the key.
Definition: Connection.java:64
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.gui.panel.connectionview.CellRenderer.CellRenderer
CellRenderer()
Creates a new instance.
Definition: CellRenderer.java:56
net.sf.gridarta.gui.panel.connectionview.Connection
Stores GameObjects related to key values.
Definition: Connection.java:34
net.sf.gridarta.gui.panel.connectionview.CellRenderer.formatKey
abstract String formatKey(@NotNull K key)
Returns a string representation for a key.
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.CellRenderer.serialVersionUID
static final long serialVersionUID
Serial Version UID.
Definition: CellRenderer.java:41