]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
5011332ba34b285afd876a8fb19ec6aafbce76b3
[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.pie;\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.Button;\r
20 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
21 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
22 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
23 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
24 import org.simantics.db.management.ISessionContext;\r
25 import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;\r
26 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;\r
27 import org.simantics.jfreechart.chart.properties.ColorPicker;\r
28 import org.simantics.jfreechart.chart.properties.DoubleValidator;\r
29 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;\r
30 import org.simantics.jfreechart.chart.properties.RVIFactory;\r
31 import org.simantics.jfreechart.chart.properties.RVIModifier;\r
32 import org.simantics.jfreechart.chart.properties.RangeComposite;\r
33 import org.simantics.jfreechart.chart.properties.VariableExistsValidator;\r
34 import org.simantics.jfreechart.chart.properties.VariableFactory;\r
35 import org.simantics.jfreechart.chart.properties.VariableModifier;\r
36 import org.simantics.layer0.Layer0;\r
37 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;\r
38 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;\r
39 import org.simantics.sysdyn.JFreeChartResource;\r
40 import org.simantics.utils.datastructures.BijectionMap;\r
41 import org.simantics.utils.datastructures.Pair;\r
42 \r
43 /**\r
44  * Composite containing the properties of a series\r
45  * @author Teemu Lempinen\r
46  *\r
47  */\r
48 public class PieSeriesPropertyComposite2 extends Composite {\r
49     \r
50     private TrackedText variable, label, time;\r
51     \r
52     public PieSeriesPropertyComposite2(Composite parent, ISessionContext context, WidgetSupport support, Pair<String[],String[]> variables,int style) {\r
53         super(parent, style);\r
54         \r
55         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);\r
56 \r
57         // Variable for the series\r
58         Label label = new Label(this, SWT.NONE);\r
59         label.setText("Variable:");\r
60         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
61 \r
62         variable = new TrackedText(this, support, SWT.BORDER);\r
63         if (variables.second == null) {\r
64                 variable.setTextFactory(new RVIFactory());\r
65                 variable.addModifyListener(new RVIModifier(variable.getWidget(), support));\r
66                 variable.setInputValidator(new VariableExistsValidator(support, variable));\r
67         } else {\r
68                 // FIXME: using bijectionmap and trackedText looses the variables that have the same label.\r
69                 BijectionMap<String , String> map = new BijectionMap<String, String>();\r
70                 for (int i = 0; i < variables.first.length; i++) {\r
71                         map.map(variables.first[i], variables.second[i]);\r
72                 }\r
73                 variable.setTextFactory(new VariableFactory(map));\r
74                 variable.addModifyListener(new VariableModifier(variable.getWidget(), support));\r
75                 variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));\r
76         }\r
77         variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));\r
78         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());\r
79 \r
80         // Range\r
81         label = new Label(this, SWT.NONE);\r
82         label.setText("Range:");\r
83         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
84         \r
85         RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE);\r
86         GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite);\r
87         \r
88         \r
89         // Label to be displayed in chart for this series\r
90         label = new Label(this, SWT.NONE);\r
91         label.setText("Label:");\r
92         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
93 \r
94         this.label = new TrackedText(this, support, SWT.BORDER);\r
95         this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));\r
96         this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
97         this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager()));\r
98         GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget());\r
99 \r
100         // Color\r
101         label = new Label(this, SWT.NONE);\r
102         label.setText("Color:");\r
103         GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
104 \r
105         Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE);\r
106         GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);\r
107 \r
108         // Time\r
109         label = new Label(this, SWT.NONE);\r
110         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
111         label.setText("Time:");\r
112         \r
113         Composite composite = new Composite(this, SWT.NONE);\r
114         GridDataFactory.fillDefaults().applyTo(composite);\r
115         GridLayoutFactory.fillDefaults().applyTo(composite);\r
116         \r
117         time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);\r
118         time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));\r
119         time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));\r
120         time.setInputValidator(new DoubleValidator(true));\r
121         time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));\r
122         GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
123         \r
124         // Exploded\r
125         label = new Label(this, SWT.NONE);\r
126         label.setText("");\r
127         GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
128         \r
129         Button exploded = new Button(this, support, SWT.CHECK);\r
130         exploded.setText("Exploded");\r
131         exploded.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Series_exploded));\r
132         exploded.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Series_exploded));\r
133         GridDataFactory.fillDefaults().applyTo(exploded.getWidget());\r
134     }\r
135 \r
136 }\r