Source Code Cross Referenced for AbstractPieItemLabelGenerator.java in  » Chart » jfreechart » org » jfree » chart » labels » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » jfreechart » org.jfree.chart.labels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
006:         *
007:         * Project Info:  http://www.jfree.org/jfreechart/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         *
027:         * ----------------------------------
028:         * AbstractPieItemLabelGenerator.java
029:         * ----------------------------------
030:         * (C) Copyright 2004-2006, by Object Refinery Limited.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   -;
034:         *
035:         * $Id: AbstractPieItemLabelGenerator.java,v 1.5.2.2 2006/05/03 10:46:36 mungady Exp $
036:         *
037:         * Changes
038:         * -------
039:         * 09-Nov-2004 : Version 1, draws out code from StandardPieItemLabelGenerator 
040:         *               and StandardPieToolTipGenerator (DG);
041:         * ------------- JFREECHART 1.0.0 ---------------------------------------------
042:         * 03-May-2006 : Fixed bug 1480978, a problem in the clone() method (DG);
043:         * 
044:         */
045:
046:        package org.jfree.chart.labels;
047:
048:        import java.io.Serializable;
049:        import java.text.MessageFormat;
050:        import java.text.NumberFormat;
051:
052:        import org.jfree.data.general.DatasetUtilities;
053:        import org.jfree.data.general.PieDataset;
054:
055:        /**
056:         * A base class used for generating pie chart item labels.
057:         */
058:        public class AbstractPieItemLabelGenerator implements  Serializable {
059:
060:            /** For serialization. */
061:            private static final long serialVersionUID = 7347703325267846275L;
062:
063:            /** The label format string. */
064:            private String labelFormat;
065:
066:            /** A number formatter for the value. */
067:            private NumberFormat numberFormat;
068:
069:            /** A number formatter for the percentage. */
070:            private NumberFormat percentFormat;
071:
072:            /**
073:             * Creates an item label generator using the specified number formatters.
074:             *
075:             * @param labelFormat  the label format string (<code>null</code> not
076:             *                     permitted).
077:             * @param numberFormat  the format object for the values (<code>null</code>
078:             *                      not permitted).
079:             * @param percentFormat  the format object for the percentages
080:             *                       (<code>null</code> not permitted).
081:             */
082:            protected AbstractPieItemLabelGenerator(String labelFormat,
083:                    NumberFormat numberFormat, NumberFormat percentFormat) {
084:
085:                if (labelFormat == null) {
086:                    throw new IllegalArgumentException(
087:                            "Null 'labelFormat' argument.");
088:                }
089:                if (numberFormat == null) {
090:                    throw new IllegalArgumentException(
091:                            "Null 'numberFormat' argument.");
092:                }
093:                if (percentFormat == null) {
094:                    throw new IllegalArgumentException(
095:                            "Null 'percentFormat' argument.");
096:                }
097:                this .labelFormat = labelFormat;
098:                this .numberFormat = numberFormat;
099:                this .percentFormat = percentFormat;
100:
101:            }
102:
103:            /**
104:             * Returns the label format string.
105:             * 
106:             * @return The label format string (never <code>null</code>).
107:             */
108:            public String getLabelFormat() {
109:                return this .labelFormat;
110:            }
111:
112:            /**
113:             * Returns the number formatter.
114:             *
115:             * @return The formatter (never <code>null</code>).
116:             */
117:            public NumberFormat getNumberFormat() {
118:                return this .numberFormat;
119:            }
120:
121:            /**
122:             * Returns the percent formatter.
123:             *
124:             * @return The formatter (never <code>null</code>).
125:             */
126:            public NumberFormat getPercentFormat() {
127:                return this .percentFormat;
128:            }
129:
130:            /**
131:             * Creates the array of items that can be passed to the 
132:             * {@link MessageFormat} class for creating labels.  The returned array
133:             * contains four values:
134:             * <ul>
135:             * <li>result[0] = the section key converted to a <code>String</code>;</li>
136:             * <li>result[1] = the formatted data value;</li>
137:             * <li>result[2] = the formatted percentage (of the total);</li>
138:             * <li>result[3] = the formatted total value.</li>
139:             * </ul>
140:             *
141:             * @param dataset  the dataset (<code>null</code> not permitted).
142:             * @param key  the key (<code>null</code> not permitted).
143:             *
144:             * @return The items (never <code>null</code>).
145:             */
146:            protected Object[] createItemArray(PieDataset dataset,
147:                    Comparable key) {
148:                Object[] result = new Object[4];
149:                double total = DatasetUtilities
150:                        .calculatePieDatasetTotal(dataset);
151:                result[0] = key.toString();
152:                Number value = dataset.getValue(key);
153:                if (value != null) {
154:                    result[1] = this .numberFormat.format(value);
155:                } else {
156:                    result[1] = "null";
157:                }
158:                double percent = 0.0;
159:                if (value != null) {
160:                    double v = value.doubleValue();
161:                    if (v > 0.0) {
162:                        percent = v / total;
163:                    }
164:                }
165:                result[2] = this .percentFormat.format(percent);
166:                result[3] = this .numberFormat.format(total);
167:                return result;
168:            }
169:
170:            /**
171:             * Generates a label for a pie section.
172:             * 
173:             * @param dataset  the dataset (<code>null</code> not permitted).
174:             * @param key  the section key (<code>null</code> not permitted).
175:             * 
176:             * @return The label (possibly <code>null</code>).
177:             */
178:            protected String generateSectionLabel(PieDataset dataset,
179:                    Comparable key) {
180:                String result = null;
181:                if (dataset != null) {
182:                    Object[] items = createItemArray(dataset, key);
183:                    result = MessageFormat.format(this .labelFormat, items);
184:                }
185:                return result;
186:            }
187:
188:            /**
189:             * Tests the generator for equality with an arbitrary object.
190:             *
191:             * @param obj  the object to test against (<code>null</code> permitted).
192:             *
193:             * @return A boolean.
194:             */
195:            public boolean equals(Object obj) {
196:                if (obj == this ) {
197:                    return true;
198:                }
199:                if (!(obj instanceof  AbstractPieItemLabelGenerator)) {
200:                    return false;
201:                }
202:
203:                AbstractPieItemLabelGenerator that = (AbstractPieItemLabelGenerator) obj;
204:                if (!this .labelFormat.equals(that.labelFormat)) {
205:                    return false;
206:                }
207:                if (!this .numberFormat.equals(that.numberFormat)) {
208:                    return false;
209:                }
210:                if (!this .percentFormat.equals(that.percentFormat)) {
211:                    return false;
212:                }
213:                return true;
214:
215:            }
216:
217:            /**
218:             * Returns an independent copy of the generator.
219:             * 
220:             * @return A clone.
221:             * 
222:             * @throws CloneNotSupportedException  should not happen.
223:             */
224:            public Object clone() throws CloneNotSupportedException {
225:                AbstractPieItemLabelGenerator clone = (AbstractPieItemLabelGenerator) super 
226:                        .clone();
227:                if (this .numberFormat != null) {
228:                    clone.numberFormat = (NumberFormat) this .numberFormat
229:                            .clone();
230:                }
231:                if (this .percentFormat != null) {
232:                    clone.percentFormat = (NumberFormat) this.percentFormat
233:                            .clone();
234:                }
235:                return clone;
236:            }
237:
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.