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.sysdyn.ui.trend.chart.properties;
\r
14 import org.eclipse.jface.dialogs.IInputValidator;
\r
15 import org.eclipse.jface.layout.GridDataFactory;
\r
16 import org.eclipse.jface.layout.GridLayoutFactory;
\r
17 import org.eclipse.swt.SWT;
\r
18 import org.eclipse.swt.widgets.Composite;
\r
19 import org.eclipse.swt.widgets.Label;
\r
20 import org.simantics.browsing.ui.swt.widgets.Button;
\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.layer0.Layer0;
\r
27 import org.simantics.modeling.ui.chart.property.DoublePropertyFactory;
\r
28 import org.simantics.modeling.ui.chart.property.DoublePropertyModifier;
\r
29 import org.simantics.sysdyn.JFreeChartResource;
\r
32 * Composite for displaying axis properties in {@link ChartAxisAndVariablesTab}
\r
34 * @author Teemu Lempinen
\r
37 public class AxisPropertyComposite extends Composite {
\r
39 TrackedText name, units, min, max;
\r
40 Button tlabels, tmarks;
\r
42 public AxisPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) {
\r
43 super(parent, style);
\r
45 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);
\r
48 Label label = new Label(this, SWT.NONE);
\r
49 label.setText("Label: ");
\r
50 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
52 units = new TrackedText(this, support, SWT.BORDER);
\r
53 units.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); // FIXME: Units
\r
54 units.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); // FIXME: Units
\r
55 units.setColorProvider(new JFreeChartPropertyColorProvider(units.getResourceManager()));
\r
56 GridDataFactory.fillDefaults().grab(true, false).applyTo(units.getWidget());
\r
59 // Minimum and maximum values
\r
60 label = new Label(this, SWT.NONE);
\r
61 label.setText("Min:");
\r
62 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
63 Composite minmax = new Composite(this, SWT.NONE);
\r
64 GridDataFactory.fillDefaults().applyTo(minmax);
\r
65 GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax);
\r
66 min = new TrackedText(minmax, support, SWT.BORDER);
\r
67 min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager()));
\r
68 min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));
\r
69 min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));
\r
70 min.setInputValidator(new DoubleValidator());
\r
72 label = new Label(minmax, SWT.NONE);
\r
73 label.setText("Max:");
\r
74 max = new TrackedText(minmax, support, SWT.BORDER);
\r
75 max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager()));
\r
76 max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));
\r
77 max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));
\r
78 max.setInputValidator(new DoubleValidator());
\r
82 label = new Label(this, SWT.NONE);
\r
83 label.setText("Color:");
\r
84 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
86 Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE);
\r
87 GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);
\r
89 // Tick and label visibility
\r
90 Composite c = new Composite(this, SWT.NONE);
\r
91 GridDataFactory.fillDefaults().span(2, 1).applyTo(c);
\r
92 GridLayoutFactory.fillDefaults().applyTo(c);
\r
93 Composite axisHide = new AxisHidePropertyComposite(c, context, support, SWT.NONE);
\r
94 GridDataFactory.fillDefaults().applyTo(axisHide);
\r
98 * Validator for validating that an input is double
\r
99 * @author Teemu Lempinen
\r
102 private class DoubleValidator implements IInputValidator {
\r
104 public String isValid(String newText) {
\r
105 if (newText.trim().isEmpty())
\r
108 Double.parseDouble(newText);
\r
110 } catch (NumberFormatException e) {
\r
111 return e.getMessage();
\r