From: jsimomaa Date: Thu, 16 Oct 2014 07:34:05 +0000 (+0000) Subject: Merged trunk@30287, @30386 to branches/sysdyn-1.8 on 2014-10-16 for 1.8.2 release. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d8369ba2dba9fa53095b45fe9cd40f94b4328b32;p=simantics%2Fsysdyn.git Merged trunk@30287, @30386 to branches/sysdyn-1.8 on 2014-10-16 for 1.8.2 release. refs #5376 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/1.8@30421 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 ebfba892..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,11 +11,11 @@ *******************************************************************************/ package org.simantics.jfreechart.chart; -import java.util.ArrayList; import java.util.HashMap; import javax.swing.SwingUtilities; +import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.Axis; import org.jfree.chart.plot.Plot; import org.simantics.db.ReadGraph; @@ -41,7 +41,7 @@ public abstract class AbstractPlot implements IPlot { protected Plot plot; protected PlotProperties currentProperties; private PlotPropertyListener listener; - + private org.jfree.chart.JFreeChart jfreechart; public AbstractPlot(ReadGraph graph, Resource resource) { this.resource = resource; @@ -67,9 +67,24 @@ public abstract class AbstractPlot implements IPlot { public Resource getResource() { return resource; } + + @Override + public void setJFreeChart(JFreeChart jfreechart) { + this.jfreechart = jfreechart; + } + + 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 @@ -143,49 +158,10 @@ public abstract class AbstractPlot implements IPlot { } @Override - public void configurePlot() { - // TODO Auto-generated method stub + public void configurePlot(PlotProperties properties) { } - 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; @@ -200,7 +176,7 @@ public abstract class AbstractPlot implements IPlot { @Override public void run() { setPlotProperties(result); - configurePlot(); + configurePlot(result); } }); } 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 df619550..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(); } @@ -91,11 +94,10 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr if (Math.abs(value.doubleValue()) > total) { filtered.addValue(value, (Comparable) row, (Comparable)column); } else { - // TODO : what is proper way to handle negative values? - other += Math.abs(value.doubleValue()); + other += value.doubleValue(); } } - if (other > 0.0) { + if (Math.abs(other) > 0.0) { filtered.addValue(other, this.other, (Comparable)column); } } @@ -116,11 +118,10 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr if (Math.abs(value.doubleValue()) > total) { filtered.addValue(value, (Comparable) row, (Comparable)column); } else { - // TODO : what is proper way to handle negative values? - other += Math.abs(value.doubleValue()); + other += value.doubleValue(); } } - if (other > 0.0) { + if (Math.abs(other) > 0.0) { filtered.addValue(other, (Comparable)row, this.other); } } @@ -182,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 c040a5f5..7a2beb42 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.jfreechart.chart; +import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.Plot; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; @@ -38,6 +39,11 @@ public interface IPlot extends IJFreeChartComponent { */ public Resource getResource(); - public void configurePlot(); + public void configurePlot(PlotProperties properties); + public PlotProperties getPlotProperties(); + + public void setJFreeChart(JFreeChart jfreechart); + + public JFreeChart getJfreechart(); } 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 ea8df3d6..2b39d630 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java @@ -84,7 +84,9 @@ public class JFreeChart implements IJFreeChart { if(jfreechart == null) jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); - + + plot.setJFreeChart(jfreechart); + if(listener == null) { listener = new JFreeChartListener(); SimanticsUI.getSession().asyncRequest(new Read>() { @@ -107,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 9c4f1193..c6242b6c 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java @@ -49,7 +49,7 @@ public class PiePlot extends AbstractPlot { * @author Teemu Lempinen * */ - private class MyPiePlot extends org.jfree.chart.plot.PiePlot { + protected static class MyPiePlot extends org.jfree.chart.plot.PiePlot { private static final long serialVersionUID = -5917620061541212934L; @@ -89,10 +89,10 @@ public class PiePlot extends AbstractPlot { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void setPlotProperties(PlotProperties properties) { - if(!(plot instanceof MyPiePlot)) + if(!(plot instanceof org.jfree.chart.plot.PiePlot)) return; - final MyPiePlot piePlot = (MyPiePlot)plot; + final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot; if(!properties.datasets.isEmpty()) { // We assume that a pie plot has only one dataset @@ -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; + } + +} diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/AxisDropAction.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/AxisDropAction.java index 20f79bb0..40bca222 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/AxisDropAction.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/AxisDropAction.java @@ -34,7 +34,7 @@ import org.simantics.utils.ui.AdaptionUtils; public class AxisDropAction implements DropActionFactory { @Override - public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException { // Make sure that both target and source are resources Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/SeriesDropAction.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/SeriesDropAction.java index 5870cd52..41c6bb69 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/SeriesDropAction.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/SeriesDropAction.java @@ -38,7 +38,7 @@ import org.simantics.utils.ui.AdaptionUtils; public class SeriesDropAction implements DropActionFactory { @Override - public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { + public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException { // Make sure that both target and source are resources Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); Resource s = AdaptionUtils.adaptToSingle(source, Resource.class);