Gridarta Editor
MapParameterView.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.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import javax.swing.JComboBox;
25 import javax.swing.JComponent;
26 import javax.swing.JPanel;
35 import org.jetbrains.annotations.NotNull;
36 
40 public class MapParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements PluginParameterView {
41 
45  @NotNull
46  private final JComboBox<MapControl<G, A, R>> value = new JComboBox<>();
47 
52  @NotNull
53  private final JComponent config = new JPanel();
54 
60  public MapParameterView(@NotNull final MapParameter<G, A, R> parameter, @NotNull final MapManager<G, A, R> mapManager) {
61  value.setModel(new MapParameterComboBoxModel<>(mapManager));
62  value.setRenderer(new MapParameterCellRenderer(mapManager));
63  value.addItemListener(new ItemListener() {
64 
65  @Override
66  public void itemStateChanged(final ItemEvent e) {
67  if (e.getStateChange() == ItemEvent.SELECTED) {
68  if (value.getSelectedIndex() == 0) {
69  parameter.setValueToCurrent();
70  } else {
71  final MapControl<?, ?, ?> mapControl = (MapControl<?, ?, ?>) value.getSelectedItem();
72  final String stringValue;
73  if (mapControl == null) {
74  stringValue = "";
75  } else {
76  final MapFile mapFile = mapControl.getMapModel().getMapFile();
77  stringValue = mapFile == null ? "" : mapFile.getMapPath().getPath();
78  }
79  parameter.setStringValue(stringValue);
80  }
81  }
82  }
83  });
84  value.setSelectedItem(parameter.getValueOrNull());
85  }
86 
87  @NotNull
88  @Override
89  public JComponent getValueComponent() {
90  return value;
91  }
92 
93  @NotNull
94  @Override
95  public JComponent getConfigComponent() {
96  return config;
97  }
98 
99 }
String getPath()
Returns the map path information.
A PluginParameter that holds a MapControl value.
A MapManager manages all opened maps.
Definition: MapManager.java:37
Graphical User Interface of Gridarta.
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
Interface for views that display plugin parameters.
MapModel< G, A, R > getMapModel()
Returns the map model.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
GameObjects are the objects based on Archetypes found on maps.
final JComboBox< MapControl< G, A, R > > value
The component for editing the parameter&#39;s value.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
MapFile getMapFile()
Returns the map file.
JComponent getValueComponent()
Returns a JComponent for editing the parameter value.
final JComponent config
The component for editing the parameter&#39;s configuration.
The location of a map file with a map directory.
Definition: MapFile.java:31
MapParameterView(@NotNull final MapParameter< G, A, R > parameter, @NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
JComponent getConfigComponent()
Returns a JComponent for editing the parameter configuration.