Gridarta Editor
ArchetypeParameterView.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.archetype;
21 
22 import java.awt.Dimension;
23 import java.awt.event.ItemEvent;
24 import java.awt.event.ItemListener;
25 import javax.swing.JComboBox;
26 import javax.swing.JComponent;
27 import javax.swing.JPanel;
37 import org.jetbrains.annotations.NotNull;
38 
42 public class ArchetypeParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements PluginParameterView {
43 
47  @NotNull
48  private final JComboBox<Archetype<G, A, R>> value = new JComboBox<>();
49 
54  @NotNull
55  private final JComponent config = new JPanel();
56 
69  public ArchetypeParameterView(@NotNull final ArchetypeParameter<G, A, R> parameter, @NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders) {
70  final ArchComboBoxModel<G, A, R> archComboBoxModel = new ArchComboBoxModel<>(archetypeSet);
71  final ArchComboBoxEditor<G, A, R> archComboBoxEditor = new ArchComboBoxEditor<>(value, archComboBoxModel, objectChooser, gameObjectAttributesModel, faceObjectProviders);
72  value.setMaximumRowCount(4);
73  value.setRenderer(new ArchComboBoxCellRenderer(faceObjectProviders));
74  value.setModel(archComboBoxModel);
75  value.setEditable(true);
76  value.setEditor(archComboBoxEditor);
77  value.setPreferredSize(new Dimension(value.getPreferredSize().width, archComboBoxEditor.getEditorComponent().getPreferredSize().height));
78  value.setSelectedItem(parameter.getValueOrNull());
79  value.addItemListener(new ItemListener() {
80 
81  @Override
82  public void itemStateChanged(final ItemEvent e) {
83  if (e.getStateChange() == ItemEvent.SELECTED) {
84  final Archetype<?, ?, ?> archetype = (Archetype<?, ?, ?>) value.getSelectedItem();
85  parameter.setStringValue(archetype.getArchetypeName());
86  }
87  }
88  });
89  }
90 
91  @NotNull
92  @Override
93  public JComponent getConfigComponent() {
94  return config;
95  }
96 
97  @NotNull
98  @Override
99  public JComponent getValueComponent() {
100  return value;
101  }
102 
103 }
Graphical User Interface of Gridarta.
JComponent getConfigComponent()
Returns a JComponent for editing the parameter configuration.
String getArchetypeName()
Returns the name of this archetype.
Interface for views that display plugin parameters.
final JComboBox< Archetype< G, A, R > > value
The component for editing the parameter&#39;s value.
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.
A PluginParameter that holds an Archetype value.
ArchetypeParameterView(@NotNull final ArchetypeParameter< G, A, R > parameter, @NotNull final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel, @NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final ObjectChooser< G, A, R > objectChooser, @NotNull final FaceObjectProviders faceObjectProviders)
Creates a new instance.
final JComponent config
The component for editing the parameter&#39;s configuration.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
Interface that captures similarities between different ArchetypeSet implementations.
Common base interface for ObjectChoosers.
JComponent getValueComponent()
Returns a JComponent for editing the parameter value.