View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.BorderLayout;
16  import java.awt.Dimension;
17  
18  import javax.swing.JComponent;
19  import javax.swing.JPanel;
20  
21  import com.eviware.soapui.support.components.JFormComponent;
22  
23  public class JComponentFormField extends AbstractSwingXFormField<JPanel>
24  {
25  	private JComponent component;
26  
27  	public JComponentFormField( String label, String description )
28  	{
29  		super( new JPanel( new BorderLayout() ) );
30  		getComponent().setPreferredSize( new Dimension( 400, 200 ) );
31  	}
32  
33  	public void setValue( String value )
34  	{
35  		if( component instanceof JFormComponent )
36  			( ( JFormComponent )component ).setValue( value );
37  	}
38  
39  	public String getValue()
40  	{
41  		if( component instanceof JFormComponent )
42  			return ( ( JFormComponent )component ).getValue();
43  		else
44  			return null;
45  	}
46  
47  	@Override
48  	public void setProperty( String name, Object value )
49  	{
50  		if( name.equals( "component" ) )
51  		{
52  			getComponent().removeAll();
53  			if( value != null )
54  			{
55  				getComponent().add( ( JComponent )value, BorderLayout.CENTER );
56  			}
57  
58  			getComponent().revalidate();
59  			getComponent().getParent().repaint();
60  		}
61  		else if( name.equals( "preferredSize"))
62  		{
63  			getComponent().setPreferredSize( ( Dimension )value );
64  			getComponent().setMaximumSize( ( Dimension )value );
65  			getComponent().setMinimumSize( ( Dimension )value );
66  			getComponent().setSize( ( Dimension )value );
67  		}
68  		else
69  		{
70  			super.setProperty( name, value );
71  		}
72  	}
73  }