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.selectedsquare;
21 
22 import java.awt.Component;
23 import javax.swing.BorderFactory;
24 import javax.swing.DefaultListCellRenderer;
25 import javax.swing.Icon;
26 import javax.swing.JList;
31 import org.jetbrains.annotations.NotNull;
32 
37 public class CellRenderer<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DefaultListCellRenderer {
38 
42  private static final int INDENT_PIXELS = 16;
43 
47  private static final long serialVersionUID = 1L;
48 
52  @NotNull
54 
58  @NotNull
59  private final Icon unknownSquareIcon;
60 
67  public CellRenderer(@NotNull final FaceObjectProviders faceObjectProviders, @NotNull final Icon unknownSquareIcon) {
68  this.faceObjectProviders = faceObjectProviders;
69  this.unknownSquareIcon = unknownSquareIcon;
70  }
71 
72  @Override
73  public Component getListCellRendererComponent(final JList<?> list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
74  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
75 
76  //DefaultListCellRenderer does not use type parameters
77  @SuppressWarnings("unchecked") GameObject<G, A, R> arch = (GameObject<G, A, R>) value;
78 
79  // arch == null should not happen, but it *can* happen when the active
80  // window gets changed by user and java is still blitting here
81  if (arch == null) {
82  setIcon(unknownSquareIcon);
83  setText("?");
84  } else {
85  arch = arch.getHead();
87  setText(arch.getBestName());
88  }
89 
90  int indent = 0;
91  if (arch != null) {
92  while (true) {
93  final GameObject<G, A, R> env = arch.getContainerGameObject();
94  if (env == null) {
95  break;
96  }
97  arch = env;
98  indent++;
99  }
100  }
101  if (indent > 0) {
102  setBorder(BorderFactory.createEmptyBorder(0, indent * INDENT_PIXELS, 0, 0)); // indentation
103  }
104 
105  return this;
106  }
107 
108 }
net.sf.gridarta.model.face.FaceObjectProviders.getFace
public< G extends GameObject< G, A, R >, A extends MapArchObject< A >, R extends Archetype< G, A, R > > ImageIcon getFace(@NotNull final BaseObject< G, A, R, ?> baseObject)
Definition: FaceObjectProviders.java:251
net.sf.gridarta.gui.panel.selectedsquare.CellRenderer.unknownSquareIcon
final Icon unknownSquareIcon
Definition: CellRenderer.java:59
net.sf.gridarta
net.sf.gridarta.model.face.FaceObjectProviders
Definition: FaceObjectProviders.java:46
net.sf.gridarta.gui.panel.selectedsquare.CellRenderer.serialVersionUID
static final long serialVersionUID
Definition: CellRenderer.java:47
net.sf.gridarta.model.maparchobject.MapArchObject
Definition: MapArchObject.java:40
net.sf
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.gui.panel.selectedsquare.CellRenderer
Definition: CellRenderer.java:37
net.sf.gridarta.model.gameobject.GameObject
Definition: GameObject.java:36
net.sf.gridarta.model.gameobject
Definition: AbstractGameObject.java:20
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.selectedsquare.CellRenderer.faceObjectProviders
final FaceObjectProviders faceObjectProviders
Definition: CellRenderer.java:53
net.sf.gridarta.gui.panel.selectedsquare.CellRenderer.INDENT_PIXELS
static final int INDENT_PIXELS
Definition: CellRenderer.java:42
net.sf.gridarta.model
net.sf.gridarta.model.face
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.panel.selectedsquare.CellRenderer.getListCellRendererComponent
Component getListCellRendererComponent(final JList<?> list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus)
Definition: CellRenderer.java:73
net.sf.gridarta.model.archetype.Archetype
Definition: Archetype.java:41
net.sf.gridarta.gui.panel.selectedsquare.CellRenderer.CellRenderer
CellRenderer(@NotNull final FaceObjectProviders faceObjectProviders, @NotNull final Icon unknownSquareIcon)
Definition: CellRenderer.java:67
arch
arch
Definition: ArchetypeTypeSetParserTest-ignoreDefinedAttribute1-result.txt:5