]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Code-level access to chart objects.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 8 Oct 2014 12:56:09 +0000 (12:56 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 8 Oct 2014 12:56:09 +0000 (12:56 +0000)
fixes #5376

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30386 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]

index 112b0f33ecfde9e5dca3c4143f7bbec4ea90f965..7ba5ea26f6ed689046f14d05056d6a1e507147b1 100644 (file)
@@ -11,7 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.jfreechart.chart;\r
 \r
-import java.util.ArrayList;\r
 import java.util.HashMap;\r
 \r
 import javax.swing.SwingUtilities;\r
@@ -77,9 +76,15 @@ public abstract class AbstractPlot implements IPlot {
     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
@@ -154,48 +159,9 @@ public abstract class AbstractPlot implements IPlot {
     \r
     @Override\r
     public void configurePlot(PlotProperties properties) {\r
-       // TODO Auto-generated method stub\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
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 b8d74bb0cea2e4c3241042d9e22ddb901dde1432..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
@@ -180,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 473ee385db562bafda2bcf5161b1fa1f02d11842..7a2beb4282c419f333e40b0dd955077f236a1e88 100644 (file)
@@ -15,7 +15,6 @@ import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.Plot;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.jfreechart.chart.AbstractPlot.PlotProperties;\r
 \r
 /**\r
  * Interface for JFreeChart.Plot type resource\r
@@ -42,6 +41,7 @@ public interface IPlot extends IJFreeChartComponent {
     \r
     public void configurePlot(PlotProperties properties);\r
     \r
+    public PlotProperties getPlotProperties();\r
     \r
     public void setJFreeChart(JFreeChart jfreechart);\r
     \r
index a6a66b728c2a4f30a12ca13790867569be01cc4e..2b39d630c1a80488771df6d2a818178c2b25df6f 100644 (file)
@@ -109,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 321c909a17b55b3dde42f651e92bb2bea71ad28c..c6242b6c90dbcbd4e555ea2527374e4f5d98c8ca 100644 (file)
@@ -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