/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2007, by :
* Corporate:
* EADS Astrium
* Individual:
* Claude Cazenave
*
* $Id: ComboBox.java,v 1.2 2008/10/15 17:22:34 cazenave Exp $
*
* Changes
* -------
* 24 janv. 08 : Initial public release
*
*/
package jsynoptic.plugins.java3d.panels;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.media.j3d.SceneGraphObject;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import jsynoptic.plugins.java3d.edit.EnumEdit;
import jsynoptic.plugins.java3d.edit.PropertyEdit;
/**
*
*/
public class ComboBox <T extends SceneGraphObject> extends JComboBox
implements PropertyEdit.UndoRedoListener,
PropertiesPanel.Editor<T,Integer>, ItemListener{
EnumEdit<T> _editor;
public ComboBox(){
super();
addItemListener(this);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
EnumEdit.Entry v = (EnumEdit.Entry) e.getItem();
_editor.setNewValue(v.value);
}
}
@Override
public void edit(PropertyEdit<T,Integer> editor){
if(_editor!=null){
_editor.removeListener(this);
}
_editor= (EnumEdit<T>) editor;
if(_editor!=null){
setModel(new DefaultComboBoxModel(_editor.getEntries()));
_editor.addListener(this);
setSelectedItem(_editor.getEntry());
}
}
@Override
public void undoRedoPerfomed(boolean isUndo) {
setSelectedItem(_editor.getEntry());
}
}