From 910b34c1664ed38aac6718a50b97389fdfa80367 Mon Sep 17 00:00:00 2001 From: lempinen Date: Mon, 12 Dec 2011 12:27:10 +0000 Subject: [PATCH] Cleaned the look of charts, chart panel elements and model browser chart elements git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23495 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.jfreechart.ontology/graph.tg | Bin 6158 -> 6294 bytes .../graph/JFreeChart.pgraph | 1 + .../simantics/sysdyn/JFreeChartResource.java | 6 + org.simantics.sysdyn.ui/icons/close.gif | Bin 0 -> 73 bytes org.simantics.sysdyn.ui/icons/maximize.gif | Bin 0 -> 69 bytes org.simantics.sysdyn.ui/icons/minimize.gif | Bin 0 -> 67 bytes .../icons/timeline_marker.png | Bin 0 -> 327 bytes org.simantics.sysdyn.ui/plugin.xml | 5 + .../contributions/AbstractNodeImager.java | 11 +- .../simantics/sysdyn/ui/trend/ChartPanel.java | 2 +- .../sysdyn/ui/trend/ChartPanelHeader.java | 201 ++++++++++-------- .../sysdyn/ui/trend/chart/BarRenderer.java | 5 +- .../sysdyn/ui/trend/chart/CategoryPlot.java | 5 + .../sysdyn/ui/trend/chart/JFreeChart.java | 21 +- .../sysdyn/ui/trend/chart/PiePlot.java | 39 +++- .../ui/trend/chart/StackedBarRenderer.java | 5 +- .../sysdyn/ui/trend/chart/XYDataset.java | 83 ++++++-- .../sysdyn/ui/trend/chart/XYPlot.java | 5 + .../pie/PieGeneralPropertiesTab.java | 6 +- 19 files changed, 263 insertions(+), 132 deletions(-) create mode 100644 org.simantics.sysdyn.ui/icons/close.gif create mode 100644 org.simantics.sysdyn.ui/icons/maximize.gif create mode 100644 org.simantics.sysdyn.ui/icons/minimize.gif create mode 100644 org.simantics.sysdyn.ui/icons/timeline_marker.png diff --git a/org.simantics.jfreechart.ontology/graph.tg b/org.simantics.jfreechart.ontology/graph.tg index f85899a232d244cf84dc745dbf95352b9274630c..d250dc962037c81ecad6348996061b139869e416 100644 GIT binary patch literal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+UDN-XnRqP9m?A^S*%7+B&ZY7bferHk~V XvHA%)9i;6+G=22TpZr`)`Ct4G?h|vG diff --git a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph index 4611e693..2526730c 100644 --- a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph +++ b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph @@ -45,6 +45,7 @@ JFREE.Plot -- JFREE.backgroundColor --> G2D.Color -- JFREE.Plot.visibleGrid --> L0.Boolean -- JFREE.Plot.rangeAxisList --> L0.List -- JFREE.Plot.visibleLabels --> L0.Boolean u@XyPb%`)o0|0bQ6Wss+ literal 0 HcmV?d00001 diff --git a/org.simantics.sysdyn.ui/icons/maximize.gif b/org.simantics.sysdyn.ui/icons/maximize.gif new file mode 100644 index 0000000000000000000000000000000000000000..5e5999be358b3b6bc40a09790750e659be2ed717 GIT binary patch literal 69 zcmZ?wbhEHb6krfwXkcK-FKhY#|G(l-7DfgJMg|=QAOOiQFv;}vuRQ%WzhO@C#q7;Y WRv+&w&KH+koDnN}WSc)DgEauWj}{{U literal 0 HcmV?d00001 diff --git a/org.simantics.sysdyn.ui/icons/minimize.gif b/org.simantics.sysdyn.ui/icons/minimize.gif new file mode 100644 index 0000000000000000000000000000000000000000..7402dc9ff32ad9379bb8ee65cef74a28911fb957 GIT binary patch literal 67 zcmZ?wbhEHb6krfwn8?6jA8*gV!0`Y7e;}#&lZBCifr&u}$Og&^0NEl_`d6NQ%fEQe T7P|)Hw1vO(S|0^7FjxZs6EG5! literal 0 HcmV?d00001 diff --git a/org.simantics.sysdyn.ui/icons/timeline_marker.png b/org.simantics.sysdyn.ui/icons/timeline_marker.png new file mode 100644 index 0000000000000000000000000000000000000000..a3fbddf88b7661e9ee2a434ad4152cc724db24c5 GIT binary patch literal 327 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^zbpD<_bdI{u9mbgZg z1m~xflqVLYGB~E>C#5QQ<|d}62BjvZR2H60wE-%+>FMGaA|c6o&@rz!QG)Hl=lY!! z1v*=JI|P}v6PV8&74ykGbnHgML`m~0TYQt3?ajRZzjDrI(GNdQ-+es!^5)m?umAh| z_lML2hJx>}8mr}YRTjS1X5c%1=To>j zEp`{T<8b2%3kmpmE&u%$g;f!Ou2+6+ab?{tp`+Eo<@Tn7>)N`e4#yAy(KQ_jApxR2 zTwy>}5{4Z&HZE$4TztEY4eB^wEm!DE&<6VJfqm!9 Wxdqp5p1KL-FnGH9xvX @@ -463,6 +464,7 @@ @@ -565,6 +567,7 @@ @@ -581,6 +584,7 @@ @@ -597,6 +601,7 @@ diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java index e6051f38..5ff989ea 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java @@ -17,6 +17,7 @@ import org.simantics.browsing.ui.swt.ImagerContributor; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.Activator; import org.simantics.sysdyn.ui.browser.nodes.BookNode; import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode; @@ -50,9 +51,13 @@ public class AbstractNodeImager extends ImagerContributor image = "icons/folder.png"; else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode) image = "icons/bricks.png"; - else if (node instanceof ExperimentNode) - image = "icons/time.png"; - else if (node instanceof InputNode) + else if (node instanceof ExperimentNode) { + SysdynResource sr = SysdynResource.getInstance(graph); + if(graph.isInstanceOf(node.data, sr.PlaybackExperiment)) + image = "icons/timeline_marker.png"; + else + image = "icons/time.png"; + } else if (node instanceof InputNode) image = "icons/brick_link.png"; else if (node instanceof ModelNode) image = "icons/chart_organisation.png"; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java index af8781d9..38370a9e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanel.java @@ -149,7 +149,7 @@ public class ChartPanel extends ViewPart { setupDropTarget(); body = new Composite(sc, SWT.NONE); - GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(body); + GridLayoutFactory.fillDefaults().margins(3, 0).spacing(0, 0).applyTo(body); GridDataFactory.fillDefaults().grab(true, true).applyTo(body); sc.setContent(body); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java index f0334fc6..e37b82fb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/ChartPanelHeader.java @@ -13,21 +13,29 @@ package org.simantics.sysdyn.ui.trend; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; +import org.simantics.sysdyn.JFreeChartResource; +import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Pair; /** * Header of a chart element in {@link ChartPanel}. Only this header is @@ -42,7 +50,29 @@ public class ChartPanelHeader extends Composite { public static int HEADER_MINIMUM_WIDTH = 250; private ChartPanel panel; private Resource resource; - private Label name, minimize, remove; + private Label name; + private Canvas iconCanvas; + private Image icon; + private ToolItem minimize, remove; + + private static ImageDescriptor closeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/close.gif")); + private static Image closeImage = closeDescriptor.createImage(); + + private static ImageDescriptor minimizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/minimize.gif")); + private static Image minimizeImage = minimizeDescriptor.createImage(); + + private static ImageDescriptor maximizeDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/maximize.gif")); + private static Image maximizeImage = maximizeDescriptor.createImage(); + + private static ImageDescriptor lineChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_line_light.png")); + private static Image lineChartImage = lineChartDescriptor.createImage(); + + private static ImageDescriptor barChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_light.png")); + private static Image barChartImage = barChartDescriptor.createImage(); + + private static ImageDescriptor pieChartDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_pie_light.png")); + private static Image pieChartImage = pieChartDescriptor.createImage(); + /** * Chart panel header with minimize and close buttons. @@ -57,34 +87,65 @@ public class ChartPanelHeader extends Composite { this.resource = chartResource; this.panel = panel; - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(this); + GridLayoutFactory.fillDefaults().margins(3, 0).numColumns(3).applyTo(this); GridDataFactory.fillDefaults().grab(true, false).applyTo(this); + // Chart icon + iconCanvas = new Canvas (this, SWT.NONE); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(16, 16).applyTo(iconCanvas); + iconCanvas.addPaintListener (new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + if(icon != null) + e.gc.drawImage (icon, 0, 0); + } + }); + // Label for the chart name (also minimize/expand) name = new Label(this, SWT.NONE); try { // name updater - SimanticsUI.getSession().syncRequest(new Read() { + SimanticsUI.getSession().syncRequest(new Read>() { @Override - public String perform(ReadGraph graph) throws DatabaseException { - return graph.getPossibleRelatedValue(resource, Layer0.getInstance(graph).HasLabel); + public Pair perform(ReadGraph graph) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + String label = graph.getPossibleRelatedValue(resource, l0.HasLabel); + Image image = null; + Resource plot = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, jfree.Plot)); + if(plot != null) { + if(graph.isInstanceOf(plot, jfree.CategoryPlot)) + image = barChartImage; + else if(graph.isInstanceOf(plot, jfree.PiePlot)) + image = pieChartImage; + else + image = lineChartImage; + } + return new Pair(label, image); } - }, new Listener() { + }, new Listener>() { @Override - public void execute(final String result) { + public void execute(final Pair result) { if(result == null) return; - + name.getDisplay().asyncExec(new Runnable() { - + @Override public void run() { - if(!name.isDisposed()) - name.setText(result); + if(!name.isDisposed() && result.first != null) + name.setText(result.first); + + if(!iconCanvas.isDisposed() && result.second != null) { + icon = result.second; + iconCanvas.redraw(); + ChartPanelHeader.this.layout(); + } } }); } @@ -104,36 +165,27 @@ public class ChartPanelHeader extends Composite { e.printStackTrace(); name.setText("No label"); } - - GridDataFactory.fillDefaults().grab(true, false).applyTo(name); - name.addMouseListener(new MinimizeListener(name)); - name.setCursor(new Cursor(name.getDisplay(), SWT.CURSOR_HAND)); - if(isMinimized()) - name.setToolTipText("Expand"); - else - name.setToolTipText("Minimize"); - - // Label for minimizing/expanding chart - minimize = new Label(this, SWT.NONE); - minimize.setText("^"); - GridDataFactory.fillDefaults().applyTo(minimize); - minimize.addMouseListener(new MinimizeListener(minimize)); - minimize.setCursor(new Cursor(minimize.getDisplay(), SWT.CURSOR_HAND)); - if(isMinimized()) + + ToolBar toolbar = new ToolBar(this, SWT.FLAT); + // item for minimizing/expanding chart + minimize = new ToolItem(toolbar, SWT.PUSH); + minimize.addSelectionListener(new MinimizeListener()); + if(isMinimized()) { minimize.setToolTipText("Expand"); - else + minimize.setImage(maximizeImage); + } else { minimize.setToolTipText("Minimize"); + minimize.setImage(minimizeImage); + } - // Label for closing/removing the chart - remove = new Label(this, SWT.NONE); - remove.setText("x"); - GridDataFactory.fillDefaults().applyTo(remove); - remove.addMouseListener(new RemoveChartListener(remove)); - remove.setCursor(new Cursor(remove.getDisplay(), SWT.CURSOR_HAND)); + // item for closing/removing the chart + remove = new ToolItem(toolbar, SWT.PUSH); + remove.setImage(closeImage); + remove.addSelectionListener(new RemoveChartListener()); remove.setToolTipText("Remove"); } - + /** * Return true if this element is minimized, false if expanded * @return true if this element is minimized, false if expanded @@ -143,39 +195,19 @@ public class ChartPanelHeader extends Composite { } /** - * Mouse listener to minimize chart button. Expands and minimizes + * Listener to minimize chart button. Expands and minimizes * the chart of this header. * * @author Teemu Lempinen * */ - private class MinimizeListener implements MouseListener { - - private Control control; - - public MinimizeListener(Control control) { - this.control = control; - } - + private class MinimizeListener implements SelectionListener { @Override - public void mouseDoubleClick(MouseEvent e) { - } - @Override - public void mouseDown(MouseEvent e) { - panel.setFocus(); - } - - @Override - public void mouseUp(MouseEvent e) { + public void widgetSelected(SelectionEvent e) { if(ChartPanelHeader.this.isDisposed()) return; - // Expand only if mouse was released inside the control - Rectangle bounds = control.getBounds(); - bounds.x = 0; - bounds.y = 0; - if(bounds.contains(e.x, e.y)) - panel.expandChart(resource); + panel.expandChart(resource); if(!name.isDisposed() && !minimize.isDisposed()) { if(isMinimized()) { @@ -185,46 +217,33 @@ public class ChartPanelHeader extends Composite { name.setToolTipText("Minimize"); minimize.setToolTipText("Minimize"); } - } + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); } } /** - * Mouse listener for removing this chart from the chart panel. + * Listener for removing this chart from the chart panel. * * @author Teemu Lempinen * */ - private class RemoveChartListener implements MouseListener { - - Control control; - - public RemoveChartListener(Control control) { - this.control = control; - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - } - - @Override - public void mouseDown(MouseEvent e) { - panel.setFocus(); - } - + private class RemoveChartListener implements SelectionListener { @Override - public void mouseUp(MouseEvent e) { + public void widgetSelected(SelectionEvent e) { if(!ChartPanelHeader.this.isDisposed()) { - // Remove only if mouse was released inside the control - Rectangle bounds = control.getBounds(); - bounds.x = 0; - bounds.y = 0; - if(bounds.contains(e.x, e.y)) - panel.removeChart(resource); + panel.removeChart(resource); } + } - + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java index d708ac5f..7d80fb88 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; +import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -30,8 +31,10 @@ public class BarRenderer extends AbstractRenderer { @Override public org.jfree.chart.renderer.AbstractRenderer getRenderer() { - if(renderer == null) + if(renderer == null) { renderer = new org.jfree.chart.renderer.category.BarRenderer(); + renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); + } return renderer; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java index 60a00925..297eb678 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java @@ -15,6 +15,7 @@ import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.Plot; import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.ui.RectangleInsets; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; @@ -81,6 +82,10 @@ public class CategoryPlot extends AbstractPlot { plot.setDomainGridlinesVisible(false); } + // Cleaner look: no outline borders + plot.setInsets(new RectangleInsets(2,2,2,2), false); + plot.setOutlineVisible(false); + return plot; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java index 830ff222..826c0320 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java @@ -11,12 +11,14 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; +import java.awt.Color; +import java.awt.Font; import java.lang.reflect.InvocationTargetException; import java.util.Collection; import javax.swing.SwingUtilities; -import org.jfree.chart.title.LegendTitle; +import org.jfree.ui.RectangleInsets; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -82,16 +84,21 @@ public class JFreeChart implements IJFreeChart { @Override public void run() { jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); + + jfreechart.setBackgroundPaint(Color.WHITE); + jfreechart.getLegend().setBorder(0, 0, 0, 0); + int size = jfreechart.getLegend().getItemFont().getSize(); + jfreechart.getLegend().setItemFont(new Font("helvetica", Font.PLAIN, size)); + org.jfree.chart.title.TextTitle t = (org.jfree.chart.title.TextTitle)title.getTitle(); - if(t.isVisible()) + if(t.isVisible()) { + t.setFont(new Font("georgia", Font.BOLD, 13)); + t.setPadding(new RectangleInsets(4, 0, 0, 0)); jfreechart.setTitle(t); + } if(legendVisible != null && !legendVisible) { - for(Object title : jfreechart.getSubtitles()) { - if(title instanceof LegendTitle) { - jfreechart.removeLegend(); - } - } + jfreechart.removeLegend(); } } }); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java index 62da8804..231b6446 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java @@ -12,15 +12,22 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.Color; +import java.awt.Font; import java.util.HashMap; +import org.jfree.chart.labels.StandardPieSectionLabelGenerator; +import org.jfree.chart.labels.StandardPieToolTipGenerator; import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.Plot; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; +import org.jfree.ui.RectangleInsets; +import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.sysdyn.JFreeChartResource; /** * Class representing a PiePlot in JFreeChart ontology @@ -30,18 +37,27 @@ import org.simantics.db.Resource; */ public class PiePlot extends AbstractPlot { - org.jfree.chart.plot.PiePlot plot; - org.jfree.data.general.PieDataset pieDataset; - DatasetChangeListener listener; + private org.jfree.chart.plot.PiePlot plot; + private org.jfree.data.general.PieDataset pieDataset; + private DatasetChangeListener listener; + + private Boolean labelsVisible; public PiePlot(ReadGraph graph, Resource resource) { super(graph, resource); + + try { + labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN); + } catch (DatabaseException e) { + e.printStackTrace(); + } } @Override public Plot getPlot() { if(plot == null) { plot = new MyPiePlot(); + plot.setToolTipGenerator(new StandardPieToolTipGenerator()); } if(!datasets.isEmpty()) { @@ -49,15 +65,16 @@ public class PiePlot extends AbstractPlot { final IDataset ds = datasets.get(0); Dataset dataset = ((PieDataset)ds).getDataset(); - plot.clearSectionPaints(true); - plot.setDrawingSupplier(new DefaultDrawingSupplier()); - if(pieDataset != null && listener != null) { pieDataset.removeChangeListener(listener); } pieDataset = (org.jfree.data.general.PieDataset)dataset; plot.setDataset(pieDataset); + if(Boolean.FALSE.equals(labelsVisible)) + plot.setLabelGenerator(null); + else if(plot.getLabelGenerator() == null) + plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); listener = new DatasetChangeListener() { @@ -83,9 +100,8 @@ public class PiePlot extends AbstractPlot { if(Boolean.TRUE.equals(exploded)) plot.setExplodePercent(name, 0.3); } - + plot.clearSectionPaints(false); plot.setDrawingSupplier(new DefaultDrawingSupplier()); - for(String name : colorMap.keySet()) plot.setSectionPaint(name, colorMap.get(name)); } @@ -93,6 +109,13 @@ public class PiePlot extends AbstractPlot { pieDataset.addChangeListener(listener); } + + // Cleaner look: no outline borders + plot.setInsets(new RectangleInsets(0,0,0,0), false); + plot.setOutlineVisible(false); + plot.setLabelBackgroundPaint(Color.WHITE); + plot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); + return plot; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java index daf266b8..cd7f4cbf 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart; +import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -29,8 +30,10 @@ public class StackedBarRenderer extends AbstractRenderer { @Override public org.jfree.chart.renderer.AbstractRenderer getRenderer() { - if(renderer == null) + if(renderer == null) { renderer = new org.jfree.chart.renderer.category.StackedBarRenderer(); + renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); + } return renderer; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java index a9d6ce80..b2981b9f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java @@ -13,12 +13,15 @@ package org.simantics.sysdyn.ui.trend.chart; import java.awt.BasicStroke; import java.awt.Color; +import java.awt.Paint; import java.awt.Stroke; import java.util.ArrayList; import java.util.List; import javax.swing.SwingUtilities; +import org.jfree.chart.ChartColor; +import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.ValueMarker; import org.jfree.chart.renderer.AbstractRenderer; @@ -155,20 +158,20 @@ public class XYDataset extends AbstractDataset { // Get a variable for the series Variable v = Variables.getVariable(graph, realizationURI + rvi); - + // Get values Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); if(object == null || !(object instanceof ArrayList)) return series; - + ArrayList datasets = new ArrayList(); for(Object o : (ArrayList)object) { if(o instanceof SysdynDataSet) datasets.add((SysdynDataSet)o); } - - + + String[] filter = graph.getPossibleRelatedValue(r, jfree.variableFilter); if(filter != null) { ArrayList result2 = VariableRVIUtils.getDataset(datasets, filter); @@ -176,7 +179,7 @@ public class XYDataset extends AbstractDataset { datasets = result2; } } - + for(SysdynDataSet dataset : datasets) { double[] va = dataset.values; @@ -228,7 +231,7 @@ public class XYDataset extends AbstractDataset { } if(timeListener == null || timeListener.isDisposed()) { - timeListener = new TimeListener(new ValueMarker(0.0)); + timeListener = new TimeListener(); SimanticsUI.getSession().asyncRequest(new Read() { @Override public Double perform(ReadGraph graph) throws DatabaseException { @@ -257,6 +260,18 @@ public class XYDataset extends AbstractDataset { return dataset; } + /** + * Class for identifying a time marker in a plot + * @author Teemu Lempinen + * + */ + private class TimeMarker extends ValueMarker { + private static final long serialVersionUID = 2018755066561629172L; + + public TimeMarker(double value, Paint paint, Stroke stroke) { + super(value, paint, stroke); + } + } private class DataSetListener implements Listener> { @@ -278,7 +293,21 @@ public class XYDataset extends AbstractDataset { @Override public void run() { - ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(new DefaultDrawingSupplier()); + + /* + * Drawing supplier with a modified first yellow. The default first + * yellow is too light to be visible against a white background + */ + Paint[] paintSequence = ChartColor.createDefaultPaintArray(); + paintSequence[3] = new Color(0xFF, 0xDD, 0x00); + DefaultDrawingSupplier drawingsupplier = new DefaultDrawingSupplier( + paintSequence, + DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, + DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); + ((AbstractXYItemRenderer)getRenderer()).getPlot().setDrawingSupplier(drawingsupplier); // Remove all series for(int i = dataset.getSeriesCount() - 1; i >= 0; i-- ) { dataset.removeSeries(dataset.getSeriesKey(i)); @@ -303,17 +332,29 @@ public class XYDataset extends AbstractDataset { } + /** + * Listener for updating the time indicator for XY plots + * @author Teemu Lempinen + * + */ private class TimeListener implements Listener { private ValueMarker marker; private boolean disposed = false; + private Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f); - public TimeListener(ValueMarker marker) { - this.marker = marker; + public TimeListener() { + this.marker = new TimeMarker(0.0, Color.red, dashStroke); } public void dispose() { this.disposed = true; + if(marker != null) { + org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); + if(plot != null) + plot.removeDomainMarker(marker); + } } @Override @@ -330,18 +371,20 @@ public class XYDataset extends AbstractDataset { public void run() { org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); - int i = 0; - for(i = 0; i < plot.getDatasetCount(); i++) { - if(plot.getDataset(i).equals(dataset)) - break; - } + if(plot == null) + return; plot.removeDomainMarker(marker); if(time != null) { - Stroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, - BasicStroke.JOIN_MITER, 10.0f, new float[] {5.0f, 3.0f, 1.0f, 3.0f}, 0.0f); - marker = new ValueMarker(time, Color.red, dashStroke); - plot.addDomainMarker(i, marker, Layer.FOREGROUND); + marker.setValue(time); + if(plot.getDomainMarkers(Layer.FOREGROUND) == null || !plot.getDomainMarkers(Layer.FOREGROUND).contains(marker)) { + int i = 0; + for(i = 0; i < plot.getDatasetCount(); i++) { + if(plot.getDataset(i) != null && plot.getDataset(i).equals(dataset)) + break; + } + plot.addDomainMarker(i, marker, Layer.FOREGROUND); + } } } @@ -390,8 +433,10 @@ public class XYDataset extends AbstractDataset { @Override public AbstractRenderer getRenderer() { - if(renderer == null) + if(renderer == null) { renderer = new XYLineAndShapeRenderer(true, false); + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + } return renderer; } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java index a64f9cf1..af0cc336 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java @@ -15,6 +15,7 @@ import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.Plot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.xy.XYDataset; +import org.jfree.ui.RectangleInsets; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; @@ -80,6 +81,10 @@ public class XYPlot extends AbstractPlot { plot.setRangeGridlinesVisible(visibleGrid); plot.setDomainGridlinesVisible(visibleGrid); + // Cleaner look: no outline borders + plot.setInsets(new RectangleInsets(2,2,2,2), false); + plot.setOutlineVisible(false); + return plot; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java index fdff61b0..bbaa7b4b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java @@ -44,7 +44,7 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { private ScrolledComposite sc; private Composite composite; - private Button htitle, hlegend; + private Button htitle, hlegend, hlabels; private TrackedText name, title; @Override @@ -101,6 +101,10 @@ public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { hlegend.setText("Legend"); hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); + hlabels = new Button(hideGroup, support, SWT.CHECK); + hlabels.setText("Section labels"); + hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true)); + hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels)); sc.setContent(composite); Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); -- 2.47.1