KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > charts > fill > JRFillPieDataset


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.charts.fill;
29
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import net.sf.jasperreports.charts.JRPieDataset;
34 import net.sf.jasperreports.charts.util.PieLabelGenerator;
35 import net.sf.jasperreports.engine.JRChartDataset;
36 import net.sf.jasperreports.engine.JRException;
37 import net.sf.jasperreports.engine.JRExpression;
38 import net.sf.jasperreports.engine.JRExpressionCollector;
39 import net.sf.jasperreports.engine.JRHyperlink;
40 import net.sf.jasperreports.engine.JRPrintHyperlink;
41 import net.sf.jasperreports.engine.JRRuntimeException;
42 import net.sf.jasperreports.engine.design.JRVerifier;
43 import net.sf.jasperreports.engine.fill.JRCalculator;
44 import net.sf.jasperreports.engine.fill.JRExpressionEvalException;
45 import net.sf.jasperreports.engine.fill.JRFillChartDataset;
46 import net.sf.jasperreports.engine.fill.JRFillHyperlinkHelper;
47 import net.sf.jasperreports.engine.fill.JRFillObjectFactory;
48
49 import org.jfree.data.general.Dataset;
50 import org.jfree.data.general.DefaultPieDataset;
51
52
53 /**
54  * @author Teodor Danciu (teodord@users.sourceforge.net)
55  * @version $Id: JRFillPieDataset.java 1364 2006-08-31 18:13:20 +0300 (Thu, 31 Aug 2006) lucianc $
56  */

57 public class JRFillPieDataset extends JRFillChartDataset implements JRPieDataset
58 {
59
60     /**
61      *
62      */

63     private DefaultPieDataset dataset = new DefaultPieDataset();
64     private Map JavaDoc labels = null;
65     
66     private Comparable JavaDoc key = null;
67     private Number JavaDoc value = null;
68     private String JavaDoc label = null;
69     
70     private Map JavaDoc sectionHyperlinks;
71     private JRPrintHyperlink sectionHyperlink;
72     
73     
74     /**
75      *
76      */

77     public JRFillPieDataset(
78         JRPieDataset pieDataset,
79         JRFillObjectFactory factory
80         )
81     {
82         super(pieDataset, factory);
83     }
84
85
86     /**
87      *
88      */

89     public JRExpression getKeyExpression()
90     {
91         return ((JRPieDataset)parent).getKeyExpression();
92     }
93         
94     /**
95      *
96      */

97     public JRExpression getValueExpression()
98     {
99         return ((JRPieDataset)parent).getValueExpression();
100     }
101         
102     /**
103      *
104      */

105     public JRExpression getLabelExpression()
106     {
107         return ((JRPieDataset)parent).getLabelExpression();
108     }
109     
110     
111     /**
112      *
113      */

114     protected void customInitialize()
115     {
116         dataset = new DefaultPieDataset();
117         labels = new HashMap JavaDoc();
118         sectionHyperlinks = new HashMap JavaDoc();
119     }
120
121     /**
122      *
123      */

124     protected void customEvaluate(JRCalculator calculator) throws JRExpressionEvalException
125     {
126         key = (Comparable JavaDoc)calculator.evaluate(getKeyExpression());
127         value = (Number JavaDoc)calculator.evaluate(getValueExpression());
128         label = (String JavaDoc)calculator.evaluate(getLabelExpression());
129         
130         if (hasSectionHyperlinks())
131         {
132             evaluateSectionHyperlink(calculator);
133         }
134     }
135
136
137     protected void evaluateSectionHyperlink(JRCalculator calculator) throws JRExpressionEvalException
138     {
139         try
140         {
141             sectionHyperlink = JRFillHyperlinkHelper.evaluateHyperlink(getSectionHyperlink(), calculator, JRExpression.EVALUATION_DEFAULT);
142         }
143         catch (JRExpressionEvalException e)
144         {
145             throw e;
146         }
147         catch (JRException e)
148         {
149             throw new JRRuntimeException(e);
150         }
151     }
152
153     /**
154      *
155      */

156     protected void customIncrement()
157     {
158         dataset.setValue(key, value);
159         labels.put( key, label );
160         
161         if (hasSectionHyperlinks())
162         {
163             sectionHyperlinks.put(key, sectionHyperlink);
164         }
165     }
166
167     /**
168      *
169      */

170     public Dataset getCustomDataset()
171     {
172         return dataset;
173     }
174
175
176     /* (non-Javadoc)
177      * @see net.sf.jasperreports.engine.JRChartDataset#getDatasetType()
178      */

179     public byte getDatasetType() {
180         return JRChartDataset.PIE_DATASET;
181     }
182
183
184     public PieLabelGenerator getLabelGenerator(){
185         return (getLabelExpression() == null) ? null : new PieLabelGenerator( labels );
186     }
187     
188     /**
189      *
190      */

191     public void collectExpressions(JRExpressionCollector collector)
192     {
193         collector.collect(this);
194     }
195
196
197     public JRHyperlink getSectionHyperlink()
198     {
199         return ((JRPieDataset) parent).getSectionHyperlink();
200     }
201
202     
203     public boolean hasSectionHyperlinks()
204     {
205         return getSectionHyperlink() != null;
206     }
207     
208     public Map JavaDoc getSectionHyperlinks()
209     {
210         return sectionHyperlinks;
211     }
212
213
214     public void validate(JRVerifier verifier)
215     {
216         verifier.verify(this);
217     }
218
219 }
220
Popular Tags