2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
11 package org.eclipse.webbrowser.internal;
13 import org.eclipse.swt.widgets.*;
14 import org.eclipse.swt.events.*;
15 import org.eclipse.swt.graphics.*;
17 * An animated image to show busy status of the Web browser.
19 public class BusyIndicator extends Canvas {
20 protected Image[] images;
21 protected Image image;
23 protected Thread busyThread;
24 protected boolean stop;
27 * BusyWidget constructor comment.
28 * @param parent org.eclipse.swt.widgets.Composite
31 public BusyIndicator(Composite parent, int style) {
34 images = ImageResource.getBusyImages();
36 addPaintListener(new PaintListener() {
37 public void paintControl(PaintEvent event) {
45 public Point computeSize(int wHint, int hHint, boolean changed) {
46 return new Point(25, 25);
50 * Creates a thread to animate the image.
52 protected synchronized void createBusyThread() {
53 if (busyThread != null)
57 busyThread = new Thread() {
63 Display.getDefault().syncExec(new Runnable() {
67 setImage(images[count]);
76 } catch (Exception e) { }
78 if (busyThread == null)
79 Display.getDefault().syncExec(new Thread() {
84 } catch (Exception e) {
85 Trace.trace(Trace.WARNING, "Busy error", e);
90 busyThread.setPriority(Thread.NORM_PRIORITY + 2);
91 busyThread.setDaemon(true);
95 public void dispose() {
102 * Return the image or <code>null</code>.
104 public Image getImage() {
109 * Returns true if it is currently busy.
113 public boolean isBusy() {
114 return (busyThread != null);
118 * Process the paint event
120 protected void onPaint(PaintEvent event) {
121 Rectangle rect = getClientArea();
122 if (rect.width == 0 || rect.height == 0)
127 gc.drawImage(image, 2, 2);
131 * Sets the indicators busy count up (true) or down (false) one.
133 * @param busy boolean
135 public synchronized void setBusy(boolean busy) {
137 if (busyThread == null)
140 if (busyThread != null) {
149 * The value <code>null</code> clears it.
151 public void setImage(Image image) {
152 if (image != this.image && !isDisposed()) {