KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > MessageWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.refactoring;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Display;
19 import org.eclipse.swt.widgets.Label;
20
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.dialogs.IDialogConstants;
23
24 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
25
26 public abstract class MessageWizardPage extends UserInputWizardPage {
27
28     public static final int STYLE_NONE= 0;
29     public static final int STYLE_INFORMATION= 1;
30     public static final int STYLE_QUESTION= 2;
31     public static final int STYLE_ERROR= 3;
32     public static final int STYLE_WARNING= 4;
33
34     private final int fStyle;
35
36     public MessageWizardPage(String JavaDoc pageName, boolean isLastUserPage, int style) {
37         super(pageName);
38         fStyle= style;
39     }
40
41     protected abstract String JavaDoc getMessageString();
42
43     protected Image getMessageImage() {
44         switch (fStyle) {
45             case STYLE_ERROR :
46                 return Display.getCurrent().getSystemImage(SWT.ICON_ERROR);
47             case STYLE_WARNING :
48                 return Display.getCurrent().getSystemImage(SWT.ICON_WARNING);
49             case STYLE_INFORMATION :
50                 return Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION);
51             case STYLE_QUESTION :
52                 return Display.getCurrent().getSystemImage(SWT.ICON_QUESTION);
53             default :
54                 return null;
55         }
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
60      */

61     public void createControl(Composite parent) {
62         initializeDialogUnits(parent);
63         Composite result= new Composite(parent, SWT.NONE);
64         setControl(result);
65         GridLayout layout= new GridLayout();
66         layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN) * 3 / 2;
67         layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
68         layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
69         layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING) * 2;
70         layout.numColumns= 2;
71         result.setLayout(layout);
72
73         Image image= getMessageImage();
74         if (image != null) {
75             Label label= new Label(result, SWT.NULL);
76             image.setBackground(label.getBackground());
77             label.setImage(image);
78             label.setLayoutData(new GridData(
79                 GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING));
80         }
81
82         String JavaDoc message= getMessageString();
83         if (message != null) {
84             Label messageLabel= new Label(result, SWT.WRAP);
85             messageLabel.setText(message);
86             GridData data= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
87             data.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
88             messageLabel.setLayoutData(data);
89             messageLabel.setFont(result.getFont());
90         }
91         Dialog.applyDialogFont(result);
92     }
93 }
94
Popular Tags