KickJava   Java API By Example, From Geeks To Geeks.

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


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.JRXyzDataset;
34 import net.sf.jasperreports.charts.JRXyzSeries;
35 import net.sf.jasperreports.charts.util.DefaultXYZDataset;
36 import net.sf.jasperreports.engine.JRChartDataset;
37 import net.sf.jasperreports.engine.JRExpressionCollector;
38 import net.sf.jasperreports.engine.JRRuntimeException;
39 import net.sf.jasperreports.engine.design.JRVerifier;
40 import net.sf.jasperreports.engine.fill.JRCalculator;
41 import net.sf.jasperreports.engine.fill.JRExpressionEvalException;
42 import net.sf.jasperreports.engine.fill.JRFillChartDataset;
43 import net.sf.jasperreports.engine.fill.JRFillObjectFactory;
44 import net.sf.jasperreports.engine.util.Pair;
45
46 import org.jfree.data.general.Dataset;
47
48 /**
49  * @author Flavius Sana (flavius_sana@users.sourceforge.net)
50  * @version $Id: JRFillXyzDataset.java 1531 2006-12-21 19:38:30 +0200 (Thu, 21 Dec 2006) teodord $
51  */

52 public class JRFillXyzDataset extends JRFillChartDataset implements JRXyzDataset {
53
54     protected JRFillXyzSeries[] xyzSeries = null;
55
56     private DefaultXYZDataset dataset = null;
57     
58     private Map JavaDoc itemHyperlinks;
59     
60     
61     public JRFillXyzDataset(JRXyzDataset xyzDataset, JRFillObjectFactory factory)
62     {
63         super( xyzDataset, factory );
64         
65         JRXyzSeries[] srcXyzSeries = xyzDataset.getSeries();
66         if(srcXyzSeries != null && srcXyzSeries.length > 0)
67         {
68             xyzSeries = new JRFillXyzSeries[srcXyzSeries.length];
69             for(int i = 0; i < xyzSeries.length; i++)
70             {
71                 xyzSeries[i] = (JRFillXyzSeries)factory.getXyzSeries( srcXyzSeries[i]);
72             }
73         }
74     }
75     
76     public JRXyzSeries[] getSeries(){
77         return xyzSeries;
78     }
79     
80     protected void customInitialize()
81     {
82         dataset = new DefaultXYZDataset();
83         itemHyperlinks = new HashMap JavaDoc();
84     }
85     
86     protected void customEvaluate( JRCalculator calculator ) throws JRExpressionEvalException
87     {
88         if (xyzSeries != null && xyzSeries.length > 0)
89         {
90             for (int i = 0; i < xyzSeries.length; i++)
91             {
92                 xyzSeries[i].evaluate( calculator );
93             }
94         }
95     }
96     
97     protected void customIncrement()
98     {
99         if (xyzSeries != null && xyzSeries .length > 0)
100         {
101             for (int i = 0; i < xyzSeries.length; i++)
102             {
103                 JRFillXyzSeries crtXyzSeries = xyzSeries[i];
104                 
105                 Comparable JavaDoc seriesName = crtXyzSeries.getSeries();
106                 if (seriesName == null)
107                 {
108                     throw new JRRuntimeException("XYZ series name is null.");
109                 }
110
111                 dataset.addValue(
112                     crtXyzSeries.getSeries(),
113                     crtXyzSeries.getXValue(),
114                     crtXyzSeries.getYValue(),
115                     crtXyzSeries.getZValue()
116                     );
117                 
118                 if (crtXyzSeries.hasItemHyperlinks())
119                 {
120                     Map JavaDoc seriesLinks = (Map JavaDoc) itemHyperlinks.get(crtXyzSeries.getSeries());
121                     if (seriesLinks == null)
122                     {
123                         seriesLinks = new HashMap JavaDoc();
124                         itemHyperlinks.put(crtXyzSeries.getSeries(), seriesLinks);
125                     }
126                     Pair xyKey = new Pair(crtXyzSeries.getXValue(), crtXyzSeries.getYValue());
127                     seriesLinks.put(xyKey, crtXyzSeries.getPrintItemHyperlink());
128                 }
129             }
130         }
131     }
132     
133     public Dataset getCustomDataset() {
134         return dataset;
135     }
136
137     /**
138      *
139      */

140     public byte getDatasetType() {
141         return JRChartDataset.XYZ_DATASET;
142     }
143
144
145     /**
146      *
147      */

148     public void collectExpressions(JRExpressionCollector collector)
149     {
150         collector.collect(this);
151     }
152     
153     
154     public boolean hasItemHyperlinks()
155     {
156         boolean foundLinks = false;
157         if (xyzSeries != null && xyzSeries.length > 0)
158         {
159             for (int i = 0; i < xyzSeries.length && !foundLinks; i++)
160             {
161                 JRFillXyzSeries serie = xyzSeries[i];
162                 foundLinks = serie.hasItemHyperlinks();
163             }
164         }
165         return foundLinks;
166     }
167
168     
169     public Map JavaDoc getItemHyperlinks()
170     {
171         return itemHyperlinks;
172     }
173
174
175     public void validate(JRVerifier verifier)
176     {
177         verifier.verify(this);
178     }
179
180
181 }
182
Popular Tags