001/**
002 * DoubleEditor.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.util.Collection;
012
013import javax.swing.JComponent;
014import javax.swing.JFormattedTextField;
015
016/**
017 * Parameter Editor for Double values.
018 * 
019 * @author Juan A. Recio-Garcia
020 * @version 1.0
021 * @see ParameterEditor
022 */
023public class DoubleEditor extends JFormattedTextField implements
024                ParameterEditor {
025        private static final long serialVersionUID = 1L;
026
027        
028        /**
029         *  Creates a new instance
030         */
031        public DoubleEditor() {
032                setValue(new Double(0));
033        }
034
035        /**
036         * Returns a Double object
037         */
038        public Object getEditorValue() {
039            try{
040                return new Double(getText());
041            }catch(Exception e){}
042            return null;
043        }
044
045        /**
046         * Returns the JComponent
047         */
048        public JComponent getJComponent() {
049                return (JComponent) this;
050        }
051
052        /**
053         * Receives a Double value
054         */
055        public void setEditorValue(Object defaultValue) {
056                if(defaultValue==null)
057                {
058                    this.setText("");
059                    return;
060                } 
061                if (!(defaultValue instanceof Double))
062                        return;
063                Double value = (Double) defaultValue;
064                this.setValue(value);
065        }
066
067        /**
068         * Does nothing
069         */
070        public void setAllowedValues(Collection<Object> allowedValues)
071        {
072            //any
073        }
074}