1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011, 2014 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.jfreechart.chart.properties.pie;
\r
14 import org.eclipse.jface.layout.GridDataFactory;
\r
15 import org.eclipse.jface.layout.GridLayoutFactory;
\r
16 import org.eclipse.jface.layout.LayoutConstants;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.custom.ScrolledComposite;
\r
19 import org.eclipse.swt.graphics.Point;
\r
20 import org.eclipse.swt.widgets.Composite;
\r
21 import org.eclipse.swt.widgets.Group;
\r
22 import org.eclipse.swt.widgets.Label;
\r
23 import org.eclipse.ui.IWorkbenchSite;
\r
24 import org.simantics.browsing.ui.swt.widgets.Button;
\r
25 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
\r
26 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;
\r
27 import org.simantics.browsing.ui.swt.widgets.TrackedText;
\r
28 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
29 import org.simantics.db.management.ISessionContext;
\r
30 import org.simantics.jfreechart.ChartPropertyOptions;
\r
31 import org.simantics.jfreechart.chart.properties.AdjustableTab;
\r
32 import org.simantics.jfreechart.chart.properties.BooleanPropertyFactory;
\r
33 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;
\r
34 import org.simantics.jfreechart.chart.properties.DoublePropertyFactory2;
\r
35 import org.simantics.jfreechart.chart.properties.DoublePropertyModifier2;
\r
36 import org.simantics.jfreechart.chart.properties.DoubleValidator;
\r
37 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;
\r
38 import org.simantics.jfreechart.chart.properties.TitleFactory;
\r
39 import org.simantics.jfreechart.chart.properties.TitleModifier;
\r
40 import org.simantics.layer0.Layer0;
\r
41 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;
\r
42 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
\r
43 import org.simantics.sysdyn.JFreeChartResource;
\r
46 * General properties of a pie chart
\r
47 * @author Teemu Lempinen
\r
48 * @author Tuomas Miettinen
\r
51 public class PieGeneralPropertiesTab extends AdjustableTab {
\r
53 private ScrolledComposite sc;
\r
54 private Button htitle, hlegend, hlabels;
\r
55 private TrackedText name, title, time;
\r
57 private boolean showTime = true;
\r
58 private boolean showFilter = false;
\r
59 private Group general;
\r
60 private Composite labelColumn1;
\r
61 private Composite propertyColumn1;
\r
62 private Composite labelColumn2;
\r
63 private Composite propertyColumn2;
\r
64 private Label labelName;
\r
65 private Label labelTitle;
\r
66 private Label labelTime;
\r
67 private Group hideGroup;
\r
68 private Group filteringGroup;
\r
69 private Label labelUse;
\r
70 private Label labelPercent;
\r
71 private Button useFilter;
\r
72 private TrackedText fraction;
\r
75 public PieGeneralPropertiesTab() {
\r
79 public PieGeneralPropertiesTab(int options) {
\r
80 showTime = ((options & ChartPropertyOptions.SHOW_TIME) > 0);
\r
81 showFilter = ((options & ChartPropertyOptions.SHOW_FILTER) > 0);
\r
85 protected void createAndAddControls(Composite body, IWorkbenchSite site,
\r
86 ISessionContext context, WidgetSupport support) {
\r
87 // Scrolled composite containing all of the properties in this tab
\r
88 sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);
\r
89 sc.setExpandHorizontal(true);
\r
90 sc.setExpandVertical(true);
\r
92 composite = new Composite(sc, SWT.NONE);
\r
94 // General properties
\r
95 general = new Group(composite, SWT.NONE);
\r
96 general.setText("General");
\r
98 // first column: labels
\r
99 labelColumn1 = new Composite(general, SWT.NONE);
\r
101 // first column: name and title
\r
102 propertyColumn1 = new Composite(general, SWT.NONE);
\r
104 // first column: labels
\r
105 labelColumn2 = new Composite(general, SWT.NONE);
\r
107 // first column: type and time
\r
108 propertyColumn2 = new Composite(general, SWT.NONE);
\r
111 labelName = new Label(labelColumn1, SWT.NONE);
\r
112 labelName.setText("Name:");
\r
114 name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
115 name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));
\r
116 name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
117 name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
119 // Dummy data for now. Waiting for different pie chart types
\r
120 labelTitle = new Label(labelColumn2, SWT.NONE);
\r
121 labelTitle.setText("");
\r
123 labelTitle = new Label(propertyColumn2, SWT.NONE);
\r
124 labelTitle.setText("");
\r
126 // Title (Which is different than name)
\r
127 labelTitle = new Label(labelColumn1, SWT.NONE);
\r
128 labelTitle.setText("Title:");
\r
130 title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
131 title.setTextFactory(new TitleFactory());
\r
132 title.addModifyListener(new TitleModifier());
\r
133 title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
137 labelTime = new Label(labelColumn2, SWT.NONE);
\r
138 labelTime.setText("Time:");
\r
140 time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER);
\r
141 time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time));
\r
142 time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time));
\r
143 time.setInputValidator(new DoubleValidator(true));
\r
144 time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));
\r
146 // Group for hide options
\r
147 hideGroup = new Group(composite, SWT.NONE);
\r
148 hideGroup.setText("Hide");
\r
150 htitle = new Button(hideGroup, support, SWT.CHECK);
\r
151 htitle.setText("Title");
\r
152 htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));
\r
153 htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));
\r
154 hlegend = new Button(hideGroup, support, SWT.CHECK);
\r
155 hlegend.setText("Legend");
\r
156 hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));
\r
157 hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));
\r
158 hlabels = new Button(hideGroup, support, SWT.CHECK);
\r
159 hlabels.setText("Section labels");
\r
160 hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));
\r
161 hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));
\r
164 filteringGroup = new Group(composite, SWT.NONE);
\r
165 filteringGroup.setText("Filter");
\r
166 labelUse = new Label(filteringGroup, SWT.NONE);
\r
167 labelUse.setText("Use:");
\r
168 useFilter = new Button(filteringGroup, support, SWT.CHECK);
\r
169 useFilter.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used, false));
\r
170 useFilter.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used));
\r
171 labelPercent = new Label(filteringGroup, SWT.NONE);
\r
172 labelPercent.setText("Percent:");
\r
173 fraction = new TrackedText(filteringGroup, support, SWT.BORDER);
\r
174 fraction.setTextFactory(new DoublePropertyFactory2(JFreeChartResource.URIs.Plot,JFreeChartResource.URIs.Filter_fraction));
\r
175 fraction.addModifyListener(new DoublePropertyModifier2(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_fraction));
\r
176 fraction.setInputValidator(new DoubleValidator(true));
\r
177 fraction.setColorProvider(new JFreeChartPropertyColorProvider(fraction.getResourceManager()));
\r
180 sc.setContent(composite);
\r
184 protected void createControlLayoutVertical() {
\r
185 // Scrolled composite containing all of the properties in this tab
\r
186 GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
\r
187 GridLayoutFactory.fillDefaults().applyTo(sc);
\r
190 GridLayoutFactory.fillDefaults().numColumns(1).margins(3, 3).applyTo(composite);
\r
192 GridLayoutFactory.fillDefaults().numColumns(1).margins(3, 3).applyTo(composite);
\r
194 // General properties
\r
195 GridDataFactory.fillDefaults().grab(true, false).applyTo(general);
\r
196 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(general);
\r
198 // first column: labels
\r
199 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);
\r
200 GridLayoutFactory.fillDefaults().applyTo(labelColumn1);
\r
202 // first column: name and title
\r
203 GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);
\r
204 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);
\r
206 // first column: labels
\r
207 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);
\r
208 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);
\r
210 // first column: type and time
\r
211 GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);
\r
212 GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);
\r
215 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelName);
\r
217 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
\r
219 // Dummy data for now. Waiting for different pie chart types
\r
220 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelTitle);
\r
222 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelTitle);
\r
224 // Title (Which is different than name)
\r
225 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelTitle);
\r
227 GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());
\r
231 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelTime);
\r
233 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());
\r
235 // Group for hide options
\r
236 GridDataFactory.fillDefaults().applyTo(hideGroup);
\r
237 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);
\r
240 GridDataFactory.fillDefaults().applyTo(filteringGroup);
\r
241 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(filteringGroup);
\r
242 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelUse);
\r
243 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelPercent);
\r
244 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fraction.getWidget());
\r
247 size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
248 sc.setMinSize(size);
\r
252 protected void createControlLayoutHorizontal(boolean wideScreen) {
\r
253 // Scrolled composite containing all of the properties in this tab
\r
254 GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
\r
255 GridLayoutFactory.fillDefaults().applyTo(sc);
\r
258 GridLayoutFactory.fillDefaults().numColumns(3).margins(3, 3).applyTo(composite);
\r
260 GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);
\r
262 // General properties
\r
263 GridDataFactory.fillDefaults().grab(true, false).applyTo(general);
\r
264 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general);
\r
266 // first column: labels
\r
267 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);
\r
268 GridLayoutFactory.fillDefaults().applyTo(labelColumn1);
\r
270 // first column: name and title
\r
271 GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);
\r
272 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);
\r
274 // first column: labels
\r
275 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);
\r
276 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);
\r
278 // first column: type and time
\r
279 GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);
\r
280 GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);
\r
283 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelName);
\r
285 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
\r
287 // Dummy data for now. Waiting for different pie chart types
\r
288 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelTitle);
\r
290 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelTitle);
\r
292 // Title (Which is different than name)
\r
293 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelTitle);
\r
295 GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());
\r
299 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelTime);
\r
301 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());
\r
303 // Group for hide options
\r
304 GridDataFactory.fillDefaults().applyTo(hideGroup);
\r
305 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);
\r
308 GridDataFactory.fillDefaults().applyTo(filteringGroup);
\r
309 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(filteringGroup);
\r
310 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelUse);
\r
311 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(labelPercent);
\r
312 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fraction.getWidget());
\r
315 size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
316 sc.setMinSize(size);
\r