1
2
3
4
5
6
7
8
9
10
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.text.Document;
19
20 import com.eviware.soapui.support.DocumentListenerAdapter;
21 import com.eviware.soapui.support.components.JUndoableTextField;
22 import com.eviware.x.form.XFormTextField;
23
24 public class JTextFieldFormField extends AbstractSwingXFormField<JUndoableTextField> implements XFormTextField
25 {
26 private boolean updating;
27 private String oldValue;
28
29 public JTextFieldFormField()
30 {
31 super( new JUndoableTextField() );
32
33 getComponent().getDocument().addDocumentListener( new DocumentListenerAdapter()
34 {
35
36 @Override
37 public void update( Document document )
38 {
39 String text = getComponent().getText();
40
41 if( !updating )
42 fireValueChanged( text, oldValue );
43
44 oldValue = text;
45 }
46 } );
47 }
48
49 public void setRequired( boolean required, String message )
50 {
51 super.setRequired( required, message );
52
53 if( required )
54 getComponent().setBorder(
55 BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Color.RED ), BorderFactory
56 .createEmptyBorder( 2, 2, 2, 2 ) ) );
57 else
58 getComponent().setBorder(
59 BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( Color.GRAY ), BorderFactory
60 .createEmptyBorder( 2, 2, 2, 2 ) ) );
61 }
62
63 public void setValue( String value )
64 {
65 updating = true;
66 oldValue = null;
67 getComponent().setText( value );
68 updating = false;
69 }
70
71 public String getValue()
72 {
73 return getComponent().getText();
74 }
75
76 public void setWidth( int columns )
77 {
78 getComponent().setColumns( columns );
79 }
80 }