From: lempinen Date: Wed, 7 Dec 2011 12:50:54 +0000 (+0000) Subject: Moved chart modifications to awt thread X-Git-Tag: simantics-1.6~78 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=35da83644ee1a8b3f51235d40a10cd7b44b6376c;p=simantics%2Fsysdyn.git Moved chart modifications to awt thread git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23437 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java index 661fdf48..87aa81ce 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java @@ -11,7 +11,9 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; -import java.util.HashMap; +import java.util.Collection; + +import javax.swing.SwingUtilities; import org.jfree.chart.title.LegendTitle; import org.simantics.databoard.Bindings; @@ -39,8 +41,7 @@ public class JFreeChart implements IJFreeChart { private ITitle title; private Boolean legendVisible; - private HashMap plots; - private IPlot firstPlot = null; + private IPlot plot; /** * @@ -56,15 +57,11 @@ public class JFreeChart implements IJFreeChart { title = graph.adapt(titleResource, ITitle.class); legendVisible = graph.getPossibleRelatedValue(chartResource, jfree.Chart_visibleLegend, Bindings.BOOLEAN); - plots = new HashMap(); - for(Resource plotResource : graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot))) { - IPlot plot = graph.adapt(plotResource, IPlot.class); - plots.put(plotResource, plot); - if(firstPlot == null) - firstPlot = plot; + Collection plotsCollection = graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot)); + for(Resource plotResource : plotsCollection) { + this.plot = graph.adapt(plotResource, IPlot.class); } - } catch(DatabaseException e) { e.printStackTrace(); } @@ -75,21 +72,27 @@ public class JFreeChart implements IJFreeChart { */ @Override public org.jfree.chart.JFreeChart getChart() { - if(plots.size() == 0) + if(plot == null) return null; - jfreechart = new org.jfree.chart.JFreeChart(firstPlot.getPlot()); - - // setVisible does not work in TextTitle, have to use this workaround - org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); - if(t.isVisible()) - jfreechart.setTitle(t); - - if(legendVisible != null && !legendVisible) { - for(Object title : jfreechart.getSubtitles()) { - if(title instanceof LegendTitle) - ((LegendTitle)title).setVisible(legendVisible); + jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + // setVisible does not work in TextTitle, have to use this workaround + org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); + if(t.isVisible()) + jfreechart.setTitle(t); + + if(legendVisible != null && !legendVisible) { + for(Object title : jfreechart.getSubtitles()) { + if(title instanceof LegendTitle) + ((LegendTitle)title).setVisible(legendVisible); + } + } } - } + }); return jfreechart; } @@ -97,7 +100,7 @@ public class JFreeChart implements IJFreeChart { public void dispose() { // Call dispose to title and plots to disable their possible listeners title.dispose(); - for(IPlot plot : plots.values()) + if(plot != null) plot.dispose(); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java index 62cc00d5..b3b07e49 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java @@ -14,6 +14,8 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.Color; import java.util.HashMap; +import javax.swing.SwingUtilities; + import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.Plot; import org.jfree.data.general.Dataset; @@ -43,25 +45,30 @@ public class PiePlot extends AbstractPlot { if(!datasets.isEmpty()) { // We assume that a pie plot has only one dataset IDataset ds = datasets.get(0); - Dataset dataset = ((PieDataset)ds).getDataset(); + final Dataset dataset = ((PieDataset)ds).getDataset(); + final HashMap colorMap = ((PieDataset)ds).getColorMap(); + final HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); if(dataset instanceof org.jfree.data.general.PieDataset) { - plot.clearSectionPaints(true); - plot.setDrawingSupplier(new DefaultDrawingSupplier()); - plot.setDataset(null); - - org.jfree.data.general.PieDataset pieDataset = (org.jfree.data.general.PieDataset)dataset; - plot.setDataset(pieDataset); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + plot.clearSectionPaints(true); + plot.setDrawingSupplier(new DefaultDrawingSupplier()); + + org.jfree.data.general.PieDataset pieDataset = (org.jfree.data.general.PieDataset)dataset; + plot.setDataset(pieDataset); - HashMap colorMap = ((PieDataset)ds).getColorMap(); - for(String name : colorMap.keySet()) - plot.setSectionPaint(name, colorMap.get(name)); + for(String name : colorMap.keySet()) + plot.setSectionPaint(name, colorMap.get(name)); - HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); - for(String name : explodedMap.keySet()) { - Boolean exploded = explodedMap.get(name); - if(Boolean.TRUE.equals(exploded)) - plot.setExplodePercent(name, 0.3); - } + for(String name : explodedMap.keySet()) { + Boolean exploded = explodedMap.get(name); + if(Boolean.TRUE.equals(exploded)) + plot.setExplodePercent(name, 0.3); + } + } + }); } } return plot;