001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.charts.fill;
029:
030: import java.util.HashMap;
031: import java.util.Map;
032:
033: import net.sf.jasperreports.charts.JRXyzDataset;
034: import net.sf.jasperreports.charts.JRXyzSeries;
035: import net.sf.jasperreports.charts.util.DefaultXYZDataset;
036: import net.sf.jasperreports.engine.JRChartDataset;
037: import net.sf.jasperreports.engine.JRExpressionCollector;
038: import net.sf.jasperreports.engine.JRRuntimeException;
039: import net.sf.jasperreports.engine.design.JRVerifier;
040: import net.sf.jasperreports.engine.fill.JRCalculator;
041: import net.sf.jasperreports.engine.fill.JRExpressionEvalException;
042: import net.sf.jasperreports.engine.fill.JRFillChartDataset;
043: import net.sf.jasperreports.engine.fill.JRFillObjectFactory;
044: import net.sf.jasperreports.engine.util.Pair;
045:
046: import org.jfree.data.general.Dataset;
047:
048: /**
049: * @author Flavius Sana (flavius_sana@users.sourceforge.net)
050: * @version $Id: JRFillXyzDataset.java 1531 2006-12-21 17:38:30Z teodord $
051: */
052: public class JRFillXyzDataset extends JRFillChartDataset implements
053: JRXyzDataset {
054:
055: protected JRFillXyzSeries[] xyzSeries = null;
056:
057: private DefaultXYZDataset dataset = null;
058:
059: private Map itemHyperlinks;
060:
061: public JRFillXyzDataset(JRXyzDataset xyzDataset,
062: JRFillObjectFactory factory) {
063: super (xyzDataset, factory);
064:
065: JRXyzSeries[] srcXyzSeries = xyzDataset.getSeries();
066: if (srcXyzSeries != null && srcXyzSeries.length > 0) {
067: xyzSeries = new JRFillXyzSeries[srcXyzSeries.length];
068: for (int i = 0; i < xyzSeries.length; i++) {
069: xyzSeries[i] = (JRFillXyzSeries) factory
070: .getXyzSeries(srcXyzSeries[i]);
071: }
072: }
073: }
074:
075: public JRXyzSeries[] getSeries() {
076: return xyzSeries;
077: }
078:
079: protected void customInitialize() {
080: dataset = new DefaultXYZDataset();
081: itemHyperlinks = new HashMap();
082: }
083:
084: protected void customEvaluate(JRCalculator calculator)
085: throws JRExpressionEvalException {
086: if (xyzSeries != null && xyzSeries.length > 0) {
087: for (int i = 0; i < xyzSeries.length; i++) {
088: xyzSeries[i].evaluate(calculator);
089: }
090: }
091: }
092:
093: protected void customIncrement() {
094: if (xyzSeries != null && xyzSeries.length > 0) {
095: for (int i = 0; i < xyzSeries.length; i++) {
096: JRFillXyzSeries crtXyzSeries = xyzSeries[i];
097:
098: Comparable seriesName = crtXyzSeries.getSeries();
099: if (seriesName == null) {
100: throw new JRRuntimeException(
101: "XYZ series name is null.");
102: }
103:
104: dataset.addValue(crtXyzSeries.getSeries(), crtXyzSeries
105: .getXValue(), crtXyzSeries.getYValue(),
106: crtXyzSeries.getZValue());
107:
108: if (crtXyzSeries.hasItemHyperlinks()) {
109: Map seriesLinks = (Map) itemHyperlinks
110: .get(crtXyzSeries.getSeries());
111: if (seriesLinks == null) {
112: seriesLinks = new HashMap();
113: itemHyperlinks.put(crtXyzSeries.getSeries(),
114: seriesLinks);
115: }
116: Pair xyKey = new Pair(crtXyzSeries.getXValue(),
117: crtXyzSeries.getYValue());
118: seriesLinks.put(xyKey, crtXyzSeries
119: .getPrintItemHyperlink());
120: }
121: }
122: }
123: }
124:
125: public Dataset getCustomDataset() {
126: return dataset;
127: }
128:
129: /**
130: *
131: */
132: public byte getDatasetType() {
133: return JRChartDataset.XYZ_DATASET;
134: }
135:
136: /**
137: *
138: */
139: public void collectExpressions(JRExpressionCollector collector) {
140: collector.collect(this );
141: }
142:
143: public boolean hasItemHyperlinks() {
144: boolean foundLinks = false;
145: if (xyzSeries != null && xyzSeries.length > 0) {
146: for (int i = 0; i < xyzSeries.length && !foundLinks; i++) {
147: JRFillXyzSeries serie = xyzSeries[i];
148: foundLinks = serie.hasItemHyperlinks();
149: }
150: }
151: return foundLinks;
152: }
153:
154: public Map getItemHyperlinks() {
155: return itemHyperlinks;
156: }
157:
158: public void validate(JRVerifier verifier) {
159: verifier.verify(this);
160: }
161:
162: }
|