]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/org/simantics/processeditor/dialogs/PipelineDialog.java
fixing subclipse caused problems
[simantics/3d.git] / org.simantics.proconf.processeditor / src / org / simantics / processeditor / dialogs / PipelineDialog.java
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.dialogs;\r
12 \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
24 \r
25 public class PipelineDialog extends Dialog implements KeyListener{\r
26         Text pipeRadiusText;\r
27         Text turnRadiusText;\r
28         \r
29         double pipeDiameter = 0.0;\r
30         double turnRadius = 0.0;\r
31         \r
32         public PipelineDialog(Shell parentShell) {\r
33                 super(parentShell);\r
34         }\r
35         \r
36         public PipelineDialog(Shell parentShell, double pipeRadius, double turnRadius) {\r
37                 super(parentShell);\r
38                 this.pipeDiameter = pipeRadius;\r
39                 this.turnRadius = turnRadius;\r
40         }\r
41 \r
42         \r
43         @Override\r
44         protected void configureShell(Shell newShell) {\r
45                 super.configureShell(newShell);\r
46                 newShell.setText("Configure new pipeline");\r
47         }\r
48         \r
49         @Override\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
57                 \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
73                 \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
79                 }\r
80                         \r
81                 \r
82                 return composite;\r
83         }\r
84         \r
85         @Override\r
86         public int open() {\r
87                 return super.open();\r
88         }\r
89         \r
90         \r
91         \r
92         \r
93         public void keyPressed(KeyEvent e) {\r
94                 \r
95                 \r
96         }\r
97         \r
98         public void keyReleased(KeyEvent e) {\r
99                 boolean ok = true;\r
100                 try {\r
101                         pipeDiameter = Double.parseDouble(pipeRadiusText.getText());\r
102                         turnRadius = Double.parseDouble(turnRadiusText.getText());\r
103                         if (pipeDiameter <= 0.0)\r
104                                 ok = false;\r
105                         if (turnRadius <= 0.0)\r
106                                 ok = false;\r
107                         \r
108                 } catch (NumberFormatException err) {\r
109                         ok = false;\r
110                 }\r
111                 if (ok) {\r
112                         this.getButton(IDialogConstants.OK_ID).setEnabled(true);\r
113                 } else {\r
114                         this.getButton(IDialogConstants.OK_ID).setEnabled(false);\r
115                 }\r
116         }\r
117 \r
118 \r
119         public double getPipeDiameter() {\r
120                 return pipeDiameter;\r
121         }\r
122 \r
123 \r
124         public double getTurnRadius() {\r
125                 return turnRadius;\r
126         }\r
127 \r
128 \r
129         \r
130         \r
131         \r
132 }\r