KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > util > swing > InputVerifierNumber


1 /*
2  * Project: Gulden Utilies
3  * Class: de.gulden.util.swing.InputVerifierNumber
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the Gulden Utilities,
9  * 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 JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25
26 /**
27  * Class InputVerifierNumber.
28  *
29  * @author Jens Gulden
30  * @version snapshot-beautyj-1.1
31  */

32 public class InputVerifierNumber extends InputVerifier JavaDoc {
33
34     // ------------------------------------------------------------------------
35
// --- field ---
36
// ------------------------------------------------------------------------
37

38     /**
39      * The type.
40      */

41     protected Class JavaDoc type;
42
43
44     // ------------------------------------------------------------------------
45
// --- constructors ---
46
// ------------------------------------------------------------------------
47

48     /**
49      * Creates a new instance of InputVerifierNumber.
50      */

51     public InputVerifierNumber() {
52         this(Integer JavaDoc.class);
53     }
54
55     /**
56      * Creates a new instance of InputVerifierNumber.
57      */

58     public InputVerifierNumber(Class JavaDoc type) {
59         super();
60         setType(type);
61     }
62
63
64     // ------------------------------------------------------------------------
65
// --- methods ---
66
// ------------------------------------------------------------------------
67

68     public boolean verify(JComponent JavaDoc input) {
69         // can only verify JTextComponent
70
javax.swing.text.JTextComponent JavaDoc textComponent=(javax.swing.text.JTextComponent JavaDoc)input;
71         Number JavaDoc number=(Number JavaDoc)de.gulden.util.Toolbox.invokeValueOf(type,textComponent.getText());
72         return (number!=null);
73     }
74
75     /**
76      * Returns the type.
77      */

78     public Class JavaDoc getType() {
79         return type;
80     }
81
82     /**
83      * Sets the type.
84      */

85     public void setType(Class JavaDoc _type) {
86         type = _type;
87     }
88
89 } // end InputVerifierNumber
90
Popular Tags