01: package com.technoetic.xplanner.charts;
02:
03: import java.util.Date;
04: import java.util.Enumeration;
05: import java.util.Hashtable;
06: import java.util.Map;
07:
08: import de.laures.cewolf.DatasetProduceException;
09: import de.laures.cewolf.DatasetProducer;
10: import org.jfree.data.DefaultPieDataset;
11:
12: import com.technoetic.xplanner.db.IterationStatisticsQuery;
13:
14: /**
15: * User: Mateusz Prokopowicz
16: * Date: Apr 12, 2005
17: * Time: 3:25:26 PM
18: */
19: public abstract class XplannerPieChartData implements DatasetProducer {
20: protected DefaultPieDataset dataSet = new DefaultPieDataset();
21:
22: public void setStatistics(IterationStatisticsQuery statistics) {
23: Hashtable data = getData(statistics);
24: Enumeration enumeration = data.keys();
25:
26: while (enumeration.hasMoreElements()) {
27:
28: Object group = enumeration.nextElement();
29: String groupName = (group != null) ? group.toString()
30: : "null";
31:
32: double value = ((Double) data.get(groupName)).doubleValue();
33:
34: // Note, doubles are rounded to the nearest integer for clarity and ease of display
35: Long roundedValue = new Long(Math.round(value));
36: if (roundedValue.longValue() != 0) {
37: dataSet.setValue(groupName + " (" + roundedValue + ")",
38: roundedValue);
39: }
40: }
41: }
42:
43: protected abstract Hashtable getData(
44: IterationStatisticsQuery statistics);
45:
46: public Object produceDataset(Map params)
47: throws DatasetProduceException {
48: return dataSet;
49: }
50:
51: public boolean hasExpired(Map params, Date since) {
52: return true;
53: }
54:
55: public String getProducerId() {
56: return getClass().getName();
57: }
58: }
|