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.xyline;
\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
30 import org.simantics.sysdyn.ui.trend.chart.properties.AxisHidePropertyComposite;
\r
31 import org.simantics.sysdyn.ui.trend.chart.properties.ColorPicker;
\r
32 import org.simantics.sysdyn.ui.trend.chart.properties.JFreeChartPropertyColorProvider;
\r
35 * Composite for displaying axis properties in {@link XYLineAxisAndVariablesTab}
\r
37 * @author Teemu Lempinen
\r
40 public class AxisPropertyComposite extends Composite {
\r
42 TrackedText name, units, min, max;
\r
43 Button tlabels, tmarks;
\r
45 public AxisPropertyComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) {
\r
46 super(parent, style);
\r
48 GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(this);
\r
51 Label label = new Label(this, SWT.NONE);
\r
52 label.setText("Label: ");
\r
53 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
55 units = new TrackedText(this, support, SWT.BORDER);
\r
56 units.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel, "")); // FIXME: Units
\r
57 units.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel)); // FIXME: Units
\r
58 units.setColorProvider(new JFreeChartPropertyColorProvider(units.getResourceManager()));
\r
59 GridDataFactory.fillDefaults().grab(true, false).applyTo(units.getWidget());
\r
62 // Minimum and maximum values
\r
63 label = new Label(this, SWT.NONE);
\r
64 label.setText("Min:");
\r
65 GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);
\r
66 Composite minmax = new Composite(this, SWT.NONE);
\r
67 GridDataFactory.fillDefaults().applyTo(minmax);
\r
68 GridLayoutFactory.fillDefaults().numColumns(3).applyTo(minmax);
\r
69 min = new TrackedText(minmax, support, SWT.BORDER);
\r
70 min.setColorProvider(new JFreeChartPropertyColorProvider(min.getResourceManager()));
\r
71 min.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_min));
\r
72 min.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_min));
\r
73 min.setInputValidator(new DoubleValidator());
\r
75 label = new Label(minmax, SWT.NONE);
\r
76 label.setText("Max:");
\r
77 max = new TrackedText(minmax, support, SWT.BORDER);
\r
78 max.setColorProvider(new JFreeChartPropertyColorProvider(max.getResourceManager()));
\r
79 max.setTextFactory(new DoublePropertyFactory(JFreeChartResource.URIs.Axis_max));
\r
80 max.addModifyListener(new DoublePropertyModifier(context, JFreeChartResource.URIs.Axis_max));
\r
81 max.setInputValidator(new DoubleValidator());
\r
85 label = new Label(this, SWT.NONE);
\r
86 label.setText("Color:");
\r
87 GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);
\r
89 Composite colorPicker = new ColorPicker(this, context, support, SWT.NONE);
\r
90 GridDataFactory.fillDefaults().grab(true, false).applyTo(colorPicker);
\r
92 // Tick and label visibility
\r
93 Composite c = new Composite(this, SWT.NONE);
\r
94 GridDataFactory.fillDefaults().span(2, 1).applyTo(c);
\r
95 GridLayoutFactory.fillDefaults().applyTo(c);
\r
96 Composite axisHide = new AxisHidePropertyComposite(c, context, support, SWT.NONE);
\r
97 GridDataFactory.fillDefaults().applyTo(axisHide);
\r
101 * Validator for validating that an input is double
\r
102 * @author Teemu Lempinen
\r
105 private class DoubleValidator implements IInputValidator {
\r
107 public String isValid(String newText) {
\r
108 if (newText.trim().isEmpty())
\r
111 Double.parseDouble(newText);
\r
113 } catch (NumberFormatException e) {
\r
114 return e.getMessage();
\r