KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nqadmin > swingSet > formatting > SSNumericField


1 /* $Id: SSNumericField.java,v 1.5 2005/02/04 22:42:06 yoda2 Exp $
2  *
3  * Tab Spacing = 4
4  *
5  * Copyright (c) 2004-2005, The Pangburn Company, Prasanth R. Pasala and
6  * Diego Gil
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * Redistributions of source code must retain the above copyright notice, this
13  * list of conditions and the following disclaimer. Redistributions in binary
14  * form must reproduce the above copyright notice, this list of conditions and
15  * the following disclaimer in the documentation and/or other materials
16  * provided with the distribution. The names of its contributors may not be
17  * used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  */

33
34 package com.nqadmin.swingSet.formatting;
35
36 import javax.swing.JFormattedTextField.AbstractFormatterFactory;
37
38 import java.text.NumberFormat JavaDoc;
39 import javax.swing.text.NumberFormatter JavaDoc;
40 import java.util.Locale JavaDoc;
41 import javax.swing.JTextField JavaDoc;
42
43 /**
44  *
45  * @author dags
46  */

47
48 public class SSNumericField extends SSFormattedTextField {
49     
50     private int precision = 1;
51     private int decimals = 0;
52
53     /**
54      * Holds value of property minimumIntegerDigits.
55      */

56     private int minimumIntegerDigits;
57
58     /** Creates a new instance of PgNumericField */
59     public SSNumericField() {
60         this(new SSNumericFormatterFactory());
61     }
62     
63     public SSNumericField(int precision, int decimals) {
64         this(new SSNumericFormatterFactory(precision, decimals));
65     }
66             
67     
68     public SSNumericField(javax.swing.JFormattedTextField.AbstractFormatterFactory factory) {
69         super(factory);
70         this.setHorizontalAlignment(JTextField.RIGHT);
71     }
72     
73     public int getPrecision() {
74         return precision;
75     }
76     
77     public int getDecimals() {
78         return decimals;
79     }
80     
81     public void setPrecision(int precision) {
82         this.precision = precision;
83         this.setFormatterFactory(new SSNumericFormatterFactory(precision, decimals));
84     }
85     
86     public void setDecimals(int decimals) {
87         this.decimals = decimals;
88     }
89
90     /**
91      * Getter for property minimumIntegerDigits.
92      * @return Value of property minimumIntegerDigits.
93      */

94     public int getMinimumIntegerDigits() {
95
96         return this.minimumIntegerDigits;
97     }
98
99     /**
100      * Setter for property minimumIntegerDigits.
101      * @param minimumIntegerDigits New value of property minimumIntegerDigits.
102      */

103     public void setMinimumIntegerDigits(int minimumIntegerDigits) {
104
105         this.minimumIntegerDigits = minimumIntegerDigits;
106     }
107 }
108
109 /*
110  * $Log: SSNumericField.java,v $
111  * Revision 1.5 2005/02/04 22:42:06 yoda2
112  * Updated Copyright info.
113  *
114  * Revision 1.4 2005/01/18 23:38:01 dags
115  * Diego's name fix
116  *
117  * Revision 1.3 2004/12/13 20:50:16 dags
118  * Fix package name
119  *
120  * Revision 1.2 2004/12/13 18:46:13 prasanth
121  * Added License.
122  *
123  */

124
Popular Tags