1 | package de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation; |
2 | |
3 | import java.util.Collection; |
4 | |
5 | import org.eclipse.swt.widgets.Composite; |
6 | import org.jfree.chart.ChartFactory; |
7 | import org.jfree.data.general.DefaultPieDataset; |
8 | |
9 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.AbstractPie; |
10 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.PieEntity; |
11 | |
12 | public class JFreeChartPieViewer extends AbstractJFreeChartChart<AbstractPie> { |
13 | |
14 | DefaultPieDataset pieDataset=null; |
15 | |
16 | public JFreeChartPieViewer(Composite parent, int style) { |
17 | super(parent, style); |
18 | } |
19 | |
20 | protected void initChart() { |
21 | if(pieDataset != null) |
22 | chart = ChartFactory.createPieChart3D("Pie", pieDataset, true, true, true); |
23 | else |
24 | chart = ChartFactory.createPieChart3D("Pie", new DefaultPieDataset(), true, true, true); |
25 | } |
26 | |
27 | public void setData(Collection<AbstractPie> data){ |
28 | assert((data.size() == 1) && (data.iterator().next() instanceof AbstractPie)); |
29 | |
30 | AbstractPie pie = (AbstractPie)data.iterator().next(); |
31 | |
32 | pieDataset = new DefaultPieDataset(); |
33 | for (PieEntity pe : pie.getEntities(40)){ |
34 | pieDataset.setValue(pe.getLabel(), pe.getValue()); |
35 | } |
36 | initChart(); |
37 | chart.setTitle(pie.getLabel()); |
38 | this.setChart(chart); |
39 | |
40 | this.forceRedraw(); |
41 | } |
42 | } |