Source Code Cross Referenced for PieChartExpression.java in  » Report » pentaho-report » org » pentaho » plugin » jfreereport » reportcharts » 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 » Report » pentaho report » org.pentaho.plugin.jfreereport.reportcharts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         */
013:        package org.pentaho.plugin.jfreereport.reportcharts;
014:
015:        import java.util.ArrayList;
016:        import java.util.List;
017:
018:        import org.jfree.chart.ChartFactory;
019:        import org.jfree.chart.JFreeChart;
020:        import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
021:        import org.jfree.chart.plot.PiePlot;
022:        import org.jfree.chart.plot.Plot;
023:        import org.jfree.data.general.Dataset;
024:        import org.jfree.data.general.PieDataset;
025:        import org.jfree.util.Rotation;
026:
027:        public class PieChartExpression extends AbstractChartExpression {
028:
029:            private static final long serialVersionUID = 5755617219149952355L;
030:
031:            private boolean rotationClockwise = true;
032:
033:            private String explodeSegment;
034:
035:            private Double explodePct;
036:
037:            private boolean ignoreNulls = true;
038:
039:            private boolean ignoreZeros = true;
040:
041:            private String pieLabelFormat = StandardPieSectionLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT;
042:
043:            private boolean circular = true;
044:
045:            private String pieLegendLabelFormat = StandardPieSectionLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT;
046:
047:            protected PieDataset pieDS;
048:
049:            private List seriesColors = new ArrayList();
050:
051:            public PieChartExpression() {
052:                super ();
053:            }
054:
055:            public boolean isRotationClockwise() {
056:                return rotationClockwise;
057:            }
058:
059:            public void setRotationClockwise(boolean value) {
060:                rotationClockwise = value;
061:            }
062:
063:            public boolean isIgnoreNulls() {
064:                return ignoreNulls;
065:            }
066:
067:            public void setIgnoreNulls(boolean value) {
068:                ignoreNulls = value;
069:            }
070:
071:            public boolean isIgnoreZeros() {
072:                return ignoreZeros;
073:            }
074:
075:            public void setIgnoreZeros(boolean value) {
076:                ignoreZeros = value;
077:            }
078:
079:            public String getExplodeSegment() {
080:                return explodeSegment;
081:            }
082:
083:            public void setExplodeSegment(String value) {
084:                explodeSegment = value;
085:            }
086:
087:            public Double getExplodePct() {
088:                return explodePct;
089:            }
090:
091:            public void setExplodePct(Double value) {
092:                explodePct = value;
093:            }
094:
095:            public String getPieLabelFormat() {
096:                return pieLabelFormat;
097:            }
098:
099:            public void setPieLabelFormat(String value) {
100:                pieLabelFormat = value;
101:            }
102:
103:            public String getPieLegendLabelFormat() {
104:                return pieLegendLabelFormat;
105:            }
106:
107:            public void setPieLegendLabelFormat(String value) {
108:                pieLegendLabelFormat = value;
109:            }
110:
111:            public boolean getIsCircular() {
112:                return circular;
113:            }
114:
115:            public void setCircular(boolean value) {
116:                circular = value;
117:            }
118:
119:            public JFreeChart getChart(Dataset dataset) {
120:
121:                PieDataset pieDataset = null;
122:                if (dataset instanceof  PieDataset) {
123:                    pieDataset = (PieDataset) dataset;
124:                }
125:
126:                pieDS = pieDataset;
127:                JFreeChart rtn = null;
128:                if (isThreeD()) {
129:                    rtn = ChartFactory.createPieChart3D(getTitle(), pieDataset,
130:                            isShowLegend(), false, false);
131:                } else {
132:                    rtn = ChartFactory.createPieChart(getTitle(), pieDataset,
133:                            isShowLegend(), false, false);
134:                }
135:
136:                return rtn;
137:            }
138:
139:            protected void setExplode(PiePlot pp) {
140:                int explodeType = 0; // 0 = value, 1 = min, 2 = max
141:                if ("minValue".equals(explodeSegment)) { //$NON-NLS-1$
142:                    explodeType = 1;
143:                } else if ("maxValue".equals(explodeSegment)) { //$NON-NLS-1$
144:                    explodeType = 2;
145:                }
146:                int actualSegment = 0;
147:                if (explodeType == 0) {
148:                    try {
149:                        actualSegment = Integer.parseInt(explodeSegment);
150:                        if (actualSegment >= 0) {
151:                            pp.setExplodePercent(pieDS.getKey(actualSegment),
152:                                    explodePct.doubleValue());
153:                        }
154:                    } catch (Exception ignored) {
155:                    }
156:                    return;
157:                }
158:                int minSegment = -1;
159:                int maxSegment = -1;
160:                Number minNum = new Double(Integer.MAX_VALUE);
161:                Number maxNum = new Double(Integer.MIN_VALUE);
162:                // Calculate min and max...
163:                if (pieDS != null) {
164:                    int itemCount = pieDS.getItemCount();
165:                    for (int i = 0; i < itemCount; i++) {
166:                        Number nbr = pieDS.getValue(i);
167:                        if (nbr.doubleValue() > maxNum.doubleValue()) {
168:                            maxNum = nbr;
169:                            maxSegment = i;
170:                        }
171:                        if (nbr.doubleValue() < minNum.doubleValue()) {
172:                            minNum = nbr;
173:                            minSegment = i;
174:                        }
175:                    }
176:                    if ("minValue".equals(explodeSegment)) { //$NON-NLS-1$
177:                        if (minSegment >= 0) {
178:                            pp.setExplodePercent(pieDS.getKey(minSegment),
179:                                    explodePct.doubleValue());
180:                        }
181:                    } else {
182:                        if (maxSegment >= 0) {
183:                            pp.setExplodePercent(pieDS.getKey(maxSegment),
184:                                    explodePct.doubleValue());
185:                        }
186:                    }
187:                }
188:
189:            }
190:
191:            /*
192:             * Getter/ setter methods for slice colors
193:             * Ingo Klose 23.10.2007
194:             */
195:            public String getSeriesColor(final int index) {
196:                return (String) seriesColors.get(index);
197:            }
198:
199:            public int getSeriesColorCount() {
200:                return seriesColors.size();
201:            }
202:
203:            public String[] getSeriesColor() {
204:                return (String[]) seriesColors.toArray(new String[seriesColors
205:                        .size()]);
206:            }
207:
208:            public void setSeriesColor(final int index, final String field) {
209:                if (seriesColors.size() == index) {
210:                    seriesColors.add(field);
211:                } else {
212:                    seriesColors.set(index, field);
213:                }
214:            }
215:
216:            protected void setChartProperties(JFreeChart chart) {
217:                super .setChartProperties(chart);
218:                Plot plot = chart.getPlot();
219:                PiePlot pp = (PiePlot) plot;
220:                pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE
221:                        : Rotation.ANTICLOCKWISE);
222:                if ((explodeSegment != null) && (explodePct != null)) {
223:                    setExplode(pp);
224:                    // pp.setExplodePercent(explodeSegment.intValue(),
225:                    // explodePct.doubleValue());
226:                }
227:                pp.setIgnoreNullValues(ignoreNulls);
228:                pp.setIgnoreZeroValues(ignoreZeros);
229:                if (!pieLabelFormat
230:                        .equals(StandardPieSectionLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT)) {
231:                    StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
232:                            pieLabelFormat);
233:                    pp.setLabelGenerator(labelGen);
234:                }
235:
236:                if (!pieLegendLabelFormat
237:                        .equals(StandardPieSectionLabelGenerator.DEFAULT_SECTION_LABEL_FORMAT)) {
238:                    StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
239:                            pieLegendLabelFormat);
240:                    pp.setLegendLabelGenerator(labelGen);
241:                }
242:
243:                /*
244:                 * Setting the color of the slices
245:                 * Ingo Klose 23.10.2007
246:                 */
247:                for (int i = 0; i < seriesColors.size(); i++) {
248:                    pp.setSectionPaint(pieDS.getKey(i),
249:                            getColorFromString((String) seriesColors.get(i)));
250:                }
251:
252:                pp.setCircular(circular);
253:            }
254:
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.