Gridarta Editor
MapParameterCellRenderer.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.plugin.parameter.map;
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 MapParameterCellRenderer extends DefaultListCellRenderer {
31 
35  private static final long serialVersionUID = 1L;
36 
40  @NotNull
42 
47  public MapParameterCellRenderer(@NotNull final MapManager<?, ?, ?> mapManager) {
48  this.mapManager = mapManager;
49  }
50 
51  @Override
52  public Component getListCellRendererComponent(@NotNull final JList<?> list, @Nullable final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
53  final String newVal;
54  if (value instanceof MapControl) {
55  newVal = ((MapControl<?, ?, ?>) value).getMapModel().getMapArchObject().getMapName();
56  } else {
57  final MapControl<?, ?, ?> mapControl = mapManager.getCurrentMap();
58  final String mapName = mapControl != null ? mapControl.getMapModel().getMapArchObject().getMapName() : "";
59  newVal = "Current - " + mapName;
60  }
61  return super.getListCellRendererComponent(list, newVal, index, isSelected, cellHasFocus);
62  }
63 
64 }
A MapManager manages all opened maps.
Definition: MapManager.java:37
MapModel< G, A, R > getMapModel()
Returns the map model.
MapParameterCellRenderer(@NotNull final MapManager<?, ?, ?> mapManager)
Create a new instance.
Base package of all Gridarta classes.
MapControl< G, A, R > getCurrentMap()
Returns the current map.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Component getListCellRendererComponent(@NotNull final JList<?> list, @Nullable final Object value, final int index, final boolean isSelected, final boolean cellHasFocus)
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35