Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/Dialog.d @ 60:f44bd8465f2f
Fix Dialog.getButton
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 14 Apr 2008 00:46:30 +0200 |
parents | ea8ff534f622 |
children | 46a6e0e6ccd4 |
rev | line source |
---|---|
8 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.dialogs.Dialog; | |
14 | |
15 import dwtx.jface.dialogs.IDialogBlockedHandler; | |
16 import dwtx.jface.dialogs.IDialogSettings; | |
17 import dwtx.jface.dialogs.IDialogConstants; | |
18 // import tango.util.Arrays; | |
19 | |
20 import dwt.DWT; | |
21 import dwt.events.SelectionAdapter; | |
22 import dwt.events.SelectionEvent; | |
23 import dwt.graphics.Font; | |
24 import dwt.graphics.FontData; | |
25 import dwt.graphics.FontMetrics; | |
26 import dwt.graphics.GC; | |
27 import dwt.graphics.Image; | |
28 import dwt.graphics.Point; | |
29 import dwt.layout.FormData; | |
30 import dwt.layout.GridData; | |
31 import dwt.layout.GridLayout; | |
32 import dwt.widgets.Button; | |
33 import dwt.widgets.Composite; | |
34 import dwt.widgets.Control; | |
35 import dwt.widgets.Display; | |
36 import dwt.widgets.Shell; | |
37 import dwtx.core.runtime.IProgressMonitor; | |
38 import dwtx.core.runtime.IStatus; | |
39 import dwtx.core.runtime.Status; | |
40 import dwtx.jface.resource.JFaceResources; | |
41 import dwtx.jface.util.Policy; | |
42 import dwtx.jface.window.IShellProvider; | |
43 import dwtx.jface.window.SameShellProvider; | |
44 import dwtx.jface.window.Window; | |
45 | |
46 import dwt.dwthelper.utils; | |
47 | |
48 /** | |
49 * A dialog is a specialized window used for narrow-focused communication with | |
50 * the user. | |
51 * <p> | |
52 * Dialogs are usually modal. Consequently, it is generally bad practice to open | |
53 * a dialog without a parent. A modal dialog without a parent is not prevented | |
54 * from disappearing behind the application's other windows, making it very | |
55 * confusing for the user. | |
56 * </p> | |
57 * <p> | |
58 * If there is more than one modal dialog is open the second one should be | |
59 * parented off of the shell of the first one otherwise it is possible that the | |
60 * OS will give focus to the first dialog potentially blocking the UI. | |
61 * </p> | |
62 */ | |
63 public abstract class Dialog : Window { | |
64 /** | |
65 * Image registry key for error image (value | |
66 * <code>"dialog_error_image"</code>). | |
67 * | |
68 * @deprecated use | |
69 * dwt.widgets.Display.getSystemImage(DWT.ICON_ERROR) | |
70 */ | |
71 public static const String DLG_IMG_ERROR = "dialog_error_image"; //$NON-NLS-1$ | |
72 | |
73 /** | |
74 * Image registry key for info image (value <code>"dialog_info_image"</code>). | |
75 * | |
76 * @deprecated use | |
77 * dwt.widgets.Display.getSystemImage(DWT.ICON_INFORMATION) | |
78 */ | |
79 public static const String DLG_IMG_INFO = "dialog_info_imageg"; //$NON-NLS-1$ | |
80 | |
81 /** | |
82 * Image registry key for question image (value | |
83 * <code>"dialog_question_image"</code>). | |
84 * | |
85 * @deprecated dwt.widgets.Display.getSystemImage(DWT.ICON_QUESTION) | |
86 */ | |
87 public static const String DLG_IMG_QUESTION = "dialog_question_image"; //$NON-NLS-1$ | |
88 | |
89 /** | |
90 * Image registry key for warning image (value | |
91 * <code>"dialog_warning_image"</code>). | |
92 * | |
93 * @deprecated use | |
94 * dwt.widgets.Display.getSystemImage(DWT.ICON_WARNING) | |
95 */ | |
96 public static const String DLG_IMG_WARNING = "dialog_warning_image"; //$NON-NLS-1$ | |
97 | |
98 /** | |
99 * Image registry key for info message image (value | |
100 * <code>"dialog_messasge_info_image"</code>). | |
101 * | |
102 * @since 2.0 | |
103 */ | |
104 public static const String DLG_IMG_MESSAGE_INFO = "dialog_messasge_info_image"; //$NON-NLS-1$ | |
105 | |
106 /** | |
107 * Image registry key for info message image (value | |
108 * <code>"dialog_messasge_warning_image"</code>). | |
109 * | |
110 * @since 2.0 | |
111 */ | |
112 public static const String DLG_IMG_MESSAGE_WARNING = "dialog_messasge_warning_image"; //$NON-NLS-1$ | |
113 | |
114 /** | |
115 * Image registry key for info message image (value | |
116 * <code>"dialog_message_error_image"</code>). | |
117 * | |
118 * @since 2.0 | |
119 */ | |
120 public static const String DLG_IMG_MESSAGE_ERROR = "dialog_message_error_image"; //$NON-NLS-1$ | |
121 | |
122 /** | |
123 * Image registry key for help image (value | |
124 * <code>"dialog_help_image"</code>). | |
125 * | |
126 * @since 3.2 | |
127 */ | |
128 public static const String DLG_IMG_HELP = "dialog_help_image"; //$NON-NLS-1$ | |
129 | |
130 /** | |
131 * The ellipsis is the string that is used to represent shortened text. | |
132 * | |
133 * @since 3.0 | |
134 */ | |
135 public static const String ELLIPSIS = "..."; //$NON-NLS-1$ | |
136 | |
137 /** | |
138 * The dialog settings key name for stored dialog x location. | |
139 * | |
140 * @since 3.2 | |
141 */ | |
142 private static const String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$ | |
143 | |
144 /** | |
145 * The dialog settings key name for stored dialog y location. | |
146 * | |
147 * @since 3.2 | |
148 */ | |
149 private static const String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$ | |
150 | |
151 /** | |
152 * The dialog settings key name for stored dialog width. | |
153 * | |
154 * @since 3.2 | |
155 */ | |
156 private static const String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$ | |
157 | |
158 /** | |
159 * The dialog settings key name for stored dialog height. | |
160 * | |
161 * @since 3.2 | |
162 */ | |
163 private static const String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$ | |
164 | |
165 /** | |
166 * The dialog settings key name for the font used when the dialog | |
167 * height and width was stored. | |
168 * | |
169 *@since 3.2 | |
170 */ | |
171 private static const String DIALOG_FONT_DATA = "DIALOG_FONT_NAME"; //$NON-NLS-1$ | |
172 | |
173 /** | |
174 * A value that can be used for stored dialog width or height that | |
175 * indicates that the default bounds should be used. | |
176 * | |
177 * @since 3.2 | |
178 */ | |
179 public static const int DIALOG_DEFAULT_BOUNDS = -1; | |
180 | |
181 /** | |
182 * Constants that can be used for specifying the strategy for persisting | |
183 * dialog bounds. These constants represent bit masks that can be used | |
184 * together. | |
185 * | |
186 *@since 3.2 | |
187 */ | |
188 | |
189 /** | |
190 * Persist the last location of the dialog. | |
191 * @since 3.2 | |
192 */ | |
193 public static const int DIALOG_PERSISTLOCATION = 0x0001; | |
194 /** | |
195 * Persist the last known size of the dialog. | |
196 * @since 3.2 | |
197 */ | |
198 public static const int DIALOG_PERSISTSIZE = 0x0002; | |
199 | |
200 /** | |
201 * The dialog area; <code>null</code> until dialog is layed out. | |
202 */ | |
203 protected Control dialogArea; | |
204 | |
205 /** | |
206 * The button bar; <code>null</code> until dialog is layed out. | |
207 */ | |
208 public Control buttonBar; | |
209 | |
210 /** | |
211 * Collection of buttons created by the <code>createButton</code> method. | |
212 */ | |
213 private Button[int] buttons; | |
214 | |
215 /** | |
216 * Font metrics to use for determining pixel sizes. | |
217 */ | |
218 private FontMetrics fontMetrics; | |
219 | |
220 /** | |
221 * Number of horizontal dialog units per character, value <code>4</code>. | |
222 */ | |
223 private static const int HORIZONTAL_DIALOG_UNIT_PER_CHAR = 4; | |
224 | |
225 /** | |
226 * Number of vertical dialog units per character, value <code>8</code>. | |
227 */ | |
228 private static const int VERTICAL_DIALOG_UNITS_PER_CHAR = 8; | |
229 | |
230 /** | |
231 * Returns the number of pixels corresponding to the height of the given | |
232 * number of characters. | |
233 * <p> | |
234 * The required <code>FontMetrics</code> parameter may be created in the | |
235 * following way: <code> | |
236 * GC gc = new GC(control); | |
237 * gc.setFont(control.getFont()); | |
238 * fontMetrics = gc.getFontMetrics(); | |
239 * gc.dispose(); | |
240 * </code> | |
241 * </p> | |
242 * | |
243 * @param fontMetrics | |
244 * used in performing the conversion | |
245 * @param chars | |
246 * the number of characters | |
247 * @return the number of pixels | |
248 * @since 2.0 | |
249 */ | |
250 public static int convertHeightInCharsToPixels(FontMetrics fontMetrics, | |
251 int chars) { | |
252 return fontMetrics.getHeight() * chars; | |
253 } | |
254 | |
255 /** | |
256 * Returns the number of pixels corresponding to the given number of | |
257 * horizontal dialog units. | |
258 * <p> | |
259 * The required <code>FontMetrics</code> parameter may be created in the | |
260 * following way: <code> | |
261 * GC gc = new GC(control); | |
262 * gc.setFont(control.getFont()); | |
263 * fontMetrics = gc.getFontMetrics(); | |
264 * gc.dispose(); | |
265 * </code> | |
266 * </p> | |
267 * | |
268 * @param fontMetrics | |
269 * used in performing the conversion | |
270 * @param dlus | |
271 * the number of horizontal dialog units | |
272 * @return the number of pixels | |
273 * @since 2.0 | |
274 */ | |
275 public static int convertHorizontalDLUsToPixels(FontMetrics fontMetrics, | |
276 int dlus) { | |
277 // round to the nearest pixel | |
278 return (fontMetrics.getAverageCharWidth() * dlus + HORIZONTAL_DIALOG_UNIT_PER_CHAR / 2) | |
279 / HORIZONTAL_DIALOG_UNIT_PER_CHAR; | |
280 } | |
281 | |
282 /** | |
283 * Returns the number of pixels corresponding to the given number of | |
284 * vertical dialog units. | |
285 * <p> | |
286 * The required <code>FontMetrics</code> parameter may be created in the | |
287 * following way: <code> | |
288 * GC gc = new GC(control); | |
289 * gc.setFont(control.getFont()); | |
290 * fontMetrics = gc.getFontMetrics(); | |
291 * gc.dispose(); | |
292 * </code> | |
293 * </p> | |
294 * | |
295 * @param fontMetrics | |
296 * used in performing the conversion | |
297 * @param dlus | |
298 * the number of vertical dialog units | |
299 * @return the number of pixels | |
300 * @since 2.0 | |
301 */ | |
302 public static int convertVerticalDLUsToPixels(FontMetrics fontMetrics, | |
303 int dlus) { | |
304 // round to the nearest pixel | |
305 return (fontMetrics.getHeight() * dlus + VERTICAL_DIALOG_UNITS_PER_CHAR / 2) | |
306 / VERTICAL_DIALOG_UNITS_PER_CHAR; | |
307 } | |
308 | |
309 /** | |
310 * Returns the number of pixels corresponding to the width of the given | |
311 * number of characters. | |
312 * <p> | |
313 * The required <code>FontMetrics</code> parameter may be created in the | |
314 * following way: <code> | |
315 * GC gc = new GC(control); | |
316 * gc.setFont(control.getFont()); | |
317 * fontMetrics = gc.getFontMetrics(); | |
318 * gc.dispose(); | |
319 * </code> | |
320 * </p> | |
321 * | |
322 * @param fontMetrics | |
323 * used in performing the conversion | |
324 * @param chars | |
325 * the number of characters | |
326 * @return the number of pixels | |
327 * @since 2.0 | |
328 */ | |
329 public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, | |
330 int chars) { | |
331 return fontMetrics.getAverageCharWidth() * chars; | |
332 } | |
333 | |
334 /** | |
335 * Shortens the given text <code>textValue</code> so that its width in | |
336 * pixels does not exceed the width of the given control. Overrides | |
337 * characters in the center of the original string with an ellipsis ("...") | |
338 * if necessary. If a <code>null</code> value is given, <code>null</code> | |
339 * is returned. | |
340 * | |
341 * @param textValue | |
342 * the original string or <code>null</code> | |
343 * @param control | |
344 * the control the string will be displayed on | |
345 * @return the string to display, or <code>null</code> if null was passed | |
346 * in | |
347 * | |
348 * @since 3.0 | |
349 */ | |
350 public static String shortenText(String textValue, Control control) { | |
351 if (textValue is null) { | |
352 return null; | |
353 } | |
354 GC gc = new GC(control); | |
355 int maxWidth = control.getBounds().width - 5; | |
356 int maxExtent = gc.textExtent(textValue).x; | |
357 if (maxExtent < maxWidth) { | |
358 gc.dispose(); | |
359 return textValue; | |
360 } | |
361 int length = textValue.length; | |
362 int charsToClip = cast(int) Math.round(0.95f*length * (1 - (cast(float)maxWidth/maxExtent))); | |
363 int pivot = length / 2; | |
364 int start = pivot - (charsToClip/2); | |
365 int end = pivot + (charsToClip/2) + 1; | |
366 while (start >= 0 && end < length) { | |
367 String s1 = textValue.substring(0, start); | |
368 String s2 = textValue.substring(end, length); | |
369 String s = s1 ~ ELLIPSIS ~ s2; | |
370 int l = gc.textExtent(s).x; | |
371 if (l < maxWidth) { | |
372 gc.dispose(); | |
373 return s; | |
374 } | |
375 start--; | |
376 end++; | |
377 } | |
378 gc.dispose(); | |
379 return textValue; | |
380 } | |
381 | |
382 /** | |
383 * Create a default instance of the blocked handler which does not do | |
384 * anything. | |
385 */ | |
386 public static IDialogBlockedHandler blockedHandler; | |
387 static this(){ | |
388 blockedHandler = new class IDialogBlockedHandler { | |
389 /* | |
390 * (non-Javadoc) | |
391 * | |
392 * @see dwtx.jface.dialogs.IDialogBlockedHandler#clearBlocked() | |
393 */ | |
394 public void clearBlocked() { | |
395 // No default behaviour | |
396 } | |
397 | |
398 /* | |
399 * (non-Javadoc) | |
400 * | |
401 * @see dwtx.jface.dialogs.IDialogBlockedHandler#showBlocked(dwtx.core.runtime.IProgressMonitor, | |
402 * dwtx.core.runtime.IStatus, java.lang.String) | |
403 */ | |
404 public void showBlocked(IProgressMonitor blocking, | |
405 IStatus blockingStatus, String blockedName) { | |
406 // No default behaviour | |
407 } | |
408 | |
409 /* | |
410 * (non-Javadoc) | |
411 * | |
412 * @see dwtx.jface.dialogs.IDialogBlockedHandler#showBlocked(dwt.widgets.Shell, | |
413 * dwtx.core.runtime.IProgressMonitor, | |
414 * dwtx.core.runtime.IStatus, java.lang.String) | |
415 */ | |
416 public void showBlocked(Shell parentShell, IProgressMonitor blocking, | |
417 IStatus blockingStatus, String blockedName) { | |
418 // No default behaviour | |
419 } | |
420 }; | |
421 } | |
422 | |
423 /** | |
424 * Creates a dialog instance. Note that the window will have no visual | |
425 * representation (no widgets) until it is told to open. By default, | |
426 * <code>open</code> blocks for dialogs. | |
427 * | |
428 * @param parentShell | |
429 * the parent shell, or <code>null</code> to create a top-level | |
430 * shell | |
431 */ | |
432 protected this(Shell parentShell) { | |
433 this(new SameShellProvider(parentShell)); | |
434 if (parentShell is null && Policy.DEBUG_DIALOG_NO_PARENT) { | |
435 Policy.getLog().log( | |
436 new Status(IStatus.INFO, Policy.JFACE, IStatus.INFO, this | |
437 .classinfo.name | |
438 ~ " created with no shell",//$NON-NLS-1$ | |
439 new Exception( null, null ))); | |
440 } | |
441 } | |
442 | |
443 /** | |
444 * Creates a dialog with the given parent. | |
445 * | |
446 * @param parentShell | |
447 * object that returns the current parent shell | |
448 * | |
449 * @since 3.1 | |
450 */ | |
451 protected this(IShellProvider parentShell) { | |
452 super(parentShell); | |
453 setShellStyle(DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL | |
454 | getDefaultOrientation()); | |
455 setBlockOnOpen(true); | |
456 } | |
457 | |
458 /** | |
459 * Notifies that this dialog's button with the given id has been pressed. | |
460 * <p> | |
461 * The <code>Dialog</code> implementation of this framework method calls | |
462 * <code>okPressed</code> if the ok button is the pressed, and | |
463 * <code>cancelPressed</code> if the cancel button is the pressed. All | |
464 * other button presses are ignored. Subclasses may override to handle other | |
465 * buttons, but should call <code>super.buttonPressed</code> if the | |
466 * default handling of the ok and cancel buttons is desired. | |
467 * </p> | |
468 * | |
469 * @param buttonId | |
470 * the id of the button that was pressed (see | |
471 * <code>IDialogConstants.*_ID</code> constants) | |
472 */ | |
473 protected void buttonPressed(int buttonId) { | |
474 if (IDialogConstants.OK_ID is buttonId) { | |
475 okPressed(); | |
476 } else if (IDialogConstants.CANCEL_ID is buttonId) { | |
477 cancelPressed(); | |
478 } | |
479 } | |
480 | |
481 /** | |
482 * Notifies that the cancel button of this dialog has been pressed. | |
483 * <p> | |
484 * The <code>Dialog</code> implementation of this framework method sets | |
485 * this dialog's return code to <code>Window.CANCEL</code> and closes the | |
486 * dialog. Subclasses may override if desired. | |
487 * </p> | |
488 */ | |
489 protected void cancelPressed() { | |
490 setReturnCode(CANCEL); | |
491 close(); | |
492 } | |
493 | |
494 /** | |
495 * Returns the number of pixels corresponding to the height of the given | |
496 * number of characters. | |
497 * <p> | |
498 * This method may only be called after <code>initializeDialogUnits</code> | |
499 * has been called. | |
500 * </p> | |
501 * <p> | |
502 * Clients may call this framework method, but should not override it. | |
503 * </p> | |
504 * | |
505 * @param chars | |
506 * the number of characters | |
507 * @return the number of pixels | |
508 */ | |
509 protected int convertHeightInCharsToPixels(int chars) { | |
510 // test for failure to initialize for backward compatibility | |
511 if (fontMetrics is null) { | |
512 return 0; | |
513 } | |
514 return convertHeightInCharsToPixels(fontMetrics, chars); | |
515 } | |
516 | |
517 /** | |
518 * Returns the number of pixels corresponding to the given number of | |
519 * horizontal dialog units. | |
520 * <p> | |
521 * This method may only be called after <code>initializeDialogUnits</code> | |
522 * has been called. | |
523 * </p> | |
524 * <p> | |
525 * Clients may call this framework method, but should not override it. | |
526 * </p> | |
527 * | |
528 * @param dlus | |
529 * the number of horizontal dialog units | |
530 * @return the number of pixels | |
531 */ | |
532 protected int convertHorizontalDLUsToPixels(int dlus) { | |
533 // test for failure to initialize for backward compatibility | |
534 if (fontMetrics is null) { | |
535 return 0; | |
536 } | |
537 return convertHorizontalDLUsToPixels(fontMetrics, dlus); | |
538 } | |
539 | |
540 /** | |
541 * Returns the number of pixels corresponding to the given number of | |
542 * vertical dialog units. | |
543 * <p> | |
544 * This method may only be called after <code>initializeDialogUnits</code> | |
545 * has been called. | |
546 * </p> | |
547 * <p> | |
548 * Clients may call this framework method, but should not override it. | |
549 * </p> | |
550 * | |
551 * @param dlus | |
552 * the number of vertical dialog units | |
553 * @return the number of pixels | |
554 */ | |
555 protected int convertVerticalDLUsToPixels(int dlus) { | |
556 // test for failure to initialize for backward compatibility | |
557 if (fontMetrics is null) { | |
558 return 0; | |
559 } | |
560 return convertVerticalDLUsToPixels(fontMetrics, dlus); | |
561 } | |
562 | |
563 /** | |
564 * Returns the number of pixels corresponding to the width of the given | |
565 * number of characters. | |
566 * <p> | |
567 * This method may only be called after <code>initializeDialogUnits</code> | |
568 * has been called. | |
569 * </p> | |
570 * <p> | |
571 * Clients may call this framework method, but should not override it. | |
572 * </p> | |
573 * | |
574 * @param chars | |
575 * the number of characters | |
576 * @return the number of pixels | |
577 */ | |
578 protected int convertWidthInCharsToPixels(int chars) { | |
579 // test for failure to initialize for backward compatibility | |
580 if (fontMetrics is null) { | |
581 return 0; | |
582 } | |
583 return convertWidthInCharsToPixels(fontMetrics, chars); | |
584 } | |
585 | |
586 /** | |
587 * Creates a new button with the given id. | |
588 * <p> | |
589 * The <code>Dialog</code> implementation of this framework method creates | |
590 * a standard push button, registers it for selection events including | |
591 * button presses, and registers default buttons with its shell. The button | |
592 * id is stored as the button's client data. If the button id is | |
593 * <code>IDialogConstants.CANCEL_ID</code>, the new button will be | |
594 * accessible from <code>getCancelButton()</code>. If the button id is | |
595 * <code>IDialogConstants.OK_ID</code>, the new button will be accesible | |
596 * from <code>getOKButton()</code>. Note that the parent's layout is | |
597 * assumed to be a <code>GridLayout</code> and the number of columns in | |
598 * this layout is incremented. Subclasses may override. | |
599 * </p> | |
600 * | |
601 * @param parent | |
602 * the parent composite | |
603 * @param id | |
604 * the id of the button (see <code>IDialogConstants.*_ID</code> | |
605 * constants for standard dialog button ids) | |
606 * @param label | |
607 * the label from the button | |
608 * @param defaultButton | |
609 * <code>true</code> if the button is to be the default button, | |
610 * and <code>false</code> otherwise | |
611 * | |
612 * @return the new button | |
613 * | |
614 * @see #getCancelButton | |
615 * @see #getOKButton() | |
616 */ | |
617 protected Button createButton(Composite parent, int id, String label, | |
618 bool defaultButton) { | |
619 // increment the number of columns in the button bar | |
620 (cast(GridLayout) parent.getLayout()).numColumns++; | |
621 Button button = new Button(parent, DWT.PUSH); | |
622 button.setText(label); | |
623 button.setFont(JFaceResources.getDialogFont()); | |
624 button.setData(new ValueWrapperInt(id)); | |
625 button.addSelectionListener(new class SelectionAdapter { | |
626 public void widgetSelected(SelectionEvent event) { | |
627 buttonPressed((cast(ValueWrapperInt) event.widget.getData()).value); | |
628 } | |
629 }); | |
630 if (defaultButton) { | |
631 Shell shell = parent.getShell(); | |
632 if (shell !is null) { | |
633 shell.setDefaultButton(button); | |
634 } | |
635 } | |
636 buttons[id] = button; | |
637 setButtonLayoutData(button); | |
638 return button; | |
639 } | |
640 | |
641 /** | |
642 * Creates and returns the contents of this dialog's button bar. | |
643 * <p> | |
644 * The <code>Dialog</code> implementation of this framework method lays | |
645 * out a button bar and calls the <code>createButtonsForButtonBar</code> | |
646 * framework method to populate it. Subclasses may override. | |
647 * </p> | |
648 * <p> | |
649 * The returned control's layout data must be an instance of | |
650 * <code>GridData</code>. | |
651 * </p> | |
652 * | |
653 * @param parent | |
654 * the parent composite to contain the button bar | |
655 * @return the button bar control | |
656 */ | |
657 protected Control createButtonBar(Composite parent) { | |
658 Composite composite = new Composite(parent, DWT.NONE); | |
659 // create a layout with spacing and margins appropriate for the font | |
660 // size. | |
661 GridLayout layout = new GridLayout(); | |
662 layout.numColumns = 0; // this is incremented by createButton | |
663 layout.makeColumnsEqualWidth = true; | |
664 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); | |
665 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
666 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
667 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
668 composite.setLayout(layout); | |
669 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END | |
670 | GridData.VERTICAL_ALIGN_CENTER); | |
671 composite.setLayoutData(data); | |
672 composite.setFont(parent.getFont()); | |
673 | |
674 // Add the buttons to the button bar. | |
675 createButtonsForButtonBar(composite); | |
676 return composite; | |
677 } | |
678 | |
679 /** | |
680 * Adds buttons to this dialog's button bar. | |
681 * <p> | |
682 * The <code>Dialog</code> implementation of this framework method adds | |
683 * standard ok and cancel buttons using the <code>createButton</code> | |
684 * framework method. These standard buttons will be accessible from | |
685 * <code>getCancelButton</code>, and <code>getOKButton</code>. | |
686 * Subclasses may override. | |
687 * </p> | |
688 * | |
689 * @param parent | |
690 * the button bar composite | |
691 */ | |
692 protected void createButtonsForButtonBar(Composite parent) { | |
693 // create OK and Cancel buttons by default | |
694 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, | |
695 true); | |
696 createButton(parent, IDialogConstants.CANCEL_ID, | |
697 IDialogConstants.CANCEL_LABEL, false); | |
698 } | |
699 | |
700 /* | |
701 * @see Window.initializeBounds() | |
702 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
703 protected override void initializeBounds() { |
8 | 704 String platform = DWT.getPlatform(); |
705 if ("carbon".equals(platform)) { //$NON-NLS-1$ | |
706 // On Mac OS X the default button must be the right-most button | |
707 Shell shell = getShell(); | |
708 if (shell !is null) { | |
709 Button defaultButton = shell.getDefaultButton(); | |
710 if (defaultButton !is null | |
711 && isContained(buttonBar, defaultButton)) { | |
712 defaultButton.moveBelow(null); | |
713 } | |
714 } | |
715 } | |
716 | |
717 super.initializeBounds(); | |
718 } | |
719 | |
720 /** | |
721 * Returns true if the given Control is a direct or indirect child of | |
722 * container. | |
723 * | |
724 * @param container | |
725 * the potential parent | |
726 * @param control | |
727 * @return bool <code>true</code> if control is a child of container | |
728 */ | |
729 private bool isContained(Control container, Control control) { | |
730 Composite parent; | |
731 while ((parent = control.getParent()) !is null) { | |
732 if (parent is container) { | |
733 return true; | |
734 } | |
735 control = parent; | |
736 } | |
737 return false; | |
738 } | |
739 | |
740 /** | |
741 * The <code>Dialog</code> implementation of this <code>Window</code> | |
742 * method creates and lays out the top level composite for the dialog, and | |
743 * determines the appropriate horizontal and vertical dialog units based on | |
744 * the font size. It then calls the <code>createDialogArea</code> and | |
745 * <code>createButtonBar</code> methods to create the dialog area and | |
746 * button bar, respectively. Overriding <code>createDialogArea</code> and | |
747 * <code>createButtonBar</code> are recommended rather than overriding | |
748 * this method. | |
749 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
750 protected override Control createContents(Composite parent) { |
8 | 751 // create the top level composite for the dialog |
752 Composite composite = new Composite(parent, 0); | |
753 GridLayout layout = new GridLayout(); | |
754 layout.marginHeight = 0; | |
755 layout.marginWidth = 0; | |
756 layout.verticalSpacing = 0; | |
757 composite.setLayout(layout); | |
758 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
759 applyDialogFont(composite); | |
760 // initialize the dialog units | |
761 initializeDialogUnits(composite); | |
762 // create the dialog area and button bar | |
763 dialogArea = createDialogArea(composite); | |
764 buttonBar = createButtonBar(composite); | |
765 | |
766 return composite; | |
767 } | |
768 | |
769 /** | |
770 * Creates and returns the contents of the upper part of this dialog (above | |
771 * the button bar). | |
772 * <p> | |
773 * The <code>Dialog</code> implementation of this framework method creates | |
774 * and returns a new <code>Composite</code> with standard margins and | |
775 * spacing. | |
776 * </p> | |
777 * <p> | |
778 * The returned control's layout data must be an instance of | |
779 * <code>GridData</code>. This method must not modify the parent's | |
780 * layout. | |
781 * </p> | |
782 * <p> | |
783 * Subclasses must override this method but may call <code>super</code> as | |
784 * in the following example: | |
785 * </p> | |
786 * | |
787 * <pre> | |
788 * Composite composite = (Composite) super.createDialogArea(parent); | |
789 * //add controls to composite as necessary | |
790 * return composite; | |
791 * </pre> | |
792 * | |
793 * @param parent | |
794 * the parent composite to contain the dialog area | |
795 * @return the dialog area control | |
796 */ | |
797 protected Control createDialogArea(Composite parent) { | |
798 // create a composite with standard margins and spacing | |
799 Composite composite = new Composite(parent, DWT.NONE); | |
800 GridLayout layout = new GridLayout(); | |
801 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
802 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); | |
803 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
804 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
805 composite.setLayout(layout); | |
806 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
807 applyDialogFont(composite); | |
808 return composite; | |
809 } | |
810 | |
811 /** | |
812 * Returns the button created by the method <code>createButton</code> for | |
813 * the specified ID as defined on <code>IDialogConstants</code>. If | |
814 * <code>createButton</code> was never called with this ID, or if | |
815 * <code>createButton</code> is overridden, this method will return | |
816 * <code>null</code>. | |
817 * | |
818 * @param id | |
819 * the id of the button to look for | |
820 * | |
821 * @return the button for the ID or <code>null</code> | |
822 * | |
823 * @see #createButton(Composite, int, String, bool) | |
824 * @since 2.0 | |
825 */ | |
826 protected Button getButton(int id) { | |
60 | 827 if( auto btn = id in buttons ){ |
828 return *btn; | |
829 } | |
830 return null; | |
8 | 831 } |
832 | |
833 /** | |
834 * Returns the button bar control. | |
835 * <p> | |
836 * Clients may call this framework method, but should not override it. | |
837 * </p> | |
838 * | |
839 * @return the button bar, or <code>null</code> if the button bar has not | |
840 * been created yet | |
841 */ | |
842 protected Control getButtonBar() { | |
843 return buttonBar; | |
844 } | |
845 | |
846 /** | |
847 * Returns the button created when <code>createButton</code> is called | |
848 * with an ID of <code>IDialogConstants.CANCEL_ID</code>. If | |
849 * <code>createButton</code> was never called with this parameter, or if | |
850 * <code>createButton</code> is overridden, <code>getCancelButton</code> | |
851 * will return <code>null</code>. | |
852 * | |
853 * @return the cancel button or <code>null</code> | |
854 * | |
855 * @see #createButton(Composite, int, String, bool) | |
856 * @since 2.0 | |
857 * @deprecated Use <code>getButton(IDialogConstants.CANCEL_ID)</code> | |
858 * instead. This method will be removed soon. | |
859 */ | |
860 protected Button getCancelButton() { | |
861 return getButton(IDialogConstants.CANCEL_ID); | |
862 } | |
863 | |
864 /** | |
865 * Returns the dialog area control. | |
866 * <p> | |
867 * Clients may call this framework method, but should not override it. | |
868 * </p> | |
869 * | |
870 * @return the dialog area, or <code>null</code> if the dialog area has | |
871 * not been created yet | |
872 */ | |
873 protected Control getDialogArea() { | |
874 return dialogArea; | |
875 } | |
876 | |
877 /** | |
878 * Returns the standard dialog image with the given key. Note that these | |
879 * images are managed by the dialog framework, and must not be disposed by | |
880 * another party. | |
881 * | |
882 * @param key | |
883 * one of the <code>Dialog.DLG_IMG_* </code> constants | |
884 * @return the standard dialog image | |
885 * | |
886 * NOTE: Dialog does not use the following images in the registry | |
887 * DLG_IMG_ERROR DLG_IMG_INFO DLG_IMG_QUESTION DLG_IMG_WARNING | |
888 * | |
889 * They are now coming directly from DWT, see ImageRegistry. For backwards | |
890 * compatibility they are still supported, however new code should use DWT | |
891 * for these. | |
892 * | |
893 * @see Display#getSystemImage(int) | |
894 */ | |
895 public static Image getImage(String key) { | |
896 return JFaceResources.getImageRegistry().get(key); | |
897 } | |
898 | |
899 /** | |
900 * Returns the button created when <code>createButton</code> is called | |
901 * with an ID of <code>IDialogConstants.OK_ID</code>. If | |
902 * <code>createButton</code> was never called with this parameter, or if | |
903 * <code>createButton</code> is overridden, <code>getOKButton</code> | |
904 * will return <code>null</code>. | |
905 * | |
906 * @return the OK button or <code>null</code> | |
907 * | |
908 * @see #createButton(Composite, int, String, bool) | |
909 * @since 2.0 | |
910 * @deprecated Use <code>getButton(IDialogConstants.OK_ID)</code> instead. | |
911 * This method will be removed soon. | |
912 */ | |
913 protected Button getOKButton() { | |
914 return getButton(IDialogConstants.OK_ID); | |
915 } | |
916 | |
917 /** | |
918 * Initializes the computation of horizontal and vertical dialog units based | |
919 * on the size of current font. | |
920 * <p> | |
921 * This method must be called before any of the dialog unit based conversion | |
922 * methods are called. | |
923 * </p> | |
924 * | |
925 * @param control | |
926 * a control from which to obtain the current font | |
927 */ | |
928 protected void initializeDialogUnits(Control control) { | |
929 // Compute and store a font metric | |
930 GC gc = new GC(control); | |
931 gc.setFont(JFaceResources.getDialogFont()); | |
932 fontMetrics = gc.getFontMetrics(); | |
933 gc.dispose(); | |
934 } | |
935 | |
936 /** | |
937 * Notifies that the ok button of this dialog has been pressed. | |
938 * <p> | |
939 * The <code>Dialog</code> implementation of this framework method sets | |
940 * this dialog's return code to <code>Window.OK</code> and closes the | |
941 * dialog. Subclasses may override. | |
942 * </p> | |
943 */ | |
944 protected void okPressed() { | |
945 setReturnCode(OK); | |
946 close(); | |
947 } | |
948 | |
949 /** | |
950 * Set the layout data of the button to a GridData with appropriate heights | |
951 * and widths. | |
952 * | |
953 * @param button | |
954 */ | |
955 protected void setButtonLayoutData(Button button) { | |
956 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
957 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
958 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
959 data.widthHint = Math.max(widthHint, minSize.x); | |
960 button.setLayoutData(data); | |
961 } | |
962 | |
963 /** | |
964 * Set the layout data of the button to a FormData with appropriate heights | |
965 * and widths. | |
966 * | |
967 * @param button | |
968 */ | |
969 protected void setButtonLayoutFormData(Button button) { | |
970 FormData data = new FormData(); | |
971 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | |
972 Point minSize = button.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
973 data.width = Math.max(widthHint, minSize.x); | |
974 button.setLayoutData(data); | |
975 } | |
976 | |
977 /** | |
978 * @see dwtx.jface.window.Window#close() | |
979 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
980 public override bool close() { |
8 | 981 if (getShell() !is null && !getShell().isDisposed()) { |
982 saveDialogBounds(getShell()); | |
983 } | |
984 | |
985 bool returnValue = super.close(); | |
986 if (returnValue) { | |
987 buttons = null; | |
988 buttonBar = null; | |
989 dialogArea = null; | |
990 } | |
991 return returnValue; | |
992 } | |
993 | |
994 /** | |
995 * Applies the dialog font to all controls that currently have the default | |
996 * font. | |
997 * | |
998 * @param control | |
999 * the control to apply the font to. Font will also be applied to | |
1000 * its children. If the control is <code>null</code> nothing | |
1001 * happens. | |
1002 */ | |
1003 public static void applyDialogFont(Control control) { | |
1004 if (control is null || dialogFontIsDefault()) { | |
1005 return; | |
1006 } | |
1007 Font dialogFont = JFaceResources.getDialogFont(); | |
1008 applyDialogFont(control, dialogFont); | |
1009 } | |
1010 | |
1011 /** | |
1012 * Sets the dialog font on the control and any of its children if thier font | |
1013 * is not otherwise set. | |
1014 * | |
1015 * @param control | |
1016 * the control to apply the font to. Font will also be applied to | |
1017 * its children. | |
1018 * @param dialogFont | |
1019 * the dialog font to set | |
1020 */ | |
1021 private static void applyDialogFont(Control control, Font dialogFont) { | |
1022 if (hasDefaultFont(control)) { | |
1023 control.setFont(dialogFont); | |
1024 } | |
1025 if ( auto comp = cast(Composite)control ) { | |
1026 Control[] children = comp.getChildren(); | |
1027 for (int i = 0; i < children.length; i++) { | |
1028 applyDialogFont(children[i], dialogFont); | |
1029 } | |
1030 } | |
1031 } | |
1032 | |
1033 /** | |
1034 * Return whether or not this control has the same font as it's default. | |
1035 * | |
1036 * @param control | |
1037 * Control | |
1038 * @return bool | |
1039 */ | |
1040 private static bool hasDefaultFont(Control control) { | |
1041 FontData[] controlFontData = control.getFont().getFontData(); | |
1042 FontData[] defaultFontData = getDefaultFont(control).getFontData(); | |
1043 if (controlFontData.length is defaultFontData.length) { | |
1044 for (int i = 0; i < controlFontData.length; i++) { | |
1045 if (controlFontData[i].opEquals(defaultFontData[i])) { | |
1046 continue; | |
1047 } | |
1048 return false; | |
1049 } | |
1050 return true; | |
1051 } | |
1052 return false; | |
1053 } | |
1054 | |
1055 /** | |
1056 * Get the default font for this type of control. | |
1057 * | |
1058 * @param control | |
1059 * @return the default font | |
1060 */ | |
1061 private static Font getDefaultFont(Control control) { | |
1062 String fontName = "DEFAULT_FONT_" ~ control.classinfo.name; //$NON-NLS-1$ | |
1063 if (JFaceResources.getFontRegistry().hasValueFor(fontName)) { | |
1064 return JFaceResources.getFontRegistry().get(fontName); | |
1065 } | |
1066 Font cached = control.getFont(); | |
1067 control.setFont(null); | |
1068 Font defaultFont = control.getFont(); | |
1069 control.setFont(cached); | |
1070 JFaceResources.getFontRegistry().put(fontName, | |
1071 defaultFont.getFontData()); | |
1072 return defaultFont; | |
1073 } | |
1074 | |
1075 /** | |
1076 * Return whether or not the dialog font is currently the same as the | |
1077 * default font. | |
1078 * | |
1079 * @return bool if the two are the same | |
1080 */ | |
1081 protected static bool dialogFontIsDefault() { | |
1082 FontData[] dialogFontData = JFaceResources.getFontRegistry() | |
1083 .getFontData(JFaceResources.DIALOG_FONT); | |
1084 FontData[] defaultFontData = JFaceResources.getFontRegistry() | |
1085 .getFontData(JFaceResources.DEFAULT_FONT); | |
1086 return ArrayEquals(dialogFontData, defaultFontData); | |
1087 } | |
1088 | |
1089 /* | |
1090 * (non-Javadoc) | |
1091 * | |
1092 * @see dwtx.jface.window.Window#create() | |
1093 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1094 public override void create() { |
8 | 1095 super.create(); |
1096 applyDialogFont(buttonBar); | |
1097 } | |
1098 | |
1099 /** | |
1100 * Get the IDialogBlockedHandler to be used by WizardDialogs and | |
1101 * ModalContexts. | |
1102 * | |
1103 * @return Returns the blockedHandler. | |
1104 */ | |
1105 public static IDialogBlockedHandler getBlockedHandler() { | |
1106 return blockedHandler; | |
1107 } | |
1108 | |
1109 /** | |
1110 * Set the IDialogBlockedHandler to be used by WizardDialogs and | |
1111 * ModalContexts. | |
1112 * | |
1113 * @param blockedHandler | |
1114 * The blockedHandler for the dialogs. | |
1115 */ | |
1116 public static void setBlockedHandler(IDialogBlockedHandler blockedHandler) { | |
1117 Dialog.blockedHandler = blockedHandler; | |
1118 } | |
1119 | |
1120 /** | |
1121 * Gets the dialog settings that should be used for remembering the bounds of | |
1122 * of the dialog, according to the dialog bounds strategy. | |
1123 * | |
1124 * @return settings the dialog settings used to store the dialog's location | |
1125 * and/or size, or <code>null</code> if the dialog's bounds should | |
1126 * never be stored. | |
1127 * | |
1128 * @since 3.2 | |
1129 * @see Dialog#getDialogBoundsStrategy() | |
1130 */ | |
1131 protected IDialogSettings getDialogBoundsSettings() { | |
1132 return null; | |
1133 } | |
1134 | |
1135 /** | |
1136 * Get the integer constant that describes the strategy for persisting the | |
1137 * dialog bounds. This strategy is ignored if the implementer does not also | |
1138 * specify the dialog settings for storing the bounds in | |
1139 * Dialog.getDialogBoundsSettings(). | |
1140 * | |
1141 * @return the constant describing the strategy for persisting the dialog | |
1142 * bounds. | |
1143 * | |
1144 * @since 3.2 | |
1145 * @see Dialog#DIALOG_PERSISTLOCATION | |
1146 * @see Dialog#DIALOG_PERSISTSIZE | |
1147 * @see Dialog#getDialogBoundsSettings() | |
1148 */ | |
1149 protected int getDialogBoundsStrategy() { | |
1150 return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE; | |
1151 } | |
1152 | |
1153 /** | |
1154 * Saves the bounds of the shell in the appropriate dialog settings. The | |
1155 * bounds are recorded relative to the parent shell, if there is one, or | |
1156 * display coordinates if there is no parent shell. | |
1157 * | |
1158 * @param shell | |
1159 * The shell whose bounds are to be stored | |
1160 * | |
1161 * @since 3.2 | |
1162 */ | |
1163 private void saveDialogBounds(Shell shell) { | |
1164 IDialogSettings settings = getDialogBoundsSettings(); | |
1165 if (settings !is null) { | |
1166 Point shellLocation = shell.getLocation(); | |
1167 Point shellSize = shell.getSize(); | |
1168 Shell parent = getParentShell(); | |
1169 if (parent !is null) { | |
1170 Point parentLocation = parent.getLocation(); | |
1171 shellLocation.x -= parentLocation.x; | |
1172 shellLocation.y -= parentLocation.y; | |
1173 } | |
1174 int strategy = getDialogBoundsStrategy(); | |
1175 if ((strategy & DIALOG_PERSISTLOCATION) !is 0) { | |
1176 settings.put(DIALOG_ORIGIN_X, shellLocation.x); | |
1177 settings.put(DIALOG_ORIGIN_Y, shellLocation.y); | |
1178 } | |
1179 if ((strategy & DIALOG_PERSISTSIZE) !is 0) { | |
1180 settings.put(DIALOG_WIDTH, shellSize.x); | |
1181 settings.put(DIALOG_HEIGHT, shellSize.y); | |
1182 FontData [] fontDatas = JFaceResources.getDialogFont().getFontData(); | |
1183 if (fontDatas.length > 0) { | |
1184 settings.put(DIALOG_FONT_DATA, fontDatas[0].toString()); | |
1185 } | |
1186 } | |
1187 } | |
1188 } | |
1189 | |
1190 /** | |
1191 * Returns the initial size to use for the shell. Overridden | |
1192 * to check whether a size has been stored in dialog settings. | |
1193 * If a size has been stored, it is returned. | |
1194 * | |
1195 * @return the initial size of the shell | |
1196 * | |
1197 * @since 3.2 | |
1198 * @see #getDialogBoundsSettings() | |
1199 * @see #getDialogBoundsStrategy() | |
1200 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1201 protected override Point getInitialSize() { |
8 | 1202 Point result = super.getInitialSize(); |
1203 | |
1204 // Check the dialog settings for a stored size. | |
1205 if ((getDialogBoundsStrategy() & DIALOG_PERSISTSIZE)!is 0) { | |
1206 IDialogSettings settings = getDialogBoundsSettings(); | |
1207 if (settings !is null) { | |
1208 // Check that the dialog font matches the font used | |
1209 // when the bounds was stored. If the font has changed, | |
1210 // we do not honor the stored settings. | |
1211 // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=132821 | |
1212 bool useStoredBounds = true; | |
1213 String previousDialogFontData = settings.get(DIALOG_FONT_DATA); | |
1214 // There is a previously stored font, so we will check it. | |
1215 // Note that if we haven't stored the font before, then we will | |
1216 // use the stored bounds. This allows restoring of dialog bounds | |
1217 // that were stored before we started storing the fontdata. | |
1218 if (previousDialogFontData !is null && previousDialogFontData.length > 0) { | |
1219 FontData [] fontDatas = JFaceResources.getDialogFont().getFontData(); | |
1220 if (fontDatas.length > 0) { | |
1221 String currentDialogFontData = fontDatas[0].toString(); | |
1222 useStoredBounds = currentDialogFontData.equalsIgnoreCase(previousDialogFontData); | |
1223 } | |
1224 } | |
1225 if (useStoredBounds) { | |
1226 try { | |
1227 // Get the stored width and height. | |
1228 int width = settings.getInt(DIALOG_WIDTH); | |
1229 if (width !is DIALOG_DEFAULT_BOUNDS) { | |
1230 result.x = width; | |
1231 } | |
1232 int height = settings.getInt(DIALOG_HEIGHT); | |
1233 if (height !is DIALOG_DEFAULT_BOUNDS) { | |
1234 result.y = height; | |
1235 } | |
1236 | |
1237 } catch (NumberFormatException e) { | |
1238 } | |
1239 } | |
1240 } | |
1241 } | |
1242 // No attempt is made to constrain the bounds. The default | |
1243 // constraining behavior in Window will be used. | |
1244 return result; | |
1245 } | |
1246 | |
1247 /** | |
1248 * Returns the initial location to use for the shell. Overridden | |
1249 * to check whether the bounds of the dialog have been stored in | |
1250 * dialog settings. If a location has been stored, it is returned. | |
1251 * | |
1252 * @param initialSize | |
1253 * the initial size of the shell, as returned by | |
1254 * <code>getInitialSize</code>. | |
1255 * @return the initial location of the shell | |
1256 * | |
1257 * @since 3.2 | |
1258 * @see #getDialogBoundsSettings() | |
1259 * @see #getDialogBoundsStrategy() | |
1260 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
8
diff
changeset
|
1261 protected override Point getInitialLocation(Point initialSize) { |
8 | 1262 Point result = super.getInitialLocation(initialSize); |
1263 if ((getDialogBoundsStrategy() & DIALOG_PERSISTLOCATION)!is 0) { | |
1264 IDialogSettings settings = getDialogBoundsSettings(); | |
1265 if (settings !is null) { | |
1266 try { | |
1267 int x = settings.getInt(DIALOG_ORIGIN_X); | |
1268 int y = settings.getInt(DIALOG_ORIGIN_Y); | |
1269 result = new Point(x, y); | |
1270 // The coordinates were stored relative to the parent shell. | |
1271 // Convert to display coordinates. | |
1272 Shell parent = getParentShell(); | |
1273 if (parent !is null) { | |
1274 Point parentLocation = parent.getLocation(); | |
1275 result.x += parentLocation.x; | |
1276 result.y += parentLocation.y; | |
1277 } | |
1278 } catch (NumberFormatException e) { | |
1279 } | |
1280 } | |
1281 } | |
1282 // No attempt is made to constrain the bounds. The default | |
1283 // constraining behavior in Window will be used. | |
1284 return result; | |
1285 } | |
1286 | |
1287 } |