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