1 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 37 public class StartupProgressMonitorDialog extends ProgressMonitorDialog { 38 39 private static final int MINIMUM_WIDTH = 500; 41 42 private static int VERTICAL_OFFSET = 85; 45 46 private static int BAR_DLUS = 9; 48 49 private String productName = null; 50 51 56 public StartupProgressMonitorDialog(Shell parent) { 57 super(parent); 58 setShellStyle(SWT.NONE); 59 } 60 61 66 private String 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 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 106 protected Image getImage() { 107 return null; 108 } 109 110 111 protected Control createDialogArea(Composite parent) { 112 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 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 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 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")) { 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 if (calculatedSize.x < MINIMUM_WIDTH) 169 calculatedSize.x = MINIMUM_WIDTH; 170 return calculatedSize; 171 } 172 173 176 protected Control createButtonBar(Composite parent) { 177 return null; 178 } 179 } 180 | Popular Tags |