01: /*
02: * Project: Gulden Utilies
03: * Class: de.gulden.util.swing.InputVerifierNumber
04: * Version: snapshot-beautyj-1.1
05: *
06: * Date: 2004-09-29
07: *
08: * This is a snapshot version of the Gulden Utilities,
09: * it is not released as a seperate version.
10: *
11: * Note: Contains auto-generated Javadoc comments created by BeautyJ.
12: *
13: * This is licensed under the GNU Lesser General Public License (LGPL)
14: * and comes with NO WARRANTY.
15: *
16: * Author: Jens Gulden
17: * Email: amoda@jensgulden.de
18: */
19:
20: package de.gulden.util.swing;
21:
22: import java.util.*;
23: import javax.swing.InputVerifier;
24: import javax.swing.JComponent;
25:
26: /**
27: * Class InputVerifierNumber.
28: *
29: * @author Jens Gulden
30: * @version snapshot-beautyj-1.1
31: */
32: public class InputVerifierNumber extends InputVerifier {
33:
34: // ------------------------------------------------------------------------
35: // --- field ---
36: // ------------------------------------------------------------------------
37:
38: /**
39: * The type.
40: */
41: protected Class type;
42:
43: // ------------------------------------------------------------------------
44: // --- constructors ---
45: // ------------------------------------------------------------------------
46:
47: /**
48: * Creates a new instance of InputVerifierNumber.
49: */
50: public InputVerifierNumber() {
51: this (Integer.class);
52: }
53:
54: /**
55: * Creates a new instance of InputVerifierNumber.
56: */
57: public InputVerifierNumber(Class type) {
58: super ();
59: setType(type);
60: }
61:
62: // ------------------------------------------------------------------------
63: // --- methods ---
64: // ------------------------------------------------------------------------
65:
66: public boolean verify(JComponent input) {
67: // can only verify JTextComponent
68: javax.swing.text.JTextComponent textComponent = (javax.swing.text.JTextComponent) input;
69: Number number = (Number) de.gulden.util.Toolbox.invokeValueOf(
70: type, textComponent.getText());
71: return (number != null);
72: }
73:
74: /**
75: * Returns the type.
76: */
77: public Class getType() {
78: return type;
79: }
80:
81: /**
82: * Sets the type.
83: */
84: public void setType(Class _type) {
85: type = _type;
86: }
87:
88: } // end InputVerifierNumber
|