1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package fi.vtt.simantics.processeditor.dialogs;
\r
13 import org.eclipse.jface.dialogs.Dialog;
\r
14 import org.eclipse.jface.dialogs.IDialogConstants;
\r
15 import org.eclipse.swt.SWT;
\r
16 import org.eclipse.swt.events.KeyEvent;
\r
17 import org.eclipse.swt.events.KeyListener;
\r
18 import org.eclipse.swt.layout.GridData;
\r
19 import org.eclipse.swt.widgets.Composite;
\r
20 import org.eclipse.swt.widgets.Control;
\r
21 import org.eclipse.swt.widgets.Label;
\r
22 import org.eclipse.swt.widgets.Shell;
\r
23 import org.eclipse.swt.widgets.Text;
\r
25 public class PipelineDialog extends Dialog implements KeyListener{
\r
26 Text pipeRadiusText;
\r
27 Text turnRadiusText;
\r
29 double pipeDiameter = 0.0;
\r
30 double turnRadius = 0.0;
\r
32 public PipelineDialog(Shell parentShell) {
\r
36 public PipelineDialog(Shell parentShell, double pipeRadius, double turnRadius) {
\r
38 this.pipeDiameter = pipeRadius;
\r
39 this.turnRadius = turnRadius;
\r
44 protected void configureShell(Shell newShell) {
\r
45 super.configureShell(newShell);
\r
46 newShell.setText("Configure new pipeline");
\r
50 protected Control createDialogArea(Composite parent) {
\r
51 Composite composite = (Composite) super.createDialogArea(parent);
\r
52 Label label = new Label(composite, SWT.WRAP);
\r
53 label.setText("Input pipeline specifications");
\r
54 GridData data = new GridData(GridData.GRAB_HORIZONTAL
\r
55 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
\r
56 | GridData.VERTICAL_ALIGN_CENTER);
\r
58 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
\r
59 label.setLayoutData(data);
\r
60 label.setFont(parent.getFont());
\r
61 label = new Label(composite, SWT.WRAP);
\r
62 label.setText("Pipe diameter");
\r
63 label.setLayoutData(data);
\r
64 label.setFont(parent.getFont());
\r
65 pipeRadiusText = new Text(composite,SWT.BORDER);
\r
66 pipeRadiusText.setLayoutData(data);
\r
67 label = new Label(composite, SWT.WRAP);
\r
68 label.setText("Pipe elbow/turn radius");
\r
69 label.setLayoutData(data);
\r
70 label.setFont(parent.getFont());
\r
71 turnRadiusText = new Text(composite,SWT.BORDER);
\r
72 turnRadiusText.setLayoutData(data);
\r
74 pipeRadiusText.addKeyListener(this);
\r
75 turnRadiusText.addKeyListener(this);
\r
76 if (pipeDiameter > 0.0 && turnRadius > 0.0) {
\r
77 pipeRadiusText.setText(Double.toString(pipeDiameter));
\r
78 turnRadiusText.setText(Double.toString(turnRadius));
\r
87 return super.open();
\r
93 public void keyPressed(KeyEvent e) {
\r
98 public void keyReleased(KeyEvent e) {
\r
101 pipeDiameter = Double.parseDouble(pipeRadiusText.getText());
\r
102 turnRadius = Double.parseDouble(turnRadiusText.getText());
\r
103 if (pipeDiameter <= 0.0)
\r
105 if (turnRadius <= 0.0)
\r
108 } catch (NumberFormatException err) {
\r
112 this.getButton(IDialogConstants.OK_ID).setEnabled(true);
\r
114 this.getButton(IDialogConstants.OK_ID).setEnabled(false);
\r
119 public double getPipeDiameter() {
\r
120 return pipeDiameter;
\r
124 public double getTurnRadius() {
\r