]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
049f701f9fe91ac297653bad98bd56d8b688f131
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.jfreechart.chart.properties.bar;\r
13 \r
14 import org.eclipse.jface.layout.GridDataFactory;\r
15 import org.eclipse.jface.layout.GridLayoutFactory;\r
16 import org.eclipse.swt.SWT;\r
17 import org.eclipse.swt.widgets.Composite;\r
18 import org.eclipse.swt.widgets.Label;\r
19 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
20 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
21 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
22 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
23 import org.simantics.db.management.ISessionContext;\r
24 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
25 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
26 import org.simantics.jfreechart.chart.properties.RVIFactory;\r
27 import org.simantics.jfreechart.chart.properties.RVIModifier;\r
28 import org.simantics.jfreechart.chart.properties.RangeComposite;\r
29 import org.simantics.jfreechart.chart.properties.VariableExistsValidator;\r
30 import org.simantics.jfreechart.chart.properties.VariableFactory;\r
31 import org.simantics.jfreechart.chart.properties.VariableModifier;\r
32 import org.simantics.layer0.Layer0;\r
33 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;\r
34 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;\r
35 import org.simantics.sysdyn.JFreeChartResource;\r
36 import org.simantics.utils.datastructures.BijectionMap;\r
37 import org.simantics.utils.datastructures.Pair;\r
38 \r
39 /**\r
40  * Composite for modifying properties of a series in a bar chart\r
41  * @author Teemu Lempinen\r
42  *\r
43  */\r
44 public class BarSeriesPropertyComposite2 extends Composite {\r
45     \r
46     private TrackedText variable, label, time;\r
47     \r
48     public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables, int style) {\r
49         super(parent, style);\r
50         \r
51         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
52 \r
53         // Variable for the series\r
54         Label label = new Label(this, SWT.NONE);\r
55         label.setText("Variable:");\r
56         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
57 \r
58         variable = new TrackedText(this, support, SWT.BORDER);\r
59         if (variables.second == null) {\r
60                 variable.setTextFactory(new RVIFactory());\r
61                 variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
62                 variable.setInputValidator(new VariableExistsValidator(support, variable));\r
63         } else {\r
64                 // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
65                 BijectionMap<String , String> map = new BijectionMap<String, String>();\r
66                 for (int i = 0; i < variables.first.length; i++) {\r
67                         map.map(variables.first[i], variables.second[i]);\r
68                 }\r
69                 variable.setTextFactory(new VariableFactory(map));\r
70                 variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
71                 variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
72         }\r
73         variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
74         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
75 \r
76         // Range\r
77         label = new Label(this, SWT.NONE);\r
78         label.setText("Range:");\r
79         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
80         \r
81         RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE);\r
82         GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite);\r
83         \r
84         \r
85         // Label to be displayed in chart for this series\r
86         label = new Label(this, SWT.NONE);\r
87         label.setText("Label:");\r
88         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
89 \r
90         this.label = new TrackedText(this, support, SWT.BORDER);\r
91         this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));\r
92         this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
93         this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager()));\r
94         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget());\r
95         \r
96         // Time\r
97         label = new Label(this, SWT.NONE);\r
98         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
99         label.setText("Time:");\r
100         \r
101         Composite composite = new Composite(this, SWT.NONE);\r
102         GridDataFactory.fillDefaults().applyTo(composite);\r
103         GridLayoutFactory.fillDefaults().applyTo(composite);\r
104         \r
105         time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);\r
106         time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));\r
107         time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));\r
108         time.setInputValidator(new DoubleValidator(true));\r
109         time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
110         GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
111     }\r
112 }\r