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.JPasswordField;
19  
20  import com.eviware.x.form.XFormTextField;
21  
22  public class JPasswordFieldFormField extends AbstractSwingXFormField<JPasswordField> implements XFormTextField
23  {
24  	public JPasswordFieldFormField()
25  	{
26  		super( new JPasswordField( 15 ) );
27  	}
28  
29  	public void setRequired( boolean required, String message )
30  	{
31  		super.setRequired( required, message );
32  
33  		if( required )
34  			getComponent().setBorder(
35  					BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Color.RED ), BorderFactory
36  							.createEmptyBorder( 2, 2, 2, 2 ) ) );
37  		else
38  			getComponent().setBorder(
39  					BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Color.GRAY ), BorderFactory
40  							.createEmptyBorder( 2, 2, 2, 2 ) ) );
41  	}
42  
43  	public void setValue( String value )
44  	{
45  		getComponent().setText( value );
46  	}
47  
48  	public String getValue()
49  	{
50  		return new String( getComponent().getPassword() );
51  	}
52  
53  	public void setWidth( int columns )
54  	{
55  		getComponent().setColumns( columns );
56  	}
57  }