]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Merged trunk@30287, @30386 to branches/sysdyn-1.8 on 2014-10-16 for 1.8.2 release.
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 16 Oct 2014 07:34:05 +0000 (07:34 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 16 Oct 2014 07:34:05 +0000 (07:34 +0000)
refs #5376

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/1.8@30421 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.jfreechart/src/org/simantics/jfreechart/chart/AbstractPlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/CategoryPlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartComposite2.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/FilteringCategoryDataset.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IJFreeChart.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/IPlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/JFreeChart.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PlotProperties.java [new file with mode: 0644]
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/AxisDropAction.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ge/SeriesDropAction.java

index ebfba89205902108caaa9e2e6447c1ac1b018ea7..7ba5ea26f6ed689046f14d05056d6a1e507147b1 100644 (file)
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart;\r
 \r
-import java.util.ArrayList;\r
 import java.util.HashMap;\r
 \r
 import javax.swing.SwingUtilities;\r
 \r
+import org.jfree.chart.JFreeChart;\r
 import org.jfree.chart.axis.Axis;\r
 import org.jfree.chart.plot.Plot;\r
 import org.simantics.db.ReadGraph;\r
@@ -41,7 +41,7 @@ public abstract class AbstractPlot implements IPlot {
     protected Plot plot;\r
     protected PlotProperties currentProperties;\r
     private PlotPropertyListener listener;\r
-\r
+    private org.jfree.chart.JFreeChart jfreechart;\r
 \r
     public AbstractPlot(ReadGraph graph, Resource resource) {\r
         this.resource = resource;\r
@@ -67,9 +67,24 @@ public abstract class AbstractPlot implements IPlot {
     public Resource getResource() {\r
         return resource;\r
     }\r
+    \r
+    @Override\r
+    public void setJFreeChart(JFreeChart jfreechart) {\r
+       this.jfreechart = jfreechart;\r
+    }\r
+    \r
+    public org.jfree.chart.JFreeChart getJfreechart() {\r
+               return jfreechart;\r
+       }\r
+    \r
+    public PlotProperties getPlotProperties() {\r
+       return currentProperties;\r
+    }\r
 \r
     protected abstract Plot newPlot();\r
-    protected abstract void setPlotProperties(PlotProperties properties);\r
+    protected void setPlotProperties(PlotProperties properties) {\r
+       this.currentProperties = properties;\r
+    }\r
     protected abstract void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException;\r
 \r
     @Override\r
@@ -143,49 +158,10 @@ public abstract class AbstractPlot implements IPlot {
     }\r
     \r
     @Override\r
-    public void configurePlot() {\r
-       // TODO Auto-generated method stub\r
+    public void configurePlot(PlotProperties properties) {\r
        \r
     }\r
 \r
-    protected class PlotProperties {\r
-        public ArrayList<IAxis> ranges;\r
-        public ArrayList<IAxis> domains;\r
-        public ArrayList<IDataset> datasets;\r
-        public HashMap<IDataset, IAxis> rangeMappings;\r
-        public HashMap<IDataset, IAxis> domainMappings;\r
-        public HashMap<String, Object> otherProperties;\r
-        \r
-        public PlotProperties() {\r
-            datasets = new ArrayList<IDataset>();\r
-            rangeMappings = new HashMap<IDataset, IAxis>();\r
-            domainMappings = new HashMap<IDataset, IAxis>();\r
-            ranges = new ArrayList<IAxis>();\r
-            domains = new ArrayList<IAxis>();\r
-            otherProperties = new HashMap<String, Object>();\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object other) {\r
-            if(!this.getClass().equals(other.getClass()))\r
-                return false;\r
-            PlotProperties p = (PlotProperties)other;\r
-            if(!ranges.equals(p.ranges))\r
-                return false;\r
-            if(!domains.equals(p.domains))\r
-                return false;\r
-            if(!datasets.equals(p.datasets))\r
-                return false;\r
-            if(!rangeMappings.equals(p.rangeMappings))\r
-                return false;\r
-            if(!domainMappings.equals(p.domainMappings))\r
-                return false;\r
-            if(!otherProperties.equals(p.otherProperties))\r
-                return false;\r
-            return true;\r
-        }\r
-    }\r
-\r
     private class PlotPropertyListener implements Listener<PlotProperties> {\r
 \r
         private boolean disposed = false;\r
@@ -200,7 +176,7 @@ public abstract class AbstractPlot implements IPlot {
                 @Override\r
                 public void run() {\r
                     setPlotProperties(result);\r
-                    configurePlot();\r
+                    configurePlot(result);\r
                 }\r
             });\r
         }\r
index dd44e61bde95ce3eab029fd8c6a6e368ed64d84d..2bf3330938d6ccffe8e27b1d0b3e43638cc9a44a 100644 (file)
@@ -103,6 +103,7 @@ public class CategoryPlot extends AbstractPlot {
         // Cleaner look: no outline borders\r
         cplot.setInsets(new RectangleInsets(2,5,2,2), false);\r
         cplot.setOutlineVisible(false);\r
+        super.setPlotProperties(properties);\r
     }\r
 \r
     @Override\r
index 20a2c1cd98c104b587099d6c0c85c49d24bcdcb3..d3e169db30b3001ec376bb7c490ce17cfe798fd2 100644 (file)
@@ -82,7 +82,7 @@ public class ChartComposite2 extends SWTAWTComponent {
        return jPanel;\r
     }\r
        \r
-       private void setPanel(final ChartPanel panel) {\r
+       protected void setPanel(final ChartPanel panel) {\r
                ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
                        \r
                        @Override\r
@@ -101,6 +101,14 @@ public class ChartComposite2 extends SWTAWTComponent {
                        }\r
                });\r
        }\r
+       \r
+       public ChartPanel getChartPanel() {\r
+               return chartPanel;\r
+       }\r
+       \r
+       public IJFreeChart getChart() {\r
+               return chart;\r
+       }\r
 \r
     /**\r
      * Creates and displays the chart defined in chartResource\r
index df619550fa82eadcc2d4a148ac58313856fe6794..aa211ba71163c4d5dec875cf47cf27236d94ef81 100644 (file)
@@ -14,9 +14,11 @@ import java.util.List;
 \r
 import org.jfree.data.category.DefaultCategoryDataset;\r
 import org.jfree.data.general.AbstractDataset;\r
+import org.jfree.data.general.DatasetChangeEvent;\r
+import org.jfree.data.general.DatasetChangeListener;\r
 \r
 @SuppressWarnings("rawtypes")\r
-public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset{\r
+public class FilteringCategoryDataset extends AbstractDataset implements org.jfree.data.category.CategoryDataset, FilteredDataset, DatasetChangeListener{\r
        \r
        private static final long serialVersionUID = -4955124650051030544L;\r
        \r
@@ -34,6 +36,7 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr
                this.filtered = new DefaultCategoryDataset();\r
                this.other = other;\r
                this.used = filtered;\r
+               this.original.addChangeListener(this);\r
                updateFiltered();\r
        }\r
        \r
@@ -91,11 +94,10 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr
                                        if (Math.abs(value.doubleValue()) > total) {\r
                                                filtered.addValue(value, (Comparable) row, (Comparable)column);\r
                                        } else {\r
-                                               // TODO : what is proper way to handle negative values?\r
-                                               other += Math.abs(value.doubleValue()); \r
+                                               other += value.doubleValue(); \r
                                        }\r
                                }\r
-                               if (other > 0.0) {\r
+                               if (Math.abs(other) > 0.0) {\r
                                        filtered.addValue(other, this.other, (Comparable)column);\r
                                }\r
                        }\r
@@ -116,11 +118,10 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr
                                        if (Math.abs(value.doubleValue()) > total) {\r
                                                filtered.addValue(value, (Comparable) row, (Comparable)column);\r
                                        } else {\r
-                                               // TODO : what is proper way to handle negative values?\r
-                                               other += Math.abs(value.doubleValue()); \r
+                                               other += value.doubleValue(); \r
                                        }\r
                                }\r
-                               if (other > 0.0) {\r
+                               if (Math.abs(other) > 0.0) {\r
                                        filtered.addValue(other, (Comparable)row, this.other);\r
                                }\r
                        }\r
@@ -182,7 +183,11 @@ public class FilteringCategoryDataset extends AbstractDataset implements org.jfr
                return other;\r
        }\r
        \r
-       \r
+       @Override\r
+       public void datasetChanged(DatasetChangeEvent event) {\r
+               // bypass change events from the original dataset.\r
+               fireDatasetChanged();\r
+       }\r
        \r
 \r
 }\r
index f03d7b4573bbb42067a321e846562fd496c014ea..44569d6a02e1b14574ec2168d94da70a09bdd888 100644 (file)
@@ -29,4 +29,6 @@ public interface IJFreeChart extends IJFreeChartComponent {
      */\r
     public JFreeChart getChart();\r
     \r
+    public IPlot getPlot();\r
+    \r
 }\r
index c040a5f5b7402038a8305d5b46afa315316715e7..7a2beb4282c419f333e40b0dd955077f236a1e88 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart;\r
 \r
+import org.jfree.chart.JFreeChart;\r
 import org.jfree.chart.plot.Plot;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -38,6 +39,11 @@ public interface IPlot extends IJFreeChartComponent {
      */\r
     public Resource getResource();\r
     \r
-    public void configurePlot();\r
+    public void configurePlot(PlotProperties properties);\r
     \r
+    public PlotProperties getPlotProperties();\r
+    \r
+    public void setJFreeChart(JFreeChart jfreechart);\r
+    \r
+    public JFreeChart getJfreechart();\r
 }\r
index ea8df3d66f4d66c770f22cbd48097b03acd34e4c..2b39d630c1a80488771df6d2a818178c2b25df6f 100644 (file)
@@ -84,7 +84,9 @@ public class JFreeChart implements IJFreeChart {
 \r
         if(jfreechart == null)\r
             jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
-\r
+        \r
+        plot.setJFreeChart(jfreechart);\r
+        \r
         if(listener == null) {\r
             listener = new JFreeChartListener();\r
             SimanticsUI.getSession().asyncRequest(new Read<Pair<ITitle, Boolean>>() {\r
@@ -107,6 +109,11 @@ public class JFreeChart implements IJFreeChart {
 \r
         return jfreechart;\r
     }\r
+    \r
+    @Override\r
+    public IPlot getPlot() {\r
+       return plot;\r
+    }\r
 \r
     @Override\r
     public void dispose() {\r
index 9c4f1193ce00a765a52925a517a46e4860dace9d..c6242b6c90dbcbd4e555ea2527374e4f5d98c8ca 100644 (file)
@@ -49,7 +49,7 @@ public class PiePlot extends AbstractPlot {
      * @author Teemu Lempinen\r
      *\r
      */\r
-    private class MyPiePlot extends org.jfree.chart.plot.PiePlot {\r
+    protected static class MyPiePlot extends org.jfree.chart.plot.PiePlot {\r
 \r
         private static final long serialVersionUID = -5917620061541212934L;\r
 \r
@@ -89,10 +89,10 @@ public class PiePlot extends AbstractPlot {
     @SuppressWarnings({ "unchecked", "rawtypes" })\r
     @Override\r
     protected void setPlotProperties(PlotProperties properties) {\r
-        if(!(plot instanceof MyPiePlot))\r
+        if(!(plot instanceof org.jfree.chart.plot.PiePlot))\r
             return;\r
         \r
-        final MyPiePlot piePlot = (MyPiePlot)plot;\r
+        final org.jfree.chart.plot.PiePlot piePlot = (org.jfree.chart.plot.PiePlot)plot;\r
         \r
         if(!properties.datasets.isEmpty()) {\r
             // We assume that a pie plot has only one dataset\r
@@ -167,6 +167,7 @@ public class PiePlot extends AbstractPlot {
         piePlot.setOutlineVisible(false);\r
         piePlot.setLabelBackgroundPaint(Color.WHITE);\r
         piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11));\r
+        super.setPlotProperties(properties);\r
     }\r
 \r
 }\r
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 (file)
index 0000000..37c21bc
--- /dev/null
@@ -0,0 +1,44 @@
+package org.simantics.jfreechart.chart;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+public class PlotProperties {\r
+        \r
+        public ArrayList<IAxis> ranges;\r
+        public ArrayList<IAxis> domains;\r
+        public ArrayList<IDataset> datasets;\r
+        public HashMap<IDataset, IAxis> rangeMappings;\r
+        public HashMap<IDataset, IAxis> domainMappings;\r
+        public HashMap<String, Object> otherProperties;\r
+        \r
+        public PlotProperties() {\r
+            datasets = new ArrayList<IDataset>();\r
+            rangeMappings = new HashMap<IDataset, IAxis>();\r
+            domainMappings = new HashMap<IDataset, IAxis>();\r
+            ranges = new ArrayList<IAxis>();\r
+            domains = new ArrayList<IAxis>();\r
+            otherProperties = new HashMap<String, Object>();\r
+        }\r
+\r
+        @Override\r
+        public boolean equals(Object other) {\r
+            if(!this.getClass().equals(other.getClass()))\r
+                return false;\r
+            PlotProperties p = (PlotProperties)other;\r
+            if(!ranges.equals(p.ranges))\r
+                return false;\r
+            if(!domains.equals(p.domains))\r
+                return false;\r
+            if(!datasets.equals(p.datasets))\r
+                return false;\r
+            if(!rangeMappings.equals(p.rangeMappings))\r
+                return false;\r
+            if(!domainMappings.equals(p.domainMappings))\r
+                return false;\r
+            if(!otherProperties.equals(p.otherProperties))\r
+                return false;\r
+            return true;\r
+        }\r
+          \r
+}\r
index 20f79bb0276fd28c30408c5eb7e0171868a555d6..40bca222405f68e5dfa02ff6d1b54429393a14c3 100644 (file)
@@ -34,7 +34,7 @@ import org.simantics.utils.ui.AdaptionUtils;
 public class AxisDropAction  implements DropActionFactory {\r
 \r
     @Override\r
-    public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException {\r
+    public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {\r
         // Make sure that both target and source are resources\r
         Resource t = AdaptionUtils.adaptToSingle(target, Resource.class);\r
         Resource s = AdaptionUtils.adaptToSingle(source, Resource.class);\r
index 5870cd5290c528e717b594766a5c7e90b3709c99..41c6bb69cfe9443aebf9ce207f21e84dacf7939c 100644 (file)
@@ -38,7 +38,7 @@ import org.simantics.utils.ui.AdaptionUtils;
 public class SeriesDropAction implements DropActionFactory {\r
 \r
     @Override\r
-    public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException {\r
+    public Runnable create(ReadGraph g, Object target, Object source, int operation) throws DatabaseException {\r
         // Make sure that both target and source are resources\r
         Resource t = AdaptionUtils.adaptToSingle(target, Resource.class);\r
         Resource s = AdaptionUtils.adaptToSingle(source, Resource.class);\r