01: package com.xoetrope.swing;
02:
03: import java.awt.Color;
04: import javax.swing.InputVerifier;
05: import javax.swing.JComponent;
06: import javax.swing.JTextField;
07:
08: /**
09: *
10: * @author luano
11: */
12: public class AddressInputVerifier extends InputVerifier {
13: private Color bkColor;
14: private Color errorColor = new Color(255, 220, 220);
15: private boolean allowExtension;
16:
17: /**
18: * Create a new verifier
19: * @param allowExt true if the input allows an entension
20: */
21: public AddressInputVerifier() {
22: }
23:
24: public boolean verify(JComponent input) {
25: if (bkColor == null)
26: bkColor = input.getBackground();
27:
28: JTextField tf = (JTextField) input;
29: String fileName = tf.getText().trim();
30: return showError(tf, (fileName.length() > 2));
31: }
32:
33: private boolean showError(JComponent tf, boolean state) {
34: tf.setBackground(state ? bkColor : errorColor);
35: if (state)
36: bkColor = null;
37:
38: return state;
39: }
40: }
|