001/**
002 * TextEditor.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.JScrollPane;
015import javax.swing.JTextArea;
016import javax.swing.ScrollPaneConstants;
017
018import org.apache.logging.log4j.LogManager;
019
020import es.ucm.fdi.gaia.jcolibri.connector.TypeAdaptor;
021import es.ucm.fdi.gaia.jcolibri.datatypes.Text;
022
023/**
024 * Parameter Editor for Text values.
025 * 
026 * @author Juan A. Recio-Garcia
027 * @version 1.0
028 * @see ParameterEditor
029 */
030public class TextEditor extends JScrollPane implements ParameterEditor
031{
032    private static final long serialVersionUID = 1L;
033
034    private JTextArea tarea = new JTextArea();
035
036    /**
037     * Creates a new instance
038     */
039    public TextEditor()
040    {
041        super();
042        tarea = new JTextArea();
043        this.setViewportView(tarea);
044        this.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
045
046    }
047
048    /**
049     * Returns a Text object
050     */
051    public Object getEditorValue()
052    {
053        if (tarea.getText().length() == 0)
054            return null;
055
056        try
057        {
058            TypeAdaptor ta = (TypeAdaptor) Text.class.newInstance();
059            ta.fromString(tarea.getText());
060            return ta;
061        } catch (Exception e)
062        {
063            LogManager.getLogger(this.getClass()).error(e);
064
065        }
066        return null;
067    }
068
069    /**
070     * Returns the JComponent
071     */
072    public JComponent getJComponent()
073    {
074        return (JComponent) this;
075    }
076
077   /**
078    * Receives a Text value
079    */
080    public void setEditorValue(Object value)
081    {
082        if (value == null)
083        {
084            tarea.setText("");
085            return;
086        }
087
088        tarea.setText(value.toString());
089
090    }
091
092   /** 
093    * Does nothing
094    */
095    public void setAllowedValues(Collection<Object> allowedValues)
096    {
097        // ANY
098    }
099
100}