Gridarta Editor
ArchComboBoxCellRenderer.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.dialog.plugin.parameter.archetype;
21 
22 import java.awt.Component;
23 import javax.swing.DefaultListCellRenderer;
24 import javax.swing.JList;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
30 public class ArchComboBoxCellRenderer extends DefaultListCellRenderer {
31 
32  private static final long serialVersionUID = 1L;
33 
37  @NotNull
39 
46  this.faceObjectProviders = faceObjectProviders;
47  }
48 
49  /* This is the only method defined by ListCellRenderer. We just
50  * reconfigure the label each time we're called.
51  */
52 
53  @NotNull
54  @Override
55  public Component getListCellRendererComponent(@NotNull final JList<?> list, @Nullable final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
56  /* The DefaultListCellRenderer class will take care of
57  * the JLabels text property, it's foreground and background
58  *colors, and so on.
59  */
60  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
61 
62  /* We additionally set the JLabels icon property here.
63  */
64  final BaseObject<?, ?, ?, ?> archetype = (BaseObject<?, ?, ?, ?>) value;
65  if (archetype == null) {
66  setText("");
67  setIcon(null);
68  return this;
69  }
70  setText(archetype.getArchetype().getArchetypeName());
71 
72  setIcon(faceObjectProviders.getFace(archetype));
73 
74  return this;
75  }
76 
77 }
net.sf.gridarta.gui.dialog.plugin.parameter.archetype.ArchComboBoxCellRenderer
Definition: ArchComboBoxCellRenderer.java:30
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.model.baseobject.BaseObject.getArchetype
R getArchetype()
Returns the Archetype this GameObject is based on.
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.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)
Returns the face of a BaseObject as an ImageIcon.
Definition: FaceObjectProviders.java:251
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.gui.dialog.plugin.parameter.archetype.ArchComboBoxCellRenderer.faceObjectProviders
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
Definition: ArchComboBoxCellRenderer.java:38
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.gui.dialog.plugin.parameter.archetype.ArchComboBoxCellRenderer.serialVersionUID
static final long serialVersionUID
Definition: ArchComboBoxCellRenderer.java:32
net.sf.gridarta.gui.dialog.plugin.parameter.archetype.ArchComboBoxCellRenderer.ArchComboBoxCellRenderer
ArchComboBoxCellRenderer(@NotNull final FaceObjectProviders faceObjectProviders)
Creates a new instance.
Definition: ArchComboBoxCellRenderer.java:45
net.sf.gridarta.gui.dialog.plugin.parameter.archetype.ArchComboBoxCellRenderer.getListCellRendererComponent
Component getListCellRendererComponent(@NotNull final JList<?> list, @Nullable final Object value, final int index, final boolean isSelected, final boolean cellHasFocus)
Definition: ArchComboBoxCellRenderer.java:55