comparison dwtx/jface/dialogs/PopupDialog.d @ 71:4878bef4a38e

Some fixing
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 04:03:58 +0200
parents 46a6e0e6ccd4
children 5df4896124c7
comparison
equal deleted inserted replaced
70:46a6e0e6ccd4 71:4878bef4a38e
104 private static const String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$ 104 private static const String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$
105 105
106 /** 106 /**
107 * The dialog settings key name for remembering if the persisted bounds 107 * The dialog settings key name for remembering if the persisted bounds
108 * should be accessed. 108 * should be accessed.
109 * 109 *
110 * @deprecated Since 3.4, this is retained only for backward compatibility. 110 * @deprecated Since 3.4, this is retained only for backward compatibility.
111 */ 111 */
112 private static final String DIALOG_USE_PERSISTED_BOUNDS = "DIALOG_USE_PERSISTED_BOUNDS"; //$NON-NLS-1$ 112 private static final String DIALOG_USE_PERSISTED_BOUNDS = "DIALOG_USE_PERSISTED_BOUNDS"; //$NON-NLS-1$
113 113
114 /** 114 /**
115 * The dialog settings key name for remembering if the bounds persisted 115 * The dialog settings key name for remembering if the bounds persisted
116 * prior to 3.4 have been migrated to the 3.4 settings. 116 * prior to 3.4 have been migrated to the 3.4 settings.
117 * 117 *
118 * @since 3.4 118 * @since 3.4
119 * @deprecated This is marked deprecated at its introduction to discourage 119 * @deprecated This is marked deprecated at its introduction to discourage
120 * future dependency 120 * future dependency
121 */ 121 */
122 private static final String DIALOG_VALUE_MIGRATED_TO_34 = "hasBeenMigratedTo34"; //$NON-NLS-1$ 122 private static final String DIALOG_VALUE_MIGRATED_TO_34 = "hasBeenMigratedTo34"; //$NON-NLS-1$
194 persistLocation = persistSize; 194 persistLocation = persistSize;
195 } 195 }
196 } 196 }
197 197
198 /** 198 /**
199 * 199 *
200 * Remember bounds action for the dialog. 200 * Remember bounds action for the dialog.
201 */ 201 */
202 private class PersistSizeAction extends Action { 202 private class PersistSizeAction : Action {
203 203
204 PersistSizeAction() { 204 this() {
205 super(JFaceResources.getString("PopupDialog.persistSize"), //$NON-NLS-1$ 205 super(JFaceResources.getString("PopupDialog.persistSize"), //$NON-NLS-1$
206 IAction.AS_CHECK_BOX); 206 IAction.AS_CHECK_BOX);
207 setChecked(persistSize); 207 setChecked(persistSize);
208 } 208 }
209 209
210 /* 210 /*
211 * (non-Javadoc) 211 * (non-Javadoc)
212 * 212 *
213 * @see dwtx.jface.action.IAction#run() 213 * @see dwtx.jface.action.IAction#run()
214 */ 214 */
215 public void run() { 215 public void run() {
216 persistSize = isChecked(); 216 persistSize = isChecked();
217 } 217 }
218 } 218 }
219 219
220 /** 220 /**
221 * 221 *
222 * Remember location action for the dialog. 222 * Remember location action for the dialog.
223 */ 223 */
224 private class PersistLocationAction extends Action { 224 private class PersistLocationAction : Action {
225 225
226 PersistLocationAction() { 226 this() {
227 super(JFaceResources.getString("PopupDialog.persistLocation"), //$NON-NLS-1$ 227 super(JFaceResources.getString("PopupDialog.persistLocation"), //$NON-NLS-1$
228 IAction.AS_CHECK_BOX); 228 IAction.AS_CHECK_BOX);
229 setChecked(persistLocation); 229 setChecked(persistLocation);
230 } 230 }
231 231
232 /* 232 /*
233 * (non-Javadoc) 233 * (non-Javadoc)
234 * 234 *
235 * @see dwtx.jface.action.IAction#run() 235 * @see dwtx.jface.action.IAction#run()
236 */ 236 */
237 public void run() { 237 public void run() {
238 persistLocation = isChecked(); 238 persistLocation = isChecked();
239 } 239 }
240 } 240 }
241 241
242 /** 242 /**
243 * Shell style appropriate for a simple hover popup that cannot get focus. 243 * Shell style appropriate for a simple hover popup that cannot get focus.
244 * 244 *
245 */ 245 */
246 public const static int HOVER_SHELLSTYLE = DWT.NO_FOCUS | DWT.ON_TOP 246 public const static int HOVER_SHELLSTYLE = DWT.NO_FOCUS | DWT.ON_TOP
247 | DWT.TOOL; 247 | DWT.TOOL;
248 248
249 /** 249 /**
280 */ 280 */
281 public const static int POPUP_HORIZONTALSPACING = 1; 281 public const static int POPUP_HORIZONTALSPACING = 1;
282 282
283 /** 283 /**
284 * Image registry key for menu image. 284 * Image registry key for menu image.
285 * 285 *
286 * @since 3.3 286 * @since 3.3
287 */ 287 */
288 public static final String POPUP_IMG_MENU = "popup_menu_image"; //$NON-NLS-1$ 288 public static final String POPUP_IMG_MENU = "popup_menu_image"; //$NON-NLS-1$
289 289
290 /** 290 /**
291 * Image registry key for disabled menu image. 291 * Image registry key for disabled menu image.
292 * 292 *
293 * @since 3.3 293 * @since 3.3
294 */ 294 */
295 public static final String POPUP_IMG_MENU_DISABLED = "popup_menu_image_diabled"; //$NON-NLS-1$ 295 public static final String POPUP_IMG_MENU_DISABLED = "popup_menu_image_diabled"; //$NON-NLS-1$
296 296
297 /** 297 /**
298 * 298 *
299 */ 299 */
300 private static final GridLayoutFactory POPUP_LAYOUT_FACTORY; 300 private static final GridLayoutFactory POPUP_LAYOUT_FACTORY;
301 301
302 static this(){ 302 static this(){
303 LAYOUTDATA_GRAB_BOTH = GridDataFactory.fillDefaults().grab(true,true); 303 LAYOUTDATA_GRAB_BOTH = GridDataFactory.fillDefaults().grab(true,true);
384 * shown. 384 * shown.
385 */ 385 */
386 private bool persistLocation = false; 386 private bool persistLocation = false;
387 /** 387 /**
388 * Flag specifying whether to use new 3.4 API instead of the old one. 388 * Flag specifying whether to use new 3.4 API instead of the old one.
389 * 389 *
390 * @since 3.4 390 * @since 3.4
391 */ 391 */
392 private bool isUsing34API = true; 392 private bool isUsing34API = true;
393 393
394 /** 394 /**
431 * Text to be shown in an upper title area, or <code>null</code> 431 * Text to be shown in an upper title area, or <code>null</code>
432 * if there is no title. 432 * if there is no title.
433 * @param infoText 433 * @param infoText
434 * Text to be shown in a lower info area, or <code>null</code> 434 * Text to be shown in a lower info area, or <code>null</code>
435 * if there is no info area. 435 * if there is no info area.
436 * 436 *
437 * @see PopupDialog#getDialogSettings() 437 * @see PopupDialog#getDialogSettings()
438 * @deprecated As of 3.4, replaced by 438 * @deprecated As of 3.4, replaced by
439 * {@link #PopupDialog(Shell, int, bool, bool, bool, bool, bool, String, String)} 439 * {@link #PopupDialog(Shell, int, bool, bool, bool, bool, bool, String, String)}
440 */ 440 */
441 public PopupDialog(Shell parent, int shellStyle, bool takeFocusOnOpen, 441 public this(Shell parent, int shellStyle, bool takeFocusOnOpen,
442 bool persistBounds, bool showDialogMenu, 442 bool persistBounds, bool showDialogMenu,
443 bool showPersistActions, String titleText, String infoText) { 443 bool showPersistActions, String titleText, String infoText) {
444 this(parent, shellStyle, takeFocusOnOpen, persistBounds, persistBounds, 444 this(parent, shellStyle, takeFocusOnOpen, persistBounds, persistBounds,
445 showDialogMenu, showPersistActions, titleText, infoText, false); 445 showDialogMenu, showPersistActions, titleText, infoText, false);
446 } 446 }
447 447
448 /** 448 /**
449 * Constructs a new instance of <code>PopupDialog</code>. 449 * Constructs a new instance of <code>PopupDialog</code>.
450 * 450 *
451 * @param parent 451 * @param parent
452 * The parent shell. 452 * The parent shell.
453 * @param shellStyle 453 * @param shellStyle
454 * The shell style. 454 * The shell style.
455 * @param takeFocusOnOpen 455 * @param takeFocusOnOpen
482 * Text to be shown in an upper title area, or <code>null</code> 482 * Text to be shown in an upper title area, or <code>null</code>
483 * if there is no title. 483 * if there is no title.
484 * @param infoText 484 * @param infoText
485 * Text to be shown in a lower info area, or <code>null</code> 485 * Text to be shown in a lower info area, or <code>null</code>
486 * if there is no info area. 486 * if there is no info area.
487 * 487 *
488 * @see PopupDialog#getDialogSettings() 488 * @see PopupDialog#getDialogSettings()
489 * 489 *
490 * @since 3.4 490 * @since 3.4
491 */ 491 */
492 public PopupDialog(Shell parent, int shellStyle, bool takeFocusOnOpen, 492 public this(Shell parent, int shellStyle, bool takeFocusOnOpen,
493 bool persistSize, bool persistLocation, 493 bool persistSize, bool persistLocation,
494 bool showDialogMenu, bool showPersistActions, 494 bool showDialogMenu, bool showPersistActions,
495 String titleText, String infoText) { 495 String titleText, String infoText) {
496 this(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation, 496 this(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation,
497 showDialogMenu, showPersistActions, titleText, infoText, true); 497 showDialogMenu, showPersistActions, titleText, infoText, true);
498 498
499 } 499 }
500 500
501 /** 501 /**
502 * Constructs a new instance of <code>PopupDialog</code>. 502 * Constructs a new instance of <code>PopupDialog</code>.
503 * 503 *
504 * @param parent 504 * @param parent
505 * The parent shell. 505 * The parent shell.
506 * @param shellStyle 506 * @param shellStyle
507 * The shell style. 507 * The shell style.
508 * @param takeFocusOnOpen 508 * @param takeFocusOnOpen
537 * @param infoText 537 * @param infoText
538 * Text to be shown in a lower info area, or <code>null</code> 538 * Text to be shown in a lower info area, or <code>null</code>
539 * if there is no info area. 539 * if there is no info area.
540 * @param use34API 540 * @param use34API
541 * <code>true</code> if 3.4 API should be used 541 * <code>true</code> if 3.4 API should be used
542 * 542 *
543 * @see PopupDialog#getDialogSettings() 543 * @see PopupDialog#getDialogSettings()
544 * 544 *
545 * @since 3.4 545 * @since 3.4
546 */ 546 */
547 private PopupDialog(Shell parent, int shellStyle, bool takeFocusOnOpen, 547 private this(Shell parent, int shellStyle, bool takeFocusOnOpen,
548 bool persistSize, bool persistLocation, 548 bool persistSize, bool persistLocation,
549 bool showDialogMenu, bool showPersistActions, 549 bool showDialogMenu, bool showPersistActions,
550 String titleText, String infoText, bool use34API) { 550 String titleText, String infoText, bool use34API) {
551 super(parent); 551 super(parent);
552 // Prior to 3.4, we encouraged use of DWT.NO_TRIM and provided a 552 // Prior to 3.4, we encouraged use of DWT.NO_TRIM and provided a
651 }); 651 });
652 } 652 }
653 653
654 private void asyncClose() { 654 private void asyncClose() {
655 // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=152010 655 // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=152010
656 getShell().getDisplay().asyncExec(new Runnable() { 656 getShell().getDisplay().asyncExec(new class Runnable {
657 public void run() { 657 public void run() {
658 close(); 658 close();
659 } 659 }
660 }); 660 });
661 } 661 }
863 */ 863 */
864 protected Control createInfoTextArea(Composite parent) { 864 protected Control createInfoTextArea(Composite parent) {
865 // Status label 865 // Status label
866 infoLabel = new Label(parent, DWT.RIGHT); 866 infoLabel = new Label(parent, DWT.RIGHT);
867 infoLabel.setText(infoText); 867 infoLabel.setText(infoText);
868 868
869 GridDataFactory.fillDefaults().grab(true, false).align(DWT.FILL, 869 GridDataFactory.fillDefaults().grab(true, false).align_(DWT.FILL,
870 DWT.BEGINNING).applyTo(infoLabel); 870 DWT.BEGINNING).applyTo(infoLabel);
871 infoLabel.setForeground(parent.getDisplay().getSystemColor( 871 infoLabel.setForeground(parent.getDisplay().getSystemColor(
872 DWT.COLOR_WIDGET_DARK_SHADOW)); 872 DWT.COLOR_WIDGET_DARK_SHADOW));
873 return infoLabel; 873 return infoLabel;
874 } 874 }
1034 * modified if the persist bounds action is shown on the menu and the user 1034 * modified if the persist bounds action is shown on the menu and the user
1035 * has changed its value. Subclasses may override this method. 1035 * has changed its value. Subclasses may override this method.
1036 * 1036 *
1037 * @return <code>true</code> if the dialog's bounds will be persisted, 1037 * @return <code>true</code> if the dialog's bounds will be persisted,
1038 * <code>false</code> if it will not. 1038 * <code>false</code> if it will not.
1039 * 1039 *
1040 * @deprecated As of 3.4, please use {@link #getPersistLocation()} or 1040 * @deprecated As of 3.4, please use {@link #getPersistLocation()} or
1041 * {@link #getPersistSize()} to determine separately whether 1041 * {@link #getPersistSize()} to determine separately whether
1042 * size or location should be persisted. 1042 * size or location should be persisted.
1043 */ 1043 */
1044 protected bool getPersistBounds() { 1044 protected bool getPersistBounds() {
1048 /** 1048 /**
1049 * Return a bool indicating whether this dialog will persist its 1049 * Return a bool indicating whether this dialog will persist its
1050 * location. This value is initially set in the dialog's constructor, but 1050 * location. This value is initially set in the dialog's constructor, but
1051 * can be modified if the persist location action is shown on the menu and 1051 * can be modified if the persist location action is shown on the menu and
1052 * the user has changed its value. Subclasses may override this method. 1052 * the user has changed its value. Subclasses may override this method.
1053 * 1053 *
1054 * @return <code>true</code> if the dialog's location will be persisted, 1054 * @return <code>true</code> if the dialog's location will be persisted,
1055 * <code>false</code> if it will not. 1055 * <code>false</code> if it will not.
1056 * 1056 *
1057 * @see #getPersistSize() 1057 * @see #getPersistSize()
1058 * @since 3.4 1058 * @since 3.4
1059 */ 1059 */
1060 protected bool getPersistLocation() { 1060 protected bool getPersistLocation() {
1061 return persistLocation; 1061 return persistLocation;
1064 /** 1064 /**
1065 * Return a bool indicating whether this dialog will persist its size. 1065 * Return a bool indicating whether this dialog will persist its size.
1066 * This value is initially set in the dialog's constructor, but can be 1066 * This value is initially set in the dialog's constructor, but can be
1067 * modified if the persist size action is shown on the menu and the user has 1067 * modified if the persist size action is shown on the menu and the user has
1068 * changed its value. Subclasses may override this method. 1068 * changed its value. Subclasses may override this method.
1069 * 1069 *
1070 * @return <code>true</code> if the dialog's size will be persisted, 1070 * @return <code>true</code> if the dialog's size will be persisted,
1071 * <code>false</code> if it will not. 1071 * <code>false</code> if it will not.
1072 * 1072 *
1073 * @see #getPersistLocation() 1073 * @see #getPersistLocation()
1074 * @since 3.4 1074 * @since 3.4
1075 */ 1075 */
1076 protected bool getPersistSize() { 1076 protected bool getPersistSize() {
1077 return persistSize; 1077 return persistSize;
1248 * Return the default size to use for the shell. This default size is used 1248 * Return the default size to use for the shell. This default size is used
1249 * if the dialog does not have any persisted size to restore. The default 1249 * if the dialog does not have any persisted size to restore. The default
1250 * implementation returns the preferred size of the shell. Subclasses should 1250 * implementation returns the preferred size of the shell. Subclasses should
1251 * override this method when an alternate default size is desired, rather 1251 * override this method when an alternate default size is desired, rather
1252 * than overriding {@link #getInitialSize()}. 1252 * than overriding {@link #getInitialSize()}.
1253 * 1253 *
1254 * @return the initial size of the shell 1254 * @return the initial size of the shell
1255 * 1255 *
1256 * @see #getPersistSize() 1256 * @see #getPersistSize()
1257 * @since 3.4 1257 * @since 3.4
1258 */ 1258 */
1259 protected Point getDefaultSize() { 1259 protected Point getDefaultSize() {
1260 return super.getInitialSize(); 1260 return super.getInitialSize();
1265 * is used if the dialog does not have any persisted location to restore. 1265 * is used if the dialog does not have any persisted location to restore.
1266 * The default implementation uses the location computed by 1266 * The default implementation uses the location computed by
1267 * {@link dwtx.jface.window.Window#getInitialLocation(Point)}. 1267 * {@link dwtx.jface.window.Window#getInitialLocation(Point)}.
1268 * Subclasses should override this method when an alternate default location 1268 * Subclasses should override this method when an alternate default location
1269 * is desired, rather than overriding {@link #getInitialLocation(Point)}. 1269 * is desired, rather than overriding {@link #getInitialLocation(Point)}.
1270 * 1270 *
1271 * @param initialSize 1271 * @param initialSize
1272 * the initial size of the shell, as returned by 1272 * the initial size of the shell, as returned by
1273 * <code>getInitialSize</code>. 1273 * <code>getInitialSize</code>.
1274 * @return the initial location of the shell 1274 * @return the initial location of the shell
1275 * 1275 *
1276 * @see #getPersistLocation() 1276 * @see #getPersistLocation()
1277 * @since 3.4 1277 * @since 3.4
1278 */ 1278 */
1279 protected Point getDefaultLocation(Point initialSize) { 1279 protected Point getDefaultLocation(Point initialSize) {
1280 return super.getInitialLocation(initialSize); 1280 return super.getInitialLocation(initialSize);
1345 } 1345 }
1346 1346
1347 /** 1347 /**
1348 * Get the foreground color that should be used for this popup. Subclasses 1348 * Get the foreground color that should be used for this popup. Subclasses
1349 * may override. 1349 * may override.
1350 * 1350 *
1351 * @return the foreground color to be used. Should not be <code>null</code>. 1351 * @return the foreground color to be used. Should not be <code>null</code>.
1352 * 1352 *
1353 * @since 3.4 1353 * @since 3.4
1354 * 1354 *
1355 * @see #getForegroundColorExclusions() 1355 * @see #getForegroundColorExclusions()
1356 */ 1356 */
1357 protected Color getForeground() { 1357 protected Color getForeground() {
1358 return getDefaultForeground(); 1358 return getDefaultForeground();
1359 } 1359 }
1360 1360
1361 /** 1361 /**
1362 * Get the background color that should be used for this popup. Subclasses 1362 * Get the background color that should be used for this popup. Subclasses
1363 * may override. 1363 * may override.
1364 * 1364 *
1365 * @return the background color to be used. Should not be <code>null</code>. 1365 * @return the background color to be used. Should not be <code>null</code>.
1366 * 1366 *
1367 * @since 3.4 1367 * @since 3.4
1368 * 1368 *
1369 * @see #getBackgroundColorExclusions() 1369 * @see #getBackgroundColorExclusions()
1370 */ 1370 */
1371 protected Color getBackground() { 1371 protected Color getBackground() {
1372 return getDefaultBackground(); 1372 return getDefaultBackground();
1373 } 1373 }
1374 1374
1375 /** 1375 /**
1376 * Return the default foreground color used for popup dialogs. 1376 * Return the default foreground color used for popup dialogs.
1377 * 1377 *
1378 * @return the default foreground color. 1378 * @return the default foreground color.
1379 */ 1379 */
1380 private Color getDefaultForeground() { 1380 private Color getDefaultForeground() {
1381 return getShell().getDisplay() 1381 return getShell().getDisplay()
1382 .getSystemColor(DWT.COLOR_INFO_FOREGROUND); 1382 .getSystemColor(DWT.COLOR_INFO_FOREGROUND);
1383 } 1383 }
1384 1384
1385 /** 1385 /**
1386 * Return the default background color used for popup dialogs. 1386 * Return the default background color used for popup dialogs.
1387 * 1387 *
1388 * @return the default background color 1388 * @return the default background color
1389 */ 1389 */
1390 private Color getDefaultBackground() { 1390 private Color getDefaultBackground() {
1391 return getShell().getDisplay() 1391 return getShell().getDisplay()
1392 .getSystemColor(DWT.COLOR_INFO_BACKGROUND); 1392 .getSystemColor(DWT.COLOR_INFO_BACKGROUND);
1595 settings.put(key, DIALOG_VALUE_MIGRATED_TO_34); 1595 settings.put(key, DIALOG_VALUE_MIGRATED_TO_34);
1596 } 1596 }
1597 1597
1598 /** 1598 /**
1599 * The dialog is being disposed. Dispose of any resources allocated. 1599 * The dialog is being disposed. Dispose of any resources allocated.
1600 * 1600 *
1601 */ 1601 */
1602 private void handleDispose() { 1602 private void handleDispose() {
1603 if (infoFont !is null && !infoFont.isDisposed()) { 1603 if (infoFont !is null && !infoFont.isDisposed()) {
1604 infoFont.dispose(); 1604 infoFont.dispose();
1605 } 1605 }