1 28 package net.sf.jasperreports.charts.fill; 29 30 import java.util.HashMap ; 31 import java.util.Map ; 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 52 public class JRFillXyzDataset extends JRFillChartDataset implements JRXyzDataset { 53 54 protected JRFillXyzSeries[] xyzSeries = null; 55 56 private DefaultXYZDataset dataset = null; 57 58 private Map 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 (); 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 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 seriesLinks = (Map ) itemHyperlinks.get(crtXyzSeries.getSeries()); 121 if (seriesLinks == null) 122 { 123 seriesLinks = new HashMap (); 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 140 public byte getDatasetType() { 141 return JRChartDataset.XYZ_DATASET; 142 } 143 144 145 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 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 |