]> gerrit.simantics Code Review - simantics/3d.git/blob
b1ea4e1a543172ab03038b66263e87de7b16e22f
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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.events.SelectionEvent;\r
19 import org.eclipse.swt.events.SelectionListener;\r
20 import org.eclipse.swt.layout.GridData;\r
21 import org.eclipse.swt.widgets.Button;\r
22 import org.eclipse.swt.widgets.Composite;\r
23 import org.eclipse.swt.widgets.Control;\r
24 import org.eclipse.swt.widgets.Label;\r
25 import org.eclipse.swt.widgets.Shell;\r
26 import org.eclipse.swt.widgets.Text;\r
27 \r
28 public class FloorConfigureDialog extends Dialog implements KeyListener,SelectionListener {\r
29         \r
30         private boolean floorEnabled = true;\r
31         private double floorHeight = 0.0;\r
32         \r
33         private Text floorHeightText = null;\r
34         private Button floorEnabledButton = null;\r
35         \r
36         public FloorConfigureDialog(Shell shell) {\r
37                 super(shell);\r
38         }\r
39         \r
40         @Override\r
41         protected Control createDialogArea(Composite parent) {\r
42                 Composite composite = (Composite) super.createDialogArea(parent);\r
43                 Label label = new Label(composite, SWT.WRAP);\r
44         label.setText("Configure floor");\r
45         GridData data = new GridData(GridData.GRAB_HORIZONTAL\r
46                 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
47                 | GridData.VERTICAL_ALIGN_CENTER);\r
48                 \r
49         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
50         label.setLayoutData(data);\r
51         label.setFont(parent.getFont());\r
52         floorEnabledButton = new Button(composite,SWT.CHECK);\r
53         floorEnabledButton.setText("Enabled");\r
54         label = new Label(composite, SWT.WRAP);\r
55         label.setText("Height");\r
56         label.setLayoutData(data);\r
57         label.setFont(parent.getFont());\r
58         floorHeightText = new Text(composite,SWT.NONE);\r
59                 \r
60                 \r
61         floorHeightText.addKeyListener(this);\r
62                 floorEnabledButton.addSelectionListener(this);\r
63                 floorEnabledButton.setSelection(floorEnabled);\r
64                 floorHeightText.setText(Double.toString(floorHeight));\r
65                 \r
66                 return composite;\r
67         }\r
68         \r
69         @Override\r
70         protected void configureShell(Shell newShell) {\r
71                 super.configureShell(newShell);\r
72                 newShell.setText("Configure floor");\r
73         }\r
74         \r
75         public void keyPressed(KeyEvent e) {\r
76                 \r
77         }\r
78         \r
79         public void keyReleased(KeyEvent e) {\r
80                 boolean ok = true;\r
81                 try {\r
82                         floorHeight = Double.parseDouble(floorHeightText.getText());    \r
83                 } catch (NumberFormatException err) {\r
84                         ok = false;\r
85                 }\r
86                 if (ok) {\r
87                         this.getButton(IDialogConstants.OK_ID).setEnabled(true);\r
88                 } else {\r
89                         this.getButton(IDialogConstants.OK_ID).setEnabled(false);\r
90                 }\r
91         }\r
92         \r
93         public void widgetDefaultSelected(SelectionEvent e) {\r
94                 \r
95         }\r
96         \r
97         public void widgetSelected(SelectionEvent e) {\r
98                 floorEnabled = floorEnabledButton.getSelection();\r
99         }\r
100 \r
101         public boolean isFloorEnabled() {\r
102                 return floorEnabled;\r
103         }\r
104 \r
105         public double getFloorHeight() {\r
106                 return floorHeight;\r
107         }\r
108 \r
109 }\r