comparison dwt/browser.old/PromptDialog.d @ 288:4ee8c4237614

old branches... commit by mistake
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 18:00:50 -0700
parents
children
comparison
equal deleted inserted replaced
287:9cbe6285f746 288:4ee8c4237614
1 /*******************************************************************************
2 * Copyright (c) 2003, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 module dwt.browser.PromptDialog;
12
13 import dwt.dwthelper.utils;
14
15 import dwt.DWT;
16 import dwt.layout.GridData;
17 import dwt.layout.GridLayout;
18 import dwt.widgets.Button;
19 import dwt.widgets.Composite;
20 import dwt.widgets.Dialog;
21 import dwt.widgets.Display;
22 import dwt.widgets.Event;
23 import dwt.widgets.Label;
24 import dwt.widgets.Listener;
25 import dwt.widgets.Monitor;
26 import dwt.widgets.Shell;
27 import dwt.widgets.Text;
28 import dwt.widgets.Widget;
29
30 class PromptDialog extends Dialog {
31
32 PromptDialog(Shell parent, int style) {
33 super(parent, style);
34 }
35
36 PromptDialog(Shell parent) {
37 this(parent, 0);
38 }
39
40 void alertCheck(String title, String text, String check, ref int checkValue) {
41 Shell parent = getParent();
42 final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
43 if (title !is null) shell.setText(title);
44 GridLayout gridLayout = new GridLayout();
45 shell.setLayout(gridLayout);
46 Label label = new Label(shell, DWT.WRAP);
47 label.setText(text);
48 GridData data = new GridData();
49 Monitor monitor = parent.getMonitor();
50 int maxWidth = monitor.getBounds().width * 2 / 3;
51 int width = label.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
52 data.widthHint = Math.min(width, maxWidth);
53 data.horizontalAlignment = GridData.FILL;
54 data.grabExcessHorizontalSpace = true;
55 label.setLayoutData (data);
56
57 final Button checkButton = check !is null ? new Button(shell, DWT.CHECK) : null;
58 if (checkButton !is null) {
59 checkButton.setText(check);
60 checkButton.setSelection(checkValue[0] !is 0);
61 data = new GridData ();
62 data.horizontalAlignment = GridData.BEGINNING;
63 checkButton.setLayoutData (data);
64 }
65 Button okButton = new Button(shell, DWT.PUSH);
66 okButton.setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$
67 data = new GridData ();
68 data.horizontalAlignment = GridData.CENTER;
69 okButton.setLayoutData (data);
70 okButton.addListener(DWT.Selection, new Listener() {
71 public void handleEvent(Event event) {
72 if (checkButton !is null) checkValue[0] = checkButton.getSelection() ? 1 : 0;
73 shell.close();
74 }
75 });
76
77 shell.pack();
78 shell.open();
79 Display display = parent.getDisplay();
80 while (!shell.isDisposed()) {
81 if (!display.readAndDispatch()) display.sleep();
82 }
83 }
84
85 void confirmEx(String title, String text, String check, String button0, String button1, String button2, int defaultIndex, final int[] checkValue, final int[] result) {
86 Shell parent = getParent();
87 final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
88 shell.setText(title);
89 GridLayout gridLayout = new GridLayout();
90 shell.setLayout(gridLayout);
91 Label label = new Label(shell, DWT.WRAP);
92 label.setText(text);
93 GridData data = new GridData();
94 Monitor monitor = parent.getMonitor();
95 int maxWidth = monitor.getBounds().width * 2 / 3;
96 int width = label.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
97 data.widthHint = Math.min(width, maxWidth);
98 data.horizontalAlignment = GridData.FILL;
99 data.grabExcessHorizontalSpace = true;
100 label.setLayoutData (data);
101
102 final Button[] buttons = new Button[4];
103 Listener listener = new Listener() {
104 public void handleEvent(Event event) {
105 if (buttons[0] !is null) checkValue[0] = buttons[0].getSelection() ? 1 : 0;
106 Widget widget = event.widget;
107 for (int i = 1; i < buttons.length; i++) {
108 if (widget is buttons[i]) {
109 result[0] = i - 1;
110 break;
111 }
112 }
113 shell.close();
114 }
115 };
116 if (check !is null) {
117 buttons[0] = new Button(shell, DWT.CHECK);
118 buttons[0].setText(check);
119 buttons[0].setSelection(checkValue[0] !is 0);
120 data = new GridData ();
121 data.horizontalAlignment = GridData.BEGINNING;
122 buttons[0].setLayoutData (data);
123 }
124 Composite composite = new Composite(shell, DWT.NONE);
125 data = new GridData();
126 data.horizontalAlignment = GridData.CENTER;
127 composite.setLayoutData (data);
128 GridLayout layout = new GridLayout();
129 layout.makeColumnsEqualWidth = true;
130 composite.setLayout(layout);
131 int buttonCount = 0;
132 if (button0 !is null) {
133 buttons[1] = new Button(composite, DWT.PUSH);
134 buttons[1].setText(button0);
135 buttons[1].addListener(DWT.Selection, listener);
136 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
137 buttonCount++;
138 }
139 if (button1 !is null) {
140 buttons[2] = new Button(composite, DWT.PUSH);
141 buttons[2].setText(button1);
142 buttons[2].addListener(DWT.Selection, listener);
143 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
144 buttonCount++;
145 }
146 if (button2 !is null) {
147 buttons[3] = new Button(composite, DWT.PUSH);
148 buttons[3].setText(button2);
149 buttons[3].addListener(DWT.Selection, listener);
150 buttons[3].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
151 buttonCount++;
152 }
153 layout.numColumns = buttonCount;
154 Button defaultButton = buttons [defaultIndex + 1];
155 if (defaultButton !is null) shell.setDefaultButton (defaultButton);
156
157 shell.pack();
158 shell.open();
159 Display display = parent.getDisplay();
160 while (!shell.isDisposed()) {
161 if (!display.readAndDispatch()) display.sleep();
162 }
163 }
164
165 void prompt(String title, String text, String check, final String[] value, final int[] checkValue, final int[] result) {
166 Shell parent = getParent();
167 final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
168 if (title !is null) shell.setText(title);
169 GridLayout gridLayout = new GridLayout();
170 shell.setLayout(gridLayout);
171 Label label = new Label(shell, DWT.WRAP);
172 label.setText(text);
173 GridData data = new GridData();
174 Monitor monitor = parent.getMonitor();
175 int maxWidth = monitor.getBounds().width * 2 / 3;
176 int width = label.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
177 data.widthHint = Math.min(width, maxWidth);
178 data.horizontalAlignment = GridData.FILL;
179 data.grabExcessHorizontalSpace = true;
180 label.setLayoutData (data);
181
182 final Text valueText = new Text(shell, DWT.BORDER);
183 if (value[0] !is null) valueText.setText(value[0]);
184 data = new GridData();
185 width = valueText.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
186 if (width > maxWidth) data.widthHint = maxWidth;
187 data.horizontalAlignment = GridData.FILL;
188 data.grabExcessHorizontalSpace = true;
189 valueText.setLayoutData(data);
190
191 final Button[] buttons = new Button[3];
192 Listener listener = new Listener() {
193 public void handleEvent(Event event) {
194 if (buttons[0] !is null) checkValue[0] = buttons[0].getSelection() ? 1 : 0;
195 value[0] = valueText.getText();
196 result[0] = event.widget is buttons[1] ? 1 : 0;
197 shell.close();
198 }
199 };
200 if (check !is null) {
201 buttons[0] = new Button(shell, DWT.CHECK);
202 buttons[0].setText(check);
203 buttons[0].setSelection(checkValue[0] !is 0);
204 data = new GridData ();
205 data.horizontalAlignment = GridData.BEGINNING;
206 buttons[0].setLayoutData (data);
207 }
208 Composite composite = new Composite(shell, DWT.NONE);
209 data = new GridData();
210 data.horizontalAlignment = GridData.CENTER;
211 composite.setLayoutData (data);
212 composite.setLayout(new GridLayout(2, true));
213 buttons[1] = new Button(composite, DWT.PUSH);
214 buttons[1].setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$
215 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
216 buttons[1].addListener(DWT.Selection, listener);
217 buttons[2] = new Button(composite, DWT.PUSH);
218 buttons[2].setText(DWT.getMessage("SWT_Cancel")); //$NON-NLS-1$
219 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
220 buttons[2].addListener(DWT.Selection, listener);
221
222 shell.pack();
223 shell.open();
224 Display display = parent.getDisplay();
225 while (!shell.isDisposed()) {
226 if (!display.readAndDispatch()) display.sleep();
227 }
228 }
229
230 void promptUsernameAndPassword(String title, String text, String check, final String[] user, final String[] pass, final int[] checkValue, final int[] result) {
231 Shell parent = getParent();
232 final Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL);
233 shell.setText(title);
234 GridLayout gridLayout = new GridLayout();
235 shell.setLayout(gridLayout);
236 Label label = new Label(shell, DWT.WRAP);
237 label.setText(text);
238 GridData data = new GridData();
239 Monitor monitor = parent.getMonitor();
240 int maxWidth = monitor.getBounds().width * 2 / 3;
241 int width = label.computeSize(DWT.DEFAULT, DWT.DEFAULT).x;
242 data.widthHint = Math.min(width, maxWidth);
243 data.horizontalAlignment = GridData.FILL;
244 data.grabExcessHorizontalSpace = true;
245 label.setLayoutData (data);
246
247 Label userLabel = new Label(shell, DWT.NONE);
248 userLabel.setText(DWT.getMessage("SWT_Username")); //$NON-NLS-1$
249
250 final Text userText = new Text(shell, DWT.BORDER);
251 if (user[0] !is null) userText.setText(user[0]);
252 data = new GridData();
253 data.horizontalAlignment = GridData.FILL;
254 data.grabExcessHorizontalSpace = true;
255 userText.setLayoutData(data);
256
257 Label passwordLabel = new Label(shell, DWT.NONE);
258 passwordLabel.setText(DWT.getMessage("SWT_Password")); //$NON-NLS-1$
259
260 final Text passwordText = new Text(shell, DWT.PASSWORD | DWT.BORDER);
261 if (pass[0] !is null) passwordText.setText(pass[0]);
262 data = new GridData();
263 data.horizontalAlignment = GridData.FILL;
264 data.grabExcessHorizontalSpace = true;
265 passwordText.setLayoutData(data);
266
267 final Button[] buttons = new Button[3];
268 Listener listener = new Listener() {
269 public void handleEvent(Event event) {
270 if (buttons[0] !is null) checkValue[0] = buttons[0].getSelection() ? 1 : 0;
271 user[0] = userText.getText();
272 pass[0] = passwordText.getText();
273 result[0] = event.widget is buttons[1] ? 1 : 0;
274 shell.close();
275 }
276 };
277 if (check !is null) {
278 buttons[0] = new Button(shell, DWT.CHECK);
279 buttons[0].setText(check);
280 buttons[0].setSelection(checkValue[0] !is 0);
281 data = new GridData ();
282 data.horizontalAlignment = GridData.BEGINNING;
283 buttons[0].setLayoutData (data);
284 }
285 Composite composite = new Composite(shell, DWT.NONE);
286 data = new GridData();
287 data.horizontalAlignment = GridData.CENTER;
288 composite.setLayoutData (data);
289 composite.setLayout(new GridLayout(2, true));
290 buttons[1] = new Button(composite, DWT.PUSH);
291 buttons[1].setText(DWT.getMessage("SWT_OK")); //$NON-NLS-1$
292 buttons[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
293 buttons[1].addListener(DWT.Selection, listener);
294 buttons[2] = new Button(composite, DWT.PUSH);
295 buttons[2].setText(DWT.getMessage("SWT_Cancel")); //$NON-NLS-1$
296 buttons[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
297 buttons[2].addListener(DWT.Selection, listener);
298
299 shell.setDefaultButton(buttons[1]);
300 shell.pack();
301 shell.open();
302 Display display = parent.getDisplay();
303 while (!shell.isDisposed()) {
304 if (!display.readAndDispatch()) display.sleep();
305 }
306 }
307 }