001/**
002 * StringEditor.java
003 * jCOLIBRI2 framework. 
004 * @author Juan A. Recio-Garc�a.
005 * GAIA - Group for Artificial Intelligence Applications
006 * http://gaia.fdi.ucm.es
007 * 02/11/2007
008 */
009package es.ucm.fdi.gaia.jcolibri.method.gui.editors;
010
011import java.awt.Dimension;
012import java.util.Collection;
013
014import javax.swing.JComponent;
015import javax.swing.JTextField;
016
017/**
018 * Parameter Editor for String values.
019 * 
020 * @author Juan A. Recio-Garcia
021 * @version 1.0
022 * @see ParameterEditor
023 */
024public class StringEditor extends JTextField implements ParameterEditor {
025        private static final long serialVersionUID = 1L;
026        
027        /**
028         *  Creates a new instance
029         */
030        public StringEditor() {
031        this.setMaximumSize(new Dimension(50,20));
032        }
033
034        /**
035         * Returns a String object
036         */
037        public Object getEditorValue() {
038            if(getText().length()==0)
039                return null;
040                return getText();
041        }
042
043        /**
044         * Returns the JComponent
045         */
046        public JComponent getJComponent() {
047                return (JComponent) this;
048        }
049
050        /**
051         * Receives a String value
052         */
053        public void setEditorValue(Object defaultValue) {
054                if(defaultValue == null)
055                {
056                    this.setText("");
057                    return;
058                }
059                String value = defaultValue.toString();
060                this.setText(value);
061        }
062
063        /**
064         * Does nothing
065         */
066        public void setAllowedValues(Collection<Object> allowedValues)
067        {
068            // ANY 
069        }
070
071}