View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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() );
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(
36  							BorderFactory.createLineBorder( Color.RED ), 
37  							BorderFactory.createEmptyBorder( 2, 2, 2, 2 )));
38  		else
39  			getComponent().setBorder( 
40  					BorderFactory.createCompoundBorder(
41  							BorderFactory.createLineBorder( Color.GRAY ), 
42  							BorderFactory.createEmptyBorder( 2, 2, 2, 2 )));
43  	}
44  
45  	public void setValue(String value)
46  	{
47  		getComponent().setText( value );
48  	}
49  
50  	public String getValue()
51  	{
52  		return new String( getComponent().getPassword() );
53  	}
54  
55  	public void setWidth(int columns)
56  	{
57  		getComponent().setColumns( columns );
58  	}
59  }