1 11 package org.eclipse.ui.splash; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.jface.dialogs.ProgressIndicator; 15 import org.eclipse.jface.window.Window; 16 import org.eclipse.jface.wizard.ProgressMonitorPart; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.graphics.Color; 19 import org.eclipse.swt.graphics.Font; 20 import org.eclipse.swt.graphics.Point; 21 import org.eclipse.swt.graphics.RGB; 22 import org.eclipse.swt.graphics.Rectangle; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Display; 25 import org.eclipse.swt.widgets.Label; 26 import org.eclipse.swt.widgets.Shell; 27 import org.eclipse.ui.internal.StartupThreading.StartupRunnable; 28 29 35 public abstract class BasicSplashHandler extends AbstractSplashHandler { 36 37 42 class AbsolutePositionProgressMonitorPart extends ProgressMonitorPart { 43 public AbsolutePositionProgressMonitorPart(Composite parent) { 44 super(parent, null); 45 setLayout(null); 46 } 47 48 public ProgressIndicator getProgressIndicator() { 49 return fProgressIndicator; 50 } 51 52 public Label getProgressText() { 53 return fLabel; 54 } 55 56 59 public void beginTask(final String name, final int totalWork) { 60 61 updateUI(new Runnable () { 62 63 public void run() { 64 if (isDisposed()) 65 return; 66 AbsolutePositionProgressMonitorPart.super.beginTask(name, 67 totalWork); 68 } 69 }); 70 71 } 72 73 78 public void done() { 79 80 updateUI(new Runnable () { 81 82 public void run() { 83 if (isDisposed()) 84 return; 85 AbsolutePositionProgressMonitorPart.super.done(); 86 } 87 }); 88 89 } 90 91 96 public void internalWorked(final double work) { 97 98 updateUI(new Runnable () { 99 100 public void run() { 101 if (isDisposed()) 102 return; 103 AbsolutePositionProgressMonitorPart.super 104 .internalWorked(work); 105 } 106 }); 107 108 } 109 110 115 public void setFont(final Font font) { 116 117 updateUI(new Runnable () { 118 119 public void run() { 120 if (isDisposed()) 121 return; 122 AbsolutePositionProgressMonitorPart.super.setFont(font); 123 } 124 }); 125 126 } 127 128 133 protected void updateLabel() { 134 135 updateUI(new Runnable () { 136 137 public void run() { 138 if (isDisposed()) 139 return; 140 AbsolutePositionProgressMonitorPart.super.updateLabel(); 141 } 142 }); 143 144 } 145 } 146 147 private Color foreground = null; 148 private AbsolutePositionProgressMonitorPart monitor; 149 private Rectangle messageRect; 150 private Rectangle progressRect; 151 152 157 public IProgressMonitor getBundleProgressMonitor() { 158 if (monitor == null) { 159 Composite parent = new Composite(getSplash(), Window.getDefaultOrientation()); 160 Point size = getSplash().getSize(); 161 parent.setBounds(new Rectangle(0,0,size.x,size.y)); 162 monitor = new AbsolutePositionProgressMonitorPart(parent); 163 monitor.setSize(size); 164 if (progressRect != null) 165 monitor.getProgressIndicator().setBounds(progressRect); 166 else 167 monitor.getProgressIndicator().setVisible(false); 168 169 if (messageRect != null) 170 monitor.getProgressText().setBounds(messageRect); 171 else 172 monitor.getProgressText().setVisible(false); 173 174 if (foreground != null) 175 monitor.getProgressText().setForeground(foreground); 176 monitor.setBackgroundMode(SWT.INHERIT_FORCE); 177 monitor.setBackgroundImage(getSplash().getShell() 178 .getBackgroundImage()); 179 } 180 return monitor; 181 } 182 183 188 public void dispose() { 189 super.dispose(); 190 if (foreground != null) 191 foreground.dispose(); 192 } 193 194 201 protected void setForeground(RGB foregroundRGB) { 202 if (monitor != null) 203 return; 204 if (this.foreground != null) 205 this.foreground.dispose(); 206 this.foreground = new Color(getSplash().getShell().getDisplay(), 207 foregroundRGB); 208 } 209 210 216 protected Color getForeground() { 217 return foreground; 218 } 219 220 227 protected void setMessageRect(Rectangle messageRect) { 228 this.messageRect = messageRect; 229 } 230 231 238 protected void setProgressRect(Rectangle progressRect) { 239 this.progressRect = progressRect; 240 } 241 242 264 protected Composite getContent() { 265 return (Composite) getBundleProgressMonitor(); 266 } 267 268 277 private void updateUI(final Runnable r) { 278 Shell splashShell = getSplash(); 279 if (splashShell == null || splashShell.isDisposed()) 280 return; 281 282 Display display = splashShell.getDisplay(); 283 284 if (Thread.currentThread() == display.getThread()) 285 r.run(); else { 287 StartupRunnable startupRunnable = new StartupRunnable() { 290 291 public void runWithException() throws Throwable { 292 r.run(); 293 } 294 }; 295 display.asyncExec(startupRunnable); 296 } 297 } 298 } 299 | Popular Tags |