From 90b6edc3f1a286b1833e7f27c7963cfd1a52ea9c Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 21 Dec 2011 09:41:33 +0000 Subject: [PATCH] added XY Area renderer git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23658 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.jfreechart.ontology/graph.tg | Bin 6733 -> 6813 bytes .../graph/JFreeChart.pgraph | 3 + .../simantics/sysdyn/JFreeChartResource.java | 13 ++- .../org/simantics/sysdyn/SysdynResource.java | 7 +- org.simantics.sysdyn.ui/adapters.xml | 2 +- .../newComponents/NewXYLineChartHandler.java | 5 +- .../sysdyn/ui/trend/chart/ChartUtils.java | 2 + .../sysdyn/ui/trend/chart/XYAreaRenderer.java | 40 +++++++ .../sysdyn/ui/trend/chart/XYDataset.java | 63 ++++++----- .../sysdyn/ui/trend/chart/XYLineRenderer.java | 41 ++++++++ .../sysdyn/ui/trend/chart/XYPlot.java | 13 ++- .../bar/BarGeneralPropertiesTab.java | 6 +- .../xyline/XYLineGeneralPropertiesTab.java | 98 +++++++++++++++++- 13 files changed, 246 insertions(+), 47 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java diff --git a/org.simantics.jfreechart.ontology/graph.tg b/org.simantics.jfreechart.ontology/graph.tg index 32d291bd66ab100b8531c63ed4ed5c748555e2ba..b48384c3c9643f06abc96f041414f02f93920b2f 100644 GIT binary patch literal 6813 zcmb7}i>W62_yju)E+QXp9JM|Nj$W)>tb&D-3+ z;{K=ieqYaNX{TQdEme%<|@XU~}_?0qNy*-}Z|vP*)cmMbj>t<=F?+LpL9?j&_L z9(ST_D>JKM!$nz`g)S|Vd-)H3{+E7hS@pTJ;g-V)(m3kNMe=WV_goxj|JYA=6trCr zv%9m6)x1@ne37{%3R?fD>{$&G%vZ+W?4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dip~P~iIorbhLHXfGO`KzpIU^Wg8jy~1y@ z&i@0?x?ejz>w5Qt@4;06(zDewZuMl(J)bqQ)swBB ztoq$(&lKWhjoOVyLbC}l8F|C&N9!!GSAjB zYlUp*d(`j_w2u_{aDhK9@FxZS7_93%gf>~%$ND%3)BWMMAldE@S@k=8-0Ba&r+R)n zlC7R>^<>rWM|%XOdVXt?t)6W4WYu&2`(Ubfo~@p7t0$|TN)-% znCk1Et)6kKC##;%*DjdqmpxlO<5o{rJ?{tBh}I|1$}-QIZ0lVF?OjQ>F} z|DTXYVeZ1XR*`qy~me+xTy)c-YOWF<~U8ezKD3O4XZ?~ywHtecL65uEY|;uP8M F{U4Nd?E(M* diff --git a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph index 5aa93b6b..01933123 100644 --- a/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph +++ b/org.simantics.jfreechart.ontology/graph/JFreeChart.pgraph @@ -105,6 +105,9 @@ JFREE.Series () { public JFreeChartResource perform(ReadGraph graph) throws DatabaseException { - QueryControl qc = graph.getService(QueryControl.class); - return new JFreeChartResource(qc.getIndependentGraph(graph)); + return new JFreeChartResource(graph); } }); session.registerService(JFreeChartResource.class, ret); diff --git a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java index dda9fead..6ea72e25 100644 --- a/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java @@ -5,7 +5,6 @@ import org.simantics.db.ReadGraph; import org.simantics.db.request.Read; import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.service.QueryControl; public class SysdynResource { @@ -875,8 +874,7 @@ public class SysdynResource { Session session = graph.getSession(); SysdynResource ret = session.peekService(SysdynResource.class); if(ret == null) { - QueryControl qc = graph.getService(QueryControl.class); - ret = new SysdynResource(qc.getIndependentGraph(graph)); + ret = new SysdynResource(graph); session.registerService(SysdynResource.class, ret); } return ret; @@ -887,8 +885,7 @@ public class SysdynResource { if(ret == null) { ret = session.syncRequest(new Read() { public SysdynResource perform(ReadGraph graph) throws DatabaseException { - QueryControl qc = graph.getService(QueryControl.class); - return new SysdynResource(qc.getIndependentGraph(graph)); + return new SysdynResource(graph); } }); session.registerService(SysdynResource.class, ret); diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index 390ea2d9..ecd9bdd0 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -10,5 +10,5 @@ VTT Technical Research Centre of Finland - initial API and implementation --> - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java index 46b44408..98c94da8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewXYLineChartHandler.java @@ -79,12 +79,15 @@ public class NewXYLineChartHandler extends AbstractHandler { l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); Resource rangeAxis = GraphUtils.create2(g, jfree.NumberAxis, l0.HasName, "NumberAxis" + UUID.randomUUID().toString()); + + Resource renderer = GraphUtils.create2(g, jfree.XYLineRenderer); Resource dataset = GraphUtils.create2(g, jfree.XYDataset, l0.HasName, "XYDataset" + UUID.randomUUID().toString(), jfree.Dataset_mapToDomainAxis, domainAxis, jfree.Dataset_mapToRangeAxis, rangeAxis, - jfree.Dataset_seriesList, ListUtils.create(g, new ArrayList())); + jfree.Dataset_seriesList, ListUtils.create(g, new ArrayList()), + jfree.Dataset_renderer, renderer); GraphUtils.create2(g, jfree.XYPlot, l0.HasName, "XYPlot" + UUID.randomUUID().toString(), diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java index 32081bbe..92e8ba4d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java @@ -77,11 +77,13 @@ public class ChartUtils { JFreeChartResource jfree = JFreeChartResource.getInstance(graph); Layer0 l0 = Layer0.getInstance(graph); + // Create a dataset for the axis Resource dataset = GraphUtils.create2(graph, jfree.XYDataset, l0.HasName, "XYDataset" + UUID.randomUUID().toString(), jfree.Dataset_mapToDomainAxis, domainAxis, jfree.Dataset_mapToRangeAxis, rangeAxis, + jfree.Dataset_renderer, GraphUtils.create2(graph, jfree.XYLineRenderer), l0.PartOf, plot); return dataset; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java new file mode 100644 index 00000000..65337783 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Renderer representing jfree chart renderer for xy areas + * @author Teemu Lempinen + * + */ +public class XYAreaRenderer extends AbstractRenderer { + + private org.jfree.chart.renderer.xy.XYAreaRenderer renderer; + + public XYAreaRenderer(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + @Override + public org.jfree.chart.renderer.AbstractRenderer getRenderer() { + if(renderer == null) { + renderer = new org.jfree.chart.renderer.xy.XYAreaRenderer(); + renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + } + return renderer; + } + +} \ No newline at end of file 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 30f65e95..35cf2eec 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 @@ -50,6 +50,7 @@ import org.simantics.sysdyn.adapter.SysdynVariableProperties; import org.simantics.sysdyn.adapter.VariableRVIUtils; import org.simantics.sysdyn.manager.SysdynDataSet; import org.simantics.ui.SimanticsUI; +import org.simantics.utils.datastructures.Pair; /** * Class representing a JFreeChart.XYDataset @@ -59,7 +60,7 @@ import org.simantics.ui.SimanticsUI; */ public class XYDataset extends AbstractDataset { - private XYLineAndShapeRenderer renderer; + private IRenderer renderer; public XYDataset(ReadGraph graph, final Resource datasetResource) { super(graph, datasetResource); @@ -77,18 +78,24 @@ public class XYDataset extends AbstractDataset { if(datasetListener == null || datasetListener.isDisposed()) { datasetListener = new DataSetListener(); - SimanticsUI.getSession().asyncRequest(new Read>() { + SimanticsUI.getSession().asyncRequest(new Read, IRenderer>>() { @Override - public ArrayList perform(ReadGraph graph) throws DatabaseException { + public Pair, IRenderer> perform(ReadGraph graph) throws DatabaseException { JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + // Renderer + IRenderer renderer = null; + Resource rendererResource = graph.getPossibleObject(resource, jfree.Dataset_renderer); + if(rendererResource != null) + renderer = graph.adapt(rendererResource, IRenderer.class); + ArrayList series = new ArrayList(); String realizationURI = getRealizationURI(graph); if(realizationURI == null) - return series; // No experiment -> No results + return new Pair, IRenderer>(series, renderer); // No experiment -> No results // Get a variable for the x-axis (if not time) double[] domainValues = null; @@ -129,7 +136,7 @@ public class XYDataset extends AbstractDataset { // Get values Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT); if(object == null || !(object instanceof ArrayList)) - return series; + return new Pair, IRenderer>(series, renderer); ArrayList datasets = new ArrayList(); @@ -191,7 +198,7 @@ public class XYDataset extends AbstractDataset { } } } - return series; + return new Pair, IRenderer>(series, renderer); } }, datasetListener); @@ -245,7 +252,7 @@ public class XYDataset extends AbstractDataset { } } - private class DataSetListener implements Listener> { + private class DataSetListener implements Listener, IRenderer>> { private boolean disposed = false; @@ -259,27 +266,33 @@ public class XYDataset extends AbstractDataset { } @Override - public void execute(final ArrayList series) { + public void execute(Pair, IRenderer> result) { + final ArrayList series = result.first; + renderer = result.second; + // Modify series in AWT thread to avoid synchronization problems SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - /* - * 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); + org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); + if(plot != null) { + /* + * 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); + plot.setDrawingSupplier(drawingsupplier); + } // Remove all series for(int i = dataset.getSeriesCount() - 1; i >= 0; i-- ) { dataset.removeSeries(dataset.getSeriesKey(i)); @@ -406,10 +419,12 @@ public class XYDataset extends AbstractDataset { @Override public AbstractRenderer getRenderer() { if(renderer == null) { - renderer = new XYLineAndShapeRenderer(true, false); + XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); + return renderer; + } else { + return renderer.getRenderer(); } - return renderer; } /** diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java new file mode 100644 index 00000000..cb2a6d14 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.trend.chart; + +import org.jfree.chart.labels.StandardXYToolTipGenerator; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; + +/** + * Renderer representing jfree chart renderer for xy lines + * @author Teemu Lempinen + * + */ +public class XYLineRenderer extends AbstractRenderer { + + XYLineAndShapeRenderer renderer; + + public XYLineRenderer(ReadGraph graph, Resource resource) { + super(graph, resource); + } + + @Override + public org.jfree.chart.renderer.AbstractRenderer getRenderer() { + 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 a4767c3c..bea1ce22 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 @@ -37,19 +37,26 @@ public class XYPlot extends AbstractPlot { protected Plot newPlot() { return new org.jfree.chart.plot.XYPlot(null, null, null, null); } - + @Override protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException { JFreeChartResource jfree = JFreeChartResource.getInstance(graph); Boolean visibleGrid = graph.getPossibleRelatedValue(resource, jfree.Plot_visibleGrid); properties.otherProperties.put("visibleGrid", visibleGrid); + if(!properties.datasets.isEmpty()) { + IDataset idataset = properties.datasets.get(0); + Resource renderer = graph.getPossibleObject(idataset.getResource(), jfree.Dataset_renderer); + if(renderer != null) { + properties.otherProperties.put("renderer", graph.adapt(renderer, IRenderer.class)); + } + } } @Override protected void setPlotProperties(PlotProperties properties) { if(!(plot instanceof org.jfree.chart.plot.XYPlot)) return; - + org.jfree.chart.plot.XYPlot xyplot = (org.jfree.chart.plot.XYPlot)plot; xyplot.clearDomainAxes(); xyplot.clearRangeAxes(); @@ -81,7 +88,7 @@ public class XYPlot extends AbstractPlot { xyplot.setRangeGridlinesVisible(visibleGrid); xyplot.setDomainGridlinesVisible(visibleGrid); - + // Cleaner look: no outline borders xyplot.setInsets(new RectangleInsets(2,5,2,10), false); xyplot.setOutlineVisible(false); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java index 5982d6dc..be09d06a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java @@ -89,17 +89,17 @@ public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); GridLayoutFactory.fillDefaults().applyTo(labelColumn1); - // first column: name and title + // second column: name and title Composite propertyColumn1 = new Composite(general, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1); GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1); - // first column: labels + // third column: labels Composite labelColumn2 = new Composite(general, SWT.NONE); GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2); GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2); - // first column: type and time + // fourth column: type and time Composite propertyColumn2 = new Composite(general, SWT.NONE); GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java index 857a7caf..c4e730da 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java @@ -11,13 +11,16 @@ *******************************************************************************/ package org.simantics.sysdyn.ui.trend.chart.properties.xyline; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -25,17 +28,23 @@ import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.swt.widgets.Button; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; import org.simantics.browsing.ui.swt.widgets.impl.Widget; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; import org.simantics.modeling.ui.chart.property.DoublePropertyFactory; import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; import org.simantics.sysdyn.JFreeChartResource; @@ -62,7 +71,7 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl private ScrolledComposite sc; private Composite composite; private TrackedText name, title, xlabel, xvariable, xmin, xmax; - private Combo type; + private TrackedCombo type; private Button hgrid, htitle, hlegend; private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl(); @@ -107,9 +116,11 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); label.setText("Type:"); - type = new Combo(c, SWT.BORDER | SWT.READ_ONLY); - type.setItems(new String[] {"Line", "Fancy", "Area", "3D"}); - type.select(0); + type = new TrackedCombo(c, support, SWT.BORDER | SWT.READ_ONLY); + type.addModifyListener(new TypeModifyListener()); + type.setItemFactory(new TypeItemFactory()); + type.setSelectionFactory(new TypeSelectionFactory()); + GridDataFactory.fillDefaults().applyTo(type.getWidget()); // Title (Which is different than name) label = new Label(general, SWT.NONE); @@ -224,5 +235,82 @@ public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor impl } }); } + + /** + * + * @author Teemu Lempinen + * + */ + private class TypeSelectionFactory extends ReadFactoryImpl { + @Override + public String perform(ReadGraph graph, Resource chart) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.XYPlot)); + if(plot != null) { + Collection datasets = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.XYDataset)); + if(!datasets.isEmpty()) { + Resource dataset = datasets.iterator().next(); + if(dataset != null) { + Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, jfree.Dataset_renderer, jfree.Renderer)); + if(renderer != null && graph.isInstanceOf(renderer, jfree.XYAreaRenderer)) + return "Area"; + } + } + } + return "Line"; + } + } + + /** + * RangeItemFactory finds all inexes of a given enumeration + * and adds "Sum" and "All" to the returned indexes + * @author Teemu Lempinen + * + */ + private class TypeItemFactory extends ReadFactoryImpl> { + @Override + public Map perform(ReadGraph graph, Resource series) throws DatabaseException { + LinkedHashMap result = new LinkedHashMap(); + result.put("Line", "Line"); + result.put("Area", "Area"); +// result.put("Stacked Area", "Stacked Area"); + return result; + } + } + + /** + * TypeModifyListener for modifying the type of a bar chart + * @author Teemu Lempinen + * + */ + private class TypeModifyListener extends ComboModifyListenerImpl { + @Override + public void applyText(WriteGraph graph, Resource chart, String text) throws DatabaseException { + JFreeChartResource jfree = JFreeChartResource.getInstance(graph); + Layer0 l0 = Layer0.getInstance(graph); + + Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.XYPlot)); + if(plot == null) + return; + + Collection datasets = graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.XYDataset)); + if(datasets == null || datasets.isEmpty()) + return; + + for(Resource dataset : datasets) { + graph.deny(dataset, jfree.Dataset_renderer); + + Resource renderer; + if(text.equals("Area")) + renderer = GraphUtils.create2(graph, jfree.XYAreaRenderer); + else + renderer = GraphUtils.create2(graph, jfree.XYLineRenderer); + + graph.claim(dataset, jfree.Dataset_renderer, renderer); + } + } + } } \ No newline at end of file -- 2.47.1