View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.soapui.support.components.JUndoableTextArea;
23  import com.eviware.x.form.XFormTextField;
24  
25  public class JTextAreaFormField extends AbstractSwingXFormField<JComponent> implements XFormTextField
26  {
27  	private JScrollPane scrollPane;
28  
29  	public JTextAreaFormField()
30  	{
31  		super( new JUndoableTextArea() );
32  
33  		scrollPane = new JScrollPane( super.getComponent() );
34  	}
35  
36  	public void setRequired( boolean required, String message )
37  	{
38  		super.setRequired( required, message );
39  
40  		if( required )
41  			getComponent().setBorder(
42  					BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Color.RED ), BorderFactory
43  							.createEmptyBorder( 2, 2, 2, 2 ) ) );
44  		else
45  			getComponent().setBorder(
46  					BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Color.GRAY ), BorderFactory
47  							.createEmptyBorder( 2, 2, 2, 2 ) ) );
48  	}
49  
50  	public JTextArea getTextArea()
51  	{
52  		return ( JTextArea )super.getComponent();
53  	}
54  
55  	public JComponent getComponent()
56  	{
57  		return scrollPane;
58  	}
59  
60  	public void setValue( String value )
61  	{
62  		getTextArea().setText( value );
63  	}
64  
65  	public String getValue()
66  	{
67  		return getTextArea().getText();
68  	}
69  
70  	public void setWidth( int columns )
71  	{
72  		getTextArea().setColumns( columns );
73  	}
74  
75  	@Override
76  	public boolean isMultiRow()
77  	{
78  		return true;
79  	}
80  }