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 javax.swing.JTextField;
023import javax.swing.event.DocumentEvent;
024import javax.swing.event.DocumentListener;
025import net.sf.gridarta.model.archetype.Archetype;
026import net.sf.gridarta.model.gameobject.GameObject;
027import net.sf.gridarta.model.maparchobject.MapArchObject;
028import net.sf.gridarta.plugin.parameter.PluginParameter;
029
030public class ParameterNameEditor<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JTextField {
031
032    private static final long serialVersionUID = 1L;
033
034    private final PluginParameter<G, A, R, ?> parameter;
035
036    private final DocumentListener documentListener = new DocumentListener() {
037
038        @Override
039        public void insertUpdate(final DocumentEvent e) {
040            change();
041        }
042
043        @Override
044        public void removeUpdate(final DocumentEvent e) {
045            change();
046        }
047
048        @Override
049        public void changedUpdate(final DocumentEvent e) {
050            change();
051        }
052
053    };
054
055    public ParameterNameEditor(final PluginParameter<G, A, R, ?> parameter) {
056        this.parameter = parameter;
057        setText(parameter.getName());
058        getDocument().addDocumentListener(documentListener);
059    }
060
061    private void change() {
062        parameter.setName(getText());
063    }
064
065}