View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.x.impl.swing;
    14
    15  import java.awt.Color;
    16
    17  import javax.swing.BorderFactory;
    18  import javax.swing.JComponent;
    19  import javax.swing.JScrollPane;
    20  import javax.swing.JTextArea;
    21
    22  import com.eviware.x.form.XFormTextField;
    23
    24  public class JTextAreaFormField extends AbstractSwingXFormField<JComponent> implements XFormTextField
    25  {
    26  	private JScrollPane scrollPane;
    27
    28  	public JTextAreaFormField()
    29  	{
    30  		super( new JTextArea() );
    31
    32  		scrollPane = new JScrollPane( super.getComponent() );
    33  	}
    34
    35  	public void setRequired(boolean required, String message)
    36  	{
    37  		super.setRequired(required, message);
    38
    39  		if( required )
    40  			getComponent().setBorder(
    41  					BorderFactory.createCompoundBorder(
    42  							BorderFactory.createLineBorder( Color.RED ),
    43  							BorderFactory.createEmptyBorder( 2, 2, 2, 2 )));
    44  		else
    45  			getComponent().setBorder(
    46  					BorderFactory.createCompoundBorder(
    47  							BorderFactory.createLineBorder( Color.GRAY ),
    48  							BorderFactory.createEmptyBorder( 2, 2, 2, 2 )));
    49  	}
    50
    51  	public JTextArea getTextArea()
    52  	{
    53  		return (JTextArea) super.getComponent();
    54  	}
    55
    56  	public JComponent getComponent()
    57  	{
    58  		return scrollPane;
    59  	}
    60
    61  	public void setValue(String value)
    62  	{
    63  		getTextArea().setText( value );
    64  	}
    65
    66  	public String getValue()
    67  	{
    68  		return getTextArea().getText();
    69  	}
    70
    71  	public void setWidth(int columns)
    72  	{
    73  		getTextArea().setColumns( columns );
    74  	}
    75
    76  	@Override
    77  	public boolean isMultiRow()
    78  	{
    79  		return true;
    80  	}
    81  }