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.JRPieDataset; 34 import net.sf.jasperreports.charts.util.PieLabelGenerator; 35 import net.sf.jasperreports.engine.JRChartDataset; 36 import net.sf.jasperreports.engine.JRException; 37 import net.sf.jasperreports.engine.JRExpression; 38 import net.sf.jasperreports.engine.JRExpressionCollector; 39 import net.sf.jasperreports.engine.JRHyperlink; 40 import net.sf.jasperreports.engine.JRPrintHyperlink; 41 import net.sf.jasperreports.engine.JRRuntimeException; 42 import net.sf.jasperreports.engine.design.JRVerifier; 43 import net.sf.jasperreports.engine.fill.JRCalculator; 44 import net.sf.jasperreports.engine.fill.JRExpressionEvalException; 45 import net.sf.jasperreports.engine.fill.JRFillChartDataset; 46 import net.sf.jasperreports.engine.fill.JRFillHyperlinkHelper; 47 import net.sf.jasperreports.engine.fill.JRFillObjectFactory; 48 49 import org.jfree.data.general.Dataset; 50 import org.jfree.data.general.DefaultPieDataset; 51 52 53 57 public class JRFillPieDataset extends JRFillChartDataset implements JRPieDataset 58 { 59 60 63 private DefaultPieDataset dataset = new DefaultPieDataset(); 64 private Map labels = null; 65 66 private Comparable key = null; 67 private Number value = null; 68 private String label = null; 69 70 private Map sectionHyperlinks; 71 private JRPrintHyperlink sectionHyperlink; 72 73 74 77 public JRFillPieDataset( 78 JRPieDataset pieDataset, 79 JRFillObjectFactory factory 80 ) 81 { 82 super(pieDataset, factory); 83 } 84 85 86 89 public JRExpression getKeyExpression() 90 { 91 return ((JRPieDataset)parent).getKeyExpression(); 92 } 93 94 97 public JRExpression getValueExpression() 98 { 99 return ((JRPieDataset)parent).getValueExpression(); 100 } 101 102 105 public JRExpression getLabelExpression() 106 { 107 return ((JRPieDataset)parent).getLabelExpression(); 108 } 109 110 111 114 protected void customInitialize() 115 { 116 dataset = new DefaultPieDataset(); 117 labels = new HashMap (); 118 sectionHyperlinks = new HashMap (); 119 } 120 121 124 protected void customEvaluate(JRCalculator calculator) throws JRExpressionEvalException 125 { 126 key = (Comparable )calculator.evaluate(getKeyExpression()); 127 value = (Number )calculator.evaluate(getValueExpression()); 128 label = (String )calculator.evaluate(getLabelExpression()); 129 130 if (hasSectionHyperlinks()) 131 { 132 evaluateSectionHyperlink(calculator); 133 } 134 } 135 136 137 protected void evaluateSectionHyperlink(JRCalculator calculator) throws JRExpressionEvalException 138 { 139 try 140 { 141 sectionHyperlink = JRFillHyperlinkHelper.evaluateHyperlink(getSectionHyperlink(), calculator, JRExpression.EVALUATION_DEFAULT); 142 } 143 catch (JRExpressionEvalException e) 144 { 145 throw e; 146 } 147 catch (JRException e) 148 { 149 throw new JRRuntimeException(e); 150 } 151 } 152 153 156 protected void customIncrement() 157 { 158 dataset.setValue(key, value); 159 labels.put( key, label ); 160 161 if (hasSectionHyperlinks()) 162 { 163 sectionHyperlinks.put(key, sectionHyperlink); 164 } 165 } 166 167 170 public Dataset getCustomDataset() 171 { 172 return dataset; 173 } 174 175 176 179 public byte getDatasetType() { 180 return JRChartDataset.PIE_DATASET; 181 } 182 183 184 public PieLabelGenerator getLabelGenerator(){ 185 return (getLabelExpression() == null) ? null : new PieLabelGenerator( labels ); 186 } 187 188 191 public void collectExpressions(JRExpressionCollector collector) 192 { 193 collector.collect(this); 194 } 195 196 197 public JRHyperlink getSectionHyperlink() 198 { 199 return ((JRPieDataset) parent).getSectionHyperlink(); 200 } 201 202 203 public boolean hasSectionHyperlinks() 204 { 205 return getSectionHyperlink() != null; 206 } 207 208 public Map getSectionHyperlinks() 209 { 210 return sectionHyperlinks; 211 } 212 213 214 public void validate(JRVerifier verifier) 215 { 216 verifier.verify(this); 217 } 218 219 } 220 | Popular Tags |