1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 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.BooleanPropertyFactory;
\r
32 import org.simantics.jfreechart.chart.properties.BooleanSelectionListener;
\r
33 import org.simantics.jfreechart.chart.properties.DoublePropertyFactory2;
\r
34 import org.simantics.jfreechart.chart.properties.DoublePropertyModifier2;
\r
35 import org.simantics.jfreechart.chart.properties.DoubleValidator;
\r
36 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;
\r
37 import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor;
\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
50 public class PieGeneralPropertiesTab extends LabelPropertyTabContributor {
\r
52 private ScrolledComposite sc;
\r
53 private Composite composite;
\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
60 public PieGeneralPropertiesTab() {
\r
64 public PieGeneralPropertiesTab(int options) {
\r
65 showTime = ((options & ChartPropertyOptions.SHOW_TIME) > 0);
\r
66 showFilter = ((options & ChartPropertyOptions.SHOW_FILTER) > 0);
\r
70 public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {
\r
71 // Scrolled composite containing all of the properties in this tab
\r
72 sc = new ScrolledComposite(body, SWT.NONE | SWT.H_SCROLL | SWT.V_SCROLL);
\r
73 GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
\r
74 GridLayoutFactory.fillDefaults().applyTo(sc);
\r
75 sc.setExpandHorizontal(true);
\r
76 sc.setExpandVertical(true);
\r
78 composite = new Composite(sc, SWT.NONE);
\r
80 GridLayoutFactory.fillDefaults().numColumns(3).margins(3, 3).applyTo(composite);
\r
82 GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite);
\r
84 // General properties
\r
85 Group general = new Group(composite, SWT.NONE);
\r
86 GridDataFactory.fillDefaults().grab(true, false).applyTo(general);
\r
87 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(4).applyTo(general);
\r
88 general.setText("General");
\r
90 // first column: labels
\r
91 Composite labelColumn1 = new Composite(general, SWT.NONE);
\r
92 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn1);
\r
93 GridLayoutFactory.fillDefaults().applyTo(labelColumn1);
\r
95 // first column: name and title
\r
96 Composite propertyColumn1 = new Composite(general, SWT.NONE);
\r
97 GridDataFactory.fillDefaults().grab(true, true).applyTo(propertyColumn1);
\r
98 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(propertyColumn1);
\r
100 // first column: labels
\r
101 Composite labelColumn2 = new Composite(general, SWT.NONE);
\r
102 GridDataFactory.fillDefaults().grab(false, true).applyTo(labelColumn2);
\r
103 GridLayoutFactory.fillDefaults().spacing(0, LayoutConstants.getSpacing().y).applyTo(labelColumn2);
\r
105 // first column: type and time
\r
106 Composite propertyColumn2 = new Composite(general, SWT.NONE);
\r
107 GridDataFactory.fillDefaults().grab(false, true).applyTo(propertyColumn2);
\r
108 GridLayoutFactory.fillDefaults().applyTo(propertyColumn2);
\r
111 Label label = new Label(labelColumn1, SWT.NONE);
\r
112 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
113 label.setText("Name:");
\r
115 name = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
116 GridDataFactory.fillDefaults().grab(true, false).applyTo(name.getWidget());
\r
117 name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));
\r
118 name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
119 name.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
121 // Dummy data for now. Waiting for different pie chart types
\r
122 label = new Label(labelColumn2, SWT.NONE);
\r
123 GridDataFactory.fillDefaults().grab(false, true).applyTo(label);
\r
126 label = new Label(propertyColumn2, SWT.NONE);
\r
127 GridDataFactory.fillDefaults().grab(false, true).applyTo(label);
\r
130 // Title (Which is different than name)
\r
131 label = new Label(labelColumn1, SWT.NONE);
\r
132 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
133 label.setText("Title:");
\r
135 title = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn1, support, SWT.BORDER);
\r
136 GridDataFactory.fillDefaults().grab(true, false).applyTo(title.getWidget());
\r
137 title.setTextFactory(new TitleFactory());
\r
138 title.addModifyListener(new TitleModifier());
\r
139 title.setColorProvider(new JFreeChartPropertyColorProvider(name.getResourceManager()));
\r
143 label = new Label(labelColumn2, SWT.NONE);
\r
144 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
145 label.setText("Time:");
\r
147 time = new org.simantics.browsing.ui.swt.widgets.TrackedText(propertyColumn2, support, SWT.BORDER);
\r
148 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(time.getWidget());
\r
149 time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Chart_time));
\r
150 time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Chart_time));
\r
151 time.setInputValidator(new DoubleValidator(true));
\r
152 time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));
\r
154 // Group for hide options
\r
155 Group hideGroup = new Group(composite, SWT.NONE);
\r
156 GridDataFactory.fillDefaults().applyTo(hideGroup);
\r
157 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(hideGroup);
\r
158 hideGroup.setText("Hide");
\r
160 htitle = new Button(hideGroup, support, SWT.CHECK);
\r
161 htitle.setText("Title");
\r
162 htitle.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible, true));
\r
163 htitle.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.TextTitle, JFreeChartResource.URIs.visible));
\r
164 hlegend = new Button(hideGroup, support, SWT.CHECK);
\r
165 hlegend.setText("Legend");
\r
166 hlegend.setSelectionFactory(new BooleanPropertyFactory(null, JFreeChartResource.URIs.Chart_visibleLegend, true));
\r
167 hlegend.addSelectionListener(new BooleanSelectionListener(context, null, JFreeChartResource.URIs.Chart_visibleLegend));
\r
168 hlabels = new Button(hideGroup, support, SWT.CHECK);
\r
169 hlabels.setText("Section labels");
\r
170 hlabels.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels, true));
\r
171 hlabels.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Plot_visibleLabels));
\r
174 Group filteringGroup = new Group(composite, SWT.NONE);
\r
175 GridDataFactory.fillDefaults().applyTo(filteringGroup);
\r
176 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(filteringGroup);
\r
177 filteringGroup.setText("Filter");
\r
178 label = new Label(filteringGroup, SWT.NONE);
\r
179 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
180 label.setText("Use:");
\r
181 Button useFilter = new Button(filteringGroup, support, SWT.CHECK);
\r
182 useFilter.setSelectionFactory(new BooleanPropertyFactory(JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used, false));
\r
183 useFilter.addSelectionListener(new BooleanSelectionListener(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_used));
\r
184 label = new Label(filteringGroup, SWT.NONE);
\r
185 GridDataFactory.fillDefaults().grab(false, true).align(SWT.END, SWT.CENTER).applyTo(label);
\r
186 label.setText("Percent:");
\r
187 TrackedText fraction = new TrackedText(filteringGroup, support, SWT.BORDER);
\r
188 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(fraction.getWidget());
\r
189 fraction.setTextFactory(new DoublePropertyFactory2(JFreeChartResource.URIs.Plot,JFreeChartResource.URIs.Filter_fraction));
\r
190 fraction.addModifyListener(new DoublePropertyModifier2(context, JFreeChartResource.URIs.Plot, JFreeChartResource.URIs.Filter_fraction));
\r
191 fraction.setInputValidator(new DoubleValidator(true));
\r
192 fraction.setColorProvider(new JFreeChartPropertyColorProvider(fraction.getResourceManager()));
\r
195 sc.setContent(composite);
\r
196 Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
\r
197 sc.setMinSize(size);
\r