1 11 package org.eclipse.jface.dialogs; 12 13 import org.eclipse.jface.resource.ImageDescriptor; 14 import org.eclipse.jface.resource.JFaceResources; 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.Font; 17 import org.eclipse.swt.graphics.FontMetrics; 18 import org.eclipse.swt.graphics.GC; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.swt.graphics.Point; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.widgets.Button; 23 import org.eclipse.swt.widgets.Control; 24 import org.eclipse.swt.widgets.Shell; 25 26 30 public abstract class DialogPage implements IDialogPage, IMessageProvider { 31 34 private Control control; 35 36 41 private String title = null; 42 43 48 private String description = null; 49 50 55 private Image image = null; 56 57 62 private ImageDescriptor imageDescriptor = null; 63 64 67 private String message = null; 68 69 72 private int messageType = NONE; 73 74 77 private String errorMessage = null; 78 79 82 private FontMetrics fontMetrics; 83 84 87 protected DialogPage() { 88 } 90 91 97 protected DialogPage(String title) { 98 this.title = title; 99 } 100 101 109 protected DialogPage(String title, ImageDescriptor image) { 110 this(title); 111 imageDescriptor = image; 112 } 113 114 129 protected int convertHeightInCharsToPixels(int chars) { 130 if (fontMetrics == null) { 132 return 0; 133 } 134 return Dialog.convertHeightInCharsToPixels(fontMetrics, chars); 135 } 136 137 152 protected int convertHorizontalDLUsToPixels(int dlus) { 153 if (fontMetrics == null) { 155 return 0; 156 } 157 return Dialog.convertHorizontalDLUsToPixels(fontMetrics, dlus); 158 } 159 160 175 protected int convertVerticalDLUsToPixels(int dlus) { 176 if (fontMetrics == null) { 178 return 0; 179 } 180 return Dialog.convertVerticalDLUsToPixels(fontMetrics, dlus); 181 } 182 183 198 protected int convertWidthInCharsToPixels(int chars) { 199 if (fontMetrics == null) { 201 return 0; 202 } 203 return Dialog.convertWidthInCharsToPixels(fontMetrics, chars); 204 } 205 206 210 public void dispose() { 211 if (image != null) { 213 image.dispose(); 214 image = null; 215 } 216 } 217 218 223 public Control getControl() { 224 return control; 225 } 226 227 230 public String getDescription() { 231 return description; 232 } 233 234 239 protected String getDialogFontName() { 240 return JFaceResources.DIALOG_FONT; 241 } 242 243 246 public String getErrorMessage() { 247 return errorMessage; 248 } 249 250 255 protected Font getFont() { 256 return JFaceResources.getFontRegistry().get(getDialogFontName()); 257 } 258 259 262 public Image getImage() { 263 if (image == null) { 264 if (imageDescriptor != null) { 265 image = imageDescriptor.createImage(); 266 } 267 } 268 return image; 269 } 270 271 274 public String getMessage() { 275 return message; 276 } 277 278 281 public int getMessageType() { 282 return messageType; 283 } 284 285 292 public Shell getShell() { 293 return getControl().getShell(); 294 } 295 296 299 public String getTitle() { 300 return title; 301 } 302 303 315 protected final String getToolTipText(int widgetId) { 316 return null; 318 } 319 320 331 protected void initializeDialogUnits(Control testControl) { 332 GC gc = new GC(testControl); 334 gc.setFont(JFaceResources.getDialogFont()); 335 fontMetrics = gc.getFontMetrics(); 336 gc.dispose(); 337 } 338 339 349 protected GridData setButtonLayoutData(Button button) { 350 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 351 int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 352 Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); 353 data.widthHint = Math.max(widthHint, minSize.x); 354 button.setLayoutData(data); 355 return data; 356 } 357 358 364 protected boolean isControlCreated() { 365 return control != null; 366 } 367 368 373 public void performHelp() { 374 } 376 377 381 protected void setControl(Control newControl) { 382 control = newControl; 383 } 384 385 388 public void setDescription(String description) { 389 this.description = description; 390 } 391 392 398 public void setErrorMessage(String newMessage) { 399 errorMessage = newMessage; 400 } 401 402 405 public void setImageDescriptor(ImageDescriptor desc) { 406 imageDescriptor = desc; 407 if (image != null) { 408 image.dispose(); 409 image = null; 410 } 411 } 412 413 422 public void setMessage(String newMessage) { 423 setMessage(newMessage, NONE); 424 } 425 426 448 public void setMessage(String newMessage, int newType) { 449 message = newMessage; 450 messageType = newType; 451 } 452 453 458 public void setTitle(String title) { 459 this.title = title; 460 } 461 462 467 public void setVisible(boolean visible) { 468 control.setVisible(visible); 469 } 470 } 471 | Popular Tags |