001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2011 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.gui.dialog.plugin.parameter; 021 022import java.awt.event.ItemEvent; 023import java.awt.event.ItemListener; 024import javax.swing.JComboBox; 025import javax.swing.JComponent; 026import javax.swing.JPanel; 027import net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel; 028import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; 029import net.sf.gridarta.model.archetype.Archetype; 030import net.sf.gridarta.model.archetypeset.ArchetypeSet; 031import net.sf.gridarta.model.face.FaceObjectProviders; 032import net.sf.gridarta.model.gameobject.GameObject; 033import net.sf.gridarta.model.maparchobject.MapArchObject; 034import net.sf.gridarta.plugin.parameter.ArchetypeParameter; 035import org.jetbrains.annotations.NotNull; 036 037public class ArchParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements PluginParameterView<G, A, R> { 038 039 @NotNull 040 private final JComponent config = new JPanel(); 041 042 @NotNull 043 private final JComboBox value; 044 045 @NotNull 046 private final ArchetypeParameter<G, A, R> parameter; 047 048 /** 049 * Creates a new instance. 050 * @param faceObjectProviders the face object providers for looking up 051 * faces 052 */ 053 public ArchParameterView(@NotNull final ArchetypeParameter<G, A, R> param, @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) { 054 value = new ArchComboBox<G, A, R>(gameObjectAttributesModel, archetypeSet, objectChooser, faceObjectProviders); 055 parameter = param; 056 value.setSelectedItem(param.getValue()); 057 value.addItemListener(new ItemListener() { 058 059 @Override 060 public void itemStateChanged(final ItemEvent e) { 061 if (e.getStateChange() == ItemEvent.SELECTED) { 062 //JComboBox does not use type parameters 063 @SuppressWarnings("unchecked") 064 final Archetype<G, A, R> archetype = (Archetype<G, A, R>) value.getSelectedItem(); 065 parameter.setStringValue(archetype.getArchetypeName()); 066 } 067 } 068 }); 069 } 070 071 @NotNull 072 @Override 073 public JComponent getConfigComponent() { 074 return config; 075 } 076 077 @NotNull 078 @Override 079 public JComponent getValueComponent() { 080 return value; 081 } 082 083}