]> gerrit.simantics Code Review - simantics/3d.git/blob - dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/dialogs/JMEDialog.java
9e2950db2ab385118b047cdd19957ff60923d51a
[simantics/3d.git] / dev / org.simantics.proconf.g3d / src / org / simantics / proconf / g3d / dialogs / JMEDialog.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.proconf.g3d.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.MouseAdapter;\r
17 import org.eclipse.swt.events.MouseEvent;\r
18 import org.eclipse.swt.events.SelectionAdapter;\r
19 import org.eclipse.swt.events.SelectionEvent;\r
20 import org.eclipse.swt.graphics.Color;\r
21 import org.eclipse.swt.graphics.RGB;\r
22 import org.eclipse.swt.layout.GridData;\r
23 import org.eclipse.swt.widgets.Button;\r
24 import org.eclipse.swt.widgets.ColorDialog;\r
25 import org.eclipse.swt.widgets.Composite;\r
26 import org.eclipse.swt.widgets.Control;\r
27 import org.eclipse.swt.widgets.Label;\r
28 import org.eclipse.swt.widgets.Shell;\r
29 \r
30 public class JMEDialog extends Dialog {\r
31         private boolean bounds;\r
32         private boolean normals;\r
33         private boolean wireframe;\r
34         private float[] floatColor = null;\r
35         private Button boundsButton;\r
36         private Button normalsButton;\r
37         private Button wireframeButton;\r
38         private Composite colorComposite;\r
39         private Color color = null;\r
40         \r
41         public JMEDialog(Shell parentShell) {\r
42                 super(parentShell);\r
43         }\r
44 \r
45         \r
46         @Override\r
47         protected void configureShell(Shell newShell) {\r
48                 super.configureShell(newShell);\r
49                 newShell.setText("Configure new pipeline");\r
50         }\r
51         \r
52         @Override\r
53         protected Control createDialogArea(Composite parent) {\r
54                 Composite composite = (Composite) super.createDialogArea(parent);\r
55                 Label label = new Label(composite, SWT.WRAP);\r
56         label.setText("JME Configuration");\r
57         GridData data = new GridData(GridData.GRAB_HORIZONTAL\r
58                 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
59                 | GridData.VERTICAL_ALIGN_CENTER);\r
60                 \r
61         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
62         boundsButton = new Button(composite,SWT.CHECK);\r
63         boundsButton.setText("Show bounds");\r
64         boundsButton.addSelectionListener(new SelectionAdapter() {\r
65                 @Override\r
66                 public void widgetSelected(SelectionEvent e) {\r
67                         bounds = boundsButton.getSelection();\r
68                 }\r
69         });\r
70         boundsButton.setSelection(bounds);\r
71         normalsButton = new Button(composite,SWT.CHECK);\r
72         normalsButton.setText("Show normals");\r
73         normalsButton.addSelectionListener(new SelectionAdapter() {\r
74                 @Override\r
75                 public void widgetSelected(SelectionEvent e) {\r
76                         normals = normalsButton.getSelection();\r
77                 }\r
78         });\r
79         normalsButton.setSelection(normals);\r
80         wireframeButton = new Button(composite,SWT.CHECK);\r
81         wireframeButton.setText("Show wireframe");\r
82         wireframeButton.addSelectionListener(new SelectionAdapter() {\r
83                 @Override\r
84                 public void widgetSelected(SelectionEvent e) {\r
85                         wireframe = wireframeButton.getSelection();\r
86                 }\r
87         });\r
88         wireframeButton.setSelection(wireframe);\r
89         \r
90         colorComposite = new Composite(composite,SWT.BORDER);\r
91         colorComposite.addMouseListener(new MouseAdapter() {\r
92                 @Override\r
93                 public void mouseUp(MouseEvent e) {\r
94                         ColorDialog dialog = new ColorDialog(JMEDialog.this.getShell());\r
95                         RGB rgb = dialog.open();\r
96                         if (rgb != null) {\r
97                                 if (color != null)\r
98                                         color.dispose();\r
99                                 color = new Color(JMEDialog.this.getShell().getDisplay(),rgb);\r
100                                 colorComposite.setBackground(color);\r
101                                 floatColor = new float[]{rgb.red/255.f,rgb.green/255.f,rgb.blue/255.f};\r
102                         }\r
103                 }\r
104         });\r
105                 updateColor();\r
106                 \r
107                 return composite;\r
108         }\r
109         \r
110         @Override\r
111         public int open() {\r
112                 return super.open();\r
113         }\r
114 \r
115 \r
116         public boolean isBounds() {\r
117                 return bounds;\r
118         }\r
119 \r
120 \r
121         public void setBounds(boolean bounds) {\r
122                 this.bounds = bounds;\r
123         }\r
124 \r
125 \r
126         public boolean isNormals() {\r
127                 return normals;\r
128         }\r
129 \r
130 \r
131         public void setNormals(boolean normals) {\r
132                 this.normals = normals;\r
133         }\r
134 \r
135 \r
136         public boolean isWireframe() {\r
137                 return wireframe;\r
138         }\r
139 \r
140 \r
141         public void setWireframe(boolean wireframe) {\r
142                 this.wireframe = wireframe;\r
143         }\r
144         \r
145         \r
146         public float[] getFloatColor() {\r
147                 return floatColor;\r
148         }\r
149 \r
150         public void setFloatColor(float[] c) {\r
151                 this.floatColor = c;\r
152                 if (floatColor == null)\r
153                         return;\r
154                 \r
155                 updateColor();\r
156         }\r
157         \r
158         private void updateColor() {\r
159                 if (colorComposite == null)\r
160                         return;\r
161                 if (color != null)\r
162                         color.dispose();\r
163                 RGB rgb = new RGB((int)(floatColor[0]*255.f),(int)(floatColor[1]*255.f),(int)(floatColor[2]*255.f));\r
164                 color = new Color(JMEDialog.this.getShell().getDisplay(),rgb);\r
165                 colorComposite.setBackground(color);\r
166         }\r
167 \r
168         \r
169 \r
170 \r
171         \r
172         \r
173         \r
174 }\r