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