2
* JasperReports - Free Java Reporting Library.
3
* Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
4
* http://www.jaspersoft.com
6
* Unless you have purchased a commercial license agreement from Jaspersoft,
7
* the following license terms apply:
9
* This program is part of JasperReports.
11
* JasperReports is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
16
* JasperReports is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
24
package net.sf.jasperreports.components.spiderchart;
26
import java.util.HashMap;
29
import net.sf.jasperreports.charts.JRCategorySeries;
30
import net.sf.jasperreports.charts.fill.JRFillCategorySeries;
31
import net.sf.jasperreports.charts.util.CategoryLabelGenerator;
32
import net.sf.jasperreports.engine.JRExpressionCollector;
33
import net.sf.jasperreports.engine.JRRuntimeException;
34
import net.sf.jasperreports.engine.fill.JRCalculator;
35
import net.sf.jasperreports.engine.fill.JRExpressionEvalException;
36
import net.sf.jasperreports.engine.fill.JRFillElementDataset;
37
import net.sf.jasperreports.engine.fill.JRFillObjectFactory;
39
import org.jfree.data.category.DefaultCategoryDataset;
40
import org.jfree.data.general.Dataset;
44
* @author sanda zaharia (shertage@users.sourceforge.net)
45
* @version $Id: FillSpiderDataset.java 3877 2010-07-14 15:25:08Z shertage $
47
public class FillSpiderDataset extends JRFillElementDataset implements SpiderDataset
53
protected JRFillCategorySeries[] categorySeries = null;
55
private DefaultCategoryDataset dataset = null;
56
private Map labelsMap = null;
58
private Map itemHyperlinks;
64
public FillSpiderDataset(
65
SpiderDataset spiderDataset,
66
JRFillObjectFactory factory
69
super(spiderDataset, factory);
72
JRCategorySeries[] srcCategorySeries = spiderDataset.getSeries();
73
if (srcCategorySeries != null && srcCategorySeries.length > 0)
75
categorySeries = new JRFillCategorySeries[srcCategorySeries.length];
76
for(int i = 0; i < srcCategorySeries.length; i++)
78
categorySeries[i] = (JRFillCategorySeries)factory.getCategorySeries(srcCategorySeries[i]);
87
public JRCategorySeries[] getSeries()
89
return categorySeries;
96
protected void customInitialize()
100
itemHyperlinks = null;
106
protected void customEvaluate(JRCalculator calculator) throws JRExpressionEvalException
108
if (categorySeries != null && categorySeries.length > 0)
110
for(int i = 0; i < categorySeries.length; i++)
112
categorySeries[i].evaluate(calculator);
120
protected void customIncrement()
122
if (categorySeries != null && categorySeries.length > 0)
126
dataset = new DefaultCategoryDataset();
127
labelsMap = new HashMap();
128
itemHyperlinks = new HashMap();
131
for(int i = 0; i < categorySeries.length; i++)
133
JRFillCategorySeries crtCategorySeries = categorySeries[i];
135
Comparable seriesName = crtCategorySeries.getSeries();
136
if (seriesName == null)
138
throw new JRRuntimeException("Category series name is null.");
142
crtCategorySeries.getValue(),
143
crtCategorySeries.getSeries(),
144
crtCategorySeries.getCategory()
147
if (crtCategorySeries.getLabelExpression() != null)
149
Map seriesLabels = (Map)labelsMap.get(seriesName);
150
if (seriesLabels == null)
152
seriesLabels = new HashMap();
153
labelsMap.put(seriesName, seriesLabels);
156
seriesLabels.put(crtCategorySeries.getCategory(), crtCategorySeries.getLabel());
159
if (crtCategorySeries.hasItemHyperlinks())
161
Map seriesLinks = (Map) itemHyperlinks.get(seriesName);
162
if (seriesLinks == null)
164
seriesLinks = new HashMap();
165
itemHyperlinks.put(seriesName, seriesLinks);
167
seriesLinks.put(crtCategorySeries.getCategory(), crtCategorySeries.getPrintItemHyperlink());
176
public Dataset getCustomDataset()
184
public Object getLabelGenerator()
186
return new CategoryLabelGenerator(labelsMap);
193
public void collectExpressions(JRExpressionCollector collector)
195
SpiderChartCompiler.collectExpressions(this, collector);
199
public Map getItemHyperlinks()
201
return itemHyperlinks;
205
public boolean hasItemHyperlinks()
207
boolean foundLinks = false;
208
if (categorySeries != null && categorySeries.length > 0)
210
for (int i = 0; i < categorySeries.length && !foundLinks; i++)
212
JRFillCategorySeries serie = categorySeries[i];
213
foundLinks = serie.hasItemHyperlinks();
219
public void finishDataset()
221
//one last increment is required in certain cases