KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > StartupProgressMonitorDialog


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.runtime.IProduct;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.jface.dialogs.ProgressIndicator;
17 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
18 import org.eclipse.jface.util.Geometry;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.graphics.Point;
22 import org.eclipse.swt.graphics.Rectangle;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.Monitor;
29 import org.eclipse.swt.widgets.Shell;
30
31 /**
32  * This class implements a simple dialog with text and progress bar.
33  *
34  * @since 3.1
35  *
36  */

37 public class StartupProgressMonitorDialog extends ProgressMonitorDialog {
38
39     // make the dialog itself at least 500 pixels wide
40
private static final int MINIMUM_WIDTH = 500;
41
42     // how many pixels should the dialog be shown below the center of the
43
// display area
44
private static int VERTICAL_OFFSET = 85;
45     
46     // used to determine the height of the progress bar
47
private static int BAR_DLUS = 9;
48
49     private String JavaDoc productName = null;
50     
51     /**
52      * Construct an instance of this dialog.
53      *
54      * @param parent
55      */

56     public StartupProgressMonitorDialog(Shell parent) {
57         super(parent);
58         setShellStyle(SWT.NONE);
59     }
60     
61     /**
62      *
63      * Answer the message that will be used in the startup progress dialog
64      * @return the message
65      */

66     private String JavaDoc getProductName() {
67         if(productName==null) {
68             IProduct product = Platform.getProduct();
69             if (product != null) {
70                 productName = product.getName();
71             }
72             if (productName == null) {
73                 productName = WorkbenchMessages.Startup_DefaultProductName;
74             }
75         }
76         return productName;
77     }
78
79     protected Control createContents(Composite parent) {
80         Composite container = new Composite(parent, SWT.NONE);
81         GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
82         container.setLayoutData(gridData);
83         GridLayout gridLayout = new GridLayout();
84         gridLayout.horizontalSpacing = 0;
85         gridLayout.marginWidth = 0;
86         gridLayout.marginHeight = 0;
87         gridLayout.verticalSpacing = 0;
88         container.setLayout(gridLayout);
89
90         Composite progressArea = new Composite(container, SWT.NONE);
91         super.createContents(progressArea);
92
93         // making the margins the same in each direction
94
gridLayout = (GridLayout) progressArea.getLayout();
95         gridLayout.marginHeight = gridLayout.marginWidth;
96
97         gridData = (GridData) progressArea.getLayoutData();
98         gridData.verticalAlignment = SWT.CENTER;
99
100         return container;
101     }
102     
103     /*
104      * Simple dialog has no image.
105      */

106     protected Image getImage() {
107         return null;
108     }
109
110     /* Overridden to not call createMessageArea and to add another label */
111     protected Control createDialogArea(Composite parent) {
112         // progress indicator
113
progressIndicator = new ProgressIndicator(parent);
114         GridData gd = new GridData();
115         gd.heightHint = convertVerticalDLUsToPixels(BAR_DLUS);
116         gd.horizontalAlignment = GridData.FILL;
117         gd.grabExcessHorizontalSpace = true;
118         gd.horizontalSpan = 2;
119         progressIndicator.setLayoutData(gd);
120         // label showing current task
121
subTaskLabel = new Label(parent, SWT.LEFT);
122         gd = new GridData(GridData.FILL_HORIZONTAL);
123         gd.minimumWidth = MINIMUM_WIDTH / 2;
124         subTaskLabel.setLayoutData(gd);
125         subTaskLabel.setFont(parent.getFont());
126         // label showing product name
127
Label productLabel = new Label(parent, SWT.RIGHT);
128         productLabel.moveBelow(subTaskLabel);
129         
130         gd = new GridData(SWT.RIGHT);
131         productLabel.setLayoutData(gd);
132         productLabel.setFont(parent.getFont());
133         productLabel.setText(getProductName());
134         return parent;
135     }
136
137     /*
138      * see org.eclipse.jface.Window.getInitialLocation()
139      */

140     protected Point getInitialLocation(Point initialSize) {
141         Composite parent = getShell().getParent();
142         
143         if (parent == null)
144             return super.getInitialLocation(initialSize);
145
146         Monitor monitor = parent.getMonitor();
147         Point referencePoint;
148         Rectangle monitorBounds;
149         if (SWT.getPlatform().equals("carbon")) {//$NON-NLS-1$
150
monitorBounds = monitor.getClientArea();
151             referencePoint = Geometry.centerPoint(monitorBounds);
152             referencePoint.y = monitorBounds.height / 3 + monitorBounds.y;
153         } else {
154             monitorBounds = monitor.getBounds();
155             referencePoint = Geometry.centerPoint(monitorBounds);
156         }
157         
158         return new Point(referencePoint.x - (initialSize.x / 2),
159                 Math.max(monitorBounds.y, Math.min(referencePoint.y
160                         + VERTICAL_OFFSET, monitorBounds.y
161                         + monitorBounds.height - initialSize.y)));
162     }
163
164     protected Point getInitialSize() {
165         Point calculatedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT,
166                 true);
167         //ensure the initial width is no less than the minimum
168
if (calculatedSize.x < MINIMUM_WIDTH)
169             calculatedSize.x = MINIMUM_WIDTH;
170         return calculatedSize;
171     }
172
173     /*
174      * Do not call super as we do not want any buttons in the button bar.
175      */

176     protected Control createButtonBar(Composite parent) {
177         return null;
178     }
179 }
180
Popular Tags