]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Cleaned the look of charts, chart panel elements and model browser chart elements
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 12 Dec 2011 12:27:10 +0000 (12:27 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 12 Dec 2011 12:27:10 +0000 (12:27 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23495 ac1ea38d-2e2b-0410-8846-a27921b304fc

19 files changed:
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/icons/close.gif [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/maximize.gif [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/minimize.gif [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/timeline_marker.png [new file with mode: 0644]
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.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/JFreeChart.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/StackedBarRenderer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.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/pie/PieGeneralPropertiesTab.java

index f85899a232d244cf84dc745dbf95352b9274630c..d250dc962037c81ecad6348996061b139869e416 100644 (file)
Binary files a/org.simantics.jfreechart.ontology/graph.tg and b/org.simantics.jfreechart.ontology/graph.tg differ
index 4611e693c7400fedc398739e4aa91256581865e3..2526730c6ff753dd024f365beb734e5fe3c26141 100644 (file)
@@ -45,6 +45,7 @@ JFREE.Plot <T L0.Entity
     >-- JFREE.backgroundColor --> G2D.Color <R L0.HasProperty : L0.FunctionalRelation
     >-- JFREE.Plot.visibleGrid --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
     >-- JFREE.Plot.rangeAxisList --> L0.List <R L0.HasProperty : L0.FunctionalRelation
+    >-- JFREE.Plot.visibleLabels --> L0.Boolean <R L0.HasProperty : L0.FunctionalRelation
     
 JFREE.CategoryPlot <T JFREE.Plot
 JFREE.XYPlot <T JFREE.Plot
index 3b89a5cfd8c78c3471bcda01b686b1e6451069a6..a748d41191639682df8f093955ea6f169f9fe50f 100644 (file)
@@ -63,6 +63,8 @@ public class JFreeChartResource {
     public final Resource Plot_rangeAxis_Inverse;\r
     public final Resource Plot_visibleGrid;\r
     public final Resource Plot_visibleGrid_Inverse;\r
+    public final Resource Plot_visibleLabels;\r
+    public final Resource Plot_visibleLabels_Inverse;\r
     public final Resource Position;\r
     public final Resource Renderer;\r
     public final Resource Right;\r
@@ -154,6 +156,8 @@ public class JFreeChartResource {
         public static final String Plot_rangeAxis_Inverse = "http://www.simantics.org/JFreeChart-1.0/Plot/rangeAxis/Inverse";\r
         public static final String Plot_visibleGrid = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleGrid";\r
         public static final String Plot_visibleGrid_Inverse = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleGrid/Inverse";\r
+        public static final String Plot_visibleLabels = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleLabels";\r
+        public static final String Plot_visibleLabels_Inverse = "http://www.simantics.org/JFreeChart-1.0/Plot/visibleLabels/Inverse";\r
         public static final String Position = "http://www.simantics.org/JFreeChart-1.0/Position";\r
         public static final String Renderer = "http://www.simantics.org/JFreeChart-1.0/Renderer";\r
         public static final String Right = "http://www.simantics.org/JFreeChart-1.0/Right";\r
@@ -255,6 +259,8 @@ public class JFreeChartResource {
         Plot_rangeAxis_Inverse = getResourceOrNull(graph, URIs.Plot_rangeAxis_Inverse);\r
         Plot_visibleGrid = getResourceOrNull(graph, URIs.Plot_visibleGrid);\r
         Plot_visibleGrid_Inverse = getResourceOrNull(graph, URIs.Plot_visibleGrid_Inverse);\r
+        Plot_visibleLabels = getResourceOrNull(graph, URIs.Plot_visibleLabels);\r
+        Plot_visibleLabels_Inverse = getResourceOrNull(graph, URIs.Plot_visibleLabels_Inverse);\r
         Position = getResourceOrNull(graph, URIs.Position);\r
         Renderer = getResourceOrNull(graph, URIs.Renderer);\r
         Right = getResourceOrNull(graph, URIs.Right);\r
diff --git a/org.simantics.sysdyn.ui/icons/close.gif b/org.simantics.sysdyn.ui/icons/close.gif
new file mode 100644 (file)
index 0000000..1aca259
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/close.gif differ
diff --git a/org.simantics.sysdyn.ui/icons/maximize.gif b/org.simantics.sysdyn.ui/icons/maximize.gif
new file mode 100644 (file)
index 0000000..5e5999b
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/maximize.gif differ
diff --git a/org.simantics.sysdyn.ui/icons/minimize.gif b/org.simantics.sysdyn.ui/icons/minimize.gif
new file mode 100644 (file)
index 0000000..7402dc9
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/minimize.gif differ
diff --git a/org.simantics.sysdyn.ui/icons/timeline_marker.png b/org.simantics.sysdyn.ui/icons/timeline_marker.png
new file mode 100644 (file)
index 0000000..a3fbddf
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/timeline_marker.png differ
index d4922270fa912eca984173f58f58915508b36496..7b2f5227d54219ed0e0cc00685573f1b46ec64ca 100644 (file)
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newExperiment"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/time.png"\r
                   id="org.simantics.sysdyn.ui.browser.newExperiment"\r
                   label="Experiment"\r
                   style="push">\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newPlaybackExperiment"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/timeline_marker.png"\r
                   id="org.simantics.sysdyn.ui.browser.newPlaybackExperiment"\r
                   label="Playback Experiment"\r
                   style="push">\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newXYLineChart"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/chart_line.png"\r
                   id="org.simantics.sysdyn.ui.browser.newXYLineChart"\r
                   label="Line Chart"\r
                   style="push">\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newBarChart"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/chart_bar.png"\r
                   id="org.simantics.sysdyn.ui.browser.newBarChart"\r
                   label="Bar Chart"\r
                   style="push">\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newPieChart"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/chart_pie.png"\r
                   id="org.simantics.sysdyn.ui.browser.newPieChart"\r
                   label="Pie Chart"\r
                   style="push">\r
index e6051f38b83975508734e0d939d8d4969576b01a..5ff989ea28ee4291c35f4f51edec120f788d993c 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.browsing.ui.swt.ImagerContributor;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
@@ -50,9 +51,13 @@ public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>
             image = "icons/folder.png";\r
         else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
             image = "icons/bricks.png";\r
-        else if (node instanceof ExperimentNode)\r
-            image = "icons/time.png";\r
-        else if (node instanceof InputNode)\r
+        else if (node instanceof ExperimentNode) {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            if(graph.isInstanceOf(node.data, sr.PlaybackExperiment))\r
+                image = "icons/timeline_marker.png";\r
+            else\r
+                image = "icons/time.png";\r
+        } else if (node instanceof InputNode)\r
             image = "icons/brick_link.png";\r
         else if (node instanceof ModelNode)\r
             image = "icons/chart_organisation.png";\r
index af8781d9de16357745dabccd7747df13524e37a9..38370a9ec010858cabfcaaf143924c4433a5dbfe 100644 (file)
@@ -149,7 +149,7 @@ public class ChartPanel extends ViewPart {
         setupDropTarget();\r
 \r
         body = new Composite(sc, SWT.NONE);\r
-        GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(body);\r
+        GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(body);\r
 \r
         sc.setContent(body);\r
index f0334fc6a2aac58bc267a82a7f86215a804e9767..e37b82fbf03909c7bdb80ba37c9b9f8e8bc2d7f1 100644 (file)
@@ -13,21 +13,29 @@ package org.simantics.sysdyn.ui.trend;
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseListener;\r
-import org.eclipse.swt.graphics.Cursor;\r
-import org.eclipse.swt.graphics.Rectangle;\r
+import org.eclipse.swt.events.PaintEvent;\r
+import org.eclipse.swt.events.PaintListener;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.widgets.Canvas;\r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.ToolBar;\r
+import org.eclipse.swt.widgets.ToolItem;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
 /**\r
  * Header of a chart element in {@link ChartPanel}. Only this header is\r
@@ -42,7 +50,29 @@ public class ChartPanelHeader extends Composite {
     public static int HEADER_MINIMUM_WIDTH = 250;\r
     private ChartPanel panel;\r
     private Resource resource;\r
-    private Label name, minimize, remove;\r
+    private Label name;\r
+    private Canvas iconCanvas;\r
+    private Image icon;\r
+    private ToolItem minimize, remove;\r
+\r
+    private static ImageDescriptor closeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/close.gif"));\r
+    private static Image closeImage = closeDescriptor.createImage();\r
+\r
+    private static ImageDescriptor minimizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/minimize.gif"));\r
+    private static Image minimizeImage = minimizeDescriptor.createImage();\r
+\r
+    private static ImageDescriptor maximizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/maximize.gif"));\r
+    private static Image maximizeImage = maximizeDescriptor.createImage();\r
+\r
+    private static ImageDescriptor lineChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_line_light.png"));\r
+    private static Image lineChartImage = lineChartDescriptor.createImage();\r
+\r
+    private static ImageDescriptor barChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_light.png"));\r
+    private static Image barChartImage = barChartDescriptor.createImage();\r
+\r
+    private static ImageDescriptor pieChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_pie_light.png"));\r
+    private static Image pieChartImage = pieChartDescriptor.createImage();\r
+\r
 \r
     /**\r
      * Chart panel header with minimize and close buttons.\r
@@ -57,34 +87,65 @@ public class ChartPanelHeader extends Composite {
         this.resource = chartResource;\r
         this.panel = panel;\r
 \r
-        GridLayoutFactory.fillDefaults().numColumns(3).applyTo(this);\r
+        GridLayoutFactory.fillDefaults().margins(3, 0).numColumns(3).applyTo(this);\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(this);\r
 \r
+        // Chart icon\r
+        iconCanvas = new Canvas (this, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(16, 16).applyTo(iconCanvas);\r
+        iconCanvas.addPaintListener (new PaintListener() {\r
+\r
+            @Override\r
+            public void paintControl(PaintEvent e) {\r
+                if(icon != null)\r
+                    e.gc.drawImage (icon, 0, 0);                \r
+            }\r
+        });\r
+\r
         // Label for the chart name (also minimize/expand)\r
         name = new Label(this, SWT.NONE);\r
 \r
         try {\r
             // name updater\r
-            SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+            SimanticsUI.getSession().syncRequest(new Read<Pair<String, Image>>() {\r
 \r
                 @Override\r
-                public String perform(ReadGraph graph) throws DatabaseException {\r
-                    return graph.getPossibleRelatedValue(resource, Layer0.getInstance(graph).HasLabel);\r
+                public Pair<String, Image> perform(ReadGraph graph) throws DatabaseException {\r
+                    JFreeChartResource jfree = JFreeChartResource.getInstance(graph);\r
+                    Layer0 l0 = Layer0.getInstance(graph);\r
+                    String label = graph.getPossibleRelatedValue(resource, l0.HasLabel);\r
+                    Image image = null;\r
+                    Resource plot = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, jfree.Plot));\r
+                    if(plot != null) {\r
+                        if(graph.isInstanceOf(plot, jfree.CategoryPlot))\r
+                            image = barChartImage;\r
+                        else if(graph.isInstanceOf(plot, jfree.PiePlot))\r
+                            image = pieChartImage;\r
+                        else\r
+                            image = lineChartImage;\r
+                    }\r
+                    return new Pair<String, Image>(label, image);\r
                 }\r
 \r
-            }, new Listener<String>() {\r
+            }, new Listener<Pair<String, Image>>() {\r
 \r
                 @Override\r
-                public void execute(final String result) {\r
+                public void execute(final Pair<String, Image> result) {\r
                     if(result == null)\r
                         return;\r
-                    \r
+\r
                     name.getDisplay().asyncExec(new Runnable() {\r
-                        \r
+\r
                         @Override\r
                         public void run() {\r
-                            if(!name.isDisposed())\r
-                                name.setText(result);\r
+                            if(!name.isDisposed() && result.first != null)\r
+                                name.setText(result.first);\r
+\r
+                            if(!iconCanvas.isDisposed() && result.second != null) {\r
+                                icon = result.second;\r
+                                iconCanvas.redraw();\r
+                                ChartPanelHeader.this.layout();\r
+                            }\r
                         }\r
                     });\r
                 }\r
@@ -104,36 +165,27 @@ public class ChartPanelHeader extends Composite {
             e.printStackTrace();\r
             name.setText("No label");\r
         }\r
-\r
-\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(name);\r
-        name.addMouseListener(new MinimizeListener(name));\r
-        name.setCursor(new Cursor(name.getDisplay(), SWT.CURSOR_HAND));\r
-        if(isMinimized())\r
-            name.setToolTipText("Expand");\r
-        else\r
-            name.setToolTipText("Minimize");\r
-\r
-        // Label for minimizing/expanding chart\r
-        minimize = new Label(this, SWT.NONE);\r
-        minimize.setText("^");\r
-        GridDataFactory.fillDefaults().applyTo(minimize);\r
-        minimize.addMouseListener(new MinimizeListener(minimize));\r
-        minimize.setCursor(new Cursor(minimize.getDisplay(), SWT.CURSOR_HAND));\r
-        if(isMinimized())\r
+\r
+        ToolBar toolbar = new ToolBar(this, SWT.FLAT);\r
+        // item for minimizing/expanding chart\r
+        minimize = new ToolItem(toolbar, SWT.PUSH);\r
+        minimize.addSelectionListener(new MinimizeListener());\r
+        if(isMinimized()) {\r
             minimize.setToolTipText("Expand");\r
-        else\r
+            minimize.setImage(maximizeImage);\r
+        } else {\r
             minimize.setToolTipText("Minimize");\r
+            minimize.setImage(minimizeImage);\r
+        }\r
 \r
-        // Label for closing/removing the chart\r
-        remove = new Label(this, SWT.NONE);\r
-        remove.setText("x");\r
-        GridDataFactory.fillDefaults().applyTo(remove);\r
-        remove.addMouseListener(new RemoveChartListener(remove));\r
-        remove.setCursor(new Cursor(remove.getDisplay(), SWT.CURSOR_HAND));\r
+        // item for closing/removing the chart\r
+        remove = new ToolItem(toolbar, SWT.PUSH);\r
+        remove.setImage(closeImage);\r
+        remove.addSelectionListener(new RemoveChartListener());\r
         remove.setToolTipText("Remove");\r
     }\r
-    \r
+\r
     /**\r
      * Return true if this element is minimized, false if expanded\r
      * @return true if this element is minimized, false if expanded\r
@@ -143,39 +195,19 @@ public class ChartPanelHeader extends Composite {
     }\r
 \r
     /**\r
-     * Mouse listener to minimize chart button. Expands and minimizes \r
+     * Listener to minimize chart button. Expands and minimizes \r
      * the chart of this header.\r
      * \r
      * @author Teemu Lempinen\r
      *\r
      */\r
-    private class MinimizeListener implements MouseListener {\r
-\r
-        private Control control;\r
-\r
-        public MinimizeListener(Control control) {\r
-            this.control = control;\r
-        }\r
-\r
+    private class MinimizeListener implements SelectionListener {\r
         @Override\r
-        public void mouseDoubleClick(MouseEvent e) {\r
-        }\r
-        @Override\r
-        public void mouseDown(MouseEvent e) {\r
-            panel.setFocus();\r
-        }\r
-\r
-        @Override\r
-        public void mouseUp(MouseEvent e) {\r
+        public void widgetSelected(SelectionEvent e) {\r
             if(ChartPanelHeader.this.isDisposed())\r
                 return;\r
 \r
-            // Expand only if mouse was released inside the control\r
-            Rectangle bounds = control.getBounds();\r
-            bounds.x = 0;\r
-            bounds.y = 0;\r
-            if(bounds.contains(e.x, e.y))\r
-                panel.expandChart(resource);\r
+            panel.expandChart(resource);\r
 \r
             if(!name.isDisposed() && !minimize.isDisposed()) {\r
                 if(isMinimized()) {\r
@@ -185,46 +217,33 @@ public class ChartPanelHeader extends Composite {
                     name.setToolTipText("Minimize");\r
                     minimize.setToolTipText("Minimize");\r
                 }\r
-            }\r
+            }            \r
+        }\r
+\r
+        @Override\r
+        public void widgetDefaultSelected(SelectionEvent e) {\r
+            widgetSelected(e);\r
         }\r
 \r
     }\r
 \r
     /**\r
-     * Mouse listener for removing this chart from the chart panel.\r
+     * Listener for removing this chart from the chart panel.\r
      * \r
      * @author Teemu Lempinen\r
      *\r
      */\r
-    private class RemoveChartListener implements MouseListener {\r
-\r
-        Control control;\r
-\r
-        public RemoveChartListener(Control control) {\r
-            this.control = control;\r
-        }\r
-\r
-        @Override\r
-        public void mouseDoubleClick(MouseEvent e) {\r
-        }\r
-\r
-        @Override\r
-        public void mouseDown(MouseEvent e) {\r
-            panel.setFocus();\r
-        }\r
-\r
+    private class RemoveChartListener implements SelectionListener {\r
         @Override\r
-        public void mouseUp(MouseEvent e) {\r
+        public void widgetSelected(SelectionEvent e) {\r
             if(!ChartPanelHeader.this.isDisposed()) {\r
-                // Remove only if mouse was released inside the control\r
-                Rectangle bounds = control.getBounds();\r
-                bounds.x = 0;\r
-                bounds.y = 0;\r
-                if(bounds.contains(e.x, e.y))\r
-                    panel.removeChart(resource);\r
+                panel.removeChart(resource);\r
             }\r
+        }\r
 \r
-\r
+        @Override\r
+        public void widgetDefaultSelected(SelectionEvent e) {\r
+            widgetSelected(e);\r
         }\r
 \r
     }\r
index d708ac5f90e4a18ce5ab80995276ce3f7cfe6348..7d80fb887e79377bb48061b4fb357629be3e1fa0 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart;\r
 \r
+import org.jfree.chart.labels.StandardCategoryToolTipGenerator;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 \r
@@ -30,8 +31,10 @@ public class BarRenderer extends AbstractRenderer {
     \r
     @Override\r
     public org.jfree.chart.renderer.AbstractRenderer getRenderer() {\r
-        if(renderer == null)\r
+        if(renderer == null) {\r
             renderer = new org.jfree.chart.renderer.category.BarRenderer();\r
+            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());\r
+        }\r
         return renderer;\r
     }\r
 \r
index 60a0092502bb48ac8ffb61b103a888a487788d5f..297eb678ec066710e93c8c5b447595773fe15686 100644 (file)
@@ -15,6 +15,7 @@ import org.jfree.chart.axis.CategoryAxis;
 import org.jfree.chart.axis.ValueAxis;\r
 import org.jfree.chart.plot.Plot;\r
 import org.jfree.chart.renderer.category.CategoryItemRenderer;\r
+import org.jfree.ui.RectangleInsets;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -81,6 +82,10 @@ public class CategoryPlot extends AbstractPlot {
             plot.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
     }\r
 \r
index 830ff222692e4f34005796c95756f7bb36f2a737..826c032002c75de65d51b3e73661efa6e36f9368 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart;\r
 \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
 \r
-import org.jfree.chart.title.LegendTitle;\r
+import org.jfree.ui.RectangleInsets;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -82,16 +84,21 @@ public class JFreeChart implements IJFreeChart {
                 @Override\r
                 public void run() {\r
                     jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot());\r
+                    \r
+                    jfreechart.setBackgroundPaint(Color.WHITE);\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
+                    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
-                        for(Object title : jfreechart.getSubtitles()) {\r
-                            if(title instanceof LegendTitle) {\r
-                                jfreechart.removeLegend();\r
-                            }\r
-                        }\r
+                        jfreechart.removeLegend();\r
                     }\r
                 }\r
             });\r
index 62da880447ce480a171dbe432650d1afc5e78e75..231b6446d2113dcb6a665bc8e5a1915985d74243 100644 (file)
 package org.simantics.sysdyn.ui.trend.chart;\r
 \r
 import java.awt.Color;\r
+import java.awt.Font;\r
 import java.util.HashMap;\r
 \r
+import org.jfree.chart.labels.StandardPieSectionLabelGenerator;\r
+import org.jfree.chart.labels.StandardPieToolTipGenerator;\r
 import org.jfree.chart.plot.DefaultDrawingSupplier;\r
 import org.jfree.chart.plot.Plot;\r
 import org.jfree.data.general.Dataset;\r
 import org.jfree.data.general.DatasetChangeEvent;\r
 import org.jfree.data.general.DatasetChangeListener;\r
+import org.jfree.ui.RectangleInsets;\r
+import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.JFreeChartResource;\r
 \r
 /**\r
  * Class representing a PiePlot in JFreeChart ontology\r
@@ -30,18 +37,27 @@ import org.simantics.db.Resource;
  */\r
 public class PiePlot extends AbstractPlot {\r
 \r
-    org.jfree.chart.plot.PiePlot plot;\r
-    org.jfree.data.general.PieDataset pieDataset;\r
-    DatasetChangeListener listener;\r
+    private org.jfree.chart.plot.PiePlot plot;\r
+    private org.jfree.data.general.PieDataset pieDataset;\r
+    private DatasetChangeListener listener;\r
+    \r
+    private Boolean labelsVisible;\r
 \r
     public PiePlot(ReadGraph graph, Resource resource) {\r
         super(graph, resource);\r
+        \r
+        try {\r
+            labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN);\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
     }\r
 \r
     @Override\r
     public Plot getPlot() {\r
         if(plot == null) {\r
             plot = new MyPiePlot();\r
+            plot.setToolTipGenerator(new StandardPieToolTipGenerator());\r
         }\r
 \r
         if(!datasets.isEmpty()) {\r
@@ -49,15 +65,16 @@ public class PiePlot extends AbstractPlot {
             final IDataset ds = datasets.get(0);\r
             Dataset dataset = ((PieDataset)ds).getDataset();\r
 \r
-            plot.clearSectionPaints(true);\r
-            plot.setDrawingSupplier(new DefaultDrawingSupplier());\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
+            if(Boolean.FALSE.equals(labelsVisible))\r
+                plot.setLabelGenerator(null);\r
+            else if(plot.getLabelGenerator() == null)\r
+                plot.setLabelGenerator(new StandardPieSectionLabelGenerator());\r
             \r
             listener = new DatasetChangeListener() {\r
                 \r
@@ -83,9 +100,8 @@ public class PiePlot extends AbstractPlot {
                         if(Boolean.TRUE.equals(exploded))\r
                             plot.setExplodePercent(name, 0.3);\r
                     } \r
-                    \r
+                    plot.clearSectionPaints(false);\r
                     plot.setDrawingSupplier(new DefaultDrawingSupplier());\r
-\r
                     for(String name : colorMap.keySet())\r
                         plot.setSectionPaint(name, colorMap.get(name));\r
                 }\r
@@ -93,6 +109,13 @@ public class PiePlot extends AbstractPlot {
             \r
             pieDataset.addChangeListener(listener);\r
         }\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
index daf266b8d8d78315ba79342a83476b685f07e425..cd7f4cbf0e0d7f889b5cea6dc4c65c9b7c08081a 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.trend.chart;\r
 \r
+import org.jfree.chart.labels.StandardCategoryToolTipGenerator;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 \r
@@ -29,8 +30,10 @@ public class StackedBarRenderer extends AbstractRenderer {
     \r
     @Override\r
     public org.jfree.chart.renderer.AbstractRenderer getRenderer() {\r
-        if(renderer == null)\r
+        if(renderer == null) {\r
             renderer = new org.jfree.chart.renderer.category.StackedBarRenderer();\r
+            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());\r
+        }\r
         return renderer;\r
     }\r
 \r
index a9d6ce8088e4dc499a6ed289d3cf914c727abac6..b2981b9f04e8631e3f73957698ba244ae0aa40fe 100644 (file)
@@ -13,12 +13,15 @@ package org.simantics.sysdyn.ui.trend.chart;
 \r
 import java.awt.BasicStroke;\r
 import java.awt.Color;\r
+import java.awt.Paint;\r
 import java.awt.Stroke;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
 import javax.swing.SwingUtilities;\r
 \r
+import org.jfree.chart.ChartColor;\r
+import org.jfree.chart.labels.StandardXYToolTipGenerator;\r
 import org.jfree.chart.plot.DefaultDrawingSupplier;\r
 import org.jfree.chart.plot.ValueMarker;\r
 import org.jfree.chart.renderer.AbstractRenderer;\r
@@ -155,20 +158,20 @@ public class XYDataset extends AbstractDataset {
                                 // Get a variable for the series\r
                                 Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
 \r
-                                \r
+\r
                                 // Get values\r
                                 Object object =  v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT);\r
                                 if(object == null || !(object instanceof ArrayList<?>))\r
                                     return series;\r
-                                \r
+\r
                                 ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
 \r
                                 for(Object o : (ArrayList<?>)object) {\r
                                     if(o instanceof SysdynDataSet)\r
                                         datasets.add((SysdynDataSet)o);\r
                                 }\r
-                                \r
-                                \r
+\r
+\r
                                 String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter);\r
                                 if(filter != null) {\r
                                     ArrayList<SysdynDataSet> result2 = VariableRVIUtils.getDataset(datasets, filter);\r
@@ -176,7 +179,7 @@ public class XYDataset extends AbstractDataset {
                                         datasets = result2;\r
                                     }\r
                                 }\r
-                                \r
+\r
                                 for(SysdynDataSet dataset : datasets) {\r
                                     double[] va = dataset.values;\r
 \r
@@ -228,7 +231,7 @@ public class XYDataset extends AbstractDataset {
         }\r
 \r
         if(timeListener == null || timeListener.isDisposed()) {\r
-            timeListener = new TimeListener(new ValueMarker(0.0));\r
+            timeListener = new TimeListener();\r
             SimanticsUI.getSession().asyncRequest(new Read<Double>() {\r
                 @Override\r
                 public Double perform(ReadGraph graph) throws DatabaseException {\r
@@ -257,6 +260,18 @@ public class XYDataset extends AbstractDataset {
         return dataset;\r
     }\r
 \r
+    /**\r
+     * Class for identifying a time marker in a plot\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    private class TimeMarker extends ValueMarker {\r
+        private static final long serialVersionUID = 2018755066561629172L;\r
+\r
+        public TimeMarker(double value, Paint paint, Stroke stroke) {\r
+            super(value, paint, stroke);\r
+        }\r
+    }\r
 \r
     private class DataSetListener implements Listener<ArrayList<TempSeries>> {\r
 \r
@@ -278,7 +293,21 @@ public class XYDataset extends AbstractDataset {
 \r
                 @Override\r
                 public void run() {\r
-                    ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(new DefaultDrawingSupplier());\r
+\r
+                    /*\r
+                     *  Drawing supplier with a modified first yellow. The default first\r
+                     *  yellow is too light to be visible against a white background\r
+                     */\r
+                    Paint[] paintSequence = ChartColor.createDefaultPaintArray();\r
+                    paintSequence[3] = new Color(0xFF, 0xDD, 0x00);\r
+                    DefaultDrawingSupplier drawingsupplier = new DefaultDrawingSupplier(\r
+                            paintSequence,\r
+                            DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,\r
+                            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,\r
+                            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,\r
+                            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,\r
+                            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);\r
+                    ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(drawingsupplier);\r
                     // Remove all series\r
                     for(int i = dataset.getSeriesCount() - 1; i >= 0; i-- ) {\r
                         dataset.removeSeries(dataset.getSeriesKey(i));\r
@@ -303,17 +332,29 @@ public class XYDataset extends AbstractDataset {
     }\r
 \r
 \r
+    /**\r
+     * Listener for updating the time indicator for XY plots\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
     private class TimeListener implements Listener<Double> {\r
 \r
         private ValueMarker marker;\r
         private boolean disposed = false;\r
+        private Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,\r
+                BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f);\r
 \r
-        public TimeListener(ValueMarker marker) {\r
-            this.marker = marker;\r
+        public TimeListener() {\r
+            this.marker = new TimeMarker(0.0, Color.red, dashStroke);\r
         }\r
 \r
         public void dispose() {\r
             this.disposed = true;\r
+            if(marker != null) {\r
+                org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot();\r
+                if(plot != null)\r
+                    plot.removeDomainMarker(marker);\r
+            }\r
         }\r
 \r
         @Override\r
@@ -330,18 +371,20 @@ public class XYDataset extends AbstractDataset {
                 public void run() {\r
                     org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot();\r
 \r
-                    int i = 0;\r
-                    for(i = 0; i < plot.getDatasetCount(); i++) {\r
-                        if(plot.getDataset(i).equals(dataset))\r
-                            break;\r
-                    }\r
+                    if(plot == null)\r
+                        return;\r
 \r
                     plot.removeDomainMarker(marker);\r
                     if(time != null) {\r
-                        Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,\r
-                                BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f);\r
-                        marker = new ValueMarker(time, Color.red, dashStroke);\r
-                        plot.addDomainMarker(i, marker, Layer.FOREGROUND);\r
+                        marker.setValue(time);\r
+                        if(plot.getDomainMarkers(Layer.FOREGROUND) == null || !plot.getDomainMarkers(Layer.FOREGROUND).contains(marker)) {\r
+                            int i = 0;\r
+                            for(i = 0; i < plot.getDatasetCount(); i++) {\r
+                                if(plot.getDataset(i) != null && plot.getDataset(i).equals(dataset))\r
+                                    break;\r
+                            }\r
+                            plot.addDomainMarker(i, marker, Layer.FOREGROUND);\r
+                        }\r
                     }\r
 \r
                 }\r
@@ -390,8 +433,10 @@ public class XYDataset extends AbstractDataset {
 \r
     @Override\r
     public AbstractRenderer getRenderer() {\r
-        if(renderer == null)\r
+        if(renderer == null) {\r
             renderer = new XYLineAndShapeRenderer(true, false);\r
+            renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());\r
+        }\r
         return renderer;\r
     }\r
 }\r
index a64f9cf16e8779245e93830789cbd32ba7843088..af0cc336a94b7c0033827155e07bfb7b7279d737 100644 (file)
@@ -15,6 +15,7 @@ import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.Plot;\r
 import org.jfree.chart.renderer.xy.XYItemRenderer;\r
 import org.jfree.data.xy.XYDataset;\r
+import org.jfree.ui.RectangleInsets;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
@@ -80,6 +81,10 @@ public class XYPlot extends AbstractPlot {
         plot.setRangeGridlinesVisible(visibleGrid);\r
         plot.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
     }\r
 \r
index fdff61b0ab0a156830c2f437cd2df28e53d231ec..bbaa7b4b6e5b25cbbca0f8cc0d4cd13ef8d38147 100644 (file)
@@ -44,7 +44,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
 \r
     private ScrolledComposite sc;\r
     private Composite composite;\r
-    private Button htitle, hlegend;\r
+    private Button htitle, hlegend, hlabels;\r
     private TrackedText name, title;\r
 \r
     @Override\r
@@ -101,6 +101,10 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
         hlegend.setText("Legend");\r
         hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));\r
         hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));\r
+        hlabels = new Button(hideGroup, support, SWT.CHECK);\r
+        hlabels.setText("Section labels");\r
+        hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));\r
+        hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));\r
         \r
         sc.setContent(composite);\r
         Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r