KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > xml > factory > objects > DecimalFormatObjectDescription


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------------------------
28  * DecimalFormatObjectDescription.java
29  * -----------------------------------
30  * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: DecimalFormatObjectDescription.java,v 1.5 2005/11/14 11:01:44 mungady Exp $
36  *
37  * Changes (from 19-Feb-2003)
38  * -------------------------
39  * 19-Feb-2003 : Added standard header and Javadocs (DG);
40  * 29-Apr-2003 : Distilled from the JFreeReport project and moved into JCommon
41  *
42  */

43
44 package org.jfree.xml.factory.objects;
45
46 import java.text.DecimalFormat JavaDoc;
47 import java.text.DecimalFormatSymbols JavaDoc;
48
49 /**
50  * An object-description for a <code>DecimalFormat</code> object.
51  *
52  * @author Thomas Morgner
53  */

54 public class DecimalFormatObjectDescription extends BeanObjectDescription {
55
56     /**
57      * Creates a new object description.
58      */

59     public DecimalFormatObjectDescription() {
60         this(DecimalFormat JavaDoc.class);
61     }
62
63     /**
64      * Creates a new object description.
65      *
66      * @param className the class.
67      */

68     public DecimalFormatObjectDescription(final Class JavaDoc className) {
69         super(className, false);
70         setParameterDefinition("localizedPattern", String JavaDoc.class);
71         setParameterDefinition("pattern", String JavaDoc.class);
72         setParameterDefinition("decimalFormatSymbols", DecimalFormatSymbols JavaDoc.class);
73         setParameterDefinition("decimalSeparatorAlwaysShown", Boolean.TYPE);
74         setParameterDefinition("groupingSize", Integer.TYPE);
75         setParameterDefinition("groupingUsed", Boolean.TYPE);
76         setParameterDefinition("maximumFractionDigits", Integer.TYPE);
77         setParameterDefinition("maximumIntegerDigits", Integer.TYPE);
78         setParameterDefinition("minimumFractionDigits", Integer.TYPE);
79         setParameterDefinition("minimumIntegerDigits", Integer.TYPE);
80         setParameterDefinition("multiplier", Integer.TYPE);
81         setParameterDefinition("negativePrefix", String JavaDoc.class);
82         setParameterDefinition("negativeSuffix", String JavaDoc.class);
83 // setParameterDefinition("parseBigDecimal", Boolean.TYPE);
84
setParameterDefinition("parseIntegerOnly", Boolean.TYPE);
85         setParameterDefinition("positivePrefix", String JavaDoc.class);
86         setParameterDefinition("positiveSuffix", String JavaDoc.class);
87         ignoreParameter("localizedPattern");
88         ignoreParameter("pattern");
89     }
90
91     /**
92      * Creates a new object description.
93      *
94      * @param className the class.
95      * @param init initialise
96      * @deprecated should no longer be used...
97      */

98     public DecimalFormatObjectDescription(final Class JavaDoc className,
99             final boolean init) {
100         this(className);
101     }
102
103     /**
104      * Sets the parameters of this description object to match the supplied object.
105      *
106      * @param o the object (should be an instance of <code>DecimalFormat</code>).
107      *
108      * @throws ObjectFactoryException if there is a problem while reading the
109      * properties of the given object.
110      */

111     public void setParameterFromObject(final Object JavaDoc o)
112         throws ObjectFactoryException {
113         super.setParameterFromObject(o);
114         final DecimalFormat JavaDoc format = (DecimalFormat JavaDoc) o;
115         setParameter("localizedPattern", format.toLocalizedPattern());
116         setParameter("pattern", format.toPattern());
117     }
118
119     /**
120      * Creates an object (<code>DecimalFormat</code>) based on this description.
121      *
122      * @return The object.
123      */

124     public Object JavaDoc createObject() {
125         final DecimalFormat JavaDoc format = (DecimalFormat JavaDoc) super.createObject();
126         if (getParameter("pattern") != null) {
127             format.applyPattern((String JavaDoc) getParameter("pattern"));
128         }
129         if (getParameter("localizedPattern") != null) {
130             format.applyLocalizedPattern((String JavaDoc) getParameter("localizedPattern"));
131         }
132         return format;
133     }
134 }
135
Popular Tags