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.bar;
\r
14 import java.util.Collection;
\r
16 import org.eclipse.jface.layout.GridDataFactory;
\r
17 import org.eclipse.jface.layout.GridLayoutFactory;
\r
18 import org.eclipse.swt.SWT;
\r
19 import org.eclipse.swt.widgets.Composite;
\r
20 import org.eclipse.swt.widgets.Label;
\r
21 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;
\r
22 import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;
\r
23 import org.simantics.browsing.ui.swt.widgets.TrackedText;
\r
24 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
25 import org.simantics.db.management.ISessionContext;
\r
26 import org.simantics.jfreechart.ChartPropertyOptions;
\r
27 import org.simantics.jfreechart.chart.properties.ChartVariable;
\r
28 import org.simantics.jfreechart.chart.properties.ChartVariableFactory;
\r
29 import org.simantics.jfreechart.chart.properties.ChartVariableModifier;
\r
30 import org.simantics.jfreechart.chart.properties.DoubleValidator;
\r
31 import org.simantics.jfreechart.chart.properties.JFreeChartPropertyColorProvider;
\r
32 import org.simantics.jfreechart.chart.properties.RangeComposite;
\r
33 import org.simantics.jfreechart.chart.properties.StringChooser;
\r
34 import org.simantics.layer0.Layer0;
\r
35 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;
\r
36 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
\r
37 import org.simantics.sysdyn.JFreeChartResource;
\r
40 * Composite for modifying properties of a series in a bar chart
\r
41 * @author Teemu Lempinen
\r
44 public class BarSeriesPropertyComposite2 extends Composite {
\r
46 private TrackedText label, time;
\r
47 private StringChooser<ChartVariable> variable;
\r
49 public BarSeriesPropertyComposite2(Composite parent, final ISessionContext context, WidgetSupport support, Collection<ChartVariable> variables, int options, int style) {
\r
50 super(parent, style);
\r
52 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);
\r
54 // Variable for the series
\r
55 Label label = new Label(this, SWT.NONE);
\r
56 label.setText("Variable:");
\r
57 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
59 // variable = new TrackedText(this, support, SWT.BORDER);
\r
61 // // FIXME: using bijectionmap and trackedText looses the variables that have the same label.
\r
62 // BijectionMap<String , String> map = new BijectionMap<String, String>();
\r
63 // for (ChartVariable variable : variables) {
\r
64 // map.map(variable.getRvi(), variable.toString());
\r
66 // variable.setTextFactory(new VariableFactory(map));
\r
67 // variable.addModifyListener(new VariableModifier(variable.getWidget(), support));
\r
68 // variable.setInputValidator(new VariableExistsValidator(support, variable, false, true));
\r
71 variable = new StringChooser<ChartVariable>(this, support, SWT.BORDER);
\r
72 variable.setData(variables);
\r
73 variable.setObjectFactory(new ChartVariableFactory(variables));
\r
74 variable.addModifyListener(new ChartVariableModifier(variable.getWidget(), support));
\r
76 variable.setColorProvider(new JFreeChartPropertyColorProvider(this.variable.getResourceManager()));
\r
77 GridDataFactory.fillDefaults().grab(true, false).applyTo(this.variable.getWidget());
\r
80 label = new Label(this, SWT.NONE);
\r
81 label.setText("Range:");
\r
82 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
84 RangeComposite rangeComposite = new RangeComposite(this, context, support, SWT.NONE);
\r
85 GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeComposite);
\r
88 // Label to be displayed in chart for this series
\r
89 label = new Label(this, SWT.NONE);
\r
90 label.setText("Label:");
\r
91 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
93 this.label = new TrackedText(this, support, SWT.BORDER);
\r
94 this.label.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, ""));
\r
95 this.label.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));
\r
96 this.label.setColorProvider(new JFreeChartPropertyColorProvider(this.label.getResourceManager()));
\r
97 GridDataFactory.fillDefaults().grab(true, false).applyTo(this.label.getWidget());
\r
99 if ((options & ChartPropertyOptions.SHOW_TIME) > 0) {
\r
101 label = new Label(this, SWT.NONE);
\r
102 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
103 label.setText("Time:");
\r
105 Composite composite = new Composite(this, SWT.NONE);
\r
106 GridDataFactory.fillDefaults().applyTo(composite);
\r
107 GridLayoutFactory.fillDefaults().applyTo(composite);
\r
109 time = new org.simantics.browsing.ui.swt.widgets.TrackedText(composite, support, SWT.BORDER);
\r
110 time.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Series_time));
\r
111 time.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Series_time));
\r
112 time.setInputValidator(new DoubleValidator(true));
\r
113 time.setColorProvider(new JFreeChartPropertyColorProvider(time.getResourceManager()));
\r
114 GridDataFactory.fillDefaults().applyTo(time.getWidget());
\r