01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.JTextField;
19: import javax.swing.text.Document;
20:
21: import com.eviware.soapui.support.DocumentListenerAdapter;
22: import com.eviware.x.form.XFormTextField;
23:
24: public class JTextFieldFormField extends
25: AbstractSwingXFormField<JTextField> implements XFormTextField {
26: private boolean updating;
27: private String oldValue;
28:
29: public JTextFieldFormField() {
30: super (new JTextField());
31:
32: getComponent().getDocument().addDocumentListener(
33: new DocumentListenerAdapter() {
34:
35: @Override
36: public void update(Document document) {
37: String text = getComponent().getText();
38:
39: if (!updating)
40: fireValueChanged(text, oldValue);
41:
42: oldValue = text;
43: }
44: });
45: }
46:
47: public void setRequired(boolean required, String message) {
48: super .setRequired(required, message);
49:
50: if (required)
51: getComponent().setBorder(
52: BorderFactory.createCompoundBorder(BorderFactory
53: .createLineBorder(Color.RED), BorderFactory
54: .createEmptyBorder(2, 2, 2, 2)));
55: else
56: getComponent().setBorder(
57: BorderFactory
58: .createCompoundBorder(BorderFactory
59: .createLineBorder(Color.GRAY),
60: BorderFactory.createEmptyBorder(2,
61: 2, 2, 2)));
62: }
63:
64: public void setValue(String value) {
65: updating = true;
66: oldValue = null;
67: getComponent().setText(value);
68: updating = false;
69: }
70:
71: public String getValue() {
72: return getComponent().getText();
73: }
74:
75: public void setWidth(int columns) {
76: getComponent().setColumns(columns);
77: }
78: }
|