Gridarta Editor
MapListCellRenderer.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.dialog.gomap;
21 
22 import java.awt.Component;
23 import javax.swing.DefaultListCellRenderer;
24 import javax.swing.JList;
27 import org.jetbrains.annotations.NotNull;
28 
34 public class MapListCellRenderer extends DefaultListCellRenderer {
35 
39  private static final long serialVersionUID = 1L;
40 
44  @NotNull
45  private final MapsIndex mapsIndex;
46 
51  public MapListCellRenderer(@NotNull final MapsIndex mapsIndex) {
52  this.mapsIndex = mapsIndex;
53  }
54 
55  @NotNull
56  @Override
57  public Component getListCellRendererComponent(@NotNull final JList<?> list, @NotNull final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
58  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
59  final MapFile file = (MapFile) value;
60  final String name = mapsIndex.getName(file);
61  setText((name == null ? "?" : name) + " (" + file.getMapPath() + ")");
62  setToolTipText(value.toString());
63  return this;
64  }
65 
66 }
Indexes maps by map name.
Definition: MapsIndex.java:29
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
Base package of all Gridarta classes.
final MapsIndex mapsIndex
The displayed MapsIndex.
A DefaultListCellRenderer that renders values of a MapsIndex.
MapListCellRenderer(@NotNull final MapsIndex mapsIndex)
Creates a new instance.
static final long serialVersionUID
The serial version UID.
Component getListCellRendererComponent(@NotNull final JList<?> list, @NotNull final Object value, final int index, final boolean isSelected, final boolean cellHasFocus)
String getName(@NotNull final V value)
Returns the name associated with a value.
The location of a map file with a map directory.
Definition: MapFile.java:31