*******************************************************************************/\r
package org.simantics.sysdyn.ui.trend.chart;\r
\r
-import java.util.HashMap;\r
+import java.util.Collection;\r
+\r
+import javax.swing.SwingUtilities;\r
\r
import org.jfree.chart.title.LegendTitle;\r
import org.simantics.databoard.Bindings;\r
private ITitle title;\r
private Boolean legendVisible;\r
\r
- private HashMap<Resource, IPlot> plots;\r
- private IPlot firstPlot = null;\r
+ private IPlot plot;\r
\r
/**\r
* \r
title = graph.adapt(titleResource, ITitle.class);\r
legendVisible = graph.getPossibleRelatedValue(chartResource, jfree.Chart_visibleLegend, Bindings.BOOLEAN);\r
\r
- plots = new HashMap<Resource, IPlot>();\r
- for(Resource plotResource : graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot))) {\r
- IPlot plot = graph.adapt(plotResource, IPlot.class);\r
- plots.put(plotResource, plot);\r
- if(firstPlot == null)\r
- firstPlot = plot;\r
+ Collection<Resource> plotsCollection = graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot));\r
+ for(Resource plotResource : plotsCollection) {\r
+ this.plot = graph.adapt(plotResource, IPlot.class);\r
} \r
\r
-\r
} catch(DatabaseException e) {\r
e.printStackTrace();\r
}\r
*/\r
@Override\r
public org.jfree.chart.JFreeChart getChart() {\r
- if(plots.size() == 0)\r
+ if(plot == null)\r
return null;\r
- jfreechart = new org.jfree.chart.JFreeChart(firstPlot.getPlot());\r
-\r
- // setVisible does not work in TextTitle, have to use this workaround \r
- org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle();\r
- if(t.isVisible())\r
- jfreechart.setTitle(t);\r
-\r
- if(legendVisible != null && !legendVisible) {\r
- for(Object title : jfreechart.getSubtitles()) {\r
- if(title instanceof LegendTitle)\r
- ((LegendTitle)title).setVisible(legendVisible);\r
+ jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
+\r
+ SwingUtilities.invokeLater(new Runnable() {\r
+ \r
+ @Override\r
+ public void run() {\r
+ // setVisible does not work in TextTitle, have to use this workaround \r
+ org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle();\r
+ if(t.isVisible())\r
+ jfreechart.setTitle(t);\r
+\r
+ if(legendVisible != null && !legendVisible) {\r
+ for(Object title : jfreechart.getSubtitles()) {\r
+ if(title instanceof LegendTitle)\r
+ ((LegendTitle)title).setVisible(legendVisible);\r
+ }\r
+ }\r
}\r
- }\r
+ });\r
return jfreechart;\r
}\r
\r
public void dispose() {\r
// Call dispose to title and plots to disable their possible listeners\r
title.dispose();\r
- for(IPlot plot : plots.values())\r
+ if(plot != null)\r
plot.dispose();\r
}\r
\r
import java.awt.Color;\r
import java.util.HashMap;\r
\r
+import javax.swing.SwingUtilities;\r
+\r
import org.jfree.chart.plot.DefaultDrawingSupplier;\r
import org.jfree.chart.plot.Plot;\r
import org.jfree.data.general.Dataset;\r
if(!datasets.isEmpty()) {\r
// We assume that a pie plot has only one dataset\r
IDataset ds = datasets.get(0);\r
- Dataset dataset = ((PieDataset)ds).getDataset();\r
+ final Dataset dataset = ((PieDataset)ds).getDataset();\r
+ final HashMap<String, Color> colorMap = ((PieDataset)ds).getColorMap();\r
+ final HashMap<String, Boolean> explodedMap = ((PieDataset)ds).getExplodedMap();\r
if(dataset instanceof org.jfree.data.general.PieDataset) {\r
- plot.clearSectionPaints(true);\r
- plot.setDrawingSupplier(new DefaultDrawingSupplier());\r
- plot.setDataset(null);\r
- \r
- org.jfree.data.general.PieDataset pieDataset = (org.jfree.data.general.PieDataset)dataset;\r
- plot.setDataset(pieDataset);\r
+ SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ plot.clearSectionPaints(true);\r
+ plot.setDrawingSupplier(new DefaultDrawingSupplier());\r
+\r
+ org.jfree.data.general.PieDataset pieDataset = (org.jfree.data.general.PieDataset)dataset;\r
+ plot.setDataset(pieDataset);\r
\r
- HashMap<String, Color> colorMap = ((PieDataset)ds).getColorMap();\r
- for(String name : colorMap.keySet())\r
- plot.setSectionPaint(name, colorMap.get(name));\r
+ for(String name : colorMap.keySet())\r
+ plot.setSectionPaint(name, colorMap.get(name));\r
\r
- HashMap<String, Boolean> explodedMap = ((PieDataset)ds).getExplodedMap();\r
- for(String name : explodedMap.keySet()) {\r
- Boolean exploded = explodedMap.get(name);\r
- if(Boolean.TRUE.equals(exploded))\r
- plot.setExplodePercent(name, 0.3);\r
- } \r
+ for(String name : explodedMap.keySet()) {\r
+ Boolean exploded = explodedMap.get(name);\r
+ if(Boolean.TRUE.equals(exploded))\r
+ plot.setExplodePercent(name, 0.3);\r
+ } \r
+ }\r
+ });\r
}\r
}\r
return plot;\r