KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: SSPercentFormatterFactory.java,v 1.3 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 package com.nqadmin.swingSet.formatting;
34
35 import javax.swing.text.NumberFormatter JavaDoc;
36 import java.text.NumberFormat JavaDoc;
37 import java.util.Locale JavaDoc;
38
39 import java.io.Serializable JavaDoc;
40 import java.text.ParseException JavaDoc;
41 import javax.swing.JFormattedTextField JavaDoc;
42
43
44 /**
45  *
46  * @author dags
47  */

48 public class SSPercentFormatterFactory extends javax.swing.text.DefaultFormatterFactory JavaDoc implements Serializable JavaDoc {
49
50     public SSPercentFormatterFactory() {
51         this.setDefaultFormatter(new NumberFormatter JavaDoc(NumberFormat.getPercentInstance()));
52         this.setNullFormatter(null);
53         this.setEditFormatter(new NumberFormatter JavaDoc(NumberFormat.getPercentInstance(Locale.US)));
54         this.setDisplayFormatter(new NumberFormatter JavaDoc(NumberFormat.getPercentInstance()));
55     }
56     
57     public SSPercentFormatterFactory(int precision, int decimals) {
58         NumberFormat JavaDoc nfd = NumberFormat.getPercentInstance(Locale.US);
59         nfd.setMaximumFractionDigits(decimals);
60         nfd.setMinimumFractionDigits(decimals);
61         
62         nfd.setMaximumIntegerDigits(precision);
63         nfd.setMinimumIntegerDigits(1);
64         
65         this.setDefaultFormatter(new NumberFormatter JavaDoc(NumberFormat.getPercentInstance()));
66         this.setNullFormatter(null);
67         this.setEditFormatter(new NumberFormatter JavaDoc(NumberFormat.getPercentInstance(Locale.US)));
68         this.setDisplayFormatter(new NumberFormatter JavaDoc(nfd));
69
70     }
71 }
72
Popular Tags