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 net.sourceforge.phpeclipse.webbrowser.internal;
13 import org.eclipse.swt.events.PaintEvent;
14 import org.eclipse.swt.events.PaintListener;
15 import org.eclipse.swt.graphics.GC;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.swt.graphics.Point;
18 import org.eclipse.swt.graphics.Rectangle;
19 import org.eclipse.swt.widgets.Canvas;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Display;
24 * An animated image to show busy status of the Web browser.
26 public class BusyIndicator extends Canvas {
27 protected Image[] images;
29 protected Image image;
31 protected Thread busyThread;
33 protected boolean stop;
36 * BusyWidget constructor comment.
39 * org.eclipse.swt.widgets.Composite
43 public BusyIndicator(Composite parent, int style) {
46 images = ImageResource.getBusyImages();
48 addPaintListener(new PaintListener() {
49 public void paintControl(PaintEvent event) {
57 public Point computeSize(int wHint, int hHint, boolean changed) {
58 return new Point(25, 25);
62 * Creates a thread to animate the image.
64 protected synchronized void createBusyThread() {
65 if (busyThread != null)
69 busyThread = new Thread() {
76 Display.getDefault().syncExec(new Runnable() {
80 setImage(images[count]);
89 } catch (Exception e) {
92 if (busyThread == null)
93 Display.getDefault().syncExec(new Thread() {
98 } catch (Exception e) {
99 Trace.trace(Trace.WARNING, "Busy error", e);
104 busyThread.setPriority(Thread.NORM_PRIORITY + 2);
105 busyThread.setDaemon(true);
109 public void dispose() {
116 * Return the image or <code>null</code>.
118 // public Image getImage() {
123 * Returns true if it is currently busy.
127 public boolean isBusy() {
128 return (busyThread != null);
132 * Process the paint event
134 protected void onPaint(PaintEvent event) {
135 Rectangle rect = getClientArea();
136 if (rect.width == 0 || rect.height == 0)
141 gc.drawImage(image, 2, 2);
145 * Sets the indicators busy count up (true) or down (false) one.
150 public synchronized void setBusy(boolean busy) {
152 if (busyThread == null)
155 if (busyThread != null) {
163 * Set the image. The value <code>null</code> clears it.
165 public void setImage(Image image) {
166 if (image != this.image && !isDisposed()) {