]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Time property for pie and bar charts
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 14 Dec 2011 06:37:07 +0000 (06:37 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 14 Dec 2011 06:37:07 +0000 (06:37 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23538 ac1ea38d-2e2b-0410-8846-a27921b304fc

25 files changed:
org.simantics.jfreechart.ontology/META-INF/MANIFEST.MF
org.simantics.jfreechart.ontology/graph.tg
org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph
org.simantics.jfreechart.ontology/src/org/simantics/sysdyn/JFreeChartResource.java
org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/icons/chart_bar_light.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/chart_line_light.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/chart_pie_light.png [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java

index 6ab2f810ed290b9126ff53fff81d378e15d45e78..c792a6a04f3c542e8e63ec746b205d3639ec28b1 100644 (file)
@@ -5,6 +5,9 @@ Bundle-SymbolicName: org.simantics.jfreechart.ontology
 Bundle-Version: 0.1.0.qualifier
 Require-Bundle: org.simantics.layer0,
  org.simantics.layer0x.ontology;bundle-version="1.0.0",
- org.simantics.g2d.ontology;bundle-version="1.0.0"
+ org.simantics.g2d.ontology;bundle-version="1.0.0",
+ org.simantics.diagram.ontology;bundle-version="2.1.0",
+ org.simantics.structural.ontology;bundle-version="1.1.0",
+ org.simantics.modeling.ontology;bundle-version="1.1.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Export-Package: org.simantics.sysdyn
index d250dc962037c81ecad6348996061b139869e416..32d291bd66ab100b8531c63ed4ed5c748555e2ba 100644 (file)
Binary files a/org.simantics.jfreechart.ontology/graph.tg and b/org.simantics.jfreechart.ontology/graph.tg differ
index 2526730c6ff753dd024f365beb734e5fe3c26141..5aa93b6ba1814e56190b8a9b786f15ef7a134926 100644 (file)
@@ -1,6 +1,9 @@
 L0 = <http://www.simantics.org/Layer0-1.0>
 L0X = <http://www.simantics.org/Layer0X-1.0>
 G2D = <http://www.simantics.org/G2D-1.0>
+DIA = <http://www.simantics.org/Diagram-2.1>
+MOD = <http://www.simantics.org/Modeling-1.1>
+STR = <http://www.simantics.org/Structural-1.0>
 
 //#####################################################################
 // Ontology for defining JFreeChart charts
@@ -20,6 +23,7 @@ JFREE.Chart <T L0.Entity
     >-- JFREE.Chart.visibleBorder --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
     >-- JFREE.Chart.borderWidth --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- JFREE.Chart.visibleLegend --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
+    >-- JFREE.Chart.time --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
 
 //#####################################################################
 // Titles
@@ -112,4 +116,12 @@ JFREE.Bottom <T JFREE.Position
 JFREE.Top <T JFREE.Position
 JFREE.Left <T JFREE.Position
 JFREE.Right <T JFREE.Position
+
+
+//#####################################################################
+// Symbol
+//#####################################################################
+JFREE.ChartElement <T DIA.Element
+    L0.HasDescription "Element for displaying charts in diagrams"
+    >-- JFREE.ChartElement.component --> JFREE.Chart <R L0.IsWeaklyRelatedTo
         
\ No newline at end of file
index a748d41191639682df8f093955ea6f169f9fe50f..d70aca9edcf8fe3fe36e93860a03248175751b5b 100644 (file)
@@ -29,10 +29,14 @@ public class JFreeChartResource {
     public final Resource CategoryDataset;\r
     public final Resource CategoryPlot;\r
     public final Resource Chart;\r
+    public final Resource ChartElement;\r
+    public final Resource ChartElement_component;\r
     public final Resource Chart_borderColor;\r
     public final Resource Chart_borderColor_Inverse;\r
     public final Resource Chart_borderWidth;\r
     public final Resource Chart_borderWidth_Inverse;\r
+    public final Resource Chart_time;\r
+    public final Resource Chart_time_Inverse;\r
     public final Resource Chart_visibleBorder;\r
     public final Resource Chart_visibleBorder_Inverse;\r
     public final Resource Chart_visibleLegend;\r
@@ -122,10 +126,14 @@ public class JFreeChartResource {
         public static final String CategoryDataset = "http://www.simantics.org/JFreeChart-1.0/CategoryDataset";\r
         public static final String CategoryPlot = "http://www.simantics.org/JFreeChart-1.0/CategoryPlot";\r
         public static final String Chart = "http://www.simantics.org/JFreeChart-1.0/Chart";\r
+        public static final String ChartElement = "http://www.simantics.org/JFreeChart-1.0/ChartElement";\r
+        public static final String ChartElement_component = "http://www.simantics.org/JFreeChart-1.0/ChartElement/component";\r
         public static final String Chart_borderColor = "http://www.simantics.org/JFreeChart-1.0/Chart/borderColor";\r
         public static final String Chart_borderColor_Inverse = "http://www.simantics.org/JFreeChart-1.0/Chart/borderColor/Inverse";\r
         public static final String Chart_borderWidth = "http://www.simantics.org/JFreeChart-1.0/Chart/borderWidth";\r
         public static final String Chart_borderWidth_Inverse = "http://www.simantics.org/JFreeChart-1.0/Chart/borderWidth/Inverse";\r
+        public static final String Chart_time = "http://www.simantics.org/JFreeChart-1.0/Chart/time";\r
+        public static final String Chart_time_Inverse = "http://www.simantics.org/JFreeChart-1.0/Chart/time/Inverse";\r
         public static final String Chart_visibleBorder = "http://www.simantics.org/JFreeChart-1.0/Chart/visibleBorder";\r
         public static final String Chart_visibleBorder_Inverse = "http://www.simantics.org/JFreeChart-1.0/Chart/visibleBorder/Inverse";\r
         public static final String Chart_visibleLegend = "http://www.simantics.org/JFreeChart-1.0/Chart/visibleLegend";\r
@@ -225,10 +233,14 @@ public class JFreeChartResource {
         CategoryDataset = getResourceOrNull(graph, URIs.CategoryDataset);\r
         CategoryPlot = getResourceOrNull(graph, URIs.CategoryPlot);\r
         Chart = getResourceOrNull(graph, URIs.Chart);\r
+        ChartElement = getResourceOrNull(graph, URIs.ChartElement);\r
+        ChartElement_component = getResourceOrNull(graph, URIs.ChartElement_component);\r
         Chart_borderColor = getResourceOrNull(graph, URIs.Chart_borderColor);\r
         Chart_borderColor_Inverse = getResourceOrNull(graph, URIs.Chart_borderColor_Inverse);\r
         Chart_borderWidth = getResourceOrNull(graph, URIs.Chart_borderWidth);\r
         Chart_borderWidth_Inverse = getResourceOrNull(graph, URIs.Chart_borderWidth_Inverse);\r
+        Chart_time = getResourceOrNull(graph, URIs.Chart_time);\r
+        Chart_time_Inverse = getResourceOrNull(graph, URIs.Chart_time_Inverse);\r
         Chart_visibleBorder = getResourceOrNull(graph, URIs.Chart_visibleBorder);\r
         Chart_visibleBorder_Inverse = getResourceOrNull(graph, URIs.Chart_visibleBorder_Inverse);\r
         Chart_visibleLegend = getResourceOrNull(graph, URIs.Chart_visibleLegend);\r
index 420583114dd94dfd03a29ac85f06b29eadda1e07..2852c03b0c07f0b0114dced45fed1aa2ab66069d 100644 (file)
@@ -51,7 +51,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2",
  org.simantics.history;bundle-version="1.0.0",
  org.simantics.utils.thread.swt;bundle-version="1.1.0",
  org.simantics.jfreechart.ontology;bundle-version="0.1.0",
- org.eclipse.ui.forms;bundle-version="3.5.2"
+ org.eclipse.ui.forms;bundle-version="3.5.2",
+ org.simantics.scenegraph.swing;bundle-version="1.0.0"
 Bundle-Activator: org.simantics.sysdyn.ui.Activator
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.sysdyn.ui.browser.nodes
diff --git a/org.simantics.sysdyn.ui/icons/chart_bar_light.png b/org.simantics.sysdyn.ui/icons/chart_bar_light.png
new file mode 100644 (file)
index 0000000..6069b5c
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/chart_bar_light.png differ
diff --git a/org.simantics.sysdyn.ui/icons/chart_line_light.png b/org.simantics.sysdyn.ui/icons/chart_line_light.png
new file mode 100644 (file)
index 0000000..2a77b24
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/chart_line_light.png differ
diff --git a/org.simantics.sysdyn.ui/icons/chart_pie_light.png b/org.simantics.sysdyn.ui/icons/chart_pie_light.png
new file mode 100644 (file)
index 0000000..fa553c2
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/chart_pie_light.png differ
index e38b641ae383da89abdb6922f0bd9a4327062c01..afd6e255d470926cdaab9aa1cd8da34ab59753f0 100644 (file)
@@ -14,7 +14,10 @@ package org.simantics.sysdyn.ui.trend.chart;
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 \r
+import javax.swing.SwingUtilities;\r
+\r
 import org.jfree.chart.axis.Axis;\r
+import org.jfree.chart.plot.Plot;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
@@ -37,6 +40,7 @@ public abstract class AbstractPlot implements IPlot {
     protected ArrayList<IDataset> datasets;\r
     protected HashMap<IDataset, IAxis> rangeMappings;\r
     protected HashMap<IDataset, IAxis> domainMappings;\r
+    protected Plot plot;\r
     \r
     public AbstractPlot(ReadGraph graph, Resource resource) {\r
         this.resource = resource;\r
@@ -116,4 +120,23 @@ public abstract class AbstractPlot implements IPlot {
     public Resource getResource() {\r
         return resource;\r
     }\r
+    \r
+    protected abstract Plot newPlot();\r
+    protected abstract void setPlotProperties();\r
+    \r
+    @Override\r
+    public Plot getPlot() {\r
+        if(plot == null)\r
+            plot = newPlot();\r
+        \r
+        SwingUtilities.invokeLater(new Runnable() {\r
+            \r
+            @Override\r
+            public void run() {\r
+                setPlotProperties();\r
+            }\r
+        });\r
+        \r
+        return plot;\r
+    }\r
 }\r
index 75be9b983126b2ff78fcd3b6cfca5ad8afe17e63..1fa12dbdfc691b9f4b57b33c0508226f595d193b 100644 (file)
@@ -145,6 +145,21 @@ public class CategoryDataset extends AbstractDataset {
                                     }\r
                                 }\r
 \r
+                                // Find if a specific time is set for this chart\r
+                                Double chartTime = null;\r
+                                if(!datasets.isEmpty()) {\r
+                                    Layer0 l0 = Layer0.getInstance(graph);\r
+                                    Resource datasetResource = graph.getPossibleObject(r, l0.PartOf);\r
+                                    if(datasetResource != null) {\r
+                                        Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf);\r
+                                        if(plot != null) {\r
+                                            Resource chart = graph.getPossibleObject(plot, l0.PartOf);\r
+                                            if(chart != null)\r
+                                                chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time);\r
+                                        }\r
+                                    }\r
+                                }\r
+\r
                                 for(SysdynDataSet dataset : datasets) {\r
                                     double[] va = dataset.values;\r
 \r
@@ -152,9 +167,16 @@ public class CategoryDataset extends AbstractDataset {
                                     if(va == null || va.length == 0)\r
                                         continue;\r
 \r
-                                    // Time\r
+                                    /*\r
+                                     *  Time\r
+                                     *  \r
+                                     *  1. find time for the individual series.\r
+                                     *  2. find time for the whole chart\r
+                                     *  3. find simulation time\r
+                                     */\r
                                     Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE);\r
-\r
+                                    if(time == null)\r
+                                        time = chartTime;\r
                                     if(time == null)\r
                                         time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE);\r
 \r
@@ -211,7 +233,6 @@ public class CategoryDataset extends AbstractDataset {
 \r
                 @Override\r
                 public void run() {\r
-\r
                     // Remove all unused series\r
                     dataset.clear();\r
                     BarRenderer renderer = ((BarRenderer)getRenderer());\r
index 297eb678ec066710e93c8c5b447595773fe15686..69d5d7911cc51a1ca7f35ff7aaa35a1e021779fe 100644 (file)
@@ -28,7 +28,6 @@ import org.simantics.sysdyn.JFreeChartResource;
  */\r
 public class CategoryPlot extends AbstractPlot {\r
     \r
-    private org.jfree.chart.plot.CategoryPlot plot;\r
     private Boolean visibleGrid;\r
 \r
 \r
@@ -47,46 +46,50 @@ public class CategoryPlot extends AbstractPlot {
     }\r
 \r
     @Override\r
-    public Plot getPlot() {\r
-        if(plot == null) {\r
-            plot = new org.jfree.chart.plot.CategoryPlot(null, null, null, null);\r
-        }        \r
+    protected Plot newPlot() {\r
+        return new org.jfree.chart.plot.CategoryPlot(null, null, null, null);\r
+    }\r
+\r
+    @Override\r
+    protected void setPlotProperties() {\r
+        if(!(plot instanceof org.jfree.chart.plot.CategoryPlot))\r
+            return;\r
+        \r
+        org.jfree.chart.plot.CategoryPlot cplot = (org.jfree.chart.plot.CategoryPlot) plot;\r
         /* Support using multiple axis, but prefer using only one domain and \r
          * one range axis\r
          */\r
         for(int i = 0; i < ranges.size(); i++) {\r
-            plot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis());\r
+            cplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis());\r
         }\r
         \r
         for(int i = 0; i < domains.size(); i++) {\r
-            plot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis());\r
+            cplot.setDomainAxis(i, (CategoryAxis)domains.get(i).getAxis());\r
         }\r
         \r
         IAxis axis;\r
         for(int i = 0; i < datasets.size(); i++) {\r
             IDataset dataset = datasets.get(i);\r
             org.jfree.data.category.CategoryDataset ds = (org.jfree.data.category.CategoryDataset)dataset.getDataset();\r
-            plot.setDataset(i, ds);\r
+            cplot.setDataset(i, ds);\r
 //            System.out.println("setting dataset " + i + ": " + ds);\r
-            plot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer());\r
+            cplot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer());\r
             axis = rangeMappings.get(dataset);\r
             if(axis != null && ranges.contains(axis))\r
-                plot.mapDatasetToRangeAxis(i, ranges.indexOf(axis));\r
+                cplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis));\r
             axis = domainMappings.get(dataset);\r
             if(axis != null && ranges.contains(axis))\r
-                plot.mapDatasetToDomainAxis(i, domains.indexOf(axis));\r
+                cplot.mapDatasetToDomainAxis(i, domains.indexOf(axis));\r
         }\r
 \r
         if(visibleGrid != null) {\r
-            plot.setRangeGridlinesVisible(visibleGrid);\r
-            plot.setDomainGridlinesVisible(false);\r
+            cplot.setRangeGridlinesVisible(visibleGrid);\r
+            cplot.setDomainGridlinesVisible(false);\r
         }\r
         \r
         // Cleaner look: no outline borders\r
-        plot.setInsets(new RectangleInsets(2,2,2,2), false);\r
-        plot.setOutlineVisible(false);\r
-        \r
-        return plot;\r
+        cplot.setInsets(new RectangleInsets(2,2,2,2), false);\r
+        cplot.setOutlineVisible(false);\r
     }\r
 \r
 }\r
index 200f0a21888daea025070d29f131143ab5a14f74..5db0e809e6f92386280e4694b3494cb6df12a8a9 100644 (file)
@@ -17,8 +17,6 @@ import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.awt.SWT_AWT;\r
-import org.eclipse.swt.events.DisposeEvent;\r
-import org.eclipse.swt.events.DisposeListener;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.jfree.chart.ChartPanel;\r
 import org.jfree.chart.JFreeChart;\r
@@ -88,16 +86,7 @@ public class ChartComposite extends Composite {
      */\r
     private void CreateContent(final Resource chartResource) {\r
         composite = this;\r
-        \r
-        composite.addDisposeListener(new DisposeListener() {\r
-            \r
-            @Override\r
-            public void widgetDisposed(DisposeEvent e) {\r
-                if(chart != null)\r
-                    chart.dispose();                \r
-            }\r
-        });\r
-        \r
+\r
         GridLayoutFactory.fillDefaults().applyTo(composite);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
         frame = SWT_AWT.new_Frame(composite);\r
index 826c032002c75de65d51b3e73661efa6e36f9368..e9c363887bdcae7331cd715a51c8ac1926059cdd 100644 (file)
@@ -13,7 +13,6 @@ package org.simantics.sysdyn.ui.trend.chart;
 \r
 import java.awt.Color;\r
 import java.awt.Font;\r
-import java.lang.reflect.InvocationTargetException;\r
 import java.util.Collection;\r
 \r
 import javax.swing.SwingUtilities;\r
@@ -79,34 +78,34 @@ public class JFreeChart implements IJFreeChart {
         if(plot == null)\r
             return null;\r
 \r
-        try {\r
-            SwingUtilities.invokeAndWait(new RunnableWithObject(plot) {\r
-                @Override\r
-                public void run() {\r
-                    jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
-                    \r
-                    jfreechart.setBackgroundPaint(Color.WHITE);\r
+        jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
+\r
+        SwingUtilities.invokeLater(new RunnableWithObject(plot) {\r
+            @Override\r
+            public void run() {\r
+                if(jfreechart == null)\r
+                    return;\r
+\r
+                jfreechart.setBackgroundPaint(Color.WHITE);\r
+                if(jfreechart.getLegend() != null) {\r
                     jfreechart.getLegend().setBorder(0, 0, 0, 0);\r
                     int size = jfreechart.getLegend().getItemFont().getSize();\r
                     jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size));\r
-                    \r
-                    org.jfree.chart.title.TextTitle  t = (org.jfree.chart.title.TextTitle)title.getTitle();\r
-                    if(t.isVisible()) {\r
-                        t.setFont(new Font("georgia", Font.BOLD, 13));\r
-                        t.setPadding(new RectangleInsets(4, 0, 0, 0));\r
-                        jfreechart.setTitle(t);\r
-                    }\r
-\r
-                    if(legendVisible != null && !legendVisible) {\r
-                        jfreechart.removeLegend();\r
-                    }\r
                 }\r
-            });\r
-        } catch (InterruptedException e) {\r
-            e.printStackTrace();\r
-        } catch (InvocationTargetException e) {\r
-            e.printStackTrace();\r
-        }\r
+\r
+                org.jfree.chart.title.TextTitle  t = (org.jfree.chart.title.TextTitle)title.getTitle();\r
+                if(t.isVisible()) {\r
+                    t.setFont(new Font("georgia", Font.BOLD, 13));\r
+                    t.setPadding(new RectangleInsets(4, 0, 0, 0));\r
+                    jfreechart.setTitle(t);\r
+                }\r
+\r
+                if(legendVisible != null && !legendVisible) {\r
+                    jfreechart.removeLegend();\r
+                }\r
+            }\r
+        });\r
+\r
         return jfreechart;\r
     }\r
 \r
index da1b61a1b98b689153475cc3a1af153c03a78bbd..af50b718b2c02387cecb872581bd8606855d5110 100644 (file)
@@ -170,15 +170,37 @@ public class PieDataset extends AbstractDataset {
                                     }\r
                                 }\r
 \r
+                                // Find if a specific time is set for this chart\r
+                                Double chartTime = null;\r
+                                if(!datasets.isEmpty()) {\r
+                                    Layer0 l0 = Layer0.getInstance(graph);\r
+                                    Resource datasetResource = graph.getPossibleObject(r, l0.PartOf);\r
+                                    if(datasetResource != null) {\r
+                                        Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf);\r
+                                        if(plot != null) {\r
+                                            Resource chart = graph.getPossibleObject(plot, l0.PartOf);\r
+                                            if(chart != null)\r
+                                                chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time);\r
+                                        }\r
+                                    }\r
+                                }\r
+                                \r
                                 for(SysdynDataSet dataset : datasets) {\r
                                     double[] va = dataset.values;\r
 \r
                                     if(va == null || va.length == 0)\r
                                         continue;\r
 \r
-                                    // Time\r
+                                    /*\r
+                                     *  Time\r
+                                     *  \r
+                                     *  1. find time for the individual series.\r
+                                     *  2. find time for the whole chart\r
+                                     *  3. find simulation time\r
+                                     */\r
                                     Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE);\r
-\r
+                                    if(time == null)\r
+                                        time = chartTime;\r
                                     if(time == null)\r
                                         time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE);\r
 \r
index 231b6446d2113dcb6a665bc8e5a1915985d74243..556c8742601f0c3bb57a0f6b56ab5b04c05e0459 100644 (file)
@@ -37,7 +37,6 @@ import org.simantics.sysdyn.JFreeChartResource;
  */\r
 public class PiePlot extends AbstractPlot {\r
 \r
-    private org.jfree.chart.plot.PiePlot plot;\r
     private org.jfree.data.general.PieDataset pieDataset;\r
     private DatasetChangeListener listener;\r
     \r
@@ -53,28 +52,62 @@ public class PiePlot extends AbstractPlot {
         }\r
     }\r
 \r
-    @Override\r
-    public Plot getPlot() {\r
-        if(plot == null) {\r
-            plot = new MyPiePlot();\r
-            plot.setToolTipGenerator(new StandardPieToolTipGenerator());\r
+    /**\r
+     * Pie plot class with a stricter equals condition\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    private class MyPiePlot extends org.jfree.chart.plot.PiePlot {\r
+\r
+        private static final long serialVersionUID = -5917620061541212934L;\r
+\r
+        @Override\r
+        public boolean equals(Object obj) {\r
+            boolean result = super.equals(obj);\r
+            if(result == true) {\r
+                org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj;\r
+                if (this.getDataset() != that.getDataset()) {\r
+                    return false; // Normally plot does not check this. We need this to properly update the charts\r
+                }\r
+            }\r
+\r
+            return result;\r
         }\r
 \r
+    }\r
+\r
+    @Override\r
+    protected Plot newPlot() {\r
+        MyPiePlot plot = new MyPiePlot();\r
+        plot.setToolTipGenerator(new StandardPieToolTipGenerator());\r
+        return plot;\r
+    }\r
+\r
+    @Override\r
+    protected void setPlotProperties() {\r
+        if(!(plot instanceof MyPiePlot))\r
+            return;\r
+        \r
+        final MyPiePlot piePlot = (MyPiePlot)plot;\r
+        \r
         if(!datasets.isEmpty()) {\r
             // We assume that a pie plot has only one dataset\r
             final IDataset ds = datasets.get(0);\r
             Dataset dataset = ((PieDataset)ds).getDataset();\r
+            \r
+            if(dataset == null)\r
+                return;\r
 \r
             if(pieDataset != null && listener != null) {\r
                 pieDataset.removeChangeListener(listener);\r
             }\r
             \r
             pieDataset = (org.jfree.data.general.PieDataset)dataset;\r
-            plot.setDataset(pieDataset);\r
+            piePlot.setDataset(pieDataset);\r
             if(Boolean.FALSE.equals(labelsVisible))\r
-                plot.setLabelGenerator(null);\r
-            else if(plot.getLabelGenerator() == null)\r
-                plot.setLabelGenerator(new StandardPieSectionLabelGenerator());\r
+                piePlot.setLabelGenerator(null);\r
+            else if(piePlot.getLabelGenerator() == null)\r
+                piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator());\r
             \r
             listener = new DatasetChangeListener() {\r
                 \r
@@ -83,14 +116,14 @@ public class PiePlot extends AbstractPlot {
                     HashMap<String, Color> colorMap = ((PieDataset)ds).getColorMap();\r
                     HashMap<String, Boolean> explodedMap = ((PieDataset)ds).getExplodedMap();\r
                     \r
-                    for(Object o : plot.getDataset().getKeys()) {\r
+                    for(Object o : piePlot.getDataset().getKeys()) {\r
                         if(o instanceof Comparable) {\r
                             Comparable<?> key = (Comparable<?>)o;\r
                             if(explodedMap.containsKey(key) && explodedMap.get(key)) {\r
-                                plot.setExplodePercent(key, 0.3);\r
+                                piePlot.setExplodePercent(key, 0.3);\r
 \r
                             } else {\r
-                                plot.setExplodePercent(key, 0);\r
+                                piePlot.setExplodePercent(key, 0);\r
                             }\r
                         }\r
                     }\r
@@ -98,12 +131,12 @@ public class PiePlot extends AbstractPlot {
                     for(String name : explodedMap.keySet()) {\r
                         Boolean exploded = explodedMap.get(name);\r
                         if(Boolean.TRUE.equals(exploded))\r
-                            plot.setExplodePercent(name, 0.3);\r
+                            piePlot.setExplodePercent(name, 0.3);\r
                     } \r
-                    plot.clearSectionPaints(false);\r
-                    plot.setDrawingSupplier(new DefaultDrawingSupplier());\r
+                    piePlot.clearSectionPaints(false);\r
+                    piePlot.setDrawingSupplier(new DefaultDrawingSupplier());\r
                     for(String name : colorMap.keySet())\r
-                        plot.setSectionPaint(name, colorMap.get(name));\r
+                        piePlot.setSectionPaint(name, colorMap.get(name));\r
                 }\r
             };\r
             \r
@@ -111,36 +144,10 @@ public class PiePlot extends AbstractPlot {
         }\r
         \r
         // Cleaner look: no outline borders\r
-        plot.setInsets(new RectangleInsets(0,0,0,0), false);\r
-        plot.setOutlineVisible(false);\r
-        plot.setLabelBackgroundPaint(Color.WHITE);\r
-        plot.setLabelFont(new Font("helvetica", Font.PLAIN, 11));\r
-        \r
-        return plot;\r
-    }\r
-\r
-    /**\r
-     * Pie plot class with a stricter equals condition\r
-     * @author Teemu Lempinen\r
-     *\r
-     */\r
-    private class MyPiePlot extends org.jfree.chart.plot.PiePlot {\r
-\r
-        private static final long serialVersionUID = -5917620061541212934L;\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            boolean result = super.equals(obj);\r
-            if(result == true) {\r
-                org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj;\r
-                if (this.getDataset() != that.getDataset()) {\r
-                    return false; // Normally plot does not check this. We need this to properly update the charts\r
-                }\r
-            }\r
-\r
-            return result;\r
-        }\r
-\r
+        piePlot.setInsets(new RectangleInsets(0,0,0,0), false);\r
+        piePlot.setOutlineVisible(false);\r
+        piePlot.setLabelBackgroundPaint(Color.WHITE);\r
+        piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11));\r
     }\r
 \r
 }\r
index af0cc336a94b7c0033827155e07bfb7b7279d737..b30c323fb4618072bae2b2168b0479e223d37e09 100644 (file)
@@ -29,10 +29,8 @@ import org.simantics.sysdyn.JFreeChartResource;
  */\r
 public class XYPlot extends AbstractPlot {\r
 \r
-    private org.jfree.chart.plot.XYPlot plot;\r
     private Boolean visibleGrid;\r
 \r
-\r
     public XYPlot(ReadGraph graph, Resource plotResource) {\r
         super(graph, plotResource);\r
 \r
@@ -47,45 +45,49 @@ public class XYPlot extends AbstractPlot {
     }\r
 \r
     @Override\r
-    public Plot getPlot() {\r
-        if(plot == null)\r
-            plot = new org.jfree.chart.plot.XYPlot(null, null, null, null);\r
+    protected Plot newPlot() {\r
+        return new org.jfree.chart.plot.XYPlot(null, null, null, null);\r
+    }\r
+\r
+    @Override\r
+    protected void setPlotProperties() {\r
+        if(!(plot instanceof org.jfree.chart.plot.XYPlot))\r
+            return;\r
         \r
-        plot.clearDomainAxes();\r
-        plot.clearRangeAxes();\r
+        org.jfree.chart.plot.XYPlot xyplot = (org.jfree.chart.plot.XYPlot)plot;\r
+        xyplot.clearDomainAxes();\r
+        xyplot.clearRangeAxes();\r
 \r
         for(int i = 0; i < ranges.size(); i++) {\r
-            plot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis());\r
+            xyplot.setRangeAxis(i, (ValueAxis)ranges.get(i).getAxis());\r
         }\r
 \r
         for(int i = 0; i < domains.size(); i++) {\r
-            plot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis());\r
+            xyplot.setDomainAxis(i, (ValueAxis)domains.get(i).getAxis());\r
         }\r
 \r
         IAxis axis;\r
         for(int i = 0; i < datasets.size(); i++) {\r
             IDataset dataset = datasets.get(i);\r
-            plot.setDataset(i, (XYDataset)dataset.getDataset());\r
-            plot.setRenderer(i, (XYItemRenderer)dataset.getRenderer());\r
+            xyplot.setDataset(i, (XYDataset)dataset.getDataset());\r
+            xyplot.setRenderer(i, (XYItemRenderer)dataset.getRenderer());\r
             axis = rangeMappings.get(dataset);\r
             if(axis != null && ranges.contains(axis))\r
-                plot.mapDatasetToRangeAxis(i, ranges.indexOf(axis));\r
+                xyplot.mapDatasetToRangeAxis(i, ranges.indexOf(axis));\r
             axis = domainMappings.get(dataset);\r
             if(axis != null && ranges.contains(axis))\r
-                plot.mapDatasetToDomainAxis(i, domains.indexOf(axis));\r
+                xyplot.mapDatasetToDomainAxis(i, domains.indexOf(axis));\r
         }\r
 \r
         if(visibleGrid == null)\r
             visibleGrid = true;\r
 \r
-        plot.setRangeGridlinesVisible(visibleGrid);\r
-        plot.setDomainGridlinesVisible(visibleGrid);\r
+        xyplot.setRangeGridlinesVisible(visibleGrid);\r
+        xyplot.setDomainGridlinesVisible(visibleGrid);\r
         \r
         // Cleaner look: no outline borders\r
-        plot.setInsets(new RectangleInsets(2,2,2,2), false);\r
-        plot.setOutlineVisible(false);\r
-        \r
-        return plot;\r
+        xyplot.setInsets(new RectangleInsets(2,2,2,2), false);\r
+        xyplot.setOutlineVisible(false);\r
     }\r
 \r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java
new file mode 100644 (file)
index 0000000..74b984b
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.trend.chart.properties;\r
+\r
+import org.eclipse.jface.dialogs.IInputValidator;\r
+\r
+/**\r
+ * Validator for validating that an input is double.\r
+ * \r
+ * Can allow empty strings.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class DoubleValidator implements IInputValidator {\r
+    \r
+    boolean allowEmpty;\r
+    \r
+    /**\r
+     * New double validator. Does not allow empty strings\r
+     */\r
+    public DoubleValidator() {\r
+        this(false);\r
+    }\r
+    \r
+    /**\r
+     * New double validator.\r
+     * @param allowEmpty Are empty strings allowed\r
+     */\r
+    public DoubleValidator(boolean allowEmpty) {\r
+        this.allowEmpty = allowEmpty;\r
+    }\r
+    \r
+    @Override\r
+    public String isValid(String newText) {\r
+        if (allowEmpty && newText.trim().isEmpty())\r
+            return null;\r
+        try {\r
+            Double.parseDouble(newText);\r
+            return null;\r
+        } catch (NumberFormatException e) {\r
+            return e.getMessage();\r
+        }\r
+    }\r
+}\r
index c0e84e6ff8e5a052e68d91fb2870e05e9c0f0e1f..c17e6939bd5a30424cf496b1406d8ea4ed18bd29 100644 (file)
@@ -11,7 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart.properties.bar;\r
 \r
-import org.eclipse.jface.dialogs.IInputValidator;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.StructuredSelection;\r
@@ -48,6 +47,7 @@ import org.simantics.sysdyn.JFreeChartResource;
 import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner;\r
 import org.simantics.ui.utils.AdaptionUtils;\r
@@ -160,7 +160,7 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget {
         rangemin.setColorProvider(new JFreeChartPropertyColorProvider(rangemin.getResourceManager()));\r
         rangemin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));\r
         rangemin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));\r
-        rangemin.setInputValidator(new DoubleValidator());\r
+        rangemin.setInputValidator(new DoubleValidator(true));\r
 \r
         label = new Label(minmax, SWT.NONE);\r
         label.setText("Max:");\r
@@ -168,7 +168,7 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget {
         rangemax.setColorProvider(new JFreeChartPropertyColorProvider(rangemax.getResourceManager()));\r
         rangemax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));\r
         rangemax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));\r
-        rangemax.setInputValidator(new DoubleValidator());\r
+        rangemax.setInputValidator(new DoubleValidator(true));\r
 \r
         // Range Color\r
         label = new Label(rangeGroup, SWT.NONE);\r
@@ -289,24 +289,4 @@ public class BarAxisTab extends LabelPropertyTabContributor implements Widget {
             }\r
         });\r
     }\r
-\r
-\r
-    /**\r
-     * Validator for validating that an input is double\r
-     * @author Teemu Lempinen\r
-     *\r
-     */\r
-    private class DoubleValidator implements IInputValidator {\r
-        @Override\r
-        public String isValid(String newText) {\r
-            if (newText.trim().isEmpty())\r
-                return null;\r
-            try {\r
-                Double.parseDouble(newText);\r
-                return null;\r
-            } catch (NumberFormatException e) {\r
-                return e.getMessage();\r
-            }\r
-        }\r
-    }\r
 }\r
index 387f34e60b14cfebf6c4bfb0ca91e6fcd2144c62..5982d6dc30f10a06f9fac3ea88674cc4a2ae4eec 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Map;
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.layout.LayoutConstants;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.custom.ScrolledComposite;\r
 import org.eclipse.swt.graphics.Point;\r
@@ -41,8 +42,11 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
 import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;\r
@@ -58,7 +62,7 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor {
     private ScrolledComposite sc;\r
     private Composite composite;\r
     private Button hgrid, htitle, hlegend;\r
-    private TrackedText name, title;\r
+    private TrackedText name, title, time;\r
     private TrackedCombo type;\r
 \r
 \r
@@ -77,46 +81,74 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor {
         // General properties\r
         Group general = new Group(composite, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(general);\r
-        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general);\r
         general.setText("General");\r
 \r
+        // first column: labels\r
+        Composite labelColumn1 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);\r
+        GridLayoutFactory.fillDefaults().applyTo(labelColumn1);\r
+        \r
+        // first column: name and title\r
+        Composite propertyColumn1 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);\r
+        GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);\r
+        \r
+        // first column: labels\r
+        Composite labelColumn2 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);\r
+        GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);\r
+        \r
+        // first column: type and time\r
+        Composite propertyColumn2 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);\r
+        GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);\r
+        \r
         // Name\r
-        Label label = new Label(general, SWT.NONE);\r
-        GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+        Label label = new Label(labelColumn1, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
         label.setText("Name:");\r
 \r
-        Composite c = new Composite(general, SWT.NONE);\r
-        GridDataFactory.fillDefaults().applyTo(c);\r
-        GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c);\r
-\r
-        name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER);\r
+        name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());\r
         name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
         name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
         name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
 \r
         // Type\r
-        label = new Label(c, SWT.NONE);\r
-        GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label = new Label(labelColumn2, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
         label.setText("Type:");\r
 \r
-        type = new TrackedCombo(c, support, SWT.BORDER | SWT.READ_ONLY);\r
+        type = new TrackedCombo(propertyColumn2, support, SWT.BORDER | SWT.READ_ONLY);\r
         type.addModifyListener(new TypeModifyListener());\r
         type.setItemFactory(new TypeItemFactory());\r
         type.setSelectionFactory(new TypeSelectionFactory());\r
         GridDataFactory.fillDefaults().applyTo(type.getWidget());\r
 \r
         // Title (Which is different than name)\r
-        label = new Label(general, SWT.NONE);\r
-        GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label = new Label(labelColumn1, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
         label.setText("Title:");\r
 \r
-        title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);\r
+        title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());\r
         title.setTextFactory(new TitleFactory());\r
         title.addModifyListener(new TitleModifier());\r
         title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
 \r
+        // Time\r
+        label = new Label(labelColumn2, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label.setText("Time:");\r
+        \r
+        time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());\r
+        time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time));\r
+        time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time));\r
+        time.setInputValidator(new DoubleValidator(true));\r
+        time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
+        \r
         // Group for hide options\r
         Group hideGroup = new Group(composite, SWT.NONE);\r
         GridDataFactory.fillDefaults().applyTo(hideGroup);\r
@@ -136,6 +168,8 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor {
         hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));\r
         hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));\r
 \r
+        \r
+        \r
         // Resize scrolled composite\r
         sc.setContent(composite);\r
         Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
index 7ccbbc4a96e3bfb0d0cba711c296e3d825ca72c0..c7597ac041a59e0dffc34735c0af548a7e223a65 100644 (file)
@@ -22,6 +22,10 @@ import org.simantics.browsing.ui.swt.widgets.TrackedText;
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
@@ -34,7 +38,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite;
  */\r
 public class BarSeriesPropertyComposite extends Composite {\r
     \r
-    private TrackedText variable, label;\r
+    private TrackedText variable, label, time;\r
     \r
     public BarSeriesPropertyComposite(Composite parent, final ISessionContext context, WidgetSupport support, int style) {\r
         super(parent, style);\r
@@ -71,5 +75,21 @@ public class BarSeriesPropertyComposite extends Composite {
         this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
         this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager()));\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget());\r
+        \r
+        // Time\r
+        label = new Label(this, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Time:");\r
+        \r
+        Composite composite = new Composite(this, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().applyTo(composite);\r
+        \r
+        time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);\r
+        time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));\r
+        time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));\r
+        time.setInputValidator(new DoubleValidator(true));\r
+        time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
+        GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
     }\r
 }\r
index bbaa7b4b6e5b25cbbca0f8cc0d4cd13ef8d38147..10b034aa0255ecc9d9bb75f9733179484723dfa3 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.trend.chart.properties.pie;
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.layout.LayoutConstants;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.custom.ScrolledComposite;\r
 import org.eclipse.swt.graphics.Point;\r
@@ -29,8 +30,11 @@ import org.simantics.db.management.ISessionContext;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
 import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier;\r
@@ -45,7 +49,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
     private ScrolledComposite sc;\r
     private Composite composite;\r
     private Button htitle, hlegend, hlabels;\r
-    private TrackedText name, title;\r
+    private TrackedText name, title, time;\r
 \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {    \r
@@ -62,31 +66,72 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
         // General properties\r
         Group general = new Group(composite, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(general);\r
-        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general);\r
         general.setText("General");\r
 \r
+        // first column: labels\r
+        Composite labelColumn1 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);\r
+        GridLayoutFactory.fillDefaults().applyTo(labelColumn1);\r
+        \r
+        // first column: name and title\r
+        Composite propertyColumn1 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);\r
+        GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);\r
+        \r
+        // first column: labels\r
+        Composite labelColumn2 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);\r
+        GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);\r
+        \r
+        // first column: type and time\r
+        Composite propertyColumn2 = new Composite(general, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);\r
+        GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);\r
+        \r
         // Name\r
-        Label label = new Label(general, SWT.NONE);\r
-        GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+        Label label = new Label(labelColumn1, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
         label.setText("Name:");\r
 \r
-        name = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);\r
+        name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());\r
         name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
         name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
         name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
 \r
+        // Dummy data for now. Waiting for different pie chart types\r
+        label = new Label(labelColumn2, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(label);\r
+        label.setText("");\r
+        \r
+        label = new Label(propertyColumn2, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).applyTo(label);\r
+        label.setText("");\r
+        \r
         // Title (Which is different than name)\r
-        label = new Label(general, SWT.NONE);\r
-        GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label = new Label(labelColumn1, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
         label.setText("Title:");\r
 \r
-        title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER);\r
+        title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());\r
         title.setTextFactory(new TitleFactory());\r
         title.addModifyListener(new TitleModifier());\r
         title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));\r
 \r
+        // Time\r
+        label = new Label(labelColumn2, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);\r
+        label.setText("Time:");\r
+        \r
+        time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());\r
+        time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time));\r
+        time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time));\r
+        time.setInputValidator(new DoubleValidator(true));\r
+        time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
+\r
         // Group for hide options\r
         Group hideGroup = new Group(composite, SWT.NONE);\r
         GridDataFactory.fillDefaults().applyTo(hideGroup);\r
index 1e8786c4c733697d341042b6e346834045396449..dad20d4a1613f3decc94563c8c960ee8c81f113b 100644 (file)
@@ -24,9 +24,12 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
@@ -39,7 +42,7 @@ import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite;
  */\r
 public class PieSeriesPropertyComposite extends Composite {\r
     \r
-    private TrackedText variable, label;\r
+    private TrackedText variable, label, time;\r
     \r
     public PieSeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) {\r
         super(parent, style);\r
@@ -85,6 +88,22 @@ public class PieSeriesPropertyComposite extends Composite {
         Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);\r
 \r
+        // Time\r
+        label = new Label(this, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Time:");\r
+        \r
+        Composite composite = new Composite(this, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().applyTo(composite);\r
+        \r
+        time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);\r
+        time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));\r
+        time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));\r
+        time.setInputValidator(new DoubleValidator(true));\r
+        time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
+        GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
+        \r
         // Exploded\r
         label = new Label(this, SWT.NONE);\r
         label.setText("");\r
index d029ddf4e8ae1045ef675f57e96a8d092c813fb9..22228fde0ff07e8c48e76d46d73b4c632e6df714 100644 (file)
@@ -11,7 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart.properties.xyline;\r
 \r
-import org.eclipse.jface.dialogs.IInputValidator;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
@@ -29,6 +28,7 @@ import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
 import org.simantics.sysdyn.JFreeChartResource;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 \r
 /**\r
@@ -70,7 +70,7 @@ public class AxisPropertyComposite extends Composite {
         min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager()));\r
         min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));\r
         min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));\r
-        min.setInputValidator(new DoubleValidator());\r
+        min.setInputValidator(new DoubleValidator(true));\r
 \r
         label = new Label(minmax, SWT.NONE);\r
         label.setText("Max:");\r
@@ -78,7 +78,7 @@ public class AxisPropertyComposite extends Composite {
         max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager()));\r
         max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));\r
         max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));\r
-        max.setInputValidator(new DoubleValidator());\r
+        max.setInputValidator(new DoubleValidator(true));\r
 \r
         \r
         // Color\r
@@ -97,24 +97,4 @@ public class AxisPropertyComposite extends Composite {
         GridDataFactory.fillDefaults().applyTo(axisHide);\r
     }\r
     \r
-    /**\r
-     * Validator for validating that an input is double\r
-     * @author Teemu Lempinen\r
-     *\r
-     */\r
-    private class DoubleValidator implements IInputValidator {\r
-        @Override\r
-        public String isValid(String newText) {\r
-            if (newText.trim().isEmpty())\r
-                return null;\r
-            try {\r
-                Double.parseDouble(newText);\r
-                return null;\r
-            } catch (NumberFormatException e) {\r
-                return e.getMessage();\r
-            }\r
-        }\r
-    }\r
-    \r
-\r
 }\r
index 421c63c2c992a2663ab2008c05a8cefcc6c64473..857a7cafc5aabadaa06d50a4e7b8a9d6d5f8add2 100644 (file)
@@ -11,7 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart.properties.xyline;\r
 \r
-import org.eclipse.jface.dialogs.IInputValidator;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.jface.viewers.StructuredSelection;\r
@@ -44,6 +43,7 @@ import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor;
 import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener;\r
+import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory;\r
 import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier;\r
@@ -185,7 +185,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl
         xmin.setColorProvider(new JFreeChartPropertyColorProvider(xmin.getResourceManager()));\r
         xmin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));\r
         xmin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));\r
-        xmin.setInputValidator(new DoubleValidator());\r
+        xmin.setInputValidator(new DoubleValidator(true));\r
 \r
         label = new Label(minmax, SWT.NONE);\r
         label.setText("Max:");\r
@@ -193,7 +193,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl
         xmax.setColorProvider(new JFreeChartPropertyColorProvider(xmax.getResourceManager()));\r
         xmax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));\r
         xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));\r
-        xmax.setInputValidator(new DoubleValidator());\r
+        xmax.setInputValidator(new DoubleValidator(true));\r
 \r
         // Set the same width to both label rows\r
         composite.layout();\r
@@ -225,25 +225,4 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl
         });\r
     }\r
 \r
-    \r
-    /**\r
-     * Validator for validating that an input is double\r
-     * @author Teemu Lempinen\r
-     *\r
-     */\r
-    private class DoubleValidator implements IInputValidator {\r
-        @Override\r
-        public String isValid(String newText) {\r
-            if (newText.trim().isEmpty())\r
-                return null;\r
-            try {\r
-                Double.parseDouble(newText);\r
-                return null;\r
-            } catch (NumberFormatException e) {\r
-                return e.getMessage();\r
-            }\r
-        }\r
-    }\r
-    \r
-\r
-}\r
+}
\ No newline at end of file
index 39f85dcbf4dd07996e9e8007e04848da475cdcf5..26602293ecccccbb28cf53bdbf6224b6cb281d8c 100644 (file)
@@ -112,11 +112,26 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
                                 if(variable != null)\r
                                     vars.add(variable);\r
                             }\r
+                            \r
+                            // If there is no vars and only one selection, it can be a chart\r
+                            if(vars.isEmpty() && ress.size() == 1) {\r
+                                Resource r = ress.iterator().next();\r
+                                JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+                                if(graph.isInstanceOf(r, jfree.ChartElement)) {\r
+                                    if(graph.hasStatement(r, jfree.ChartElement_component)) {\r
+                                        r = graph.getSingleObject(r, jfree.ChartElement_component);\r
+                                        selectionChanged(graph, r);\r
+                                        return;\r
+                                    }\r
+                                }\r
+                            }\r
+                            \r
                         } else {\r
                             // Selection is a jfreechart\r
                             if(ress.size() == 1) {\r
                                 Resource r = ress.iterator().next();\r
-                                if(graph.isInstanceOf(r, JFreeChartResource.getInstance(graph).Chart)) {\r
+                                JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+                                if(graph.isInstanceOf(r, jfree.Chart)) {\r
                                     selectionChanged(graph, r);\r
                                     return;\r
                                 }\r