9
|
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 * Konstantin Scheglov <scheglov_ke@nlmk.ru > - Fix for bug 41172
|
|
11 * [Dialogs] Bug with Image in TitleAreaDialog
|
|
12 * Sebastian Davids <sdavids@gmx.de> - Fix for bug 82064
|
|
13 * [Dialogs] TitleAreaDialog#setTitleImage cannot be called before open()
|
|
14 * Port to the D programming language:
|
|
15 * Frank Benoit <benoit@tionex.de>
|
|
16 *******************************************************************************/
|
|
17 module dwtx.jface.dialogs.TitleAreaDialog;
|
|
18
|
12
|
19 import dwtx.jface.dialogs.IDialogConstants;
|
|
20 import dwtx.jface.dialogs.TrayDialog;
|
|
21 import dwtx.jface.dialogs.IMessageProvider;
|
9
|
22
|
|
23 import dwt.DWT;
|
|
24 import dwt.events.DisposeEvent;
|
|
25 import dwt.events.DisposeListener;
|
|
26 import dwt.graphics.Color;
|
|
27 import dwt.graphics.Image;
|
|
28 import dwt.graphics.Point;
|
|
29 import dwt.graphics.RGB;
|
|
30 import dwt.layout.FormAttachment;
|
|
31 import dwt.layout.FormData;
|
|
32 import dwt.layout.FormLayout;
|
|
33 import dwt.layout.GridData;
|
|
34 import dwt.layout.GridLayout;
|
|
35 import dwt.widgets.Composite;
|
|
36 import dwt.widgets.Control;
|
|
37 import dwt.widgets.Display;
|
|
38 import dwt.widgets.Label;
|
|
39 import dwt.widgets.Shell;
|
|
40 import dwt.widgets.Text;
|
|
41 import dwtx.jface.resource.JFaceColors;
|
|
42 import dwtx.jface.resource.JFaceResources;
|
|
43
|
12
|
44 import dwt.dwthelper.utils;
|
|
45
|
9
|
46 /**
|
|
47 * A dialog that has a title area for displaying a title and an image as well as
|
|
48 * a common area for displaying a description, a message, or an error message.
|
|
49 * <p>
|
|
50 * This dialog class may be subclassed.
|
|
51 */
|
12
|
52 public class TitleAreaDialog : TrayDialog {
|
9
|
53 /**
|
|
54 * Image registry key for error message image.
|
|
55 */
|
12
|
56 public static const String DLG_IMG_TITLE_ERROR = DLG_IMG_MESSAGE_ERROR;
|
9
|
57
|
|
58 /**
|
|
59 * Image registry key for banner image (value
|
|
60 * <code>"dialog_title_banner_image"</code>).
|
|
61 */
|
12
|
62 public static const String DLG_IMG_TITLE_BANNER = "dialog_title_banner_image";//$NON-NLS-1$
|
9
|
63
|
|
64 /**
|
|
65 * Message type constant used to display an info icon with the message.
|
|
66 *
|
|
67 * @since 2.0
|
|
68 * @deprecated
|
|
69 */
|
12
|
70 public const static String INFO_MESSAGE = "INFO_MESSAGE"; //$NON-NLS-1$
|
9
|
71
|
|
72 /**
|
|
73 * Message type constant used to display a warning icon with the message.
|
|
74 *
|
|
75 * @since 2.0
|
|
76 * @deprecated
|
|
77 */
|
12
|
78 public const static String WARNING_MESSAGE = "WARNING_MESSAGE"; //$NON-NLS-1$
|
9
|
79
|
|
80 // Space between an image and a label
|
12
|
81 private static const int H_GAP_IMAGE = 5;
|
9
|
82
|
|
83 // Minimum dialog width (in dialog units)
|
12
|
84 private static const int MIN_DIALOG_WIDTH = 350;
|
9
|
85
|
|
86 // Minimum dialog height (in dialog units)
|
12
|
87 private static const int MIN_DIALOG_HEIGHT = 150;
|
9
|
88
|
|
89 private Label titleLabel;
|
|
90
|
|
91 private Label titleImageLabel;
|
|
92
|
|
93 private Label bottomFillerLabel;
|
|
94
|
|
95 private Label leftFillerLabel;
|
|
96
|
|
97 private RGB titleAreaRGB;
|
|
98
|
|
99 Color titleAreaColor;
|
|
100
|
|
101 private String message = ""; //$NON-NLS-1$
|
|
102
|
|
103 private String errorMessage;
|
|
104
|
|
105 private Text messageLabel;
|
|
106
|
|
107 private Composite workArea;
|
|
108
|
|
109 private Label messageImageLabel;
|
|
110
|
|
111 private Image messageImage;
|
|
112
|
|
113 private bool showingError = false;
|
|
114
|
|
115 private bool titleImageLargest = true;
|
|
116
|
|
117 private int messageLabelHeight;
|
|
118
|
|
119 private Image titleAreaImage;
|
|
120
|
|
121 /**
|
|
122 * Instantiate a new title area dialog.
|
|
123 *
|
|
124 * @param parentShell
|
|
125 * the parent DWT shell
|
|
126 */
|
12
|
127 public this(Shell parentShell) {
|
9
|
128 super(parentShell);
|
|
129 }
|
|
130
|
|
131 /*
|
|
132 * @see Dialog.createContents(Composite)
|
|
133 */
|
|
134 protected Control createContents(Composite parent) {
|
|
135 // create the overall composite
|
|
136 Composite contents = new Composite(parent, DWT.NONE);
|
|
137 contents.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
138 // initialize the dialog units
|
|
139 initializeDialogUnits(contents);
|
|
140 FormLayout layout = new FormLayout();
|
|
141 contents.setLayout(layout);
|
|
142 // Now create a work area for the rest of the dialog
|
|
143 workArea = new Composite(contents, DWT.NONE);
|
|
144 GridLayout childLayout = new GridLayout();
|
|
145 childLayout.marginHeight = 0;
|
|
146 childLayout.marginWidth = 0;
|
|
147 childLayout.verticalSpacing = 0;
|
|
148 workArea.setLayout(childLayout);
|
|
149 Control top = createTitleArea(contents);
|
|
150 resetWorkAreaAttachments(top);
|
|
151 workArea.setFont(JFaceResources.getDialogFont());
|
|
152 // initialize the dialog units
|
|
153 initializeDialogUnits(workArea);
|
|
154 // create the dialog area and button bar
|
|
155 dialogArea = createDialogArea(workArea);
|
|
156 buttonBar = createButtonBar(workArea);
|
|
157 return contents;
|
|
158 }
|
|
159
|
|
160 /**
|
|
161 * Creates and returns the contents of the upper part of this dialog (above
|
|
162 * the button bar).
|
|
163 * <p>
|
|
164 * The <code>Dialog</code> implementation of this framework method creates
|
|
165 * and returns a new <code>Composite</code> with no margins and spacing.
|
|
166 * Subclasses should override.
|
|
167 * </p>
|
|
168 *
|
|
169 * @param parent
|
|
170 * The parent composite to contain the dialog area
|
|
171 * @return the dialog area control
|
|
172 */
|
|
173 protected Control createDialogArea(Composite parent) {
|
|
174 // create the top level composite for the dialog area
|
|
175 Composite composite = new Composite(parent, DWT.NONE);
|
|
176 GridLayout layout = new GridLayout();
|
|
177 layout.marginHeight = 0;
|
|
178 layout.marginWidth = 0;
|
|
179 layout.verticalSpacing = 0;
|
|
180 layout.horizontalSpacing = 0;
|
|
181 composite.setLayout(layout);
|
|
182 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
183 composite.setFont(parent.getFont());
|
|
184 // Build the separator line
|
|
185 Label titleBarSeparator = new Label(composite, DWT.HORIZONTAL
|
|
186 | DWT.SEPARATOR);
|
|
187 titleBarSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
188 return composite;
|
|
189 }
|
|
190
|
|
191 /**
|
|
192 * Creates the dialog's title area.
|
|
193 *
|
|
194 * @param parent
|
|
195 * the DWT parent for the title area widgets
|
|
196 * @return Control with the highest x axis value.
|
|
197 */
|
|
198 private Control createTitleArea(Composite parent) {
|
|
199
|
|
200 // add a dispose listener
|
12
|
201 parent.addDisposeListener(new class DisposeListener {
|
9
|
202 public void widgetDisposed(DisposeEvent e) {
|
|
203 if (titleAreaColor !is null) {
|
|
204 titleAreaColor.dispose();
|
|
205 }
|
|
206 }
|
|
207 });
|
|
208 // Determine the background color of the title bar
|
|
209 Display display = parent.getDisplay();
|
|
210 Color background;
|
|
211 Color foreground;
|
|
212 if (titleAreaRGB !is null) {
|
|
213 titleAreaColor = new Color(display, titleAreaRGB);
|
|
214 background = titleAreaColor;
|
|
215 foreground = null;
|
|
216 } else {
|
|
217 background = JFaceColors.getBannerBackground(display);
|
|
218 foreground = JFaceColors.getBannerForeground(display);
|
|
219 }
|
|
220
|
|
221 parent.setBackground(background);
|
|
222 int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
|
|
223 int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
|
|
224 // Dialog image @ right
|
|
225 titleImageLabel = new Label(parent, DWT.CENTER);
|
|
226 titleImageLabel.setBackground(background);
|
|
227 if (titleAreaImage is null)
|
|
228 titleImageLabel.setImage(JFaceResources
|
|
229 .getImage(DLG_IMG_TITLE_BANNER));
|
|
230 else
|
|
231 titleImageLabel.setImage(titleAreaImage);
|
|
232
|
|
233 FormData imageData = new FormData();
|
|
234 imageData.top = new FormAttachment(0, 0);
|
|
235 // Note: do not use horizontalSpacing on the right as that would be a
|
|
236 // regression from
|
|
237 // the R2.x style where there was no margin on the right and images are
|
|
238 // flush to the right
|
|
239 // hand side. see reopened comments in 41172
|
|
240 imageData.right = new FormAttachment(100, 0); // horizontalSpacing
|
|
241 titleImageLabel.setLayoutData(imageData);
|
|
242 // Title label @ top, left
|
|
243 titleLabel = new Label(parent, DWT.LEFT);
|
|
244 JFaceColors.setColors(titleLabel, foreground, background);
|
|
245 titleLabel.setFont(JFaceResources.getBannerFont());
|
|
246 titleLabel.setText(" ");//$NON-NLS-1$
|
|
247 FormData titleData = new FormData();
|
|
248 titleData.top = new FormAttachment(0, verticalSpacing);
|
|
249 titleData.right = new FormAttachment(titleImageLabel);
|
|
250 titleData.left = new FormAttachment(0, horizontalSpacing);
|
|
251 titleLabel.setLayoutData(titleData);
|
|
252 // Message image @ bottom, left
|
|
253 messageImageLabel = new Label(parent, DWT.CENTER);
|
|
254 messageImageLabel.setBackground(background);
|
|
255 // Message label @ bottom, center
|
|
256 messageLabel = new Text(parent, DWT.WRAP | DWT.READ_ONLY);
|
|
257 JFaceColors.setColors(messageLabel, foreground, background);
|
|
258 messageLabel.setText(" \n "); // two lines//$NON-NLS-1$
|
|
259 messageLabel.setFont(JFaceResources.getDialogFont());
|
|
260 messageLabelHeight = messageLabel.computeSize(DWT.DEFAULT, DWT.DEFAULT).y;
|
|
261 // Filler labels
|
|
262 leftFillerLabel = new Label(parent, DWT.CENTER);
|
|
263 leftFillerLabel.setBackground(background);
|
|
264 bottomFillerLabel = new Label(parent, DWT.CENTER);
|
|
265 bottomFillerLabel.setBackground(background);
|
|
266 setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
|
|
267 determineTitleImageLargest();
|
|
268 if (titleImageLargest)
|
|
269 return titleImageLabel;
|
|
270 return messageLabel;
|
|
271 }
|
|
272
|
|
273 /**
|
|
274 * Determine if the title image is larger than the title message and message
|
|
275 * area. This is used for layout decisions.
|
|
276 */
|
|
277 private void determineTitleImageLargest() {
|
|
278 int titleY = titleImageLabel.computeSize(DWT.DEFAULT, DWT.DEFAULT).y;
|
|
279 int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
|
|
280 int labelY = titleLabel.computeSize(DWT.DEFAULT, DWT.DEFAULT).y;
|
|
281 labelY += verticalSpacing;
|
|
282 labelY += messageLabelHeight;
|
|
283 labelY += verticalSpacing;
|
|
284 titleImageLargest = titleY > labelY;
|
|
285 }
|
|
286
|
|
287 /**
|
|
288 * Set the layout values for the messageLabel, messageImageLabel and
|
|
289 * fillerLabel for the case where there is a normal message.
|
|
290 *
|
|
291 * @param verticalSpacing
|
|
292 * int The spacing between widgets on the vertical axis.
|
|
293 * @param horizontalSpacing
|
|
294 * int The spacing between widgets on the horizontal axis.
|
|
295 */
|
|
296 private void setLayoutsForNormalMessage(int verticalSpacing,
|
|
297 int horizontalSpacing) {
|
|
298 FormData messageImageData = new FormData();
|
|
299 messageImageData.top = new FormAttachment(titleLabel, verticalSpacing);
|
|
300 messageImageData.left = new FormAttachment(0, H_GAP_IMAGE);
|
|
301 messageImageLabel.setLayoutData(messageImageData);
|
|
302 FormData messageLabelData = new FormData();
|
|
303 messageLabelData.top = new FormAttachment(titleLabel, verticalSpacing);
|
|
304 messageLabelData.right = new FormAttachment(titleImageLabel);
|
|
305 messageLabelData.left = new FormAttachment(messageImageLabel,
|
|
306 horizontalSpacing);
|
|
307 messageLabelData.height = messageLabelHeight;
|
|
308 if (titleImageLargest)
|
|
309 messageLabelData.bottom = new FormAttachment(titleImageLabel, 0,
|
|
310 DWT.BOTTOM);
|
|
311 messageLabel.setLayoutData(messageLabelData);
|
|
312 FormData fillerData = new FormData();
|
|
313 fillerData.left = new FormAttachment(0, horizontalSpacing);
|
|
314 fillerData.top = new FormAttachment(messageImageLabel, 0);
|
|
315 fillerData.bottom = new FormAttachment(messageLabel, 0, DWT.BOTTOM);
|
|
316 bottomFillerLabel.setLayoutData(fillerData);
|
|
317 FormData data = new FormData();
|
|
318 data.top = new FormAttachment(messageImageLabel, 0, DWT.TOP);
|
|
319 data.left = new FormAttachment(0, 0);
|
|
320 data.bottom = new FormAttachment(messageImageLabel, 0, DWT.BOTTOM);
|
|
321 data.right = new FormAttachment(messageImageLabel, 0);
|
|
322 leftFillerLabel.setLayoutData(data);
|
|
323 }
|
|
324
|
|
325 /**
|
|
326 * The <code>TitleAreaDialog</code> implementation of this
|
|
327 * <code>Window</code> methods returns an initial size which is at least
|
|
328 * some reasonable minimum.
|
|
329 *
|
|
330 * @return the initial size of the dialog
|
|
331 */
|
|
332 protected Point getInitialSize() {
|
|
333 Point shellSize = super.getInitialSize();
|
|
334 return new Point(Math.max(
|
|
335 convertHorizontalDLUsToPixels(MIN_DIALOG_WIDTH), shellSize.x),
|
|
336 Math.max(convertVerticalDLUsToPixels(MIN_DIALOG_HEIGHT),
|
|
337 shellSize.y));
|
|
338 }
|
|
339
|
|
340 /**
|
|
341 * Retained for backward compatibility.
|
|
342 *
|
|
343 * Returns the title area composite. There is no composite in this
|
|
344 * implementation so the shell is returned.
|
|
345 *
|
|
346 * @return Composite
|
|
347 * @deprecated
|
|
348 */
|
|
349 protected Composite getTitleArea() {
|
|
350 return getShell();
|
|
351 }
|
|
352
|
|
353 /**
|
|
354 * Returns the title image label.
|
|
355 *
|
|
356 * @return the title image label
|
|
357 */
|
|
358 protected Label getTitleImageLabel() {
|
|
359 return titleImageLabel;
|
|
360 }
|
|
361
|
|
362 /**
|
|
363 * Display the given error message. The currently displayed message is saved
|
|
364 * and will be redisplayed when the error message is set to
|
|
365 * <code>null</code>.
|
|
366 *
|
|
367 * @param newErrorMessage
|
|
368 * the newErrorMessage to display or <code>null</code>
|
|
369 */
|
|
370 public void setErrorMessage(String newErrorMessage) {
|
|
371 // Any change?
|
|
372 if (errorMessage is null ? newErrorMessage is null : errorMessage
|
|
373 .equals(newErrorMessage))
|
|
374 return;
|
|
375 errorMessage = newErrorMessage;
|
|
376
|
|
377 // Clear or set error message.
|
|
378 if (errorMessage is null) {
|
|
379 if (showingError) {
|
|
380 // we were previously showing an error
|
|
381 showingError = false;
|
|
382 }
|
|
383 // show the message
|
|
384 // avoid calling setMessage in case it is overridden to call
|
|
385 // setErrorMessage,
|
|
386 // which would result in a recursive infinite loop
|
|
387 if (message is null) // this should probably never happen since
|
|
388 // setMessage does this conversion....
|
|
389 message = ""; //$NON-NLS-1$
|
|
390 updateMessage(message);
|
|
391 messageImageLabel.setImage(messageImage);
|
|
392 setImageLabelVisible(messageImage !is null);
|
|
393 } else {
|
|
394 // Add in a space for layout purposes but do not
|
|
395 // change the instance variable
|
12
|
396 String displayedErrorMessage = " " ~ errorMessage; //$NON-NLS-1$
|
9
|
397 updateMessage(displayedErrorMessage);
|
|
398 if (!showingError) {
|
|
399 // we were not previously showing an error
|
|
400 showingError = true;
|
|
401 messageImageLabel.setImage(JFaceResources
|
|
402 .getImage(DLG_IMG_TITLE_ERROR));
|
|
403 setImageLabelVisible(true);
|
|
404 }
|
|
405 }
|
|
406 layoutForNewMessage();
|
|
407 }
|
|
408
|
|
409 /**
|
|
410 * Re-layout the labels for the new message.
|
|
411 */
|
|
412 private void layoutForNewMessage() {
|
|
413 int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
|
|
414 int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
|
|
415 // If there are no images then layout as normal
|
|
416 if (errorMessage is null && messageImage is null) {
|
|
417 setImageLabelVisible(false);
|
|
418 setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing);
|
|
419 } else {
|
|
420 messageImageLabel.setVisible(true);
|
|
421 bottomFillerLabel.setVisible(true);
|
|
422 leftFillerLabel.setVisible(true);
|
|
423 /**
|
|
424 * Note that we do not use horizontalSpacing here as when the
|
|
425 * background of the messages changes there will be gaps between the
|
|
426 * icon label and the message that are the background color of the
|
|
427 * shell. We add a leading space elsewhere to compendate for this.
|
|
428 */
|
|
429 FormData data = new FormData();
|
|
430 data.left = new FormAttachment(0, H_GAP_IMAGE);
|
|
431 data.top = new FormAttachment(titleLabel, verticalSpacing);
|
|
432 messageImageLabel.setLayoutData(data);
|
|
433 data = new FormData();
|
|
434 data.top = new FormAttachment(messageImageLabel, 0);
|
|
435 data.left = new FormAttachment(0, 0);
|
|
436 data.bottom = new FormAttachment(messageLabel, 0, DWT.BOTTOM);
|
|
437 data.right = new FormAttachment(messageImageLabel, 0, DWT.RIGHT);
|
|
438 bottomFillerLabel.setLayoutData(data);
|
|
439 data = new FormData();
|
|
440 data.top = new FormAttachment(messageImageLabel, 0, DWT.TOP);
|
|
441 data.left = new FormAttachment(0, 0);
|
|
442 data.bottom = new FormAttachment(messageImageLabel, 0, DWT.BOTTOM);
|
|
443 data.right = new FormAttachment(messageImageLabel, 0);
|
|
444 leftFillerLabel.setLayoutData(data);
|
|
445 FormData messageLabelData = new FormData();
|
|
446 messageLabelData.top = new FormAttachment(titleLabel,
|
|
447 verticalSpacing);
|
|
448 messageLabelData.right = new FormAttachment(titleImageLabel);
|
|
449 messageLabelData.left = new FormAttachment(messageImageLabel, 0);
|
|
450 messageLabelData.height = messageLabelHeight;
|
|
451 if (titleImageLargest)
|
|
452 messageLabelData.bottom = new FormAttachment(titleImageLabel,
|
|
453 0, DWT.BOTTOM);
|
|
454 messageLabel.setLayoutData(messageLabelData);
|
|
455 }
|
|
456 // Do not layout before the dialog area has been created
|
|
457 // to avoid incomplete calculations.
|
|
458 if (dialogArea !is null)
|
|
459 workArea.getParent().layout(true);
|
|
460 }
|
|
461
|
|
462 /**
|
|
463 * Set the message text. If the message line currently displays an error,
|
|
464 * the message is saved and will be redisplayed when the error message is
|
|
465 * set to <code>null</code>.
|
|
466 * <p>
|
|
467 * Shortcut for <code>setMessage(newMessage, IMessageProvider.NONE)</code>
|
|
468 * </p>
|
|
469 * This method should be called after the dialog has been opened as it
|
|
470 * updates the message label immediately.
|
|
471 *
|
|
472 * @param newMessage
|
|
473 * the message, or <code>null</code> to clear the message
|
|
474 */
|
|
475 public void setMessage(String newMessage) {
|
|
476 setMessage(newMessage, IMessageProvider.NONE);
|
|
477 }
|
|
478
|
|
479 /**
|
|
480 * Sets the message for this dialog with an indication of what type of
|
|
481 * message it is.
|
|
482 * <p>
|
|
483 * The valid message types are one of <code>NONE</code>,
|
|
484 * <code>INFORMATION</code>,<code>WARNING</code>, or
|
|
485 * <code>ERROR</code>.
|
|
486 * </p>
|
|
487 * <p>
|
|
488 * Note that for backward compatibility, a message of type
|
|
489 * <code>ERROR</code> is different than an error message (set using
|
|
490 * <code>setErrorMessage</code>). An error message overrides the current
|
|
491 * message until the error message is cleared. This method replaces the
|
|
492 * current message and does not affect the error message.
|
|
493 * </p>
|
|
494 *
|
|
495 * @param newMessage
|
|
496 * the message, or <code>null</code> to clear the message
|
|
497 * @param newType
|
|
498 * the message type
|
|
499 * @since 2.0
|
|
500 */
|
|
501 public void setMessage(String newMessage, int newType) {
|
|
502 Image newImage = null;
|
|
503 if (newMessage !is null) {
|
|
504 switch (newType) {
|
|
505 case IMessageProvider.NONE:
|
|
506 break;
|
|
507 case IMessageProvider.INFORMATION:
|
|
508 newImage = JFaceResources.getImage(DLG_IMG_MESSAGE_INFO);
|
|
509 break;
|
|
510 case IMessageProvider.WARNING:
|
|
511 newImage = JFaceResources.getImage(DLG_IMG_MESSAGE_WARNING);
|
|
512 break;
|
|
513 case IMessageProvider.ERROR:
|
|
514 newImage = JFaceResources.getImage(DLG_IMG_MESSAGE_ERROR);
|
|
515 break;
|
|
516 }
|
|
517 }
|
|
518 showMessage(newMessage, newImage);
|
|
519 }
|
|
520
|
|
521 /**
|
|
522 * Show the new message and image.
|
|
523 *
|
|
524 * @param newMessage
|
|
525 * @param newImage
|
|
526 */
|
|
527 private void showMessage(String newMessage, Image newImage) {
|
|
528 // Any change?
|
|
529 if (message.equals(newMessage) && messageImage is newImage) {
|
|
530 return;
|
|
531 }
|
|
532 message = newMessage;
|
|
533 if (message is null)
|
|
534 message = "";//$NON-NLS-1$
|
|
535 // Message string to be shown - if there is an image then add in
|
|
536 // a space to the message for layout purposes
|
12
|
537 String shownMessage = (newImage is null) ? message : " " ~ message; //$NON-NLS-1$
|
9
|
538 messageImage = newImage;
|
|
539 if (!showingError) {
|
|
540 // we are not showing an error
|
|
541 updateMessage(shownMessage);
|
|
542 messageImageLabel.setImage(messageImage);
|
|
543 setImageLabelVisible(messageImage !is null);
|
|
544 layoutForNewMessage();
|
|
545 }
|
|
546 }
|
|
547
|
|
548 /**
|
|
549 * Update the contents of the messageLabel.
|
|
550 *
|
|
551 * @param newMessage
|
|
552 * the message to use
|
|
553 */
|
|
554 private void updateMessage(String newMessage) {
|
|
555 messageLabel.setText(newMessage);
|
|
556 }
|
|
557
|
|
558 /**
|
|
559 * Sets the title to be shown in the title area of this dialog.
|
|
560 *
|
|
561 * @param newTitle
|
|
562 * the title show
|
|
563 */
|
|
564 public void setTitle(String newTitle) {
|
|
565 if (titleLabel is null)
|
|
566 return;
|
|
567 String title = newTitle;
|
|
568 if (title is null)
|
|
569 title = "";//$NON-NLS-1$
|
|
570 titleLabel.setText(title);
|
|
571 }
|
|
572
|
|
573 /**
|
|
574 * Sets the title bar color for this dialog.
|
|
575 *
|
|
576 * @param color
|
|
577 * the title bar color
|
|
578 */
|
|
579 public void setTitleAreaColor(RGB color) {
|
|
580 titleAreaRGB = color;
|
|
581 }
|
|
582
|
|
583 /**
|
|
584 * Sets the title image to be shown in the title area of this dialog.
|
|
585 *
|
|
586 * @param newTitleImage
|
|
587 * the title image to be shown
|
|
588 */
|
|
589 public void setTitleImage(Image newTitleImage) {
|
|
590
|
|
591 titleAreaImage = newTitleImage;
|
|
592 if (titleImageLabel !is null) {
|
|
593 titleImageLabel.setImage(newTitleImage);
|
|
594 titleImageLabel.setVisible(newTitleImage !is null);
|
|
595 if (newTitleImage !is null) {
|
|
596 determineTitleImageLargest();
|
|
597 Control top;
|
|
598 if (titleImageLargest)
|
|
599 top = titleImageLabel;
|
|
600 else
|
|
601 top = messageLabel;
|
|
602 resetWorkAreaAttachments(top);
|
|
603 }
|
|
604 }
|
|
605 }
|
|
606
|
|
607 /**
|
|
608 * Make the label used for displaying error images visible depending on
|
|
609 * bool.
|
|
610 *
|
|
611 * @param visible
|
|
612 * If <code>true</code> make the image visible, if not then
|
|
613 * make it not visible.
|
|
614 */
|
|
615 private void setImageLabelVisible(bool visible) {
|
|
616 messageImageLabel.setVisible(visible);
|
|
617 bottomFillerLabel.setVisible(visible);
|
|
618 leftFillerLabel.setVisible(visible);
|
|
619 }
|
|
620
|
|
621 /**
|
|
622 * Reset the attachment of the workArea to now attach to top as the top
|
|
623 * control.
|
|
624 *
|
|
625 * @param top
|
|
626 */
|
|
627 private void resetWorkAreaAttachments(Control top) {
|
|
628 FormData childData = new FormData();
|
|
629 childData.top = new FormAttachment(top);
|
|
630 childData.right = new FormAttachment(100, 0);
|
|
631 childData.left = new FormAttachment(0, 0);
|
|
632 childData.bottom = new FormAttachment(100, 0);
|
|
633 workArea.setLayoutData(childData);
|
|
634 }
|
|
635 }
|