~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/components/spiderchart/FillSpiderDataset.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:51:16 UTC
  • Revision ID: brian.thomason@canonical.com-20111220175116-apwo6unuaedvgzo3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JasperReports - Free Java Reporting Library.
 
3
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
 
4
 * http://www.jaspersoft.com
 
5
 *
 
6
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 
7
 * the following license terms apply:
 
8
 *
 
9
 * This program is part of JasperReports.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 * 
 
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/>.
 
23
 */
 
24
package net.sf.jasperreports.components.spiderchart;
 
25
 
 
26
import java.util.HashMap;
 
27
import java.util.Map;
 
28
 
 
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;
 
38
 
 
39
import org.jfree.data.category.DefaultCategoryDataset;
 
40
import org.jfree.data.general.Dataset;
 
41
 
 
42
 
 
43
/**
 
44
 * @author sanda zaharia (shertage@users.sourceforge.net)
 
45
 * @version $Id: FillSpiderDataset.java 3877 2010-07-14 15:25:08Z shertage $
 
46
 */
 
47
public class FillSpiderDataset extends JRFillElementDataset implements SpiderDataset
 
48
{
 
49
 
 
50
        /**
 
51
         *
 
52
         */
 
53
        protected JRFillCategorySeries[] categorySeries = null;
 
54
 
 
55
        private DefaultCategoryDataset dataset = null;
 
56
        private Map labelsMap = null;
 
57
        
 
58
        private Map itemHyperlinks;
 
59
 
 
60
        
 
61
        /**
 
62
         *
 
63
         */
 
64
        public FillSpiderDataset(
 
65
                SpiderDataset spiderDataset, 
 
66
                JRFillObjectFactory factory
 
67
                )
 
68
        {
 
69
                super(spiderDataset, factory);
 
70
 
 
71
                /*   */
 
72
                JRCategorySeries[] srcCategorySeries = spiderDataset.getSeries();
 
73
                if (srcCategorySeries != null && srcCategorySeries.length > 0)
 
74
                {
 
75
                        categorySeries = new JRFillCategorySeries[srcCategorySeries.length];
 
76
                        for(int i = 0; i < srcCategorySeries.length; i++)
 
77
                        {
 
78
                                categorySeries[i] = (JRFillCategorySeries)factory.getCategorySeries(srcCategorySeries[i]);
 
79
                        }
 
80
                }
 
81
        }
 
82
        
 
83
        
 
84
        /**
 
85
         *
 
86
         */
 
87
        public JRCategorySeries[] getSeries()
 
88
        {
 
89
                return categorySeries;
 
90
        }
 
91
 
 
92
 
 
93
        /**
 
94
         *
 
95
         */
 
96
        protected void customInitialize()
 
97
        {
 
98
                dataset = null;
 
99
                labelsMap = null;
 
100
                itemHyperlinks = null;
 
101
        }
 
102
 
 
103
        /**
 
104
         *
 
105
         */
 
106
        protected void customEvaluate(JRCalculator calculator) throws JRExpressionEvalException
 
107
        {
 
108
                if (categorySeries != null && categorySeries.length > 0)
 
109
                {
 
110
                        for(int i = 0; i < categorySeries.length; i++)
 
111
                        {
 
112
                                categorySeries[i].evaluate(calculator);
 
113
                        }
 
114
                }
 
115
        }
 
116
 
 
117
        /**
 
118
         *
 
119
         */
 
120
        protected void customIncrement()
 
121
        {
 
122
                if (categorySeries != null && categorySeries.length > 0)
 
123
                {
 
124
                        if (dataset == null)
 
125
                        {
 
126
                                dataset = new DefaultCategoryDataset();
 
127
                                labelsMap = new HashMap();
 
128
                                itemHyperlinks = new HashMap();
 
129
                        }
 
130
                        
 
131
                        for(int i = 0; i < categorySeries.length; i++)
 
132
                        {
 
133
                                JRFillCategorySeries crtCategorySeries = categorySeries[i];
 
134
                                
 
135
                                Comparable seriesName = crtCategorySeries.getSeries();
 
136
                                if (seriesName == null)
 
137
                                {
 
138
                                        throw new JRRuntimeException("Category series name is null.");
 
139
                                }
 
140
 
 
141
                                dataset.addValue(
 
142
                                        crtCategorySeries.getValue(), 
 
143
                                        crtCategorySeries.getSeries(), 
 
144
                                        crtCategorySeries.getCategory()
 
145
                                        );
 
146
 
 
147
                                if (crtCategorySeries.getLabelExpression() != null)
 
148
                                {
 
149
                                        Map seriesLabels = (Map)labelsMap.get(seriesName);
 
150
                                        if (seriesLabels == null)
 
151
                                        {
 
152
                                                seriesLabels = new HashMap();
 
153
                                                labelsMap.put(seriesName, seriesLabels);
 
154
                                        }
 
155
                                        
 
156
                                        seriesLabels.put(crtCategorySeries.getCategory(), crtCategorySeries.getLabel());
 
157
                                }
 
158
                                
 
159
                                if (crtCategorySeries.hasItemHyperlinks())
 
160
                                {
 
161
                                        Map seriesLinks = (Map) itemHyperlinks.get(seriesName);
 
162
                                        if (seriesLinks == null)
 
163
                                        {
 
164
                                                seriesLinks = new HashMap();
 
165
                                                itemHyperlinks.put(seriesName, seriesLinks);
 
166
                                        }
 
167
                                        seriesLinks.put(crtCategorySeries.getCategory(), crtCategorySeries.getPrintItemHyperlink());
 
168
                                }
 
169
                        }
 
170
                }
 
171
        }
 
172
 
 
173
        /**
 
174
         *
 
175
         */
 
176
        public Dataset getCustomDataset()
 
177
        {
 
178
                return dataset;
 
179
        }
 
180
 
 
181
        /**
 
182
         *
 
183
         */
 
184
        public Object getLabelGenerator()
 
185
        {
 
186
                return new CategoryLabelGenerator(labelsMap);
 
187
        }
 
188
 
 
189
 
 
190
        /**
 
191
         *
 
192
         */
 
193
        public void collectExpressions(JRExpressionCollector collector)
 
194
        {
 
195
                SpiderChartCompiler.collectExpressions(this, collector);
 
196
        }
 
197
 
 
198
        
 
199
        public Map getItemHyperlinks()
 
200
        {
 
201
                return itemHyperlinks;
 
202
        }
 
203
        
 
204
        
 
205
        public boolean hasItemHyperlinks()
 
206
        {
 
207
                boolean foundLinks = false;
 
208
                if (categorySeries != null && categorySeries.length > 0)
 
209
                {
 
210
                        for (int i = 0; i < categorySeries.length && !foundLinks; i++)
 
211
                        {
 
212
                                JRFillCategorySeries serie = categorySeries[i];
 
213
                                foundLinks = serie.hasItemHyperlinks();
 
214
                        }
 
215
                }
 
216
                return foundLinks;
 
217
        }
 
218
 
 
219
        public void finishDataset()
 
220
        {
 
221
                //one last increment is required in certain cases
 
222
                increment();
 
223
        }
 
224
 
 
225
        
 
226
}