From: luukkainen Date: Wed, 8 Oct 2014 12:56:09 +0000 (+0000) Subject: Code-level access to chart objects. X-Git-Tag: v1.29.0~166 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=0d2d4b2e4d1b7398314c6e8a19a2840705ac1289;p=simantics%2Fsysdyn.git Code-level access to chart objects. fixes #5376 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30386 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/AbstractPlot.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/AbstractPlot.java index 112b0f33..7ba5ea26 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/AbstractPlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/AbstractPlot.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.simantics.jfreechart.chart; -import java.util.ArrayList; import java.util.HashMap; import javax.swing.SwingUtilities; @@ -77,9 +76,15 @@ public abstract class AbstractPlot implements IPlot { public org.jfree.chart.JFreeChart getJfreechart() { return jfreechart; } + + public PlotProperties getPlotProperties() { + return currentProperties; + } protected abstract Plot newPlot(); - protected abstract void setPlotProperties(PlotProperties properties); + protected void setPlotProperties(PlotProperties properties) { + this.currentProperties = properties; + } protected abstract void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException; @Override @@ -154,48 +159,9 @@ public abstract class AbstractPlot implements IPlot { @Override public void configurePlot(PlotProperties properties) { - // TODO Auto-generated method stub } - protected class PlotProperties { - public ArrayList ranges; - public ArrayList domains; - public ArrayList datasets; - public HashMap rangeMappings; - public HashMap domainMappings; - public HashMap otherProperties; - - public PlotProperties() { - datasets = new ArrayList(); - rangeMappings = new HashMap(); - domainMappings = new HashMap(); - ranges = new ArrayList(); - domains = new ArrayList(); - otherProperties = new HashMap(); - } - - @Override - public boolean equals(Object other) { - if(!this.getClass().equals(other.getClass())) - return false; - PlotProperties p = (PlotProperties)other; - if(!ranges.equals(p.ranges)) - return false; - if(!domains.equals(p.domains)) - return false; - if(!datasets.equals(p.datasets)) - return false; - if(!rangeMappings.equals(p.rangeMappings)) - return false; - if(!domainMappings.equals(p.domainMappings)) - return false; - if(!otherProperties.equals(p.otherProperties)) - return false; - return true; - } - } - private class PlotPropertyListener implements Listener { private boolean disposed = false; diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/CategoryPlot.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/CategoryPlot.java index dd44e61b..2bf33309 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/CategoryPlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/CategoryPlot.java @@ -103,6 +103,7 @@ public class CategoryPlot extends AbstractPlot { // Cleaner look: no outline borders cplot.setInsets(new RectangleInsets(2,5,2,2), false); cplot.setOutlineVisible(false); + super.setPlotProperties(properties); } @Override diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartComposite2.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartComposite2.java index 20a2c1cd..d3e169db 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartComposite2.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartComposite2.java @@ -82,7 +82,7 @@ public class ChartComposite2 extends SWTAWTComponent { return jPanel; } - private void setPanel(final ChartPanel panel) { + protected void setPanel(final ChartPanel panel) { ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() { @Override @@ -101,6 +101,14 @@ public class ChartComposite2 extends SWTAWTComponent { } }); } + + public ChartPanel getChartPanel() { + return chartPanel; + } + + public IJFreeChart getChart() { + return chart; + } /** * Creates and displays the chart defined in chartResource diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java index b8d74bb0..aa211ba7 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java @@ -14,9 +14,11 @@ import java.util.List; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.AbstractDataset; +import org.jfree.data.general.DatasetChangeEvent; +import org.jfree.data.general.DatasetChangeListener; @SuppressWarnings("rawtypes") -public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset{ +public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset, DatasetChangeListener{ private static final long serialVersionUID = -4955124650051030544L; @@ -34,6 +36,7 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr this.filtered = new DefaultCategoryDataset(); this.other = other; this.used = filtered; + this.original.addChangeListener(this); updateFiltered(); } @@ -180,7 +183,11 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr return other; } - + @Override + public void datasetChanged(DatasetChangeEvent event) { + // bypass change events from the original dataset. + fireDatasetChanged(); + } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IJFreeChart.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IJFreeChart.java index f03d7b45..44569d6a 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IJFreeChart.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IJFreeChart.java @@ -29,4 +29,6 @@ public interface IJFreeChart extends IJFreeChartComponent { */ public JFreeChart getChart(); + public IPlot getPlot(); + } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java index 473ee385..7a2beb42 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java @@ -15,7 +15,6 @@ import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.Plot; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; -import org.simantics.jfreechart.chart.AbstractPlot.PlotProperties; /** * Interface for JFreeChart.Plot type resource @@ -42,6 +41,7 @@ public interface IPlot extends IJFreeChartComponent { public void configurePlot(PlotProperties properties); + public PlotProperties getPlotProperties(); public void setJFreeChart(JFreeChart jfreechart); diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java index a6a66b72..2b39d630 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java @@ -109,6 +109,11 @@ public class JFreeChart implements IJFreeChart { return jfreechart; } + + @Override + public IPlot getPlot() { + return plot; + } @Override public void dispose() { diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java index 321c909a..c6242b6c 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java @@ -167,6 +167,7 @@ public class PiePlot extends AbstractPlot { piePlot.setOutlineVisible(false); piePlot.setLabelBackgroundPaint(Color.WHITE); piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); + super.setPlotProperties(properties); } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PlotProperties.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PlotProperties.java new file mode 100644 index 00000000..37c21bc2 --- /dev/null +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PlotProperties.java @@ -0,0 +1,44 @@ +package org.simantics.jfreechart.chart; + +import java.util.ArrayList; +import java.util.HashMap; + +public class PlotProperties { + + public ArrayList ranges; + public ArrayList domains; + public ArrayList datasets; + public HashMap rangeMappings; + public HashMap domainMappings; + public HashMap otherProperties; + + public PlotProperties() { + datasets = new ArrayList(); + rangeMappings = new HashMap(); + domainMappings = new HashMap(); + ranges = new ArrayList(); + domains = new ArrayList(); + otherProperties = new HashMap(); + } + + @Override + public boolean equals(Object other) { + if(!this.getClass().equals(other.getClass())) + return false; + PlotProperties p = (PlotProperties)other; + if(!ranges.equals(p.ranges)) + return false; + if(!domains.equals(p.domains)) + return false; + if(!datasets.equals(p.datasets)) + return false; + if(!rangeMappings.equals(p.rangeMappings)) + return false; + if(!domainMappings.equals(p.domainMappings)) + return false; + if(!otherProperties.equals(p.otherProperties)) + return false; + return true; + } + +}