From 51e22fe677dcf6714566d91cf645494be728f2a2 Mon Sep 17 00:00:00 2001 From: luukkainen Date: Wed, 16 Jan 2013 10:49:27 +0000 Subject: [PATCH] chart component moved to jfreechart plug-in. refs #3988 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26619 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/trend/chart/AbstractAxis.java | 94 ---- .../ui/trend/chart/AbstractDataset.java | 42 -- .../sysdyn/ui/trend/chart/AbstractPlot.java | 212 -------- .../ui/trend/chart/AbstractRenderer.java | 39 -- .../sysdyn/ui/trend/chart/BarRenderer.java | 41 -- .../sysdyn/ui/trend/chart/CategoryAxis.java | 43 -- .../ui/trend/chart/CategoryDataset.java | 312 ----------- .../sysdyn/ui/trend/chart/CategoryPlot.java | 90 ---- .../sysdyn/ui/trend/chart/ChartComposite.java | 150 ------ .../sysdyn/ui/trend/chart/ChartUtils.java | 150 ------ .../ui/trend/chart/ExtendedNumberAxis.java | 53 -- .../sysdyn/ui/trend/chart/IAxis.java | 33 -- .../sysdyn/ui/trend/chart/IDataset.java | 46 -- .../sysdyn/ui/trend/chart/IJFreeChart.java | 32 -- .../ui/trend/chart/IJFreeChartComponent.java | 27 - .../sysdyn/ui/trend/chart/IPlot.java | 41 -- .../sysdyn/ui/trend/chart/IRenderer.java | 37 -- .../sysdyn/ui/trend/chart/ITitle.java | 33 -- .../sysdyn/ui/trend/chart/JFreeChart.java | 182 ------- .../sysdyn/ui/trend/chart/NumberAxis.java | 44 -- .../sysdyn/ui/trend/chart/PieDataset.java | 331 ------------ .../sysdyn/ui/trend/chart/PiePlot.java | 153 ------ .../ui/trend/chart/StackedBarRenderer.java | 40 -- .../sysdyn/ui/trend/chart/TextTitle.java | 87 --- .../sysdyn/ui/trend/chart/XYAreaRenderer.java | 40 -- .../sysdyn/ui/trend/chart/XYDataset.java | 501 ------------------ .../sysdyn/ui/trend/chart/XYLineRenderer.java | 41 -- .../sysdyn/ui/trend/chart/XYPlot.java | 97 ---- .../chart/element/ChartBoundsOutline.java | 37 -- .../chart/element/ChartElementFactory.java | 184 ------- .../chart/element/ChartElementWriter.java | 43 -- .../ui/trend/chart/element/ChartNode.java | 292 ---------- .../trend/chart/element/ChartSceneGraph.java | 159 ------ .../element/PopulateChartDropParticipant.java | 116 ---- .../trend/chart/element/ResizeListener.java | 28 - .../chart/graphexplorer/AxisChildRule.java | 68 --- .../chart/graphexplorer/AxisDropAction.java | 104 ---- .../chart/graphexplorer/AxisLabelRule.java | 67 --- .../chart/graphexplorer/SeriesChildRule.java | 67 --- .../chart/graphexplorer/SeriesDropAction.java | 139 ----- .../SeriesLabelDecorationRule.java | 63 --- .../chart/graphexplorer/SeriesLabelRule.java | 60 --- .../graphexplorer/VariableChildRule.java | 75 --- .../chart/properties/AllVariablesOfModel.java | 99 ---- .../properties/AxisHidePropertyComposite.java | 67 --- .../properties/BooleanPropertyFactory.java | 130 ----- .../properties/BooleanSelectionListener.java | 82 --- .../ui/trend/chart/properties/ChartTab.java | 46 -- .../trend/chart/properties/ColorPicker.java | 375 ------------- .../chart/properties/DoubleValidator.java | 54 -- .../JFreeChartPropertyColorProvider.java | 57 -- .../ui/trend/chart/properties/RVIFactory.java | 33 -- .../trend/chart/properties/RVIModifier.java | 117 ---- .../chart/properties/RangeComposite.java | 351 ------------ .../trend/chart/properties/TitleFactory.java | 41 -- .../trend/chart/properties/TitleModifier.java | 42 -- .../chart/properties/TrackedSpinner.java | 179 ------- .../properties/VariableExistsValidator.java | 132 ----- .../properties/VariableProposalProvider.java | 81 --- .../chart/properties/bar/BarAxisTab.java | 292 ---------- .../bar/BarGeneralPropertiesTab.java | 252 --------- .../bar/BarSeriesPropertyComposite.java | 97 ---- .../chart/properties/bar/BarSeriesTab.java | 213 -------- .../pie/PieGeneralPropertiesTab.java | 158 ------ .../pie/PieSeriesPropertyComposite.java | 121 ----- .../chart/properties/pie/PieSeriesTab.java | 211 -------- .../AxisAndVariablesExplorerComposite.java | 92 ---- .../xyline/AxisPropertyComposite.java | 100 ---- .../xyline/SeriesPropertyComposite.java | 185 ------- .../xyline/XYLineAxisAndVariablesTab.java | 301 ----------- .../xyline/XYLineGeneralPropertiesTab.java | 318 ----------- 71 files changed, 8719 deletions(-) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryAxis.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/TextTitle.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AllVariablesOfModel.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableExistsValidator.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java deleted file mode 100644 index 9f37e5ee..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractAxis.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * 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 java.awt.Color; - -import org.jfree.chart.axis.Axis; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.G2DUtils; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Abstract axis class for all JFreeChart axis - * @author Teemu Lempinen - * - */ -public abstract class AbstractAxis implements IAxis { - - protected Axis axis; - protected String label; - protected Boolean tMarksVisible, tLabelsVisible, labelVisible, lineVisible; - protected Color color; - protected Double min, max, rotate; - - /** - * Creates a new axis - * @param graph ReadGraph - * @param axisResource resource of type JFreeChart.NumberAxis - */ - public AbstractAxis(ReadGraph graph, Resource axisResource) { - try { - /* - * Axis is practically always called from a listener, - * so it is safe to always create a new axis every time. - * - * The parent listener takes care that the axis is updated. - * (And the code stays much more readable) - */ - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - label = graph.getPossibleRelatedValue(axisResource, l0.HasLabel); - tMarksVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleTickMarks, Bindings.BOOLEAN); - tLabelsVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleTickLabels, Bindings.BOOLEAN); - labelVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleLabel, Bindings.BOOLEAN); - lineVisible = graph.getPossibleRelatedValue(axisResource, jfree.Axis_visibleAxisLine, Bindings.BOOLEAN); - Resource c = graph.getPossibleObject(axisResource, jfree.color); - color = c == null ? null : G2DUtils.getColor(graph, c); - min = graph.getPossibleRelatedValue(axisResource, jfree.Axis_min, Bindings.DOUBLE); - max = graph.getPossibleRelatedValue(axisResource, jfree.Axis_max, Bindings.DOUBLE); - rotate = graph.getPossibleRelatedValue(axisResource, jfree.Axis_rotateLabelDegrees, Bindings.DOUBLE); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - @Override - public void dispose() { - - } - - @Override - public Axis getAxis() { - if(tMarksVisible != null && tMarksVisible == false) - axis.setTickMarksVisible(false); - if(tLabelsVisible != null && tLabelsVisible == false) - axis.setTickLabelsVisible(false); - if(lineVisible != null && lineVisible == false) - axis.setAxisLineVisible(false); - - if(color != null) { - axis.setAxisLinePaint(color); - axis.setLabelPaint(color); - axis.setTickLabelPaint(color); - axis.setTickMarkPaint(color); - } - // label exists and its visibility == null or true - if((labelVisible == null || labelVisible == true) && label != null) - axis.setLabel(label); - return axis; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java deleted file mode 100644 index 31a91128..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractDataset.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.simantics.db.ReadGraph; -import org.simantics.db.Resource; - - -/** - * Abstract dataset class for all JFreeChart datasets - * - * @author Teemu Lempinen - * - */ -public abstract class AbstractDataset implements IDataset { - - protected Resource resource; - - public AbstractDataset(ReadGraph graph, Resource resource) { - this.resource = resource; - } - - @Override - public void dispose() { - - } - - @Override - public Resource getResource() { - return resource; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java deleted file mode 100644 index 48e0f693..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractPlot.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * 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 java.util.ArrayList; -import java.util.HashMap; - -import javax.swing.SwingUtilities; - -import org.jfree.chart.axis.Axis; -import org.jfree.chart.plot.Plot; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.utils.ListUtils; -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.ui.SimanticsUI; - -/** - * Abstract plot class for all JFreeChart plots - * - * @author Teemu Lempinen - * - */ -public abstract class AbstractPlot implements IPlot { - - protected Resource resource; - protected Plot plot; - protected PlotProperties currentProperties; - private PlotPropertyListener listener; - - - public AbstractPlot(ReadGraph graph, Resource resource) { - this.resource = resource; - } - - @Override - public void dispose() { - if(currentProperties != null) { - for(IAxis axis : currentProperties.ranges) - axis.dispose(); - - for(IAxis axis : currentProperties.domains) - axis.dispose(); - - for(IDataset dataset : currentProperties.datasets) - dataset.dispose(); - } - if(listener != null) - listener.dispose(); - } - - @Override - public Resource getResource() { - return resource; - } - - protected abstract Plot newPlot(); - protected abstract void setPlotProperties(PlotProperties properties); - protected abstract void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException; - - @Override - public Plot getPlot() { - if(plot == null) - plot = newPlot(); - - if(listener == null || listener.isDisposed()) { - listener = new PlotPropertyListener(); - SimanticsUI.getSession().asyncRequest(new Read() { - - @Override - public PlotProperties perform(ReadGraph graph) throws DatabaseException { - - PlotProperties properties = new PlotProperties(); - - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - - HashMap axisMap = new HashMap(); - - // Get all range axis - Resource rangeList = graph.getPossibleObject(resource, jfree.Plot_rangeAxisList); - if(rangeList != null) { - for(Resource axisResource : ListUtils.toList(graph, rangeList)) { - IAxis axis = graph.adapt(axisResource, IAxis.class); - if(axis.getAxis() instanceof Axis) { - properties.ranges.add(axis); - axisMap.put(axisResource, axis); - } - } - } - - // Get all domain axis - // There usually is only one domain axis, but this supports also multiple domain axis - for(Resource axisResource : graph.syncRequest(new ObjectsWithType(resource, jfree.Plot_domainAxis, jfree.Axis))) { - IAxis axis = graph.adapt(axisResource, IAxis.class); - if(axis.getAxis() instanceof Axis) { - properties.domains.add(axis); - axisMap.put(axisResource, axis); - } - } - - // Get all datasets and map them to axis - for(Resource datasetResource : graph.syncRequest(new ObjectsWithType(resource, l0.ConsistsOf, jfree.Dataset))) { - IDataset dataset = graph.adapt(datasetResource, IDataset.class); - if(dataset != null) { - properties.datasets.add(dataset); - Resource axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToRangeAxis); - IAxis axis; - if(axisMap.containsKey(axisResource)) { - axis = axisMap.get(axisResource); - properties.rangeMappings.put(dataset, axis); - } - - axisResource = graph.getPossibleObject(datasetResource, jfree.Dataset_mapToDomainAxis); - if(axisMap.containsKey(axisResource)) { - axis = axisMap.get(axisResource); - properties.domainMappings.put(dataset, axis); - } - } - } - getOtherProperties(graph, properties); - return properties; - - } - }, listener); - } - - return plot; - } - - protected class PlotProperties { - public ArrayList ranges; - public ArrayList domains; - public ArrayList datasets; - public HashMap rangeMappings; - public HashMap domainMappings; - public HashMap otherProperties; - - public PlotProperties() { - datasets = new ArrayList(); - rangeMappings = new HashMap(); - domainMappings = new HashMap(); - ranges = new ArrayList(); - domains = new ArrayList(); - otherProperties = new HashMap(); - } - - @Override - public boolean equals(Object other) { - if(!this.getClass().equals(other.getClass())) - return false; - PlotProperties p = (PlotProperties)other; - if(!ranges.equals(p.ranges)) - return false; - if(!domains.equals(p.domains)) - return false; - if(!datasets.equals(p.datasets)) - return false; - if(!rangeMappings.equals(p.rangeMappings)) - return false; - if(!domainMappings.equals(p.domainMappings)) - return false; - if(!otherProperties.equals(p.otherProperties)) - return false; - return true; - } - } - - private class PlotPropertyListener implements Listener { - - private boolean disposed = false; - - public void dispose() { - disposed = true; - } - @Override - public void execute(final PlotProperties result) { - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - setPlotProperties(result); - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return disposed; - } - - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java deleted file mode 100644 index c38bd23a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/AbstractRenderer.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * 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.simantics.db.ReadGraph; -import org.simantics.db.Resource; - -/** - * Abstract renderer class for all JFreeChart renderers - * @author Teemu Lempinen - * - */ -public abstract class AbstractRenderer implements IRenderer { - - protected Resource resource; - - public AbstractRenderer(ReadGraph graph, Resource resource) { - this.resource = resource; - } - - @Override - public void dispose() { - } - - @Override - public Resource getResource() { - return resource; - } - -} 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 deleted file mode 100644 index 7d80fb88..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/BarRenderer.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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.StandardCategoryToolTipGenerator; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; - - -/** - * Normal bar renderer - * @author Teemu Lempinen - * - */ -public class BarRenderer extends AbstractRenderer { - - public BarRenderer(ReadGraph graph, Resource resource) { - super(graph, resource); - } - - private org.jfree.chart.renderer.category.BarRenderer renderer; - - @Override - public org.jfree.chart.renderer.AbstractRenderer getRenderer() { - 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/CategoryAxis.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryAxis.java deleted file mode 100644 index bd58da1e..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryAxis.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * 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.axis.Axis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; - -/** - * Class representing a JFreeChart.CategoryAxis - * - * @author Teemu Lempinen - * - */ -public class CategoryAxis extends AbstractAxis { - - public CategoryAxis(ReadGraph graph, Resource axisResource) { - super(graph, axisResource); - } - - @Override - public Axis getAxis() { - axis = new org.jfree.chart.axis.CategoryAxis(); - - if(rotate != null && rotate > 0) { - ((org.jfree.chart.axis.CategoryAxis)axis).setCategoryLabelPositions( - CategoryLabelPositions.createUpRotationLabelPositions(Math.toRadians(rotate))); - } - - return super.getAxis(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java deleted file mode 100644 index 258b56ec..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryDataset.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * 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 java.util.ArrayList; -import java.util.List; - -import javax.swing.SwingUtilities; - -import org.jfree.chart.plot.DefaultDrawingSupplier; -import org.jfree.chart.renderer.AbstractRenderer; -import org.jfree.chart.renderer.category.BarRenderer; -import org.jfree.data.category.DefaultCategoryDataset; -import org.jfree.data.general.Dataset; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.MissingVariableException; -import org.simantics.db.layer0.request.PossibleActiveExperiment; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.operation.Layer0X; -import org.simantics.sysdyn.Functions; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.adapter.VariableRVIUtils; -import org.simantics.sysdyn.manager.SysdynDataSet; -import org.simantics.ui.SimanticsUI; - -/** - * Class representing a JFreeChart.CategoryDataset - * - * @author Teemu Lempinen - * - */ -public class CategoryDataset extends AbstractDataset { - - private List seriesList; - private String realizationURI; - private IRenderer renderer; - private DefaultCategoryDataset dataset; - - public CategoryDataset(ReadGraph graph, Resource resource) { - super(graph, resource); - - try { - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - - // Find the model where the chart is located - Resource model = resource; - do { - model = graph.getPossibleObject(model, l0.PartOf); - } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel)); - - // Find the variable realization of the current experiment - realizationURI = null; - Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); - if (realization == null) { - Layer0X L0X = Layer0X.getInstance(graph); - realization = graph.getPossibleObject(model, L0X.HasBaseRealization); - } - if (realization != null) - realizationURI = graph.getURI(realization); - - if(realizationURI == null) - return; // No experiment -> No results - - Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList); - if(seriesList != null) - this.seriesList = ListUtils.toList(graph, seriesList); - - Resource rendererResource = graph.getPossibleObject(resource, jfree.Dataset_renderer); - renderer = graph.adapt(rendererResource, IRenderer.class); - - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - private DatasetListener listener; - - @Override - public Dataset getDataset() { - - if(seriesList == null || seriesList.isEmpty() || SimanticsUI.getSession() == null) - return null; - - if(dataset == null) { - dataset = new DefaultCategoryDataset(); - } - - if(listener == null || listener.isDisposed()) { - listener = new DatasetListener(); - SimanticsUI.getSession().asyncRequest(new Read>() { - - @Override - public ArrayList perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - - ArrayList series = new ArrayList(); - // Get properties for all series - if(seriesList != null) { - for(Resource r : seriesList) { - String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); - if(rvi == null) - continue; - - try { - // Get a variable for the series - Variable v = Variables.getVariable(graph, realizationURI + rvi); - // Get values - Variable dsVariable = v.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#"); - if(dsVariable == null) - return series; - - Object object = dsVariable.getValue(graph); - - 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); - if(result2 != null) { - datasets = result2; - } - } - - // Find if a specific time is set for this chart - Double chartTime = null; - if(!datasets.isEmpty()) { - Layer0 l0 = Layer0.getInstance(graph); - Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); - if(datasetResource != null) { - Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); - if(plot != null) { - Resource chart = graph.getPossibleObject(plot, l0.PartOf); - if(chart != null) - chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); - } - } - } - - for(SysdynDataSet dataset : datasets) { - double[] va = dataset.values; - - - if(va == null || va.length == 0) - continue; - - /* - * Time - * - * 1. find time for the individual series. - * 2. find time for the whole chart - * 3. find simulation time - */ - Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); - if(time == null) - time = chartTime; - if(time == null) { - // Get a variable for the experiment run - Variable run = Variables.getVariable(graph, realizationURI); - if(run == null) - return null; - Variable timeVar = run.browsePossible(graph, "#" + Functions.TIME + "#"); - if(timeVar != null) - time = timeVar.getValue(graph, Bindings.DOUBLE); - - } - - // Value - Double value = null; - if(time == null) { - value = va[va.length - 1]; - } else { - double[] ta = dataset.times; - for(int i = 0; i < ta.length; i++) { - double t = ta[i]; - if(time <= t) { - value = va[i]; - break; - } - } - - if(value == null) - value = va[va.length - 1]; - } - String label = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasLabel); // Called to refresh paints when label changes - String name = dataset.name; - series.add(new TempSeries(label == null || label.isEmpty() ? name : label, dataset.result, value)); - } - } catch (MissingVariableException e) { - // Do nothing, if variable was not found. Move on to the next series - } - } - } - return series; - } - - }, listener); - } - return dataset; - } - - @Override - public AbstractRenderer getRenderer() { - return renderer.getRenderer(); - } - - private class DatasetListener implements Listener> { - private boolean disposed = false; - - public void dispose() { - disposed = true; - } - - @Override - public void execute(final ArrayList series) { - // Modify series in AWT thread to avoid synchronization problems - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - // Remove all unused series - dataset.clear(); - BarRenderer renderer = ((BarRenderer)getRenderer()); - renderer.getPlot().setDrawingSupplier(new DefaultDrawingSupplier()); - - // Add found series - for(int i = 0; i < series.size(); i++) { - TempSeries s = series.get(i); - if(renderer instanceof org.jfree.chart.renderer.category.StackedBarRenderer && s.name.contains("[")) { - String category = s.name.substring(0, s.name.indexOf('[')); - if(s.result != null) - category = category + " : " + s.result; - String series = s.name.substring(s.name.indexOf('[')); - dataset.addValue(s.value, series, category); - } else { - dataset.addValue(s.value, s.result == null ? "Current" : s.result, s.name); - } - } - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return disposed; - } - }; - - @Override - public void dispose() { - super.dispose(); - if(listener != null) { - listener.dispose(); - listener = null; - } - } - - /** - * Auxiliary class containing all information needed to define a single series - * @author Teemu Lempinen - * - */ - private class TempSeries { - public String name; - public String result; - public Double value; - - public TempSeries(String name, String result, Double value) { - this.name = name; - this.value = value; - this.result = result; - } - - @Override - public String toString() { - return "TempSeries: " + name + ", " + value + ", " + result; - } - } - -} 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 deleted file mode 100644 index 14a37955..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/CategoryPlot.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * 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.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; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Class representing a CategoryPlot for JFreeChart - * @author Teemu Lempinen - * - */ -public class CategoryPlot extends AbstractPlot { - - public CategoryPlot(ReadGraph graph, Resource resource) { - super(graph, resource); - } - - @Override - protected Plot newPlot() { - return new org.jfree.chart.plot.CategoryPlot(null, null, null, null); - } - - @Override - protected void setPlotProperties(PlotProperties properties) { - if(!(plot instanceof org.jfree.chart.plot.CategoryPlot)) - return; - - org.jfree.chart.plot.CategoryPlot cplot = (org.jfree.chart.plot.CategoryPlot) plot; - /* Support using multiple axis, but prefer using only one domain and - * one range axis - */ - for(int i = 0; i < properties.ranges.size(); i++) { - cplot.setRangeAxis(i, (ValueAxis)properties.ranges.get(i).getAxis()); - } - - for(int i = 0; i < properties.domains.size(); i++) { - cplot.setDomainAxis(i, (CategoryAxis)properties.domains.get(i).getAxis()); - } - - IAxis axis; - for(int i = 0; i < properties.datasets.size(); i++) { - IDataset dataset = properties.datasets.get(i); - org.jfree.data.category.CategoryDataset ds = (org.jfree.data.category.CategoryDataset)dataset.getDataset(); - cplot.setDataset(i, ds); -// System.out.println("setting dataset " + i + ": " + ds); - cplot.setRenderer(i, (CategoryItemRenderer)dataset.getRenderer()); - axis = properties.rangeMappings.get(dataset); - if(axis != null && properties.ranges.contains(axis)) - cplot.mapDatasetToRangeAxis(i, properties.ranges.indexOf(axis)); - axis = properties.domainMappings.get(dataset); - if(axis != null && properties.ranges.contains(axis)) - cplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis)); - } - - Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid"); - if(visibleGrid != null) { - cplot.setRangeGridlinesVisible(visibleGrid); - cplot.setDomainGridlinesVisible(false); - } - - // Cleaner look: no outline borders - cplot.setInsets(new RectangleInsets(2,5,2,2), false); - cplot.setOutlineVisible(false); - } - - @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); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java deleted file mode 100644 index 13c25220..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartComposite.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * 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 java.awt.Frame; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.awt.SWT_AWT; -import org.eclipse.swt.widgets.Composite; -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.simantics.Simantics; -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.procedure.AsyncListener; -import org.simantics.db.request.Read; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.RunnableWithObject; - -/** - * Composite containing a single chart defined by a JFreeChart.Chart - * - * @author Teemu Lempinen - * - */ -public class ChartComposite extends Composite { - - private Frame frame; - private ChartPanel panel; - private Composite composite; - private IJFreeChart chart; - - /** - * A new ChartComposite with a definition in chartResourceURI - * @param parent Composite - * @param chartResourceURI URI for a JFreeChart.Chart definition - * @param style SWT style - */ - public ChartComposite(Composite parent, final String chartResourceURI, int style) { - super(parent, style | SWT.NO_BACKGROUND | SWT.EMBEDDED); - - try { - Resource chartResource = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - return graph.getPossibleResource(chartResourceURI); - } - - }); - if(chartResource != null) - CreateContent(chartResource); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - /** - * A new ChartComposite with a chartResource definition - * @param parent Composite - * @param chartResource JFreeChart.Chart resource - * @param style SWT style - */ - public ChartComposite(Composite parent, final Resource chartResource, int style) { - super(parent, style | SWT.NO_BACKGROUND | SWT.EMBEDDED); - CreateContent(chartResource); - } - - /** - * Creates and displays the chart defined in chartResource - * @param chartResource - */ - private void CreateContent(final Resource chartResource) { - composite = this; - - GridLayoutFactory.fillDefaults().applyTo(composite); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - frame = SWT_AWT.new_Frame(composite); - - // Add a listener displaying the contents of the chart. Chart is re-drawn if the definition changes - Simantics.getSession().asyncRequest(new Read() { - - @Override - public IJFreeChart perform(ReadGraph graph) throws DatabaseException { - // Adapt chartResource to a chart (XY, pie, bar, ...) - if(graph.isInstanceOf(chartResource, JFreeChartResource.getInstance(graph).Chart)) { - if(chart != null) - chart.dispose(); - chart = graph.adapt(chartResource, IJFreeChart.class); - return chart; - } else { - return null; - } - } - - } , new AsyncListener() { - - @Override - public boolean isDisposed() { - return composite.isDisposed(); - } - - @Override - public void execute(AsyncReadGraph graph, IJFreeChart chart) { - if(chart == null || composite.isDisposed()) - return; - - JFreeChart jfreeChart = chart.getChart(); - // Display the result chart - composite.getDisplay().asyncExec(new RunnableWithObject(jfreeChart) { - - @Override - public void run() { - if(composite.isDisposed()) - return; - if(panel != null) - frame.remove(panel); - composite.layout(); - JFreeChart chart = (JFreeChart)getObject(); - panel = new ChartPanel(chart, false, true, true, true, true); - frame.add(panel); - frame.repaint(); - frame.validate(); - } - }); - } - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - throwable.printStackTrace(); - - } - }); - } - -} 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 deleted file mode 100644 index 3caccec9..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ChartUtils.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.simantics.sysdyn.ui.trend.chart; - -import java.util.ArrayList; -import java.util.UUID; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.PossibleActiveExperiment; -import org.simantics.db.layer0.request.PossibleModel; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.operation.Layer0X; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Utilities for handling charts - * - * @author Teemu Lempinen - * - */ -public class ChartUtils { - - /** - * Creates a new range axis of type jfree.NumberAxis to a plot - * - * @param graph WriteGraph - * @param plot Plot resource - * @return Created number axis, null if not successful - * @throws DatabaseException - */ - public static Resource createNumberRangeAxis(WriteGraph graph, Resource plot) throws DatabaseException { - Resource axis = null; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - if(plot != null) { - // Create range axis - axis = GraphUtils.create2(graph, jfree.NumberAxis, - l0.HasName, "NumberAxis" + UUID.randomUUID().toString(), - l0.HasLabel, NameUtils.findFreshLabel(graph, "Y-axis", plot), - jfree.Plot_rangeAxis_Inverse, plot, - l0.PartOf, plot); - - // Add range axis to the plot's range axis list - Resource axisList = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); - ArrayList list = new ArrayList(); - list.add(axis); - if(axisList == null) { - axisList = ListUtils.create(graph, list); - graph.claim(plot, jfree.Plot_rangeAxisList, axisList); - } else { - ListUtils.insertBack(graph, axisList, list); - } - } - - return axis; - - } - - /** - * Create a XYDataset and map it to axis - * @param graph WriteGraph - * @param plot Plot resource containing the dataset - * @param domainAxis Mapped domain axis for the dataset - * @param rangeAxis Mapped range axis for the dataset - * @return created dataset or null if not successful - * @throws DatabaseException - */ - public static Resource createXYDataset(WriteGraph graph, Resource plot, Resource domainAxis, Resource rangeAxis) throws DatabaseException { - if(plot == null || domainAxis == null || rangeAxis == null) - return null; - - 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; - } - - /** - * Creates a new series to a dataset - * @param graph WriteGraph - * @param dataset Dataset for the new series - * @return created series or null if unsuccessful - * @throws DatabaseException - */ - public static Resource createSeries(WriteGraph graph, Resource dataset, String rvi) throws DatabaseException { - if(dataset == null) return null; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - // Create series - Resource series = GraphUtils.create2(graph, jfree.Series, - l0.HasName, "Series" + UUID.randomUUID().toString(), - jfree.variableRVI, rvi == null ? " " : rvi, - l0.PartOf, dataset); - - // Add series to the dataset's series list - Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); - ArrayList list = new ArrayList(); - list.add(series); - if(seriesList == null) { - seriesList = ListUtils.create(graph, list); - graph.claim(dataset, jfree.Dataset_seriesList, seriesList); - } else { - ListUtils.insertBack(graph, seriesList, list); - } - - return series; - } - - /** - * Find the current realization uri - * - * @param graph ReadGraph - * @param chartComponent A resource from a chart (consistsOf relation in a chart) - * @return current realization uri - * @throws DatabaseException - */ - public static String getCurrentRealizationURI(ReadGraph graph, Resource chartComponent) throws DatabaseException { - // Find the model where the chart is located - Resource model = graph.syncRequest(new PossibleModel(chartComponent)); - if(model == null) - return null; - - // Find the variable realization of the current experiment - String realizationURI = null; - Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); - if (realization == null) { - Layer0X L0X = Layer0X.getInstance(graph); - realization = graph.getPossibleObject(model, L0X.HasBaseRealization); - } - if (realization != null) - realizationURI = graph.getURI(realization); - - return realizationURI; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java deleted file mode 100644 index 329faadf..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ExtendedNumberAxis.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * 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.data.Range; - -/** - * NumberAxis that supports adding only one bound, lower or upper. - * The standard NumberAxis disables auto adjusting if even one of the bounds is set - * - * @author Teemu Lempinen - * - */ -public class ExtendedNumberAxis extends org.jfree.chart.axis.NumberAxis { - private static final long serialVersionUID = 3066266986472919998L; - - private Double lower = null; - private Double upper = null; - /** - * Use own lower and upper bounds to support using only one of them - */ - protected void autoAdjustRange() { - super.autoAdjustRange(); - Range range = getRange(); - Double lower = this.lower == null ? range.getLowerBound() : this.lower; - Double upper = this.upper == null ? range.getUpperBound() : this.upper; - if(lower > upper) - upper = lower + 1; - if(upper - lower < getAutoRangeMinimumSize()) - upper = lower + getAutoRangeMinimumSize(); - - setRange(new Range(lower, upper), false, false); - - } - - public void setLower(Double lower) { - this.lower = lower; - } - - public void setUpper(Double upper) { - this.upper = upper; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java deleted file mode 100644 index a5449856..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IAxis.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.axis.Axis; -import org.simantics.db.exception.DatabaseException; - -/** - * Interface for JFreeChart.Axis type resource - * - * @author Teemu Lempinen - * - */ -public interface IAxis extends IJFreeChartComponent { - - /** - * Returns the axis - * - * @return - * @throws DatabaseException - */ - public Axis getAxis(); - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java deleted file mode 100644 index cf91dd71..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IDataset.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * 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.renderer.AbstractRenderer; -import org.jfree.data.general.Dataset; -import org.simantics.db.Resource; - -/** - * Interface for JFreeChart.Dataset type resource - * @author Teemu Lempinen - * - */ -public interface IDataset extends IJFreeChartComponent { - - /** - * Returns the JFreeChart dataset represented by the associated resource - * - * @return JFreeChart dataset - */ - public Dataset getDataset(); - - - /** - * Returns the renderer for this dataset - * - * @return JFreeChart renderer - */ - public AbstractRenderer getRenderer(); - - /** - * Returns the resource of this dataset - * - * @return - */ - public Resource getResource(); -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java deleted file mode 100644 index 9c702c4b..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChart.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * 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.JFreeChart; -import org.simantics.db.exception.DatabaseException; -/** - * Interface for JFreeChart.Chart type resource - * - * @author Teemu Lempinen - * - */ -public interface IJFreeChart extends IJFreeChartComponent { - - /** - * Returns the chart - * - * @return - * @throws DatabaseException - */ - public JFreeChart getChart(); - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java deleted file mode 100644 index 39b42e2e..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IJFreeChartComponent.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * Interface for all components that are used to create JFreeCharts based on org.simantics.jfreechart ontology - * @author Teemu Lempinen - * - */ -public interface IJFreeChartComponent { - - /** - * Dispose this component. Disposing a component may be useful - * if the component contains listeners that need to be disposed. - */ - public void dispose(); - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java deleted file mode 100644 index ec8386ef..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IPlot.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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.plot.Plot; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; - -/** - * Interface for JFreeChart.Plot type resource - * - * @author Teemu Lempinen - * - */ -public interface IPlot extends IJFreeChartComponent { - - /** - * Returns the plot - * - * @return Title - * @throws DatabaseException - */ - public Plot getPlot(); - - /** - * Returns the resource of this plot - * - * @return - */ - public Resource getResource(); - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java deleted file mode 100644 index df832a45..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/IRenderer.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * 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.renderer.AbstractRenderer; -import org.simantics.db.Resource; - -/** - * Interface for JFreeChart.Renderer type resource - * @author Teemu Lempinen - * - */ -public interface IRenderer extends IJFreeChartComponent { - - /** - * Returns the JFreeChart AbstractRenderer represented by the associated resource - * - * @return JFreeChart renderer - */ - public AbstractRenderer getRenderer(); - - /** - * Returns the resource of this renderer - * @return - */ - public Resource getResource(); - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java deleted file mode 100644 index 07281547..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/ITitle.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.title.Title; -import org.simantics.db.exception.DatabaseException; - -/** - * Interface for JFreeChart.Title type resource - * - * @author Teemu Lempinen - * - */ -public interface ITitle extends IJFreeChartComponent { - - /** - * Returns the title - * - * @return Title - * @throws DatabaseException - */ - public Title getTitle(); - -} 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 deleted file mode 100644 index 8a2f79c0..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/JFreeChart.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * 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 java.awt.Color; -import java.awt.Font; -import java.util.Collection; - -import javax.swing.SwingUtilities; - -import org.jfree.chart.title.LegendTitle; -import org.jfree.chart.title.TextTitle; -import org.jfree.ui.RectangleInsets; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -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.ui.SimanticsUI; -import org.simantics.utils.datastructures.Pair; - -/** - * Class representing a complete JFreeChart.Chart - * - * This class supports all types of charts. The details of the chart are - * defined in plots and other adapted classes. - * - * @author Teemu Lempinen - * - */ -public class JFreeChart implements IJFreeChart { - - private org.jfree.chart.JFreeChart jfreechart; - private IPlot plot; - private ITitle title; - private Resource chartResource; - - /** - * - * @param graph ReadGraph - * @param chartResource Resource of type JFreeChart.Chart - */ - public JFreeChart(ReadGraph graph, Resource chartResource) { - this.chartResource = chartResource; - - try { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - Collection plotsCollection = graph.syncRequest(new ObjectsWithType(chartResource, l0.ConsistsOf, jfree.Plot)); - for(Resource plotResource : plotsCollection) { - this.plot = graph.adapt(plotResource, IPlot.class); - } - - } catch(DatabaseException e) { - e.printStackTrace(); - } - } - - - JFreeChartListener listener; - - /** - * Returns a new chart using the information collected in the constructor - */ - @Override - public org.jfree.chart.JFreeChart getChart() { - if(plot == null) - return null; - - if(jfreechart == null) - jfreechart = new org.jfree.chart.JFreeChart(plot.getPlot()); - - if(listener == null) { - listener = new JFreeChartListener(); - SimanticsUI.getSession().asyncRequest(new Read>() { - - @Override - public Pair perform(ReadGraph graph) throws DatabaseException { - if(chartResource == null || !graph.hasStatement(chartResource)) - return null; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - Resource titleResource = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Title)); - title = graph.adapt(titleResource, ITitle.class); - Boolean legendVisible = graph.getPossibleRelatedValue(chartResource, jfree.Chart_visibleLegend, Bindings.BOOLEAN); - return new Pair(title, legendVisible); - } - }, listener); - } - - return jfreechart; - } - - @Override - public void dispose() { - // Call dispose to title and plots to disable their possible listeners - if(title != null) - title.dispose(); - if(listener != null) - listener.dispose(); - if(plot != null) - plot.dispose(); - } - - - private class JFreeChartListener implements Listener> { - - private boolean disposed = false; - private LegendTitle legend; - - public void dispose() { - disposed = true; - } - - @Override - public void execute(final Pair result) { - if(result == null) - return; - - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if(jfreechart == null) - return; - - jfreechart.setBackgroundPaint(Color.WHITE); - - if(jfreechart.getLegend() != null && !jfreechart.getLegend().equals(legend)) { - legend = jfreechart.getLegend(); - legend.setBorder(0, 0, 0, 0); - int size = legend.getItemFont().getSize(); - legend.setItemFont(new Font("helvetica", Font.PLAIN, size)); - } - - if(Boolean.FALSE.equals(result.second)) { - jfreechart.removeLegend(); - } else if (jfreechart.getLegend() == null && legend != null){ - jfreechart.addLegend(legend); - } - - TextTitle t = (org.jfree.chart.title.TextTitle)result.first.getTitle(); - if(t.isVisible()) { - t.setFont(new Font("georgia", Font.BOLD, 13)); - t.setPadding(new RectangleInsets(4, 0, 0, 0)); - jfreechart.setTitle(t); - } else { - jfreechart.setTitle((TextTitle)null); - } - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return disposed; - } - - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java deleted file mode 100644 index eda694fe..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/NumberAxis.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * 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.axis.Axis; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; - -/** - * Class representing a JFreeChart.NumberAxis - * - * @author Teemu Lempinen - * - */ -public class NumberAxis extends AbstractAxis { - - /** - * - * @param graph ReadGraph - * @param axisResource resource of type JFreeChart.NumberAxis - */ - public NumberAxis(ReadGraph graph, Resource axisResource) { - super(graph, axisResource); - } - - - @Override - public Axis getAxis() { - axis = new ExtendedNumberAxis(); - ((ExtendedNumberAxis)axis).setLower(min); - ((ExtendedNumberAxis)axis).setUpper(max); - return super.getAxis(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java deleted file mode 100644 index 13b3ee76..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PieDataset.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * 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 java.awt.Color; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import javax.swing.SwingUtilities; - -import org.jfree.chart.renderer.AbstractRenderer; -import org.jfree.data.general.Dataset; -import org.jfree.data.general.DefaultPieDataset; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.MissingVariableException; -import org.simantics.db.layer0.request.PossibleActiveExperiment; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.diagram.G2DUtils; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.operation.Layer0X; -import org.simantics.sysdyn.Functions; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.adapter.VariableRVIUtils; -import org.simantics.sysdyn.manager.SysdynDataSet; -import org.simantics.ui.SimanticsUI; - -/** - * Class representing a PieDataset in JFreeChart ontology - * @author Teemu Lempinen - * - */ -public class PieDataset extends AbstractDataset { - - private List seriesList; - private String realizationURI; - private DefaultPieDataset dataset; - - private HashMap colorMap; - private HashMap explodedMap; - - public PieDataset(ReadGraph graph, Resource resource) { - super(graph, resource); - - try { - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - - // Find the model where the chart is located - Resource model = resource; - do { - model = graph.getPossibleObject(model, l0.PartOf); - } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel)); - - // Find the variable realization of the current experiment - realizationURI = null; - Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); - if (realization == null) { - Layer0X L0X = Layer0X.getInstance(graph); - realization = graph.getPossibleObject(model, L0X.HasBaseRealization); - } - if (realization != null) - realizationURI = graph.getURI(realization); - - if(realizationURI == null) - return; // No experiment -> No results - - Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList); - if(seriesList != null) { - this.seriesList = ListUtils.toList(graph, seriesList); - } - } catch (DatabaseException e) { - e.printStackTrace(); - } - - } - - /** - * Map of colors for different slices in a pie chart. Name - * indicates the key of the value. - * @return Map of colors for different slices in a pie chart - */ - public HashMap getColorMap() { - return colorMap; - } - - /** - * Map of exploded statuses for slices in a pie chart. Name - * indicates the key of the slice. - * @return - */ - public HashMap getExplodedMap() { - return explodedMap; - } - - @Override - public Dataset getDataset() { - if(seriesList == null || seriesList.isEmpty() || SimanticsUI.getSession() == null) - return null; - - if(dataset == null) { - dataset = new DefaultPieDataset(); - } - - if(listener == null) { - listener = new DatasetListener(); - SimanticsUI.getSession().asyncRequest(new Read>() { - - @Override - public ArrayList perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - - ArrayList series = new ArrayList(); - // Get properties for all series - if(seriesList != null) { - - colorMap = new HashMap(); - explodedMap = new HashMap(); - - for(Resource r : seriesList) { - String label = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasLabel); - String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); - if(rvi == null) - continue; - - try { - // Get visual properties - Resource c = graph.getPossibleObject(r, jfree.color); - Color color = c == null ? null : G2DUtils.getColor(graph, c); - Boolean exploded = graph.getPossibleRelatedValue(r, jfree.Series_exploded, Bindings.BOOLEAN); - - // Get a variable for the series - Variable v = Variables.getVariable(graph, realizationURI + rvi); - - // Get values - Variable dsVariable = v.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#"); - if(dsVariable == null) - return series; - - Object object = dsVariable.getValue(graph); - 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); - if(result2 != null) { - datasets = result2; - } - } - - // Find if a specific time is set for this chart - Double chartTime = null; - if(!datasets.isEmpty()) { - Layer0 l0 = Layer0.getInstance(graph); - Resource datasetResource = graph.getPossibleObject(r, l0.PartOf); - if(datasetResource != null) { - Resource plot = graph.getPossibleObject(datasetResource, l0.PartOf); - if(plot != null) { - Resource chart = graph.getPossibleObject(plot, l0.PartOf); - if(chart != null) - chartTime = graph.getPossibleRelatedValue(chart, jfree.Chart_time); - } - } - } - - for(SysdynDataSet dataset : datasets) { - double[] va = dataset.values; - - if(va == null || va.length == 0) - continue; - - /* - * Time - * - * 1. find time for the individual series. - * 2. find time for the whole chart - * 3. find simulation time - */ - Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE); - if(time == null) - time = chartTime; - if(time == null) { - // Get a variable for the experiment run - Variable run = Variables.getVariable(graph, realizationURI); - if(run == null) - return null; - Variable timeVar = run.browsePossible(graph, "#" + Functions.TIME + "#"); - if(timeVar != null) - time = timeVar.getValue(graph, Bindings.DOUBLE); - } - - // Value - Double value = null; - if(time == null) { - value = va[va.length - 1]; - } else { - double[] ta = dataset.times; - for(int i = 0; i < ta.length; i++) { - double t = ta[i]; - if(time <= t) { - value = va[i]; - break; - } - } - - if(value == null) - value = va[va.length - 1]; - } - - String name = label == null || label.isEmpty() ? dataset.name : label; - if(dataset.result != null) - name = name + " : " + dataset.result; - colorMap.put(name, color); - explodedMap.put(name, exploded); - series.add(new TempSeries(name, value)); - } - } catch (MissingVariableException e) { - // Do nothing, if variable was not found. Move on to the next series - } - } - } - return series; - } - - }, listener); - } - return dataset; - } - - private DatasetListener listener; - - private class DatasetListener implements Listener> { - - private boolean disposed = false; - - @Override - public void execute(final ArrayList series) { - // Modify series in AWT thread to avoid synchronization problems - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - // Remove all series - dataset.clear(); - - // Add found series - for(int i = 0; i < series.size(); i++) { - TempSeries s = series.get(i); - dataset.setValue(s.name, s.value); - } - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return disposed; - } - - public void dispose() { - disposed = true; - } - } - - @Override - public AbstractRenderer getRenderer() { - // No renderer for pie chart - return null; - } - - @Override - public void dispose() { - super.dispose(); - if(listener != null) { - listener.dispose(); - listener = null; - } - } - - - /** - * Auxiliary class containing all information needed to define a single series - * @author Teemu Lempinen - * - */ - private class TempSeries { - public String name; - public Double value; - - public TempSeries(String name, Double value) { - this.name = name; - this.value = value; - } - - @Override - public String toString() { - return "TempSeries: " + name + ", " + value; - } - } -} 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 deleted file mode 100644 index 126a0184..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/PiePlot.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * 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 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 - * - * @author Teemu Lempinen - * - */ -public class PiePlot extends AbstractPlot { - - private org.jfree.data.general.PieDataset pieDataset; - private DatasetChangeListener listener; - - public PiePlot(ReadGraph graph, Resource resource) { - super(graph, resource); - } - - /** - * Pie plot class with a stricter equals condition - * @author Teemu Lempinen - * - */ - private class MyPiePlot extends org.jfree.chart.plot.PiePlot { - - private static final long serialVersionUID = -5917620061541212934L; - - @Override - public boolean equals(Object obj) { - boolean result = super.equals(obj); - if(result == true) { - org.jfree.chart.plot.PiePlot that = (org.jfree.chart.plot.PiePlot) obj; - if (this.getDataset() != that.getDataset()) { - return false; // Normally plot does not check this. We need this to properly update the charts - } - } - - return result; - } - - } - - @Override - protected Plot newPlot() { - MyPiePlot plot = new MyPiePlot(); - plot.setToolTipGenerator(new StandardPieToolTipGenerator()); - return plot; - } - - @Override - protected void getOtherProperties(ReadGraph graph, PlotProperties properties) throws DatabaseException { - Boolean labelsVisible = graph.getPossibleRelatedValue(resource, JFreeChartResource.getInstance(graph).Plot_visibleLabels, Bindings.BOOLEAN); - properties.otherProperties.put("labelsVisible", labelsVisible); - } - - @Override - protected void setPlotProperties(PlotProperties properties) { - if(!(plot instanceof MyPiePlot)) - return; - - final MyPiePlot piePlot = (MyPiePlot)plot; - - if(!properties.datasets.isEmpty()) { - // We assume that a pie plot has only one dataset - final IDataset ds = properties.datasets.get(0); - Dataset dataset = ((PieDataset)ds).getDataset(); - - if(dataset == null) - return; - - if(pieDataset != null && listener != null) { - pieDataset.removeChangeListener(listener); - } - - pieDataset = (org.jfree.data.general.PieDataset)dataset; - piePlot.setDataset(pieDataset); - - Boolean labelsVisible = (Boolean)properties.otherProperties.get("labelsVisible"); - if(Boolean.FALSE.equals(labelsVisible)) - piePlot.setLabelGenerator(null); - else if(piePlot.getLabelGenerator() == null) - piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator()); - - listener = new DatasetChangeListener() { - - @Override - public void datasetChanged(DatasetChangeEvent event) { - HashMap colorMap = ((PieDataset)ds).getColorMap(); - HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); - - for(Object o : piePlot.getDataset().getKeys()) { - if(o instanceof Comparable) { - Comparable key = (Comparable)o; - if(explodedMap.containsKey(key) && explodedMap.get(key)) { - piePlot.setExplodePercent(key, 0.3); - - } else { - piePlot.setExplodePercent(key, 0); - } - } - } - - for(String name : explodedMap.keySet()) { - Boolean exploded = explodedMap.get(name); - if(Boolean.TRUE.equals(exploded)) - piePlot.setExplodePercent(name, 0.3); - } - piePlot.clearSectionPaints(false); - piePlot.setDrawingSupplier(new DefaultDrawingSupplier()); - for(String name : colorMap.keySet()) - piePlot.setSectionPaint(name, colorMap.get(name)); - } - }; - - pieDataset.addChangeListener(listener); - } - - // Cleaner look: no outline borders - piePlot.setInsets(new RectangleInsets(0,0,0,0), false); - piePlot.setOutlineVisible(false); - piePlot.setLabelBackgroundPaint(Color.WHITE); - piePlot.setLabelFont(new Font("helvetica", Font.PLAIN, 11)); - } - -} 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 deleted file mode 100644 index cd7f4cbf..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/StackedBarRenderer.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * 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.StandardCategoryToolTipGenerator; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; - -/** - * Stacked bar renderer - * @author Teemu Lempinen - * - */ -public class StackedBarRenderer extends AbstractRenderer { - - public StackedBarRenderer(ReadGraph graph, Resource resource) { - super(graph, resource); - } - - private org.jfree.chart.renderer.category.StackedBarRenderer renderer; - - @Override - public org.jfree.chart.renderer.AbstractRenderer getRenderer() { - 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/TextTitle.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/TextTitle.java deleted file mode 100644 index 7386a862..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/TextTitle.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * 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.title.Title; -import org.jfree.ui.RectangleEdge; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Class representing a JFreeChart.TextTitle - * @author Teemu Lempinen - * - */ -public class TextTitle implements ITitle { - - private org.jfree.chart.title.TextTitle textTitle; - private RectangleEdge position; - private String text; - private Boolean visible; - - public TextTitle(ReadGraph graph, Resource titleResource) { - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - try { - text = graph.getPossibleRelatedValue(titleResource, l0.HasLabel, Bindings.STRING); - Resource pos = graph.getPossibleObject(titleResource, jfree.Title_position); - position = getRectangleEdgePosition(graph, pos); - visible = graph.getPossibleRelatedValue(titleResource, jfree.visible, Bindings.BOOLEAN); - - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - /** - * Get the RectangleEdge representation for Resource position (JFreeChart.Position) - * @param graph ReadGraph - * @param position Resource of type JFreeChart.Position - * @return RectangleEdge representation for Resource position - */ - private RectangleEdge getRectangleEdgePosition(ReadGraph graph, Resource position) { - if(position == null) - return null; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - if(position.equals(jfree.Top)) - return RectangleEdge.TOP; - else if(position.equals(jfree.Bottom)) - return RectangleEdge.BOTTOM; - else if(position.equals(jfree.Left)) - return RectangleEdge.LEFT; - else if(position.equals(jfree.Right)) - return RectangleEdge.RIGHT; - else - return null; - - } - - @Override - public Title getTitle() { - textTitle = new org.jfree.chart.title.TextTitle(text); - if(position != null) - textTitle.setPosition(position); - if(visible != null) - textTitle.setVisible(visible); - return textTitle; - } - - @Override - public void dispose() { - } - -} 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 deleted file mode 100644 index 65337783..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYAreaRenderer.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 427fa8b1..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYDataset.java +++ /dev/null @@ -1,501 +0,0 @@ -/******************************************************************************* - * 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 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; -import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.data.general.Dataset; -import org.jfree.data.xy.DefaultXYDataset; -import org.jfree.ui.Layer; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.MissingVariableException; -import org.simantics.db.layer0.request.PossibleActiveExperiment; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.diagram.G2DUtils; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.operation.Layer0X; -import org.simantics.sysdyn.Functions; -import org.simantics.sysdyn.JFreeChartResource; -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 - * - * @author Teemu Lempinen - * - */ -public class XYDataset extends AbstractDataset { - - private IRenderer renderer; - - public XYDataset(ReadGraph graph, final Resource datasetResource) { - super(graph, datasetResource); - } - - private DefaultXYDataset dataset; - private DataSetListener datasetListener; - private TimeListener timeListener; - - @Override - public Dataset getDataset() { - if(dataset == null) { - dataset = new DefaultXYDataset(); - } - - if(datasetListener == null || datasetListener.isDisposed()) { - datasetListener = new DataSetListener(); - SimanticsUI.getSession().asyncRequest(new Read, IRenderer>>() { - - @Override - 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 new Pair, IRenderer>(series, renderer); // No experiment -> No results - - // Get a variable for the x-axis (if not time) - double[] domainValues = null; - Resource domainAxis = graph.getPossibleObject(resource, jfree.Dataset_mapToDomainAxis); - if(domainAxis != null) { - String rvi = graph.getPossibleRelatedValue(domainAxis, jfree.variableRVI); - if(rvi != null && !rvi.isEmpty()) { - try { - Variable domainVariable = Variables.getVariable(graph, realizationURI + rvi); - Variable valuesVariable = domainVariable.browsePossible(graph, "#" + Functions.VALUES +"#"); - if(valuesVariable != null) { - double[][] valuesArray = valuesVariable.getValue(graph); - if(valuesArray.length > 0) - domainValues = valuesArray[0]; - } - } catch(MissingVariableException e) { - //Do nothing, use time as domain axis - } - } - } - - Resource seriesList = graph.getPossibleObject(resource, jfree.Dataset_seriesList); - - // Get properties for all series - if(seriesList != null) { - for(Resource r : ListUtils.toList(graph, seriesList)) { - String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); - if(rvi == null) - continue; - - try { - // Get visual properties - Integer width = graph.getPossibleRelatedValue(r, jfree.Series_lineWidth, Bindings.INTEGER); - if(width == null) width = 1; - - Resource c = graph.getPossibleObject(r, jfree.color); - Color color = c == null ? null : G2DUtils.getColor(graph, c); - - String label = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasLabel); - - // Get a variable for the series - Variable v = Variables.getVariable(graph, realizationURI + rvi); - if(v == null) - return new Pair, IRenderer>(series, renderer); - - // Get values - Variable dsVariable = v.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#"); - Object object = null; - if(dsVariable != null) - object = dsVariable.getValue(graph); - - if(object == null || !(object instanceof ArrayList)) - return new Pair, IRenderer>(series, renderer); - - 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); - if(result2 != null) { - datasets = result2; - } - } - - for(SysdynDataSet dataset : datasets) { - double[] va = dataset.values; - - // Get domain axis values (time OR other variable) - double[] ta; - if(domainValues != null) { - ta = domainValues; - - // If domainAxis is other than time, parameter values size is different. - if(domainValues.length > va.length) { - double value = va[0]; - va = new double[domainValues.length]; - for(int i = 0; i < domainValues.length; i++) - va[i] = value; - } - - // If domainAxis is a parameter, the domainValues array is too short - if(domainValues.length < va.length && domainValues.length == 2 && domainValues[0] == domainValues[1]) { - double value = domainValues[0]; - ta = new double[va.length]; - for(int i = 0; i < va.length; i++) - ta[i] = value; - } - - } else { - ta = dataset.times; - } - - if(ta!=null && va!=null && (va.length == ta.length)) { - // Add series if everything OK - String name = dataset.name; - if(label != null) - name = label; - if(dataset.result != null && !dataset.result.isEmpty()) - name = name + " : " + dataset.result; - series.add(new TempSeries(name, new double[][] {ta, va}, width, color)); - if(ta.length == 0 || va.length == 0) - System.out.println(dataset.name + " : " + dataset.result + ". Sizes: " + va.length + " and " + ta.length); - } - } - - } catch (MissingVariableException e) { - // Do nothing, if variable was not found. Move on to the next series - } - } - } - return new Pair, IRenderer>(series, renderer); - } - - }, datasetListener); - } - - if(timeListener == null || timeListener.isDisposed()) { - timeListener = new TimeListener(); - SimanticsUI.getSession().asyncRequest(new Read() { - @Override - public Double perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - // Get properties for all series - Resource series = graph.getPossibleObject(resource, jfree.Dataset_seriesList); - if(series != null) { - List seriesList = ListUtils.toList(graph, series); - if(seriesList != null) { - String realizationURI = getRealizationURI(graph); - for(Resource r : seriesList) { - String rvi = graph.getPossibleRelatedValue(r, jfree.variableRVI); - if(rvi == null) - continue; - try { - // Get a variable for the experiment run - Variable v = Variables.getVariable(graph, realizationURI); - if(v == null) - return null; - Variable timeVar = v.browsePossible(graph, "#" + Functions.TIME + "#"); - if(timeVar != null) - return timeVar.getValue(graph, Bindings.DOUBLE); - } catch (MissingVariableException e) { - // Do nothing, if variable was not found. - } - } - } - } - return null; - } - - }, timeListener); - } - 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, IRenderer>> { - - private boolean disposed = false; - - public void dispose() { - disposed = true; - } - - @Override - public boolean isDisposed() { - return disposed; - } - - @Override - 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() { - - 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)); - } - - // Add found series - for(int i = 0; i < series.size(); i++) { - TempSeries s = series.get(i); - dataset.addSeries(s.name, s.values); - getRenderer().setSeriesStroke(i, new BasicStroke((float)s.width)); - getRenderer().setSeriesPaint(i, s.color); - } - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - } - - - /** - * 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() { - 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 - public boolean isDisposed() { - return disposed; - } - - @Override - public void execute(final Double time) { - // Modify in AWT thread to avoid synchronization problems - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - org.jfree.chart.plot.XYPlot plot = ((AbstractXYItemRenderer)getRenderer()).getPlot(); - - if(plot == null) - return; - - plot.removeDomainMarker(marker); - if(time != null) { - 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); - } - } - - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - } - - @Override - public void dispose() { - if(timeListener != null) { - timeListener.dispose(); - timeListener = null; - } - - if(datasetListener != null) { - datasetListener.dispose(); - datasetListener = null; - } - } - - - /** - * Auxiliary class containing all information needed to define a single series - * @author Teemu Lempinen - * - */ - private class TempSeries { - public double[][] values; - public String name; - public int width; - public Color color; - - public TempSeries(String name, double[][] values, int width, Color color) { - this.name = name; - this.values = values; - this.width = width; - this.color = color; - } - } - - @Override - public AbstractRenderer getRenderer() { - if(renderer == null) { - - try { - renderer = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public IRenderer perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - IRenderer renderer = null; - Resource rendererResource = graph.getPossibleObject(resource, jfree.Dataset_renderer); - if(rendererResource != null) - renderer = graph.adapt(rendererResource, IRenderer.class); - return renderer; - } - }); - } catch (DatabaseException e) { - } - if(renderer == null) { - XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); - renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); - return renderer; - } else { - return renderer.getRenderer(); - } - } else { - return renderer.getRenderer(); - } - } - - /** - * Get the realization uri of the current dataset resource - * @param graph ReadGraph - * @return realization uri for current dataset resource - * @throws DatabaseException - */ - private String getRealizationURI(ReadGraph graph) throws DatabaseException { - if(resource == null) - return null; - - Layer0 l0 = Layer0.getInstance(graph); - ModelingResources mr = ModelingResources.getInstance(graph); - - // Find the model where the chart is located - Resource model = resource; - do { - model = graph.getPossibleObject(model, l0.PartOf); - } while(model != null && !graph.isInstanceOf(model, mr.StructuralModel)); - - if(model == null) - return null; - - // Find the variable realization of the current experiment - String realizationURI = null; - Resource realization = graph.syncRequest(new PossibleActiveExperiment(model)); - if (realization == null) { - Layer0X L0X = Layer0X.getInstance(graph); - realization = graph.getPossibleObject(model, L0X.HasBaseRealization); - } - if (realization != null) - realizationURI = graph.getURI(realization); - - return realizationURI; - } -} 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 deleted file mode 100644 index cb2a6d14..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYLineRenderer.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index bea1ce22..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/XYPlot.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * 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.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; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Class representing a JFreeChart.XYPlot - * - * @author Teemu Lempinen - * - */ -public class XYPlot extends AbstractPlot { - - public XYPlot(ReadGraph graph, Resource plotResource) { - super(graph, plotResource); - } - - @Override - 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(); - - for(int i = 0; i < properties.ranges.size(); i++) { - xyplot.setRangeAxis(i, (ValueAxis)properties.ranges.get(i).getAxis()); - } - - for(int i = 0; i < properties.domains.size(); i++) { - xyplot.setDomainAxis(i, (ValueAxis)properties.domains.get(i).getAxis()); - } - - IAxis axis; - for(int i = 0; i < properties.datasets.size(); i++) { - IDataset dataset = properties.datasets.get(i); - xyplot.setDataset(i, (XYDataset)dataset.getDataset()); - xyplot.setRenderer(i, (XYItemRenderer)dataset.getRenderer()); - axis = properties.rangeMappings.get(dataset); - if(axis != null && properties.ranges.contains(axis)) - xyplot.mapDatasetToRangeAxis(i, properties.ranges.indexOf(axis)); - axis = properties.domainMappings.get(dataset); - if(axis != null && properties.ranges.contains(axis)) - xyplot.mapDatasetToDomainAxis(i, properties.domains.indexOf(axis)); - } - - Boolean visibleGrid = (Boolean)properties.otherProperties.get("visibleGrid"); - if(visibleGrid == null) - visibleGrid = true; - - 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/element/ChartBoundsOutline.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java deleted file mode 100644 index ef22ada6..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartBoundsOutline.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.simantics.sysdyn.ui.trend.chart.element; - -import java.awt.geom.Rectangle2D; - -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.element.ElementHints; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.LifeCycle; -import org.simantics.g2d.element.handler.impl.BoundsOutline; - -/** - * Outline with default bounds. Needed to avoid crashing when trying to rotate chart elements. - * @author Teemu Lempinen - * - */ -public class ChartBoundsOutline extends BoundsOutline implements LifeCycle { - private static final long serialVersionUID = -3819495313008722843L; - - Rectangle2D defaultBounds; - - public ChartBoundsOutline(Rectangle2D defaultBounds) { - this.defaultBounds = defaultBounds; - } - - @Override - public void onElementCreated(IElement e) { - e.setHint(ElementHints.KEY_BOUNDS, defaultBounds); - } - - @Override - public void onElementDestroyed(IElement e) {} - @Override - public void onElementActivated(IDiagram d, IElement e) {} - @Override - public void onElementDeactivated(IDiagram d, IElement e) {} - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java deleted file mode 100644 index 142774e7..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementFactory.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * 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.element; - -import java.awt.BasicStroke; -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.Path2D; -import java.awt.geom.QuadCurve2D; -import java.awt.geom.Rectangle2D; - -import org.jfree.chart.JFreeChart; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.adapter.ElementFactory; -import org.simantics.diagram.adapter.ElementFactoryUtil; -import org.simantics.diagram.adapter.SyncElementFactory; -import org.simantics.diagram.elements.ElementPropertySetter; -import org.simantics.diagram.synchronization.CompositeHintSynchronizer; -import org.simantics.diagram.synchronization.IHintSynchronizer; -import org.simantics.diagram.synchronization.ISynchronizationContext; -import org.simantics.diagram.synchronization.SynchronizationHints; -import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; -import org.simantics.diagram.synchronization.graph.RemoveElement; -import org.simantics.diagram.synchronization.graph.TransformSynchronizer; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.element.ElementClass; -import org.simantics.g2d.element.ElementUtils; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.LifeCycle; -import org.simantics.g2d.element.handler.impl.DefaultTransform; -import org.simantics.g2d.element.handler.impl.StaticObjectAdapter; -import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer; -import org.simantics.g2d.element.handler.impl.StaticSymbolImpl; -import org.simantics.g2d.image.Image; -import org.simantics.g2d.image.impl.ShapeImage; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.trend.chart.IJFreeChart; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; - -/** - * Element factory for creating chart elements to diagrams - * - * @author Teemu Lempinen - * - */ -public class ChartElementFactory extends SyncElementFactory { - - private static final String CLASS_ID = "Chart"; - public static final ElementFactory INSTANCE = new ChartElementFactory(); - public static final Image STATIC_IMAGE = new ShapeImage(getChartShape(), null, new BasicStroke(1f), true); - public static final double SYMBOL_CHART_SIZE = 10.0; - public static final Key KEY_CHART_COMPONENT = new KeyOf(Resource.class, "CHART_COMPONENT"); - public static final Key KEY_CHART = new KeyOf(JFreeChart.class, "CHART"); - - static Shape getChartShape() { - - Path2D path = new Path2D.Double(); - // First create the axis for a chart symbol - path.moveTo(-SYMBOL_CHART_SIZE, -SYMBOL_CHART_SIZE); - path.lineTo(-SYMBOL_CHART_SIZE, SYMBOL_CHART_SIZE); - path.lineTo( SYMBOL_CHART_SIZE, SYMBOL_CHART_SIZE); - - // Then a curve to the chart - QuadCurve2D curve = new QuadCurve2D.Double( - -SYMBOL_CHART_SIZE + 1, SYMBOL_CHART_SIZE - 1, - SYMBOL_CHART_SIZE - 5, SYMBOL_CHART_SIZE - 5, - SYMBOL_CHART_SIZE - 1, -SYMBOL_CHART_SIZE + 3); - - // Connect shapes - path.append(curve, false); - return path; - } - - // Hint synchronizer for synchronizing transform and bounds - private static final IHintSynchronizer HINT_SYNCHRONIZER = new CompositeHintSynchronizer( - TransformSynchronizer.INSTANCE); - - public static ElementClass create(ReadGraph graph, Resource chart) throws DatabaseException { - return ElementClass.compile( - new ChartSceneGraph(), - new Initializer(chart), - new StaticObjectAdapter(JFreeChartResource.getInstance(graph).ChartElement), - DefaultTransform.INSTANCE, - StaticSymbolImageInitializer.INSTANCE, - new StaticSymbolImpl(STATIC_IMAGE), - new ChartBoundsOutline(new Rectangle2D.Double(-20, -20, 60, 40)), - new ElementPropertySetter(ChartSceneGraph.KEY_SG_NODE) - ).setId(CLASS_ID); - } - - public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType) throws DatabaseException { - return create(graph, null); - } - - @Override - public void load(ReadGraph g, ICanvasContext canvas, final IDiagram diagram, Resource element, final IElement e) throws DatabaseException { - - Resource chartResource; - ElementPropertySetter ps = e.getElementClass().getSingleItem(ElementPropertySetter.class); - ps.loadProperties(e, element, g); - - AffineTransform at = DiagramGraphUtil.getAffineTransform(g, element); - // Hack for disabling all rotations in chart elements - double x = at.getTranslateX(); - double y = at.getTranslateY(); - at.setToRotation(0); - at.setToTranslation(x, y); - ElementUtils.setTransform(e, at); // Set hint transform without rotations - ps.overrideProperty(e, "Transform", at); // Set property Transform without rotations - - e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, HINT_SYNCHRONIZER); - - - Object o = e.getHint(KEY_CHART_COMPONENT); - if(o == null || !(o instanceof Resource)) { - chartResource = g.getPossibleObject(element, JFreeChartResource.getInstance(g).ChartElement_component); - } else { - chartResource = (Resource)o; - } - - if(chartResource == null || !g.hasStatement(chartResource)) { - // Remove element if there is no chart resource for it - final ISynchronizationContext syncContext = ElementFactoryUtil.getContextChecked(diagram); - g.asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - new RemoveElement(syncContext, diagram, e).perform(graph); - } - }); - return; - } - - IJFreeChart ichart = g.adapt(chartResource, IJFreeChart.class); - - if(ichart != null) { - JFreeChart chart = ichart.getChart(); - e.setHint(KEY_CHART, chart); - } - - } - - - /** - * Initializer for setting a chart component for element - * @author Teemu Lempinen - * - */ - static class Initializer implements LifeCycle { - private static final long serialVersionUID = -5822080013184271204L; - Object component; - - Initializer(Object component) { - this.component = component; - } - - @Override - public void onElementCreated(IElement e) { - if(component != null) e.setHint(KEY_CHART_COMPONENT, component); - } - - @Override - public void onElementActivated(IDiagram d, IElement e) {} - @Override - public void onElementDeactivated(IDiagram d, IElement e) {} - @Override - public void onElementDestroyed(IElement e) {} - }; -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java deleted file mode 100644 index 31ef8da5..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartElementWriter.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * 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.element; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.synchronization.graph.ElementWriter; -import org.simantics.g2d.element.IElement; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Element writer for chart elements. ChartElementWriter stores - * the reference to a chart definition into the element resource - * @author Teemu Lempinen - * - */ -public class ChartElementWriter implements ElementWriter { - - @Override - public void addToGraph(WriteGraph graph, IElement element, Resource elementResource) throws DatabaseException { - Resource chartComponent = element.getHint(ChartElementFactory.KEY_CHART_COMPONENT); - if (chartComponent == null) - throw new IllegalArgumentException("KEY_CHART_COMPONENT hint not set"); - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - graph.claim(elementResource, jfree.ChartElement_component, chartComponent); - } - - @Override - public void removeFromGraph(WriteGraph graph, Resource elementResource) throws DatabaseException { - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java deleted file mode 100644 index c1c0d437..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 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.element; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Stroke; -import java.awt.geom.AffineTransform; -import java.awt.geom.Line2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -import javax.swing.JPanel; - -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.simantics.scenegraph.ISelectionPainterNode; -import org.simantics.scenegraph.g2d.events.EventTypes; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; -import org.simantics.scenegraph.swing.ComponentNode; -import org.simantics.scenegraph.utils.GeometryUtils; -import org.simantics.scenegraph.utils.NodeUtil; - -/** - * Chart node for displaying jfreechart charts in diagrams - * @author Teemu Lempinen - * - */ -public class ChartNode extends ComponentNode implements ISelectionPainterNode { - - private static final long serialVersionUID = 5013911689968911010L; - private boolean hover = false; - private boolean dragging = false; - - private ResizeListener resizeListener; - - protected transient JFreeChart chart = null; - - public boolean dragging() { - return dragging; - } - - public void setChart(JFreeChart chart) { - this.chart = chart; - } - - public void setResizeListener(ResizeListener listener) { - this.resizeListener = listener; - } - - @SyncField({"hover"}) - public void setHover(boolean hover) { - this.hover = hover; - repaint(); - } - - @Override - public void cleanup() { - removeEventHandler(this); - super.cleanup(); - } - - @Override - public void init() { - super.init(); - } - - public static void expand(Rectangle2D rectangle, double scaleX, double scaleY) { - GeometryUtils.expandRectangle(rectangle, - 5 * scaleY > 5 ? 5 * scaleY : 5, - 3 * scaleY > 3 ? 3 * scaleY : 3, - 3 * scaleX > 3 ? 3 * scaleX : 3, - 3 * scaleX > 3 ? 3 * scaleX : 3); - } - - @Override - public void render(Graphics2D g2d) { - if (component == null && chart != null) { - // Need the chart, so this cannot be done during initialization - component = new ChartPanel(chart, false); - ((ChartPanel)component).setRefreshBuffer(false); - component.setIgnoreRepaint(true); - component.setDoubleBuffered(false); - if(bounds != null) { - component.setBounds(0, 0, 0, 0); - } - super.init(); - addEventHandler(this); - } - - if (component != null) { - AffineTransform ot = g2d.getTransform(); - g2d.transform(transform); - double scaleX = g2d.getTransform().getScaleX(); - double scaleY = g2d.getTransform().getScaleY(); - - AffineTransform at = new AffineTransform(transform); - synchronized(transform) { - at.setToTranslation(bounds.getMinX(), bounds.getMinY()); - at.scale(1/scaleX, 1/scaleY); - } - g2d.transform(at); - int width = (int)(bounds.getWidth() * scaleX); - int height = (int)(bounds.getHeight() * scaleY); - - if(hover || dragging) { - // Borders - Color orig = g2d.getColor(); - BasicStroke oldStroke = (BasicStroke) g2d.getStroke(); - g2d.setColor(Color.LIGHT_GRAY); - Rectangle2D b = new Rectangle2D.Double(0, 0, width, height); - Rectangle2D r = b.getBounds2D(); - expand(r, 1 * scaleX, 1 * scaleY); - g2d.fill(r); - - // Lower right corner for dragging - double x = r.getMaxX() - (0.33 * scaleX); - double y = r.getMaxY() - (0.33 * scaleY); - - if(r.getMaxX() - x > 0.4) { - // if there is enough space, use decorated corner - BasicStroke hilightStroke = new BasicStroke(oldStroke.getLineWidth() * 3); - for(int i = 1; i < 4; i++) { - Line2D line = new Line2D.Double( - x - (i * scaleX), - y, - x, - y - (i * scaleY)); - - g2d.setStroke(hilightStroke); - g2d.setColor(Color.GRAY); - g2d.draw(line); - - g2d.setStroke(oldStroke); - g2d.setColor(Color.BLACK); - g2d.draw(line); - } - - - } else { - // not enough space, use a non-decorated corner - float f = 3; - Rectangle2D corner = new Rectangle2D.Double(r.getMaxX() - f, r.getMaxY() - f, f, f); - g2d.setColor(Color.DARK_GRAY); - g2d.fill(corner); - } - - g2d.setStroke(oldStroke); - g2d.setColor(orig); - } - - boolean selected = NodeUtil.isSelected(this, 1); - if (selected) { - Color orig = g2d.getColor(); - Stroke origStroke = g2d.getStroke(); - - g2d.setColor(Color.RED); - double s = GeometryUtils.getScale(g2d.getTransform()); - g2d.setStroke(new BasicStroke(1f * s < 1f ? 1f : 1f * (float)s)); - - Rectangle2D b = new Rectangle2D.Double(0, 0, width, height); - Rectangle2D r = b.getBounds2D(); - expand(r, scaleX, scaleY); - g2d.draw(r); - - g2d.setColor(orig); - g2d.setStroke(origStroke); - } - - synchronized(component) { - component.setLocation((int)g2d.getTransform().getTranslateX(), (int)g2d.getTransform().getTranslateY()); - if(component.getSize().getWidth() != width || component.getSize().getHeight() != height) { - component.setSize(width, height); - } - component.paint(g2d); - } - - g2d.setTransform(ot); - } else { - /* - * Component == null - * - * The related chart definition ha been removed. - */ - System.out.println("TÄÄLLÄ, TÄÄLLÄ"); - } - } - - @Override - protected boolean mouseButtonPressed(MouseButtonPressedEvent event) { - Point2D local = controlToLocal( event.controlPosition ); - local = parentToLocal(local); - Rectangle2D bounds = getBoundsInLocal().getBounds2D(); - expand(bounds, 1, 1); - double control = 3.0; - Rectangle2D corner = new Rectangle2D.Double(bounds.getMaxX() - control, bounds.getMaxY() - control, control, control); - if (hover && corner.contains(local)) { - dragging = true; - return true; - } - return super.mouseButtonPressed(event); - } - - - @Override - protected boolean mouseMoved(MouseMovedEvent e) { - if(dragging) { - Point2D local = controlToLocal( e.controlPosition ); - local = parentToLocal(local); - - Rectangle2D bounds = getBoundsInLocal().getBounds2D(); - - if(Math.abs(bounds.getMaxX() - local.getX()) > 3 || - Math.abs(bounds.getMaxY() - local.getY()) > 3) { - resize(local); - } - return true; - } - return false; - } - - public boolean hitCorner(Point2D point) { - Rectangle2D bounds = getBoundsInLocal().getBounds2D(); - expand(bounds, 1, 1); - double control = 3.0; - Rectangle2D corner = new Rectangle2D.Double(bounds.getMaxX() - control, bounds.getMaxY() - control, control, control); - return corner.contains(point); - } - - private void resize(Point2D local) { - Rectangle2D bounds = getBoundsInLocal().getBounds2D(); - double x = bounds.getX(); - double y = bounds.getY(); - double dx = local.getX() - bounds.getMaxX(); - double dy = local.getY() - bounds.getMaxY(); - double w = bounds.getWidth() + dx; - double h = bounds.getHeight() + dy; - bounds.setRect( - x, - y, - w > 20 ? w : 20, - h > 20 ? h : 20 - ); - setBounds(bounds); - } - - @Override - protected boolean mouseDragged(MouseDragBegin e) { - if(dragging) { - return true; // Eat event for faster resize - } else { - return false; - } - } - - @Override - protected boolean mouseButtonReleased(MouseButtonReleasedEvent e) { - if(dragging) { - Point2D local = controlToLocal( e.controlPosition ); - local = parentToLocal(local); - if(Math.abs(bounds.getMaxX() - local.getX()) > 3 || - Math.abs(bounds.getMaxY() - local.getY()) > 3) { - resize(local); - } - dragging = false; - if(resizeListener != null) - resizeListener.elementResized(bounds); - } - return false; - } - - @Override - public int getEventMask() { - return EventTypes.MouseButtonPressedMask - | EventTypes.MouseMovedMask - | EventTypes.MouseButtonReleasedMask - ; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java deleted file mode 100644 index f8ea0c72..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartSceneGraph.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * 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.element; - -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.Rectangle2D; - -import org.jfree.chart.JFreeChart; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.DiagramUtils; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.g2d.element.ElementHints; -import org.simantics.g2d.element.ElementUtils; -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.SceneGraphNodeKey; -import org.simantics.g2d.element.handler.HandleMouseEvent; -import org.simantics.g2d.element.handler.InternalSize; -import org.simantics.g2d.element.handler.PropertySetter; -import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.scenegraph.Node; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.scenegraph.g2d.IG2DNode; -import org.simantics.scenegraph.g2d.events.MouseEvent; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent; -import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent; -import org.simantics.utils.datastructures.hints.IHintContext.Key; -import org.simantics.utils.datastructures.hints.IHintListener; -import org.simantics.utils.datastructures.hints.IHintObservable; - -/** - * Chart scenegraph for chart elements in diagrams - * @author Teemu Lempinen - * - */ -public class ChartSceneGraph implements SceneGraph, HandleMouseEvent, InternalSize { - private static final long serialVersionUID = 1875762898776996989L; - - public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "CHART_SG_NODE"); - public static final Key KEY_SG_SELECTION_NODE = new SceneGraphNodeKey(Node.class, "CHART_SG_SELECTION_NODE"); - - protected IHintListener hoverHintListener; - - public ChartSceneGraph() { - } - - /** - * Expands bounds a little to allow selecting and grabbing a chart element - * from outside the chart graphics - */ - @Override - public Rectangle2D getBounds(IElement e, Rectangle2D s) { - if (s==null) s = new Rectangle2D.Double(); - - IG2DNode node = (IG2DNode)e.getHint(KEY_SG_NODE); - AffineTransform at = (AffineTransform)e.getHint(ElementHints.KEY_TRANSFORM); - if(at != null && node != null && node.getBoundsInLocal() != null) { - Shape shape = node.getBoundsInLocal(); - Rectangle2D r = shape.getBounds2D(); - double scaleX = at.getScaleX(); - double scaleY = at.getScaleY(); - ChartNode.expand(r, 1 * scaleX, 1 * scaleY); - shape = r; - s.setFrame(shape.getBounds2D()); - } else { - s.setFrame((Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS)); - } - return s; - } - - @Override - public void cleanup(IElement e) { - if(hoverHintListener != null) - e.removeHintListener(hoverHintListener); - - Node node = e.removeHint(KEY_SG_NODE); - if (node != null) - node.remove(); - } - - @Override - public void init(final IElement e, G2DParentNode parent) { - ChartNode node = e.getHint(KEY_SG_NODE); - if(node == null) { - // Create a new chart node - node = parent.getOrCreateNode("chart_"+e.hashCode(), ChartNode.class); - - Rectangle2D bounds = (Rectangle2D)e.getHint(ElementHints.KEY_BOUNDS); - if(bounds == null) { - bounds = new Rectangle2D.Double(-40, -40, 80, 80); - e.setHint(ElementHints.KEY_BOUNDS, bounds); - } - node.setBounds(bounds); - - JFreeChart chart = e.getHint(ChartElementFactory.KEY_CHART); - if(chart != null) - node.setChart(chart); - - // Add a resize listener for updating bounds information to graph after resizing - node.setResizeListener(new ResizeListener() { - - @Override - public void elementResized(Rectangle2D newBounds) { - e.setHint(ElementHints.KEY_BOUNDS, newBounds); - IDiagram diagram = ElementUtils.getDiagram(e); - DiagramUtils.synchronizeHintsToBackend(diagram, e); - } - }); - - e.setHint(KEY_SG_NODE, node); - } - - // Hover listening - hoverHintListener = new IHintListener() { - @Override - public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { - - } - - @Override - public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { - if(key == ElementHints.KEY_HOVER) { - IElement e = (IElement)sender; - ChartNode name = (ChartNode) e.getHint(KEY_SG_NODE); - if (name != null) - name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER))); - } - } - }; - e.addHintListener(hoverHintListener); - - update(e); - } - - public void update(IElement e) { - PropertySetter setter = e.getElementClass().getSingleItem(PropertySetter.class); - setter.syncPropertiesToNode(e); - } - - - @Override - public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) { - if (me instanceof MouseEnterEvent) { - e.setHint(ElementHints.KEY_HOVER, true); - } else if (me instanceof MouseExitEvent) { - e.setHint(ElementHints.KEY_HOVER, false); - } - return false; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java deleted file mode 100644 index 168c2a26..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/PopulateChartDropParticipant.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * 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.element; - -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.awt.dnd.DnDConstants; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.geom.AffineTransform; -import java.io.IOException; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.common.request.UnaryRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; -import org.simantics.g2d.dnd.DnDHints; -import org.simantics.g2d.dnd.ElementClassDragItem; -import org.simantics.g2d.dnd.IDnDContext; -import org.simantics.g2d.dnd.IDropTargetParticipant; -import org.simantics.g2d.element.ElementHints; -import org.simantics.modeling.ui.diagramEditor.PopulateElementDropParticipant; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.ui.dnd.LocalObjectTransfer; -import org.simantics.ui.dnd.LocalObjectTransferable; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Drop participant for dropping chart definitions into diagrams - * @author Teemu Lempinen - * - */ -public class PopulateChartDropParticipant extends PopulateElementDropParticipant implements IDropTargetParticipant { - - public PopulateChartDropParticipant(GraphToDiagramSynchronizer synchronizer) { - super(synchronizer); - } - - @Override - public void dragEnter(DropTargetDragEvent dtde, final IDnDContext dp) { - Transferable tr = dtde.getTransferable(); - if (tr.isDataFlavorSupported(LocalObjectTransferable.FLAVOR)) { - - Session session = synchronizer.getSession(); - - Object obj = null; - - try { - obj = tr.getTransferData(LocalObjectTransferable.FLAVOR); - - // Create a structural selection from transfer data - if (!(obj instanceof IStructuredSelection)) { - obj = LocalObjectTransfer.getTransfer().getObject(); - } - - if (obj instanceof IStructuredSelection) { - - IStructuredSelection sel = (IStructuredSelection) obj; - - // Can drop only one chart at the time - if (sel.size() == 1) { - - // Get the chart definition - Resource chart = AdaptionUtils.adaptToSingle(sel, Resource.class); - if (chart == null) - return; - - ElementClassDragItem item = session.syncRequest(new UnaryRead(chart) { - - @Override - public ElementClassDragItem perform(ReadGraph graph) throws DatabaseException { - if(graph.isInstanceOf(parameter, JFreeChartResource.getInstance(graph).Chart)) { - ElementClassDragItem item = new ElementClassDragItem(ChartElementFactory.create(graph, parameter)); - AffineTransform initialTr = AffineTransform.getScaleInstance(1, 1); - item.getHintContext().setHint(ElementHints.KEY_TRANSFORM, initialTr); - return item; - } else { - return null; - } - - } - }); - - if(item != null) { - dp.add(item); - dp.getHints().setHint(DnDHints.KEY_DND_GRID_COLUMNS, Integer.valueOf(1)); - } - - } - - } - - } catch (UnsupportedFlavorException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (DatabaseException e) { - e.printStackTrace(); - } - - } - - dtde.acceptDrag(DnDConstants.ACTION_COPY); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java deleted file mode 100644 index 6c4116b5..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ResizeListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * 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.element; - -import java.awt.geom.Rectangle2D; - -/** - * Interface for listeners listening resize events in chart nodes - * @author Teemu Lempinen - * - */ -public interface ResizeListener { - - /** - * Triggered when a node has been resized - * @param newBounds new bounds for the node - */ - public void elementResized(Rectangle2D newBounds); -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java deleted file mode 100644 index 5b8c44a0..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisChildRule.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.browsing.ui.model.children.ChildRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * ChildRule for finding the axis of a JFreeChart - * - * @author Teemu Lempinen - * - */ -public class AxisChildRule implements ChildRule { - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { - ArrayList result = new ArrayList(); - if(!(parent instanceof Resource)) - return result; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - /* - * 1. chart may have multiple plots - * 2. plot may have multiple axis - */ - for(Resource plot : graph.syncRequest(new ObjectsWithType((Resource)parent, l0.ConsistsOf, jfree.Plot))) { - Resource rangeAxisList = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); - if(rangeAxisList != null) - for(Resource axis : ListUtils.toList(graph, rangeAxisList)) { - result.add(axis); - } - } - return result; - - - } - - @Override - public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { - return new ArrayList(); - } - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java deleted file mode 100644 index e6590aa0..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisDropAction.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.List; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.DropActionFactory; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.trend.chart.properties.xyline.AxisAndVariablesExplorerComposite; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Action for dropping axis on top of other axis or series in {@link AxisAndVariablesExplorerComposite} - * @author Teemu Lempinen - * - */ -public class AxisDropAction implements DropActionFactory { - - @Override - public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { - // Make sure that both target and source are resources - Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); - Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); - - if(t == null || s == null) - return null; - - // Make sure that source and target are of correct type - JFreeChartResource jfree = JFreeChartResource.getInstance(g); - if(!g.isInstanceOf(s, jfree.Axis)) - return null; - if(!g.isInstanceOf(t, jfree.Series) && !g.isInstanceOf(t, jfree.Axis)) - return null; - - return getRunnable(t, s); - } - - /** - * Get the runnable for doing the drop action - * - * @param t target resource - * @param s source resource - * @return Runnable - */ - private Runnable getRunnable(final Resource t, final Resource s) { - Runnable runnable = new Runnable() { - - @Override - public void run() { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - if(t == null || s == null) return; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource target = t; - Resource source = s; - - // Dragged axis always exists in the same list with target axis, so it is safe to get the target index - Resource plot = graph.getPossibleObject(source, l0.PartOf); - Resource axisListResource = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); - List axisList = ListUtils.toList(graph, axisListResource); - if(graph.isInstanceOf(target, jfree.Series)) { - // Dropped a axis over a series -> get the axis of the series - Resource dataset = graph.getPossibleObject(target, l0.PartOf); - target = graph.getPossibleObject(dataset, jfree.Dataset_mapToRangeAxis); - } - - // move axis to target position - int targetIndex = axisList.indexOf(target); - axisList.remove(source); - axisList.add(targetIndex, source); - - // Update the range axis list - graph.deny(plot, jfree.Plot_rangeAxisList); - axisListResource = ListUtils.create(graph, axisList); - graph.claim(plot, jfree.Plot_rangeAxisList, axisListResource); - } - - }); - } - }; - return runnable; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java deleted file mode 100644 index ee3d3636..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/AxisLabelRule.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.simantics.browsing.ui.common.ColumnKeys; -import org.simantics.browsing.ui.model.labels.LabelRule; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Label rule for range axis label - * @author Teemu Lempinen - * - */ -public class AxisLabelRule implements LabelRule { - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - /** - * Range axis label - * - * Options: - * 1. Label - * 2. Default - */ - @Override - public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource resource = (Resource)content; - String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING); - if(label == null || label.isEmpty()) { - label = "Range"; - Resource plot = graph.getPossibleObject(resource, l0.PartOf); - if(plot != null) { - Resource axisListResource = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); - if(axisListResource != null) { - List axisList = ListUtils.toList(graph, axisListResource); - if(axisList.contains(resource)) - label = label + " " + (axisList.indexOf(resource) + 1); - } - } - } - return Collections.singletonMap(ColumnKeys.SINGLE, label); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java deleted file mode 100644 index a12f844e..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesChildRule.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.browsing.ui.model.children.ChildRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Child rule for obtaining series in a chart. - * Assumes that the chart has only one plot and that plot has only one dataset - * @author Teemu Lempinen - * - */ -public class SeriesChildRule implements ChildRule { - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { - ArrayList result = new ArrayList(); - if(!(parent instanceof Resource)) - return result; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - /* - * 1. we assume that there is only one plot - * 2. we assume that the only plot has only one dataset - */ - Resource plot = graph.syncRequest(new PossibleObjectWithType((Resource)parent, l0.ConsistsOf, jfree.Plot)); - - Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); - - Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); - if(seriesList != null) - for(Resource series : ListUtils.toList(graph, seriesList)) { - result.add(series); - } - return result; - } - - @Override - public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { - return new ArrayList(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java deleted file mode 100644 index 241394bb..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesDropAction.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.Collections; -import java.util.List; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.DropActionFactory; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.trend.chart.properties.xyline.XYLineAxisAndVariablesTab; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Drop action for explorer in {@link XYLineAxisAndVariablesTab}. This action is used for dropping - * both series on axis or another sries - * - * @author Teemu Lempinen - * - */ -public class SeriesDropAction implements DropActionFactory { - - @Override - public Runnable create(ReadGraph g, Object target, Object source) throws DatabaseException { - // Make sure that both target and source are resources - Resource t = AdaptionUtils.adaptToSingle(target, Resource.class); - Resource s = AdaptionUtils.adaptToSingle(source, Resource.class); - - if(t == null || s == null) - return null; - - // Make sure that source and target are of correct type - JFreeChartResource jfree = JFreeChartResource.getInstance(g); - if(!g.isInstanceOf(s, jfree.Series)) - return null; - if(!g.isInstanceOf(t, jfree.Series) && !g.isInstanceOf(t, jfree.Axis)) - return null; - - return getRunnable(t, s); - } - - /** - * Get the runnable for doing the drop action - * - * @param t target resource - * @param s source resource - * @return Runnable - */ - private Runnable getRunnable(final Resource t, final Resource s) { - Runnable runnable = new Runnable() { - - @Override - public void run() { - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - if(t == null || s == null) return; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource target = t; - Resource source = s; - Resource droppedOnSeries = null; - - // Dropped a series over a series -> get target dataset - if(graph.isInstanceOf(target, jfree.Series)) { - droppedOnSeries = target; - Resource dataset = graph.getPossibleObject(target, l0.PartOf); - if(dataset != null) - target = dataset; - } - - // Dropped a series over an axis -> get target dataset - if(graph.isInstanceOf(target, jfree.Axis)) { - Resource dataset = graph.syncRequest(new PossibleObjectWithType(target, jfree.Dataset_mapToRangeAxis_Inverse, jfree.Dataset)); - if(dataset != null) - target = dataset; - } - - // Move series to a dataset - if(graph.isInstanceOf(target, jfree.Dataset)) { - // Remove from old dataset if it was different than the new one - Resource sourceDataset = graph.getPossibleObject(source, l0.PartOf); - if(sourceDataset != null && !sourceDataset.equals(target)) { - Resource sourceSeriesList = graph.getPossibleObject(sourceDataset, jfree.Dataset_seriesList); - if(sourceSeriesList != null) - ListUtils.removeElement(graph, sourceSeriesList, source); - } - graph.deny(source, l0.PartOf); - - // Add to new dataset - Resource targetSeriesList = graph.getPossibleObject(target, jfree.Dataset_seriesList); - if(targetSeriesList == null) { - targetSeriesList = ListUtils.create(graph, Collections.emptyList()); - graph.claim(target, jfree.Dataset_seriesList, targetSeriesList); - } - - - // Series was dropped on another series. Move the dropped series to that place and recreate the list - if(droppedOnSeries != null) { - List list = ListUtils.toList(graph, targetSeriesList); - int targetIndex = list.indexOf(droppedOnSeries); - if(list.contains(source)) - list.remove(source); - list.add(targetIndex, source); - graph.deny(target, jfree.Dataset_seriesList); - targetSeriesList = ListUtils.create(graph, list); - graph.claim(target, jfree.Dataset_seriesList, targetSeriesList); - } else { - ListUtils.insertFront(graph, targetSeriesList, Collections.singleton(source)); - } - - graph.claim(target, l0.ConsistsOf, source); - } - } - }); - } - }; - return runnable; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java deleted file mode 100644 index 1aebcdb7..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelDecorationRule.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import org.eclipse.jface.resource.FontDescriptor; -import org.simantics.browsing.ui.content.LabelDecorator; -import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; -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; -import org.simantics.ui.utils.AdaptionUtils; - -public class SeriesLabelDecorationRule implements LabelDecorationRule { - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException { - Resource resource = AdaptionUtils.adaptToSingle(content, Resource.class); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - - if (resource != null && graph.isInstanceOf(resource, jfree.Series)) { - final String[] filter = graph.getPossibleRelatedValue(resource, jfree.variableFilter, Bindings.STRING_ARRAY); - if(filter != null) { - return new LabelDecorator.Stub() { - @Override - public String decorateLabel(String label, String column, int itemIndex) { - label += " ["; - for(int i = 0; i < filter.length; i++) { - label += filter[i]; - if(i < filter.length - 1) - label += ", "; - } - label += "]"; - return label; - } - - @SuppressWarnings("unchecked") - @Override - public F decorateFont(F font, String column, int itemIndex) { - return (F) ((FontDescriptor) font); - } - }; - } - } - return null; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java deleted file mode 100644 index d334765a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/SeriesLabelRule.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.Collections; -import java.util.Map; - -import org.simantics.browsing.ui.common.ColumnKeys; -import org.simantics.browsing.ui.model.labels.LabelRule; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Label rule for dataset series - * @author Teemu Lempinen - * - */ -public class SeriesLabelRule implements LabelRule { - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - /** - * Options: - * 1. Label - * 2. Variable rvi - * 3. Default - */ - @Override - public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource resource = (Resource)content; - String label = graph.getPossibleRelatedValue(resource, l0.HasLabel, Bindings.STRING); - if(label == null || label.isEmpty()) { - label = graph.getPossibleRelatedValue(resource, jfree.variableRVI); - if(label != null && !label.isEmpty() && label.length() > 1) - label = label.substring(1).replace('/', '.'); - else - label = "Set variable"; - } - return Collections.singletonMap(ColumnKeys.SINGLE, label); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java deleted file mode 100644 index f2cf79f7..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/graphexplorer/VariableChildRule.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * 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.graphexplorer; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.browsing.ui.model.children.ChildRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * ChildRule for finding the series of an axis - * - * @author Teemu Lempinen - * - */ -public class VariableChildRule implements ChildRule { - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { - ArrayList result = new ArrayList(); - if(!(parent instanceof Resource)) - return result; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource axis = (Resource)parent; - /* - * 1. Axis belongs to a plot - * 2. Plot may have multiple datasets - * 3. Dataset is mapped to a single range axis - * 3. Dataset may have multiple seires - */ - Resource plot = graph.getPossibleObject(axis, jfree.Plot_rangeAxis_Inverse); - if(plot == null) - return result; - - for(Resource dataset : graph.syncRequest(new ObjectsWithType(plot, l0.ConsistsOf, jfree.Dataset))) { - if(graph.hasStatement(dataset, jfree.Dataset_mapToRangeAxis, axis)) { - Resource seriesList = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); - if(seriesList != null) - for(Resource series : ListUtils.toList(graph, seriesList)) { - result.add(series); - } - } - } - return result; - } - - @Override - public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { - return new ArrayList(); - } - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AllVariablesOfModel.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AllVariablesOfModel.java deleted file mode 100644 index 66ae6054..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AllVariablesOfModel.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.simantics.sysdyn.ui.trend.chart.properties; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.utils.strings.AlphanumComparator; - -/** - * Request for getting all variables of a model in a String array. Includes also - * variables inside modules. - * - * @author Teemu Lempinen - * - */ -public class AllVariablesOfModel implements Read{ - - private Resource model; - - public AllVariablesOfModel(Resource model) { - this.model = model; - } - - @Override - public String[] perform(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - SimulationResource simu = SimulationResource.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - - // Find the model of this resource - Resource model = this.model; - while(model != null && !graph.isInstanceOf(model, sr.SysdynModel)) - model = graph.getPossibleObject(model, l0.PartOf); - - if(model == null) - return new String[0]; - - // Find the models configuration - Resource conf = graph.getSingleObject(model, simu.HasConfiguration); - List items = new ArrayList(); - - // Recursively read all configurations and add items - ReadConfiguration(graph, conf, "", items); - - // Add time to the variable list - items.add("time"); - - // Finally sort the results - Collections.sort(items, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR); - return items.toArray(new String[items.size()]); - } - - /** - * Read components in a configuration and recursively all module configurations - * - * @param graph ReadGraph - * @param configuration Resource to be read - * @param path Current path from base realization - * @param items Found variables - * @throws DatabaseException - */ - private void ReadConfiguration(ReadGraph graph, Resource configuration, String path, Collection items) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - StructuralResource2 sr2 = StructuralResource2.getInstance(graph); - - String name; - for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.IndependentVariable))) { - name = path + NameUtils.getSafeName(graph, resource); - items.add(name); - } - - for(Resource resource : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Input))) { - name = path + NameUtils.getSafeName(graph, resource); - items.add(name); - } - - for(Resource module : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) { - Resource instanceOf = graph.getPossibleObject(module, l0.InstanceOf); - Resource conf = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy); - if(conf != null) { - String p = path + NameUtils.getSafeName(graph, module) + "."; - ReadConfiguration(graph, conf, p, items); - } - } - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java deleted file mode 100644 index f8334c71..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/AxisHidePropertyComposite.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.simantics.browsing.ui.swt.widgets.Button; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Class containing properties for hiding pars of an axis - * - * @author Teemu Lempinen - * - */ -public class AxisHidePropertyComposite extends Composite { - - public AxisHidePropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().applyTo(this); - - Group hideGroup = new Group(this, SWT.NONE); - hideGroup.setText("Hide"); - GridDataFactory.fillDefaults().applyTo(hideGroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); - - Button label = new Button(hideGroup, support, SWT.CHECK); - label.setText("Label"); - label.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleLabel, true)); - label.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleLabel)); - GridDataFactory.fillDefaults().applyTo(label.getWidget()); - - Button tmarks = new Button(hideGroup, support, SWT.CHECK); - tmarks.setText("Tick marks"); - tmarks.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleTickMarks, true)); - tmarks.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleTickMarks)); - GridDataFactory.fillDefaults().applyTo(tmarks.getWidget()); - - Button axisLine = new Button(hideGroup, support, SWT.CHECK); - axisLine.setText("Axis line"); - axisLine.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleAxisLine, true)); - axisLine.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleAxisLine)); - GridDataFactory.fillDefaults().applyTo(axisLine.getWidget()); - - Button tlabels = new Button(hideGroup, support, SWT.CHECK); - tlabels.setText("Tick labels"); - tlabels.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Axis_visibleTickLabels, true)); - tlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Axis_visibleTickLabels)); - GridDataFactory.fillDefaults().applyTo(tlabels.getWidget()); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java deleted file mode 100644 index 00a09548..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanPropertyFactory.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.utils.datastructures.Quad; - -/** - * PropertyFactory for finding a boolean property. Supports also finding the - * property from a first occurrence of resource ConsistsOf type HasProperty - * - * @author Teemu Lempinen - * - */ -public class BooleanPropertyFactory extends ReadFactoryImpl { - - final private String propertyURI; - final private String typeURI; - final private Boolean inverse; - final private Boolean defaultValue; - - /** - * PropertyFactory for finding a boolean property with propertyURI - * - * @param propertyURI URI for the boolean property - */ - public BooleanPropertyFactory(String propertyURI) { - this(null, propertyURI, false); - } - - /** - * PropertyFactory for finding a boolean property with propertyURI. - * - * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible) - * - * @param propertyURI URI for the boolean property - * @param inverse Invert the result? - */ - public BooleanPropertyFactory(String propertyURI, boolean inverse) { - this(null, propertyURI, inverse); - } - - /** - * PropertyFactory for finding a boolean property with propertyURI. - * - * Finds the property for first ObjectWithType(resource, L0.ConsistsOf, type) - * - * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible) - * - * @param typeURI URI for a resource (resource ConsistsOf type) (null allowed) - * @param propertyURI URI for the boolean property - * @param inverse Invert the result? - */ - public BooleanPropertyFactory(String typeURI, String propertyURI, boolean inverse) { - this(typeURI, propertyURI, inverse, false); - } - - /** - * PropertyFactory for finding a boolean property with propertyURI. - * - * Finds the property for first ObjectWithType(resource, L0.ConsistsOf, type) - * - * Supports inverting the result (e.g. if required information is IsHidden, but database contains IsVisible) - * - * @param typeURI URI for a resource (resource ConsistsOf type) (null allowed -> not used) - * @param propertyURI URI for the boolean property - * @param inverse Invert the result? - * @param defaultValue default value - */ - public BooleanPropertyFactory(String typeURI, String propertyURI, boolean inverse, boolean defaultValue) { - this.propertyURI = propertyURI; - this.inverse = inverse; - this.typeURI = typeURI; - this.defaultValue = defaultValue; - } - - @Override - public Object getIdentity(Object inputContents) { - return new Quad((Resource) inputContents, propertyURI, getClass(), defaultValue); - } - - @Override - public Boolean perform(ReadGraph graph, Resource r) throws DatabaseException { - if(typeURI == null) { - // if no typeUri, use the default resource r - return getValue(graph, r); - } else { - // typeURI was defined, find the property for the first occurence of ConsistsOf type - Resource type = graph.getResource(typeURI); - for(Resource o : graph.syncRequest(new ObjectsWithType(r, Layer0.getInstance(graph).ConsistsOf, type))) { - // Returns the value for the first occurrence - return getValue(graph, o); - } - } - // if nothing was found with typeURI - return false; - } - - /** - * Return the value for a Boolean literal possibly inverted (or default if resource != Boolean literal) - * - * @param graph ReadGraph - * @param resource Literal Boolean resource - * @return value of the parameter (or default or inverted) - * @throws DatabaseException - */ - private Boolean getValue(ReadGraph graph, Resource resource) throws DatabaseException { - Boolean value = graph.getPossibleRelatedValue(resource, graph.getResource(propertyURI), Bindings.BOOLEAN); - if(value != null) { - return !inverse.equals(value); - } else { - return defaultValue; - } - } -} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java deleted file mode 100644 index 718b9b2a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/BooleanSelectionListener.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; - -/** - * Class for setting a boolean value when a selection occurs. (check box buttons) - * - * @author Teemu Lempinen - * - */ -public class BooleanSelectionListener extends SelectionListenerImpl { - - final private String propertyURI; - final private String typeUri; - - /** - * Boolean selection listener for property with propertyURI - * - * @param context ISessionContext - * @param propertyURI uri of the boolean property - */ - public BooleanSelectionListener(ISessionContext context, String propertyURI) { - this(context, null, propertyURI); - } - - /** - * Boolean selection listener for property with propertyURI - * Sets the property for all ObjectWithType(resource, L0.ConsistsOf, type) - * - * @param context ISessionContext - * @param typeUri URI for a resource (resource ConsistsOf type) (null allowed -> not used) - * @param propertyURI uri of the boolean property - */ - public BooleanSelectionListener(ISessionContext context, String typeUri, String propertyURI) { - super(context); - this.propertyURI = propertyURI; - this.typeUri = typeUri; - } - - @Override - public void apply(WriteGraph graph, Resource chart) throws DatabaseException { - if(typeUri == null) { - setValue(graph, chart); - } else { - Resource type = graph.getResource(typeUri); - for(Resource object : graph.syncRequest(new ObjectsWithType(chart, Layer0.getInstance(graph).ConsistsOf, type))) { - setValue(graph, object); - } - } - - } - - /** - * Set boolean value for Boolean literal resource (inverts the current value). - * @param graph ReadGraph - * @param resource Boolean literal resource - * @throws DatabaseException - */ - private void setValue(WriteGraph graph, Resource resource) throws DatabaseException { - Resource property = graph.getResource(propertyURI); - Boolean value = graph.getPossibleRelatedValue(resource, property, Bindings.BOOLEAN); - graph.claimLiteral(resource, property, Boolean.FALSE.equals(value)); - } -} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java deleted file mode 100644 index 179dbe92..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ChartTab.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.Resource; -import org.simantics.db.management.ISessionContext; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.trend.chart.ChartComposite; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Tab for displaying a chart - * @author Teemu Lempinen - * - */ -public class ChartTab extends LabelPropertyTabContributor implements Widget { - - private Composite parent; - - @Override - public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - support.register(this); - this.parent = body; - } - - @Override - public void setInput(ISessionContext context, final Object input) { - Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); - new ChartComposite(parent, chart, SWT.BORDER); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java deleted file mode 100644 index 33b1fe95..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/ColorPicker.java +++ /dev/null @@ -1,375 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Device; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.ColorDialog; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.simantics.browsing.ui.swt.widgets.Button; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; -import org.simantics.utils.RunnableWithObject; -import org.simantics.utils.datastructures.Triple; - -/** - * Composite for selecting a color for a chart component - * - * @author Teemu Lempinen - * - */ -public class ColorPicker extends Composite implements Widget { - - Button defaultColor, customColor, color; - - /** - * Create a composite containing radio buttons for default or custom color. Color chooser button is active - * when the custom radio button is selected. Color chooser uses {@link ColorDialog} to select a color - * - * @param parent Composite - * @param context ISessionContext - * @param support WidgetSupport - * @param style SWT style - */ - public ColorPicker(Composite parent, ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - support.register(this); - - GridLayoutFactory.fillDefaults().numColumns(4).applyTo(this); - - defaultColor = new Button(this, support, SWT.RADIO); - defaultColor.setText("default"); - defaultColor.setSelectionFactory(new DefaultColorSelectionFactory(false)); - defaultColor.addSelectionListener(new DefaultColorSelectionListener(context)); - GridDataFactory.fillDefaults().applyTo(defaultColor.getWidget()); - - customColor = new Button(this, support, SWT.RADIO); - customColor.setText("custom"); - customColor.setSelectionFactory(new DefaultColorSelectionFactory(true)); - customColor.addSelectionListener(new DefaultColorSelectionListener(context)); - - GridDataFactory.fillDefaults().applyTo(customColor.getWidget()); - - color = new Button(this, support, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(color.getWidget()); - color.setImageFactory(new ColorImageFactoryFactory(color)); - color.addSelectionListener(new ColorSelectionListener(context)); - color.getWidget().setEnabled(false); - } - - /** - * Method for finding the resource for which the color is selected. - * - * @param graph ReadGraph - * @param input input from WidgetSupport - * @return - * @throws DatabaseException - */ - protected Resource getResource(ReadGraph graph, Resource input) throws DatabaseException { - return input; - } - - /** - * Method for getting the relation with which the g2d.Color is related to a resource - * - * @param graph ReadGraph - * @return Color relation - * @throws DatabaseException - */ - protected Resource getColorRelation(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - return jfree.color; - } - - - @Override - public void setInput(ISessionContext context, Object input) { - final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class); - - // Create a listener to define the enabled state of the color chooser button - context.getSession().asyncRequest(new Read() { - - @Override - public Boolean perform(ReadGraph graph) throws DatabaseException { - // if there is a color definition, the color chooser is active - Boolean result = graph.hasStatement(getResource(graph, resource), getColorRelation(graph)); - return result; - } - - }, new Listener() { - - @Override - public void execute(Boolean result) { - if(!color.getWidget().isDisposed()) { - color.getWidget().getDisplay().asyncExec(new RunnableWithObject(result) { - @Override - public void run() { - if(!color.getWidget().isDisposed()) - color.getWidget().setEnabled((Boolean)getObject()); - } - }); - } - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return color.getWidget().isDisposed(); - } - }); - } - - /** - * Get a colored image to be displayed in the color chooser button - * - * @param device SWT Device - * @param red Red 0-255 - * @param green Green 0-255 - * @param blue Blue 0-255 - * @return - */ - private Image getColorPickerImage(Device device, int red, int green, int blue) { - Image image = new Image(device, 20, 20); - GC gc = new GC (image); - gc.setBackground (new Color(device, red, green, blue)); - gc.fillRectangle (image.getBounds ()); - gc.dispose (); - return image; - } - - /** - * ImageFactory returning an image for color button - * @author Teemu Lempinen - * - */ - private class ColorImageFactoryFactory extends ReadFactoryImpl { - - Button button; - - public ColorImageFactoryFactory(Button button) { - super(); - this.button = button; - } - - public Object getIdentity(Object inputContents) { - return new Triple, Button>(inputContents, getClass(), button); - } - - @Override - public Image perform(ReadGraph graph, Resource input) throws DatabaseException { - if(button.getWidget().isDisposed()) - return null; - Display device = button.getWidget().getDisplay(); - if(device == null) - return null; - RGB rgb = getColor(graph, getResource(graph, input)); - return getColorPickerImage(device, rgb.red, rgb.green, rgb.blue); - } - - } - - /** - * Get RGB from a color literal resource. If resource is not a color resource, return blue (RGB 0, 0, 255) - * @param graph ReadGraph - * @param input Color literal resource (float[4]) - * @return RGB color - * @throws DatabaseException - */ - private RGB getColor(ReadGraph graph, Resource input) throws DatabaseException{ - float[] colorComponents = graph.getPossibleRelatedValue(input, getColorRelation(graph)); - RGB rgb; - if(colorComponents == null) - rgb = new RGB(0, 0, 255); - else - rgb = new RGB((int)(colorComponents[0] * 255.0f), - (int)(colorComponents[1] * 255.0f), - (int)(colorComponents[2] * 255.0f)); - return rgb; - } - - - /** - * SelectionListener for color button. - * - * @author Teemu Lempinen - * - */ - private class ColorSelectionListener extends SelectionListenerImpl { - - private SelectionEvent e; - private RGB rgb; - - /** - * - * @param context ISessionContext - */ - public ColorSelectionListener(ISessionContext context) { - super(context); - } - - @Override - public void widgetSelected(SelectionEvent e) { - if(color.getWidget().isDisposed()) - return; - // Save the event for coordinates - this.e = e; - super.widgetSelected(e); - } - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - if(color.getWidget().isDisposed()) - return; - - final Resource resource = getResource(graph, input); - final Display display = color.getWidget().getDisplay(); - final RGB oldRGB = getColor(graph, resource); - - display.asyncExec(new RunnableWithObject(oldRGB) { - public void run() { - // Use color dialog to select a color - Shell shell = new Shell(display); - ColorDialog cd = new ColorDialog(shell); - Point point = color.getWidget().toDisplay(e.x - 150, e.y - 150); - cd.getParent().setLocation(point.x, point.y); - cd.setText("Select color"); - cd.setRGB((RGB)getObject()); - rgb = cd.open(); - if(rgb == null) - return; - - SimanticsUI.getSession().asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - G2DResource g2d = G2DResource.getInstance(graph); - float[] components = new float[] {(float)rgb.red / 255.0f, (float)rgb.green / 255.0f, (float)rgb.blue / 255.0f, 1.0f}; - graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); - } - }); - - } - }); - - - - } - - } - - /** - * SelectionFactory for default and custom color radio buttons - * @author Teemu Lempinen - * - */ - private class DefaultColorSelectionFactory extends ReadFactoryImpl { - - private Boolean isCustom; - - /** - * - * @param isCustom Is this custom button? - */ - public DefaultColorSelectionFactory(Boolean isCustom) { - super(); - this.isCustom = isCustom; - } - - @Override - public Object getIdentity(Object inputContents) { - return new Triple((Resource) inputContents, getClass(), isCustom); - } - - @Override - public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException { - Resource r = graph.getPossibleObject(getResource(graph, input), getColorRelation(graph)); - boolean result = false; // Default == not selected - if(r == null && !isCustom) { - // No color definition and default-button -> selected - result = true; - } else if(r != null && isCustom) { - // color definition and custom button -> selected - result = true; - } - return result; - } - - } - - /** - * SelectionListener for default and custom radio buttons - * - * @author Teemu Lempinen - * - */ - private class DefaultColorSelectionListener extends SelectionListenerImpl { - - private SelectionEvent e; - - public DefaultColorSelectionListener(ISessionContext context) { - super(context); - } - - @Override - public void widgetSelected(SelectionEvent e) { - this.e = e; - super.widgetSelected(e); - } - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - Resource resource = getResource(graph, input); - if(customColor.getWidget().equals(e.widget)) { - // Custom selected. If there is no color already, create a default Blue color - G2DResource g2d = G2DResource.getInstance(graph); - if(graph.getPossibleObject(resource, getColorRelation(graph)) == null) { - float[] components = java.awt.Color.BLUE.getColorComponents(new float[4]); - components[3] = 1.0f; - graph.claimLiteral(resource, getColorRelation(graph), g2d.Color, components); - } - } else { - // Default selected, remove color definition - graph.deny(resource, getColorRelation(graph)); - } - } - } - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java deleted file mode 100644 index 74b984bd..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/DoubleValidator.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.jface.dialogs.IInputValidator; - -/** - * Validator for validating that an input is double. - * - * Can allow empty strings. - * - * @author Teemu Lempinen - * - */ -public class DoubleValidator implements IInputValidator { - - boolean allowEmpty; - - /** - * New double validator. Does not allow empty strings - */ - public DoubleValidator() { - this(false); - } - - /** - * New double validator. - * @param allowEmpty Are empty strings allowed - */ - public DoubleValidator(boolean allowEmpty) { - this.allowEmpty = allowEmpty; - } - - @Override - public String isValid(String newText) { - if (allowEmpty && newText.trim().isEmpty()) - return null; - try { - Double.parseDouble(newText); - return null; - } catch (NumberFormatException e) { - return e.getMessage(); - } - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java deleted file mode 100644 index d8dea9be..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/JFreeChartPropertyColorProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.jface.resource.ColorDescriptor; -import org.eclipse.jface.resource.ResourceManager; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.simantics.browsing.ui.swt.widgets.impl.ITrackedColorProvider; - -/** - * ColorProvider providing coloring scheme for chart tab text widgets - * - * @author Teemu Lempinen - * - */ -public class JFreeChartPropertyColorProvider implements ITrackedColorProvider { - - private final ResourceManager resourceManager; - - private final ColorDescriptor highlightColor = ColorDescriptor.createFrom(new RGB(254, 255, 197)); - private final ColorDescriptor inactiveColor = ColorDescriptor.createFrom(new RGB(255, 255, 255)); - private final ColorDescriptor invalidInputColor = ColorDescriptor.createFrom(new RGB(255, 128, 128)); - - public JFreeChartPropertyColorProvider(ResourceManager resourceManager) { - this.resourceManager = resourceManager; - } - - @Override - public Color getEditingBackground() { - return null; - } - - @Override - public Color getHoverBackground() { - return resourceManager.createColor(highlightColor); - } - - @Override - public Color getInactiveBackground() { - return resourceManager.createColor(inactiveColor); - } - - @Override - public Color getInvalidBackground() { - return resourceManager.createColor(invalidInputColor); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java deleted file mode 100644 index d029827b..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Class for providing RVI content to a text field with all '/' characters changed to '.' - * @author Teemu Lempinen - * - */ -public class RVIFactory extends ReadFactoryImpl { - - @Override - public String perform(ReadGraph graph, Resource input) throws DatabaseException { - String value = graph.getPossibleRelatedValue(input, JFreeChartResource.getInstance(graph).variableRVI); - return value != null ? value = value.substring(1).replace('/', '.') : ""; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java deleted file mode 100644 index 27246f5b..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.bindings.keys.ParseException; -import org.eclipse.jface.fieldassist.ContentProposalAdapter; -import org.eclipse.jface.fieldassist.IContentProposal; -import org.eclipse.jface.fieldassist.IContentProposalListener; -import org.eclipse.jface.fieldassist.IContentProposalListener2; -import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; -import org.eclipse.jface.fieldassist.TextContentAdapter; -import org.eclipse.swt.widgets.Control; -import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; -import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * Class for modifying variable name to rvi and saving it to database. - * - * Modifier also adds content proposal support to the control it is added to. - * @author Teemu Lempinen - * - */ -public class RVIModifier extends TextModifyListenerImpl { - - private boolean active; - private Control control; - - private char[] alphaNumericCharacters = { - 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö', - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö', - '1','2','3','4','5','6','7','8','9','0','.','_'}; - - /** - * Create a new RVIModifier and attach a content proposal support to control - * @param control - * @param support - */ - public RVIModifier(Control control, WidgetSupport support) { - this.control = control; - this.active = true; - - KeyStroke keyStroke = null; - try { - keyStroke = KeyStroke.getInstance("Ctrl+Space"); - } catch (ParseException e1) { - e1.printStackTrace(); - } - - SimpleContentProposalProvider scpp = new VariableProposalProvider(control, support); - scpp.setFiltering(true); - - ContentProposalAdapter adapter = new ContentProposalAdapter( - control, new TextContentAdapter(), scpp, keyStroke, alphaNumericCharacters); - adapter.setAutoActivationDelay(0); - adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); - adapter.addContentProposalListener(new IContentProposalListener2() { - - @Override - public void proposalPopupOpened(ContentProposalAdapter adapter) { - if(RVIModifier.this != null) - RVIModifier.this.deactivate(); - } - - @Override - public void proposalPopupClosed(ContentProposalAdapter adapter) { - if(RVIModifier.this != null) - RVIModifier.this.activate(); - } - }); - - adapter.addContentProposalListener(new IContentProposalListener() { - - @Override - public void proposalAccepted(IContentProposal proposal) { - if(RVIModifier.this.control != null && !RVIModifier.this.control.isDisposed()) - RVIModifier.this.modifyText(new TrackedModifyEvent(RVIModifier.this.control, proposal.getContent())); - } - }); - - - } - - - @Override - public void applyText(WriteGraph graph, Resource resource, String text) throws DatabaseException { - if(active) { - text = "/" + text.replace('.', '/'); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - graph.claimLiteral(resource, jfree.variableRVI, text, Bindings.STRING); - graph.deny(resource, jfree.variableFilter); - } - } - - public void deactivate() { - active = false; - } - - public void activate() { - active = true; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java deleted file mode 100644 index 9af6be3a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RangeComposite.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.simantics.browsing.ui.swt.widgets.TrackedCombo; -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.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.db.management.ISessionContext; -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.SysdynResource; -import org.simantics.sysdyn.ui.trend.chart.ChartUtils; -import org.simantics.utils.RunnableWithObject; -import org.simantics.utils.datastructures.Quad; -import org.simantics.utils.datastructures.Triple; -import org.simantics.utils.ui.AdaptionUtils; - -/** - * Composite for range controls in chart series properties - * @author Teemu Lempinen - * - */ -public class RangeComposite extends Composite implements Widget { - - private Composite composite; - - public RangeComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - support.register(this); - GridLayoutFactory.fillDefaults().spacing(3, 0).margins(3, 3).applyTo(this); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this); - composite = this; - } - - @Override - public void setInput(final ISessionContext context, final Object input) { - if(composite == null || composite.isDisposed()) - return; - - final Resource series = AdaptionUtils.adaptToSingle(input, Resource.class); - - /* - * Listen to the enumerations assigned to the variable in this series. - * Listener is needed because the user can change the variableRVI for the series - * and that changes the options for range - */ - context.getSession().asyncRequest(new Read>() { - - @Override - public LinkedHashMap perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - SysdynResource sr = SysdynResource.getInstance(graph); - - String realizationURI = ChartUtils.getCurrentRealizationURI(graph, series); - String rvi = graph.getPossibleRelatedValue(series, jfree.variableRVI); - if(rvi == null) - return null; - - try { - // Find the variable for the current variableRVI - Variable v = Variables.getVariable(graph, realizationURI + rvi.trim()); - if(v == null) - return null; - - // Find all enumeration replacements in the variable's path - HashMap redeclarations = new HashMap(); - Variable parent = v; - while((parent = parent.getParent(graph)) != null) { - Resource represents = parent.getRepresents(graph); - Resource type = graph.getSingleObject(represents, Layer0.getInstance(graph).InstanceOf); - if(!graph.isInheritedFrom(type, sr.Module)) - break; - - for(Resource redeclaration : graph.getObjects(represents, sr.Module_redeclaration)) { - redeclarations.put( - graph.getPossibleObject(redeclaration, sr.Redeclaration_replacedEnumeration), - graph.getPossibleObject(redeclaration, sr.Redeclaration_replacingEnumeration) - ); - } - } - - - - - Resource variable = v.getRepresents(graph); - - // Return the enumerations assigned to that variable - Resource arrayIndexes = graph.getPossibleObject(variable, sr.Variable_arrayIndexesList); - if(arrayIndexes != null) { - LinkedHashMap result = new LinkedHashMap(); - for(Resource enumeration : ListUtils.toList(graph, arrayIndexes)) { - - // Find possible redeclarations for enumeration - Resource redeclaration = enumeration; - while(redeclarations.get(redeclaration) != null) - redeclaration = redeclarations.get(redeclaration); - - String enumerationName = NameUtils.getSafeName(graph, redeclaration); - result.put(enumerationName, redeclaration); - } - return result; - } - } catch (DatabaseException e) { - // No variable was found, return null - } - return null; - } - - }, new Listener>() { - - @Override - public void execute(LinkedHashMap result) { - if(isDisposed()) - return; - - // Always modify the composite, even with null result - composite.getDisplay().asyncExec(new RunnableWithObject(result) { - @Override - public void run() { - if(composite == null || composite.isDisposed()) - return; - - // Remove all content (even with null result) - for(Control child : composite.getChildren()) - child.dispose(); - - if(getObject() == null) - return; - - // New widgetSupport for the combos - WidgetSupportImpl support = new WidgetSupportImpl(); - - Label label; - TrackedCombo combo; - LinkedHashMap result = (LinkedHashMap)getObject(); - Iterator iterator = result.keySet().iterator(); - - // For each array index (enumeration), create a label and a combo - int index = 0; - while(iterator.hasNext()) { - Object key = iterator.next(); - Composite c = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(c); - GridLayoutFactory.fillDefaults().applyTo(c); - - label = new Label(c, SWT.NONE); - label.setText((String)key); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(label); - - combo = new TrackedCombo(c, support, SWT.READ_ONLY); - combo.setItemFactory(new RangeItemFactory(index, (Resource)result.get(key))); - combo.setSelectionFactory(new RangeSelectionFactory(index)); - combo.addModifyListener(new RangeModifyListener(index, result.size())); - GridDataFactory.fillDefaults().applyTo(combo.getWidget()); - index++; - } - - // Set the width of the combo - GridLayout gl = (GridLayout)composite.getLayout(); - gl.numColumns = index; - - // Set input for the combos - support.fireInput(context, input); - - /* - * Find out if this composite is located in a scrolled composite. - * If it is, resize the scrolled composite - */ - Composite previousParent = composite.getParent(); - for(int i = 0; i < 5; i++) { - if(previousParent.getParent() instanceof ScrolledComposite) { - previousParent.layout(); - ScrolledComposite sc = (ScrolledComposite) previousParent.getParent(); - Point size = previousParent.computeSize(SWT.DEFAULT, SWT.DEFAULT); - sc.setMinSize(size); - break; - } - previousParent = previousParent.getParent(); - } - } - }); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return composite == null || composite.isDisposed(); - } - }); - } - - /** - * - * @author Teemu Lempinen - * - */ - private class RangeSelectionFactory extends ReadFactoryImpl { - - int index; - - /** - * - * @param index Index of the enumeration in the variable - */ - public RangeSelectionFactory(int index) { - this.index = index; - } - - public Object getIdentity(Object inputContents) { - return new Triple>(inputContents, index, getClass()); - } - - @Override - public String perform(ReadGraph graph, Resource series) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - String[] filter = graph.getPossibleRelatedValue(series, jfree.variableFilter, Bindings.STRING_ARRAY); - - /* - * If no filter was found or the index is not applicable, return "All" - */ - if(filter == null) - return "All"; - else if(filter.length < index) - return "All"; - else - return filter[index]; - } - - } - - /** - * RangeItemFactory finds all inexes of a given enumeration - * and adds "Sum" and "All" to the returned indexes - * @author Teemu Lempinen - * - */ - private class RangeItemFactory extends ReadFactoryImpl> { - - private int index; - private Resource enumeration; - - /** - * - * @param index Index of the enumeration in the variable - * @param enumeration The enumeration - */ - public RangeItemFactory(int index, Resource enumeration) { - this.index = index; - this.enumeration = enumeration; - } - - public Object getIdentity(Object inputContents) { - return new Quad>(inputContents, index, enumeration, getClass()); - } - @Override - public Map perform(ReadGraph graph, Resource series) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); - LinkedHashMap result = new LinkedHashMap(); - Resource enumerationIndexes = graph.getPossibleObject(enumeration, sr.Enumeration_enumerationIndexList); - List indexes = ListUtils.toList(graph, enumerationIndexes); - // First add "All" and "Sum", then all of the enumeration indexes in order - result.put("All", "All"); - result.put("Sum", "Sum"); - for(Resource index : indexes) { - String name = NameUtils.getSafeName(graph, index); - result.put(name, name); - } - return result; - } - } - - /** - * RangeModifyListener for modifying a range filter in chart series - * @author Teemu Lempinen - * - */ - private class RangeModifyListener extends ComboModifyListenerImpl { - - private int index, size; - - /** - * - * @param index Index of the modified range filter - * @param size Size of the whole filter (for situations where there is no filter) - */ - public RangeModifyListener(int index, int size) { - this.index = index; - this.size = size; - } - - @Override - public void applyText(WriteGraph graph, Resource series, String text) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - String[] filter = graph.getPossibleRelatedValue(series, jfree.variableFilter, Bindings.STRING_ARRAY); - - // If there is no filter, create a default filter with all indexes "All" - if(filter == null) { - filter = new String[size]; - for(int i = 0; i < filter.length; i++) { - filter[i] = "All"; - } - } - - // Modify the filter index - filter[index] = text; - graph.claimLiteral(series, jfree.variableFilter, filter, Bindings.STRING_ARRAY); - } - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java deleted file mode 100644 index d9a081f8..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.databoard.Bindings; -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.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * TextFactory for chart title - * @author Teemu Lempinen - * - */ -public class TitleFactory extends ReadFactoryImpl { - @Override - public String perform(ReadGraph graph, Resource chart) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Resource title = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.TextTitle)); - if(title == null) - return ""; - else { - String label = graph.getPossibleRelatedValue(title, l0.HasLabel, Bindings.STRING); - return label == null ? "" : label; - } - } -} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java deleted file mode 100644 index d47fbcdd..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TitleModifier.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.layer0.utils.direct.GraphUtils; -import org.simantics.sysdyn.JFreeChartResource; - -/** - * TitleModifier for chart title - * @author Teemu Lempinen - * - */ -public class TitleModifier extends TextModifyListenerImpl { - - @Override - public void applyText(WriteGraph graph, Resource chart, String text) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Resource title = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.TextTitle)); - if(title == null) { - title = GraphUtils.create2(graph, jfree.TextTitle, - jfree.Title_position, jfree.Top); - } - graph.claimLiteral(title, l0.HasLabel, text); - } - -} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java deleted file mode 100644 index b27ecd04..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/TrackedSpinner.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Spinner; -import org.simantics.browsing.ui.common.ErrorLogger; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory; -import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; -import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.Listener; -import org.simantics.utils.ui.SWTUtils; - -/** - * Class for implementing Widget behavior for SWT Spinner in Simantics. - * - * @author Teemu Lempinen - * - */ -public class TrackedSpinner implements Widget { - - private Spinner spinner; - private ListenerList modifyListeners; - private ReadFactory selectionFactory; - - - public TrackedSpinner(Composite parent, WidgetSupport support, int style) { - spinner = new Spinner(parent, style); - support.register(this); - - // Add a ModifyListener that uses all listeners in modifyListeners -list - spinner.addModifyListener(new ModifyListener() { - - @Override - public void modifyText(ModifyEvent e) { - if (modifyListeners != null) { - TrackedModifyEvent event = new TrackedModifyEvent(spinner, spinner.getText()); - for (Object o : modifyListeners.getListeners()) { - ((TextModifyListener) o).modifyText(event); - } - } - } - }); - } - - @Override - public void setInput(ISessionContext context, Object input) { - - // Update all modifyListeners - if (modifyListeners != null) { - for (Object o : modifyListeners.getListeners()) { - if(o instanceof Widget) { - ((Widget) o).setInput(context, input); - } - } - } - - if (selectionFactory != null) { - // Get a value for the spinner - selectionFactory.listen(context, input, new Listener() { - @Override - public void exception(Throwable t) { - ErrorLogger.defaultLogError(t); - } - @Override - public void execute(final Integer selection) { - SWTUtils.asyncExec(spinner, new Runnable() { - @Override - public void run() { - if(isDisposed()) return; - spinner.setSelection(selection); - } - }); - } - @Override - public boolean isDisposed() { - return spinner.isDisposed(); - } - }); - } - - } - - /** - * Set a selection factory for the spinner - * - * @param selectionFactory ReadFactory SelectionFactory - */ - public void setSelectionFactory(ReadFactory selectionFactory) { - this.selectionFactory = selectionFactory; - } - - /** - * Add a modifyListener for the spinner - * @param listener TextModifyListener - */ - public synchronized void addModifyListener(TextModifyListener listener) { - if (modifyListeners == null) { - modifyListeners = new ListenerList(ListenerList.IDENTITY); - } - modifyListeners.add(listener); - } - - /** - * Remove modifyListener from the spinner - * - * @param listener TextModifyListener - */ - public synchronized void removeModifyListener(TextModifyListener listener) { - if (modifyListeners == null) - return; - modifyListeners.remove(listener); - } - - /** - * Get the SWT Spinner of this TrackedSpinner widget - * @return - */ - public Spinner getWidget() { - return spinner; - } - - /** - * Set minimum value - * @param value int minimum value - */ - public void setMinimum(int value) { - spinner.setMinimum(value); - } - - /** - * Set maximum value - * @param value int maximum value - */ - public void setMaximum(int value) { - spinner.setMaximum(value); - } - - /** - * Sets the receiver's selection, minimum value, maximum value, digits, increment and page increment all at once. - * - * @param selection the new selection value - * @param minimum the new minimum value - * @param maximum the new maximum value - * @param digits the new digits value - * @param increment the new increment value - * @param pageIncrement the new pageIncrement value - */ - public void setValues(int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) { - spinner.setValues(selection, minimum, maximum, digits, increment, pageIncrement); - } - - /** - * Sets the selection, which is the receiver's position, to the argument. - * If the argument is not within the range specified by minimum and maximum, - * it will be adjusted to fall within this range. - * - * @param value - */ - public void setSelection(int value) { - spinner.setSelection(value); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableExistsValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableExistsValidator.java deleted file mode 100644 index 1247e821..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableExistsValidator.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.simantics.sysdyn.ui.trend.chart.properties; - -import org.eclipse.jface.dialogs.IInputValidator; -import org.simantics.browsing.ui.swt.widgets.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.Listener; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Variable exists validator for tracked text widgets. - * - * @author Teemu Lempinen - * - */ -public class VariableExistsValidator implements IInputValidator, Widget { - - private String[] names; - private TrackedText text; - private boolean allowEmpty; - - /** - * Validate against all variables - * - * Do not allow empty input - * @param support WidgetSupport - * @param text Text widget - */ - public VariableExistsValidator(WidgetSupport support, TrackedText text) { - this(support, text, false); - } - - /** - * Validate against all variables - * - * @param support WidgetSupport - * @param text Text widget - * @param allowEmpty Allow empty input text - */ - public VariableExistsValidator(WidgetSupport support, TrackedText text, boolean allowEmpty) { - support.register(this); - names = new String[] {"time"}; - this.text = text; - this.allowEmpty = allowEmpty; - } - - /** - * Returns null if there is a variable named newText in the model - */ - @Override - public String isValid(String newText) { - if(newText == null || newText.isEmpty()) { - if(allowEmpty) - return null; - else - return "Empty name not allowed"; - } - - synchronized (names) { - for(String s : names) { - if(newText.equals(s)) - return null; - } - } - - return "Not a valid variable name"; - } - - @Override - public void setInput(ISessionContext context, Object input) { - final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class); - - if(resource == null) { - names = new String[] {"time"}; - return; - } - - Resource model = null; - try { - /* Find the model resource. It can be found with PartOf - relations from series resource in a chart */ - model = context.getSession().syncRequest(new Read() { - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - Resource r = resource; - while((r = graph.getPossibleObject(r, Layer0.getInstance(graph).PartOf)) != null) { - if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).SysdynModel)) - return r; - } - return null; - } - - }); - - if(model != null) { - // Find all variables and set them as the reference for isValid(String) - SimanticsUI.getSession().asyncRequest( - new AllVariablesOfModel(model) - , new Listener() { - - @Override - public void execute(String[] result) { - names = result; - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return text.isDisposed(); - } - - }); - } - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java deleted file mode 100644 index c073516c..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/VariableProposalProvider.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * 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.properties; - -import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; -import org.eclipse.swt.widgets.Control; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.Resource; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.Listener; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Provides all variables a model contains - * - * @author Teemu Lempinen - * - */ -public class VariableProposalProvider extends SimpleContentProposalProvider implements Widget { - - /** - * Provides all variables a model contains. Given resource needs to be - * part of a model (i.e. using PartOf leads eventually to a SysdynModel). - * - * @param control Control that is using this provider - * @param resource A resource that is part of a model - */ - public VariableProposalProvider(final Control control, WidgetSupport support) { - super(new String [] {}); - support.register(this); - this.control = control; - } - - private Resource resource; - private Control control; - - @Override - public void setInput(ISessionContext context, Object input) { - - final Resource resource = AdaptionUtils.adaptToSingle(input, Resource.class); - if(resource == null) - return; - this.resource = resource; - - SimanticsUI.getSession().asyncRequest( - new AllVariablesOfModel(resource) - , new Listener() { - - @Override - public void execute(String[] result) { - setProposals(result); - } - - @Override - public void exception(Throwable t) { - t.printStackTrace(); - } - - @Override - public boolean isDisposed() { - return control == null || - control.isDisposed() || - !resource.equals(VariableProposalProvider.this.resource); - } - - }); - - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java deleted file mode 100644 index c17e6939..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarAxisTab.java +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************* - * 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.properties.bar; - -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.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; -import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; -import org.simantics.browsing.ui.swt.widgets.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; -import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; -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.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ui.chart.property.DoublePropertyFactory; -import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; -import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Tab for bar chart axis properties - * @author Teemu Lempinen - * - */ -public class BarAxisTab extends LabelPropertyTabContributor implements Widget { - - private TrackedSpinner angle; - private Integer angleInt = null; - private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl(); - private WidgetSupportImpl rangeAxisSupport = new WidgetSupportImpl(); - private TrackedText rangelabel, rangemin, rangemax; - private ScrolledComposite sc; - private Composite composite; - - - @Override - public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - support.register(this); - - // Scrolled composite containing all of the properties in this tab - sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); - GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(sc); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - - composite = new Composite(sc, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // Domain Axis properties - Group domainGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(domainGroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(domainGroup); - domainGroup.setText("Domain axis"); - - // Label for x-axis - Label label = new Label(domainGroup, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Label:"); - - rangelabel = new TrackedText(domainGroup, domainAxisSupport, SWT.BORDER); - rangelabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); - rangelabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - rangelabel.setColorProvider(new JFreeChartPropertyColorProvider(rangelabel.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(rangelabel.getWidget()); - - Composite axisHide = new AxisHidePropertyComposite(domainGroup, context, domainAxisSupport, SWT.NONE); - GridDataFactory.fillDefaults().span(1, 3).applyTo(axisHide); - - Label angleLabel = new Label(domainGroup, SWT.NONE); - angleLabel.setText("Label angle:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(angleLabel); - - Composite angleComposite = new Composite(domainGroup, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(angleComposite); - GridLayoutFactory.fillDefaults().applyTo(angleComposite); - angle = new TrackedSpinner(angleComposite, domainAxisSupport, SWT.BORDER); - angle.setSelectionFactory(new AngleSelectionFactory()); - angle.addModifyListener(new AngleModifyListener()); - angle.setMinimum(0); - angle.setMaximum(90); - angle.getWidget().setIncrement(5); - GridDataFactory.fillDefaults().applyTo(angle.getWidget()); - - // Domain Color - label = new Label(domainGroup, SWT.NONE); - label.setText("Color:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - Composite colorPicker = new ColorPicker(domainGroup, context, domainAxisSupport, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); - - domainGroup.layout(); - - // Range Axis properties - Group rangeGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(rangeGroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(rangeGroup); - rangeGroup.setText("Range axis"); - - // Label for range axis - label = new Label(rangeGroup, SWT.NONE); - label.setText("Label:"); - label.setAlignment(SWT.RIGHT); - GridDataFactory.fillDefaults().hint(angleLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(label); - - rangelabel = new TrackedText(rangeGroup, rangeAxisSupport, SWT.BORDER); - rangelabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); - rangelabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - rangelabel.setColorProvider(new JFreeChartPropertyColorProvider(rangelabel.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(rangelabel.getWidget()); - - axisHide = new AxisHidePropertyComposite(rangeGroup, context, rangeAxisSupport, SWT.NONE); - GridDataFactory.fillDefaults().span(1, 4).applyTo(axisHide); - - // Min and max values for range axis - label = new Label(rangeGroup, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Min:"); - - Composite minmax = new Composite(rangeGroup, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(minmax); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax); - rangemin = new TrackedText(minmax, rangeAxisSupport, SWT.BORDER); - rangemin.setColorProvider(new JFreeChartPropertyColorProvider(rangemin.getResourceManager())); - rangemin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); - rangemin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - rangemin.setInputValidator(new DoubleValidator(true)); - - label = new Label(minmax, SWT.NONE); - label.setText("Max:"); - rangemax = new TrackedText(minmax, rangeAxisSupport, SWT.BORDER); - rangemax.setColorProvider(new JFreeChartPropertyColorProvider(rangemax.getResourceManager())); - rangemax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); - rangemax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - rangemax.setInputValidator(new DoubleValidator(true)); - - // Range Color - label = new Label(rangeGroup, SWT.NONE); - label.setText("Color:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - colorPicker = new ColorPicker(rangeGroup, context, rangeAxisSupport, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); - - // Resize scrolled composite - sc.setContent(composite); - Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); - sc.setMinSize(size); - } - - /** - * ModifyListener for the angle {@link TrackedSpinner} - * - * @author Teemu Lempinen - * - */ - private class AngleModifyListener implements TextModifyListener, Widget { - - private ISessionContext context; - private Object lastInput = null; - - @Override - public void modifyText(TrackedModifyEvent e) { - if(context == null) - return; - - // Get the text value from spinner and associated resource (input) - Spinner spinner = (Spinner)e.getWidget(); - final String textValue = spinner.getText(); - final Object input = lastInput; - - try { - context.getSession().syncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Resource domainAxis = AdaptionUtils.adaptToSingle(input, Resource.class); - try { - // usually reliable, since the spinner does all the checks - Double value = Double.parseDouble(textValue); - Double oldValue = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees, Bindings.DOUBLE); - if(oldValue == null || !oldValue.equals(value)) { - graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, value, Bindings.DOUBLE); - angleInt = value.intValue(); - } - } catch (NumberFormatException e) { - graph.claimLiteral(domainAxis, jfree.Axis_rotateLabelDegrees, 0.0, Bindings.DOUBLE); - angleInt = 0; - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - } - - @Override - public void setInput(ISessionContext context, Object parameter) { - this.context = context; - lastInput = parameter; - } - - } - - /** - * Class for setting the value for angle {@link TrackedSpinner} - * @author Teemu Lempinen - * - */ - private class AngleSelectionFactory extends ReadFactoryImpl { - - @Override - public Integer perform(ReadGraph graph, Resource domainAxis) throws DatabaseException { - if(angleInt == null) { - Double angle = 0.0; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - if(domainAxis != null) { - Double value = graph.getPossibleRelatedValue(domainAxis, jfree.Axis_rotateLabelDegrees); - if(value != null) - angle = value; - } - return angle.intValue(); - } else { - return angleInt; - } - } - - } - - @Override - public void setInput(final ISessionContext context, Object input) { - final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); - if(chart == null) - return; - - context.getSession().asyncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); - if(plot == null) return; - Resource rangeAxis = graph.getPossibleObject(plot, jfree.Plot_rangeAxis); - if(rangeAxis == null) return; - rangeAxisSupport.fireInput(context, new StructuredSelection(rangeAxis)); - - Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); - if(domainAxis == null) return; - domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis)); - } - }); - } -} 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 deleted file mode 100644 index be09d06a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarGeneralPropertiesTab.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * 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.properties.bar; - -import java.util.LinkedHashMap; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.LayoutConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -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.WidgetSupport; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -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.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; - - -/** - * General properties of a bar chart - * @author Teemu Lempinen - * - */ -public class BarGeneralPropertiesTab extends LabelPropertyTabContributor { - - private ScrolledComposite sc; - private Composite composite; - private Button hgrid, htitle, hlegend; - private TrackedText name, title, time; - private TrackedCombo type; - - - @Override - public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - // Scrolled composite containing all of the properties in this tab - sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); - GridLayoutFactory.fillDefaults().applyTo(sc); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - - composite = new Composite(sc, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // General properties - Group general = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); - general.setText("General"); - - // first column: labels - Composite labelColumn1 = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); - GridLayoutFactory.fillDefaults().applyTo(labelColumn1); - - // 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); - - // 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); - - // fourth column: type and time - Composite propertyColumn2 = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); - GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); - - // Name - Label label = new Label(labelColumn1, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Name:"); - - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); - name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); - name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); - - // Type - label = new Label(labelColumn2, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Type:"); - - type = new TrackedCombo(propertyColumn2, 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(labelColumn1, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Title:"); - - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); - title.setTextFactory(new TitleFactory()); - title.addModifyListener(new TitleModifier()); - title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); - - // Time - label = new Label(labelColumn2, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Time:"); - - time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); - GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); - time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); - time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); - time.setInputValidator(new DoubleValidator(true)); - time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); - - // Group for hide options - Group hideGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(hideGroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); - hideGroup.setText("Hide"); - - hgrid = new Button(hideGroup, support, SWT.CHECK); - hgrid.setText("Grid"); - hgrid.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid, true)); - hgrid.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid)); - htitle = new Button(hideGroup, support, SWT.CHECK); - htitle.setText("Title"); - htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true)); - htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible)); - hlegend = new Button(hideGroup, support, SWT.CHECK); - hlegend.setText("Legend"); - hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); - hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); - - - - // Resize scrolled composite - sc.setContent(composite); - Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); - sc.setMinSize(size); - } - - /** - * - * @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.CategoryPlot)); - if(plot != null) { - Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.CategoryDataset)); - - if(dataset != null) { - Resource renderer = graph.syncRequest(new PossibleObjectWithType(dataset, jfree.Dataset_renderer, jfree.Renderer)); - - if(renderer != null && graph.isInstanceOf(renderer, jfree.StackedBarRenderer)) - return "Stacked"; - } - } - return "Normal"; - } - } - - /** - * 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("Normal", "Normal"); - result.put("Stacked", "Stacked"); - 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.CategoryPlot)); - if(plot == null) - return; - - Resource dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.CategoryDataset)); - if(dataset == null) - return; - - graph.deny(dataset, jfree.Dataset_renderer); - - Resource renderer; - if(text.equals("Stacked")) - renderer = GraphUtils.create2(graph, jfree.StackedBarRenderer); - else - renderer = GraphUtils.create2(graph, jfree.BarRenderer); - - graph.claim(dataset, jfree.Dataset_renderer, renderer); - } - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java deleted file mode 100644 index da07fe55..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesPropertyComposite.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * 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.properties.bar; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; -import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; -import org.simantics.browsing.ui.swt.widgets.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; -import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator; - -/** - * Composite for modifying properties of a series in a bar chart - * @author Teemu Lempinen - * - */ -public class BarSeriesPropertyComposite extends Composite { - - private TrackedText variable, label, time; - - public BarSeriesPropertyComposite(Composite parent, final ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); - - // Variable for the series - Label label = new Label(this, SWT.NONE); - label.setText("Variable:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - variable = new TrackedText(this, support, SWT.BORDER); - variable.setTextFactory(new RVIFactory()); - variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); - variable.setInputValidator(new VariableExistsValidator(support, variable)); - variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); - - // Range - label = new Label(this, SWT.NONE); - label.setText("Range:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); - - - // Label to be displayed in chart for this series - label = new Label(this, SWT.NONE); - label.setText("Label:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - this.label = new TrackedText(this, support, SWT.BORDER); - this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); - this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); - - // Time - label = new Label(this, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - label.setText("Time:"); - - Composite composite = new Composite(this, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(composite); - GridLayoutFactory.fillDefaults().applyTo(composite); - - time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); - time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); - time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); - time.setInputValidator(new DoubleValidator(true)); - time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); - GridDataFactory.fillDefaults().applyTo(time.getWidget()); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java deleted file mode 100644 index 6196c353..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/bar/BarSeriesTab.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * 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.properties.bar; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.swt.SingleSelectionInputSource; -import org.simantics.browsing.ui.swt.widgets.Button; -import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; -import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; -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.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.util.RemoverUtil; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.trend.chart.ChartUtils; -import org.simantics.sysdyn.ui.trend.chart.properties.xyline.AxisAndVariablesExplorerComposite; -import org.simantics.ui.utils.AdaptionUtils; -import org.simantics.utils.datastructures.ArrayMap; - -/** - * Tab containing the series of a bar chart - * @author Teemu Lempinen - * - */ -public class BarSeriesTab extends LabelPropertyTabContributor implements Widget { - - private GraphExplorerComposite explorer; - private ScrolledComposite propertyContainer; - private WidgetSupportImpl additionalSupport; - private Button add, remove; - private Resource chartResource; - private BarSeriesPropertyComposite spc; - - - public BarSeriesTab() { - additionalSupport = new WidgetSupportImpl(); - } - - @Override - public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { - support.register(this); - Composite composite = new Composite(body, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // (Ontology-based) GraphExplorer displaying variables in a bar chart - explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); - explorer.setBrowseContexts(SysdynResource.URIs.BarSeriesBrowseContext); - explorer.setInputSource(new SingleSelectionInputSource( - Resource.class)); - explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning - explorer.finish(); - - ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - updateSelection(context); - } - }); - GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); - - // Scrolled composite for displaying properties of a selection in explorer - propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); - GridLayoutFactory.fillDefaults().applyTo(propertyContainer); - propertyContainer.setExpandHorizontal(true); - propertyContainer.setExpandVertical(true); - - // Buttons for adding and removing variables from a pie plot - Composite buttonComposite = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(buttonComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); - - add = new Button(buttonComposite, additionalSupport, SWT.NONE); - add.setText("Add"); - add.addSelectionListener(new NewVariableListener(context)); - - remove = new Button(buttonComposite, additionalSupport, SWT.NONE); - remove.setText("Remove"); - remove.addSelectionListener(new RemoveListener(context)); - } - - /** - * Updates the content of propertyContainer - * @param context - */ - private void updateSelection(ISessionContext context) { - ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); - IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); - final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class); - if(resource == null) - return; - - for(Control child : propertyContainer.getChildren()) { - child.dispose(); - } - spc = new BarSeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); - - additionalSupport.fireInput(context, selection); - - propertyContainer.setContent(spc); - Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT); - propertyContainer.setMinSize(size); - } - - /** - * SelectionListener for adding a new variable to a plot - * @author Teemu Lempinen - * - */ - private class NewVariableListener extends SelectionListenerImpl { - - public NewVariableListener(ISessionContext context) { - super(context); - } - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - Resource dataset = null; - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - if(input == null) { - if(chartResource != null) { - Resource plot = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Plot)); - if(plot != null) - dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); - } - } else { - if(graph.isInstanceOf(input, jfree.Series)) { - dataset = graph.getPossibleObject(input, l0.PartOf); - } - } - - if(dataset != null) { - // Create series with no rvi - ChartUtils.createSeries(graph, dataset, null); - } - } - } - - /** - * SelectionListener for remove button - * @author Teemu Lempinen - * - */ - private class RemoveListener extends SelectionListenerImpl { - - public RemoveListener(ISessionContext context) { - super(context); - } - - /** - * Removes selected resource from explorer - */ - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - if(input == null) - return; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource list = null; - if(graph.isInstanceOf(input, jfree.Series)) { - // Remove series from dataset and seriesList - Resource dataset = graph.getPossibleObject(input, l0.PartOf); - if(dataset != null) - list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); - - if(list != null) - ListUtils.removeElement(graph, list, input); - RemoverUtil.remove(graph, input); - } - } - } - - @Override - public void setInput(ISessionContext context, Object input) { - chartResource = AdaptionUtils.adaptToSingle(input, Resource.class); - } - - -} 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 deleted file mode 100644 index 10b034aa..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieGeneralPropertiesTab.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * 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.properties.pie; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.LayoutConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -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.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; - -/** - * General properties of a pie chart - * @author Teemu Lempinen - * - */ -public class PieGeneralPropertiesTab extends LabelPropertyTabContributor { - - private ScrolledComposite sc; - private Composite composite; - private Button htitle, hlegend, hlabels; - private TrackedText name, title, time; - - @Override - public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - // Scrolled composite containing all of the properties in this tab - sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); - GridLayoutFactory.fillDefaults().applyTo(sc); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - - composite = new Composite(sc, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // General properties - Group general = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general); - general.setText("General"); - - // first column: labels - Composite labelColumn1 = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1); - GridLayoutFactory.fillDefaults().applyTo(labelColumn1); - - // first 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 - 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 - Composite propertyColumn2 = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2); - GridLayoutFactory.fillDefaults().applyTo(propertyColumn2); - - // Name - Label label = new Label(labelColumn1, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Name:"); - - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); - name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); - name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); - - // Dummy data for now. Waiting for different pie chart types - label = new Label(labelColumn2, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(label); - label.setText(""); - - label = new Label(propertyColumn2, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).applyTo(label); - label.setText(""); - - // Title (Which is different than name) - label = new Label(labelColumn1, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Title:"); - - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); - title.setTextFactory(new TitleFactory()); - title.addModifyListener(new TitleModifier()); - title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); - - // Time - label = new Label(labelColumn2, SWT.NONE); - GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Time:"); - - time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER); - GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget()); - time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time)); - time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time)); - time.setInputValidator(new DoubleValidator(true)); - time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); - - // Group for hide options - Group hideGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(hideGroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); - hideGroup.setText("Hide"); - - htitle = new Button(hideGroup, support, SWT.CHECK); - htitle.setText("Title"); - htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true)); - htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible)); - hlegend = new Button(hideGroup, support, SWT.CHECK); - 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); - sc.setMinSize(size); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java deleted file mode 100644 index 7ea26a41..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesPropertyComposite.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * 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.properties.pie; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -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.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; -import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; -import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; -import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator; - -/** - * Composite containing the properties of a series - * @author Teemu Lempinen - * - */ -public class PieSeriesPropertyComposite extends Composite { - - private TrackedText variable, label, time; - - public PieSeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); - - // Variable for the series - Label label = new Label(this, SWT.NONE); - label.setText("Variable:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - variable = new TrackedText(this, support, SWT.BORDER); - variable.setTextFactory(new RVIFactory()); - variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); - variable.setInputValidator(new VariableExistsValidator(support, variable)); - variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); - - // Range - label = new Label(this, SWT.NONE); - label.setText("Range:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); - - - // Label to be displayed in chart for this series - label = new Label(this, SWT.NONE); - label.setText("Label:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - this.label = new TrackedText(this, support, SWT.BORDER); - this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); - this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); - - // Color - label = new Label(this, SWT.NONE); - label.setText("Color:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); - - // Time - label = new Label(this, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - label.setText("Time:"); - - Composite composite = new Composite(this, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(composite); - GridLayoutFactory.fillDefaults().applyTo(composite); - - time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER); - time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time)); - time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time)); - time.setInputValidator(new DoubleValidator(true)); - time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager())); - GridDataFactory.fillDefaults().applyTo(time.getWidget()); - - // Exploded - label = new Label(this, SWT.NONE); - label.setText(""); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - Button exploded = new Button(this, support, SWT.CHECK); - exploded.setText("Exploded"); - exploded.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Series_exploded)); - exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded)); - GridDataFactory.fillDefaults().applyTo(exploded.getWidget()); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java deleted file mode 100644 index d05e5d28..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/pie/PieSeriesTab.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * 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.properties.pie; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.swt.SingleSelectionInputSource; -import org.simantics.browsing.ui.swt.widgets.Button; -import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; -import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; -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.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.PossibleObjectWithType; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.util.RemoverUtil; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.trend.chart.ChartUtils; -import org.simantics.sysdyn.ui.trend.chart.properties.xyline.AxisAndVariablesExplorerComposite; -import org.simantics.ui.utils.AdaptionUtils; -import org.simantics.utils.datastructures.ArrayMap; - -/** - * Tab for modifying series in a pie chart configuration - * @author Teemu Lempinen - * - */ -public class PieSeriesTab extends LabelPropertyTabContributor implements Widget { - - private GraphExplorerComposite explorer; - private ScrolledComposite propertyContainer; - private WidgetSupportImpl additionalSupport; - private Button add, remove; - private Resource chartResource; - - public PieSeriesTab() { - additionalSupport = new WidgetSupportImpl(); - } - - @Override - public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { - support.register(this); - Composite composite = new Composite(body, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // (Ontology-based) GraphExplorer displaying variables of a pie chart - explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); - explorer.setBrowseContexts(SysdynResource.URIs.PieSeriesBrowseContext); - explorer.setInputSource(new SingleSelectionInputSource( - Resource.class)); - explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning - explorer.finish(); - - ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - updateSelection(context); - } - }); - GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); - - // Scrolled composite for displaying properties of a selection in explorer - propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); - GridLayoutFactory.fillDefaults().applyTo(propertyContainer); - propertyContainer.setExpandHorizontal(true); - propertyContainer.setExpandVertical(true); - - - // Buttons for adding and removing variables from a pie plot - Composite buttonComposite = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(buttonComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); - - add = new Button(buttonComposite, additionalSupport, SWT.NONE); - add.setText("Add"); - add.addSelectionListener(new NewVariableListener(context)); - - remove = new Button(buttonComposite, additionalSupport, SWT.NONE); - remove.setText("Remove"); - remove.addSelectionListener(new RemoveListener(context)); - } - - /** - * Updates the content of propertyContainer - * @param context - */ - private void updateSelection(ISessionContext context) { - ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); - IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); - final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class); - if(resource == null) - return; - - for(Control child : propertyContainer.getChildren()) { - child.dispose(); - } - - PieSeriesPropertyComposite spc = new PieSeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); - propertyContainer.setContent(spc); - Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT); - propertyContainer.setMinSize(size); - - additionalSupport.fireInput(context, selection); - } - - - /** - * SelectionListener for adding a new variable to a plot - * @author Teemu Lempinen - * - */ - private class NewVariableListener extends SelectionListenerImpl { - - public NewVariableListener(ISessionContext context) { - super(context); - } - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource dataset = null; - if(input == null) { - if(chartResource != null) { - Resource plot = graph.syncRequest(new PossibleObjectWithType(chartResource, l0.ConsistsOf, jfree.Plot)); - if(plot != null) - dataset = graph.syncRequest(new PossibleObjectWithType(plot, l0.ConsistsOf, jfree.Dataset)); - } - } else { - if(graph.isInstanceOf(input, jfree.Series)) { - dataset = graph.getPossibleObject(input, l0.PartOf); - } - } - if(dataset != null) { - // Create series with no rvi - Resource series = ChartUtils.createSeries(graph, dataset, null); - graph.claimLiteral(series, jfree.Series_exploded, false); - } - } - } - - /** - * SelectionListener for remove button - * @author Teemu Lempinen - * - */ - private class RemoveListener extends SelectionListenerImpl { - - public RemoveListener(ISessionContext context) { - super(context); - } - - /** - * Removes selected resource from explorer - */ - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - if(input == null) - return; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource list = null; - if(graph.isInstanceOf(input, jfree.Series)) { - // Remove series from dataset and seriesList - Resource dataset = graph.getPossibleObject(input, l0.PartOf); - if(dataset != null) - list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); - - if(list != null) - ListUtils.removeElement(graph, list, input); - RemoverUtil.remove(graph, input); - } - } - } - - @Override - public void setInput(ISessionContext context, Object input) { - chartResource = AdaptionUtils.adaptToSingle(input, Resource.class); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java deleted file mode 100644 index a3ee7e6a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisAndVariablesExplorerComposite.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * 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.properties.xyline; - -import java.util.ArrayList; -import java.util.Map; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.common.ErrorLogger; -import org.simantics.browsing.ui.model.InvalidContribution; -import org.simantics.browsing.ui.model.dnd.DndBrowseContext; -import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.procedure.Procedure; -import org.simantics.db.request.Read; -import org.simantics.structural.ui.modelBrowser.ModelBrowser2; -import org.simantics.ui.SimanticsUI; - -/** - * ExplorerComposite allowing ontology-based DnD definitions. DnD Copied from {@link ModelBrowser2} - * - * @author Teemu Lempinen - * - */ -public class AxisAndVariablesExplorerComposite extends GraphExplorerComposite { - - volatile DndBrowseContext dndBrowseContext; - - public AxisAndVariablesExplorerComposite(Map args, IWorkbenchSite site, Composite parent, - WidgetSupport support, int style) { - super(args, site, parent, support, style); - - SimanticsUI.getSession().asyncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - ArrayList browseContexts = new ArrayList(); - for (String uri : getBrowseContexts()) { - Resource browseContext = graph.getPossibleResource(uri); - if (browseContext != null) - browseContexts.add(browseContext); - } - try { - dndBrowseContext = DndBrowseContext.create(graph, browseContexts); - } catch (InvalidContribution e) { - ErrorLogger.defaultLogError(e); - } - } - }); - } - - @Override - protected void handleDrop(final Object data, final NodeContext target) { - if (target == null) - return; - - SimanticsUI.getSession().asyncRequest(new Read() { - @Override - public Runnable perform(ReadGraph graph) throws DatabaseException { - if (dndBrowseContext == null) - return null; - return dndBrowseContext.getAction(graph, target, data); - } - }, new Procedure() { - @Override - public void execute(Runnable result) { - if (result != null) - result.run(); - } - - @Override - public void exception(Throwable t) { - ErrorLogger.defaultLogError(t); - } - }); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java deleted file mode 100644 index 22228fde..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/AxisPropertyComposite.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * 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.properties.xyline; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -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.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.modeling.ui.chart.property.DoublePropertyFactory; -import org.simantics.modeling.ui.chart.property.DoublePropertyModifier; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; -import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; - -/** - * Composite for displaying axis properties in {@link XYLineAxisAndVariablesTab} - * - * @author Teemu Lempinen - * - */ -public class AxisPropertyComposite extends Composite { - - TrackedText name, units, min, max; - Button tlabels, tmarks; - - public AxisPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); - - // Label (units) - Label label = new Label(this, SWT.NONE); - label.setText("Label: "); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - units = new TrackedText(this, support, SWT.BORDER); - units.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); // FIXME: Units - units.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); // FIXME: Units - units.setColorProvider(new JFreeChartPropertyColorProvider(units.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(units.getWidget()); - - - // Minimum and maximum values - label = new Label(this, SWT.NONE); - label.setText("Min:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - Composite minmax = new Composite(this, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(minmax); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax); - min = new TrackedText(minmax, support, SWT.BORDER); - min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager())); - min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); - min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - min.setInputValidator(new DoubleValidator(true)); - - label = new Label(minmax, SWT.NONE); - label.setText("Max:"); - max = new TrackedText(minmax, support, SWT.BORDER); - max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager())); - max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); - max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - max.setInputValidator(new DoubleValidator(true)); - - - // Color - label = new Label(this, SWT.NONE); - label.setText("Color:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); - - // Tick and label visibility - Composite c = new Composite(this, SWT.NONE); - GridDataFactory.fillDefaults().span(2, 1).applyTo(c); - GridLayoutFactory.fillDefaults().applyTo(c); - Composite axisHide = new AxisHidePropertyComposite(c, context, support, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(axisHide); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java deleted file mode 100644 index 1dbe6d4c..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/SeriesPropertyComposite.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * 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.properties.xyline; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; -import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; -import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; -import org.simantics.browsing.ui.swt.widgets.TrackedText; -import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; -import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener; -import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent; -import org.simantics.browsing.ui.swt.widgets.impl.Widget; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.RangeComposite; -import org.simantics.sysdyn.ui.trend.chart.properties.TrackedSpinner; -import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * Composite for displaying series properties in {@link XYLineAxisAndVariablesTab} - * - * @author Teemu Lempinen - * - */ -public class SeriesPropertyComposite extends Composite { - - private TrackedText variable, label; - private TrackedSpinner width; - - public SeriesPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) { - super(parent, style); - - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this); - - // Variable for the series - Label label = new Label(this, SWT.NONE); - label.setText("Variable:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - variable = new TrackedText(this, support, SWT.BORDER); - variable.setTextFactory(new RVIFactory()); - variable.addModifyListener(new RVIModifier(variable.getWidget(), support)); - variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager())); - variable.setInputValidator(new VariableExistsValidator(support, variable)); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget()); - - // Range - label = new Label(this, SWT.NONE); - label.setText("Range:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite); - - // Label to be displayed in chart for this series - label = new Label(this, SWT.NONE); - label.setText("Label:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - this.label = new TrackedText(this, support, SWT.BORDER); - this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); - this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget()); - - // Color - label = new Label(this, SWT.NONE); - label.setText("Color:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - - Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker); - - // Line width - label = new Label(this, SWT.NONE); - label.setText("Line width:"); - GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label); - - width = new TrackedSpinner(this, support, SWT.BORDER); - width.setSelectionFactory(new WidthSelectionFactory()); - width.addModifyListener(new WidthModifyListener()); - width.setMinimum(1); - width.setMaximum(10); - - } - - - /** - * ModifyListener for the width {@link TrackedSpinner} - * - * @author Teemu Lempinen - * - */ - private class WidthModifyListener implements TextModifyListener, Widget { - - private ISessionContext context; - private Object lastInput = null; - - @Override - public void modifyText(TrackedModifyEvent e) { - if(context == null) - return; - - // Get the text value from spinner and associated resource (input) - Spinner spinner = (Spinner)e.getWidget(); - final String textValue = spinner.getText(); - final Object input = lastInput; - - try { - context.getSession().syncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - // Apply with (textValue) to the series (input) - Resource series = AdaptionUtils.adaptToSingle(input, Resource.class); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - try { - // usually reliable, since the spinner does all the checks - Integer value = Integer.parseInt(textValue); - graph.claimLiteral(series, jfree.Series_lineWidth, value, Bindings.INTEGER); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - } - - }); - } catch (DatabaseException e1) { - e1.printStackTrace(); - } - } - - @Override - public void setInput(ISessionContext context, Object parameter) { - this.context = context; - lastInput = parameter; - } - - } - - /** - * Class for setting the value for width {@link TrackedSpinner} - * @author Teemu Lempinen - * - */ - private class WidthSelectionFactory extends ReadFactoryImpl { - - @Override - public Integer perform(ReadGraph graph, Resource axis) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Integer width = graph.getPossibleRelatedValue(axis, jfree.Series_lineWidth); - if(width == null) - // Default width == 1 - width = 1; - return width; - } - - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java deleted file mode 100644 index 3081abbb..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineAxisAndVariablesTab.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * 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.properties.xyline; - -import java.util.List; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.swt.SingleSelectionInputSource; -import org.simantics.browsing.ui.swt.widgets.Button; -import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite; -import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl; -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.PossibleObjectWithType; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.util.RemoverUtil; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.request.Read; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.JFreeChartResource; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.trend.chart.ChartUtils; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.AdaptionUtils; -import org.simantics.utils.datastructures.ArrayMap; - -/** - * PropertyTab displaying properties of axis and variables of a chart - * - * @author Teemu Lempinen - * - */ -public class XYLineAxisAndVariablesTab extends LabelPropertyTabContributor { - - private GraphExplorerComposite explorer; - private ScrolledComposite propertyContainer; - private Button addAxis, addVariable, remove; - private WidgetSupportImpl additionalSupport; - - public XYLineAxisAndVariablesTab() { - additionalSupport = new WidgetSupportImpl(); - } - - @Override - public void createControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { - Composite composite = new Composite(body, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis - explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( - "displaySelectors", "displayFilter").values(false, false), site, composite, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); - explorer.setBrowseContexts(SysdynResource.URIs.ChartAxisAndVariablesBrowseContext); - explorer.setInputSource(new SingleSelectionInputSource( - Resource.class)); - explorer.getExplorer().setAutoExpandLevel(2); // Expand everything in the beginning - explorer.finish(); - - ((Tree)explorer.getExplorerControl()).addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - updateSelection(context); - } - }); - GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); - - // Scrolled composite for displaying properties of a selection in explorer - propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); - GridLayoutFactory.fillDefaults().applyTo(propertyContainer); - propertyContainer.setExpandHorizontal(true); - propertyContainer.setExpandVertical(true); - - // Buttons for adding axis and variables and removing selected items from explorer - Composite buttonComposite = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(buttonComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); - - addAxis = new Button(buttonComposite, support, SWT.NONE); - addAxis.setText("Add axis"); - addAxis.addSelectionListener(new NewAxisListener(context)); - - addVariable = new Button(buttonComposite, additionalSupport, SWT.NONE); - addVariable.setText("Add variable"); - addVariable.addSelectionListener(new NewVariableListener(context)); - - remove = new Button(buttonComposite, additionalSupport, SWT.NONE); - remove.setText("Remove"); - remove.addSelectionListener(new RemoveListener(context)); - } - - /** - * Updates the content of propertyContainer - * @param context - */ - private void updateSelection(ISessionContext context) { - ISelectionProvider selectionProvider = (ISelectionProvider)explorer.getAdapter(ISelectionProvider.class); - IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); - final Resource resource = AdaptionUtils.adaptToSingle(selection, Resource.class); - if(resource == null) - return; - - // Get the type of the selected node (axis or series) - String typeUri = null; - try { - typeUri = SimanticsUI.getSession().syncRequest(new Read() { - - @Override - public String perform(ReadGraph graph) throws DatabaseException { - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - if(graph.isInstanceOf(resource, jfree.Axis)) - return graph.getURI(jfree.Axis); - else if (graph.isInstanceOf(resource, jfree.Series)) - return graph.getURI(jfree.Series); - return null; - } - - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - - // Create a PropertyComposite for the selected node - if(typeUri != null) { - - for(Control child : propertyContainer.getChildren()) { - child.dispose(); - } - - if(typeUri.equals(JFreeChartResource.URIs.Axis)) { - AxisPropertyComposite apc = new AxisPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); - propertyContainer.setContent(apc); - Point size = apc.computeSize(SWT.DEFAULT, SWT.DEFAULT); - propertyContainer.setMinSize(size); - } else if(typeUri.equals(JFreeChartResource.URIs.Series)) { - SeriesPropertyComposite spc = new SeriesPropertyComposite(propertyContainer, context, additionalSupport, SWT.NONE); - propertyContainer.setContent(spc); - Point size = spc.computeSize(SWT.DEFAULT, SWT.DEFAULT); - propertyContainer.setMinSize(size); - } - } - - additionalSupport.fireInput(context, selection); - } - - /** - * SelectionListener for adding a new range axis to a plot - * @author Teemu Lempinen - * - */ - private class NewAxisListener extends SelectionListenerImpl { - - public NewAxisListener(ISessionContext context) { - super(context); - } - - @Override - public void apply(WriteGraph 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.Plot)); - if(plot != null) { - Resource rangeAxis = ChartUtils.createNumberRangeAxis(graph, plot); - if(rangeAxis != null) { - Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); - ChartUtils.createXYDataset(graph, plot, domainAxis, rangeAxis); - } - } - } - } - - - /** - * SelectionListener for adding a new variable to a plot - * @author Teemu Lempinen - * - */ - private class NewVariableListener extends SelectionListenerImpl { - - public NewVariableListener(ISessionContext context) { - super(context); - } - - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - NodeContext nc = explorer.getExplorer().getRoot(); - if(nc == null) - return; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - - if(input == null) { - Resource chart = AdaptionUtils.adaptToSingle(nc, Resource.class); - if(chart == null) return; - Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); - if(plot == null) return; - Resource rangelist = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); - if(rangelist == null) return; - List list = ListUtils.toList(graph, rangelist); - if(list == null || list.isEmpty()) return; - input = list.get(0); - } - - Resource dataset; - if(graph.isInstanceOf(input, jfree.Series)) { - // Selected resource is series. Add to same dataset - dataset = graph.getPossibleObject(input, l0.PartOf); - } else { - // Selected resource is axis. Find the dataset it is mapped to or create dataset if not created already - dataset = graph.getPossibleObject(input, jfree.Dataset_mapToRangeAxis_Inverse); - if(dataset == null) { - Resource plot = graph.getPossibleObject(input, l0.PartOf); - if(plot == null) return; - Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); - if(domainAxis == null) return; - ChartUtils.createXYDataset(graph, plot, domainAxis, input); - } - } - - if(dataset != null) { - // Create series with no rvi - ChartUtils.createSeries(graph, dataset, null); - } - } - } - - - /** - * SelectionListener for remove button - * @author Teemu Lempinen - * - */ - private class RemoveListener extends SelectionListenerImpl { - - public RemoveListener(ISessionContext context) { - super(context); - } - - /** - * Removes selected resource from explorer - */ - @Override - public void apply(WriteGraph graph, Resource input) throws DatabaseException { - if(input == null) - return; - - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Layer0 l0 = Layer0.getInstance(graph); - Resource list = null; - if(graph.isInstanceOf(input, jfree.Series)) { - // Remove series from dataset and seriesList - Resource dataset = graph.getPossibleObject(input, l0.PartOf); - if(dataset != null) - list = graph.getPossibleObject(dataset, jfree.Dataset_seriesList); - } else { - // Remove associated dataset - Resource dataset = graph.getPossibleObject(input, jfree.Dataset_mapToRangeAxis_Inverse); - if(dataset != null) { - graph.deny(dataset, jfree.Dataset_mapToDomainAxis); - graph.deny(dataset, jfree.Dataset_mapToRangeAxis); - RemoverUtil.remove(graph, dataset); - } - - // Remove axis from plot and rangeAxisList - Resource plot = graph.getPossibleObject(input, l0.PartOf); - if(plot != null) - list = graph.getPossibleObject(plot, jfree.Plot_rangeAxisList); - } - if(list != null) - ListUtils.removeElement(graph, list, input); - RemoverUtil.remove(graph, input); - } - } -} 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 deleted file mode 100644 index 9bba7fcc..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/xyline/XYLineGeneralPropertiesTab.java +++ /dev/null @@ -1,318 +0,0 @@ -/******************************************************************************* - * 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.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.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -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; -import org.simantics.sysdyn.ui.properties.LabelPropertyTabContributor; -import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanPropertyFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.BooleanSelectionListener; -import org.simantics.sysdyn.ui.trend.chart.properties.DoubleValidator; -import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.RVIModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.TitleFactory; -import org.simantics.sysdyn.ui.trend.chart.properties.TitleModifier; -import org.simantics.sysdyn.ui.trend.chart.properties.VariableExistsValidator; -import org.simantics.ui.utils.AdaptionUtils; - -/** - * PropertyTab displaying general properties and x-axis properties of a chart - * - * @author Teemu Lempinen - * - */ -public class XYLineGeneralPropertiesTab extends LabelPropertyTabContributor implements Widget { - - private ScrolledComposite sc; - private Composite composite; - private TrackedText name, title, xlabel, xvariable, xmin, xmax; - private TrackedCombo type; - private Button hgrid, htitle, hlegend; - private WidgetSupportImpl domainAxisSupport = new WidgetSupportImpl(); - - @Override - public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - support.register(this); - - // Scrolled composite containing all of the properties in this tab - sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); - GridLayoutFactory.fillDefaults().applyTo(sc); - sc.setExpandHorizontal(true); - sc.setExpandVertical(true); - - composite = new Composite(sc, SWT.NONE); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); - - // General properties - Group general = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(general); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general); - general.setText("General"); - - // Name - Label nameLabel = new Label(general, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(nameLabel); - nameLabel.setText("Name:"); - nameLabel.setAlignment(SWT.RIGHT); - - Composite c = new Composite(general, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(c); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(c); - - name = new org.simantics.browsing.ui.swt.widgets.TrackedText(c, support, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget()); - name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel)); - name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); - - // Type - Label label = new Label(c, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Type:"); - - 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); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Title:"); - - title = new org.simantics.browsing.ui.swt.widgets.TrackedText(general, support, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget()); - title.setTextFactory(new TitleFactory()); - title.addModifyListener(new TitleModifier()); - title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager())); - - // Group for hide options - Group hideGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(hideGroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup); - hideGroup.setText("Hide"); - - hgrid = new Button(hideGroup, support, SWT.CHECK); - hgrid.setText("Grid"); - hgrid.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid, true)); - hgrid.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleGrid)); - htitle = new Button(hideGroup, support, SWT.CHECK); - htitle.setText("Title"); - htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true)); - htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible)); - hlegend = new Button(hideGroup, support, SWT.CHECK); - hlegend.setText("Legend"); - hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true)); - hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend)); - - - // X-Axis properties - Group xgroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(xgroup); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(3).applyTo(xgroup); - xgroup.setText("X-axis"); - - // Variable for x-axis (default: empty == time) - Label xVariableLabel = new Label(xgroup, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(xVariableLabel); - xVariableLabel.setText("Variable:"); - - xvariable = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER); - xvariable.setTextFactory(new RVIFactory()); - xvariable.addModifyListener(new RVIModifier(xvariable.getWidget(), domainAxisSupport)); - xvariable.setColorProvider(new JFreeChartPropertyColorProvider(xvariable.getResourceManager())); - xvariable.setInputValidator(new VariableExistsValidator(support, xvariable, true)); - GridDataFactory.fillDefaults().grab(true, false).applyTo(xvariable.getWidget()); - - Composite axisHide = new AxisHidePropertyComposite(xgroup, context, domainAxisSupport, SWT.NONE); - GridDataFactory.fillDefaults().span(1, 3).applyTo(axisHide); - - // Label for x-axis - label = new Label(xgroup, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Label:"); - - xlabel = new TrackedText(xgroup, domainAxisSupport, SWT.BORDER); - xlabel.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); - xlabel.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); - xlabel.setColorProvider(new JFreeChartPropertyColorProvider(xlabel.getResourceManager())); - GridDataFactory.fillDefaults().grab(true, false).applyTo(xlabel.getWidget()); - - // Min and max values for x-axis - label = new Label(xgroup, SWT.NONE); - GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label); - label.setText("Min:"); - - Composite minmax = new Composite(xgroup, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(minmax); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax); - xmin = new TrackedText(minmax, domainAxisSupport, SWT.BORDER); - xmin.setColorProvider(new JFreeChartPropertyColorProvider(xmin.getResourceManager())); - xmin.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min)); - xmin.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min)); - xmin.setInputValidator(new DoubleValidator(true)); - - label = new Label(minmax, SWT.NONE); - label.setText("Max:"); - xmax = new TrackedText(minmax, domainAxisSupport, SWT.BORDER); - xmax.setColorProvider(new JFreeChartPropertyColorProvider(xmax.getResourceManager())); - xmax.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max)); - xmax.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max)); - xmax.setInputValidator(new DoubleValidator(true)); - - // Set the same width to both label rows - composite.layout(); - GridDataFactory.fillDefaults().hint(xVariableLabel.getBounds().width, SWT.DEFAULT).align(SWT.END, SWT.CENTER).applyTo(nameLabel); - - sc.setContent(composite); - Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); - sc.setMinSize(size); - } - - @Override - public void setInput(final ISessionContext context, Object input) { - final Resource chart = AdaptionUtils.adaptToSingle(input, Resource.class); - if(chart == null) - return; - - context.getSession().asyncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - Layer0 l0 = Layer0.getInstance(graph); - JFreeChartResource jfree = JFreeChartResource.getInstance(graph); - Resource plot = graph.syncRequest(new PossibleObjectWithType(chart, l0.ConsistsOf, jfree.Plot)); - if(plot == null) return; - Resource domainAxis = graph.getPossibleObject(plot, jfree.Plot_domainAxis); - if(domainAxis == null) return; - domainAxisSupport.fireInput(context, new StructuredSelection(domainAxis)); - } - }); - } - - /** - * - * @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