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;
23 * An animated image to show busy status of the Web browser.
25 public class BusyIndicator extends Canvas {
26 protected Image[] images;
27 protected Image image;
29 protected Thread busyThread;
30 protected boolean stop;
33 * BusyWidget constructor comment.
34 * @param parent org.eclipse.swt.widgets.Composite
37 public BusyIndicator(Composite parent, int style) {
40 images = ImageResource.getBusyImages();
42 addPaintListener(new PaintListener() {
43 public void paintControl(PaintEvent event) {
51 public Point computeSize(int wHint, int hHint, boolean changed) {
52 return new Point(25, 25);
56 * Creates a thread to animate the image.
58 protected synchronized void createBusyThread() {
59 if (busyThread != null)
63 busyThread = new Thread() {
69 Display.getDefault().syncExec(new Runnable() {
73 setImage(images[count]);
82 } catch (Exception e) { }
84 if (busyThread == null)
85 Display.getDefault().syncExec(new Thread() {
90 } catch (Exception e) {
91 Trace.trace(Trace.WARNING, "Busy error", e);
96 busyThread.setPriority(Thread.NORM_PRIORITY + 2);
97 busyThread.setDaemon(true);
101 public void dispose() {
108 * Return the image or <code>null</code>.
110 public Image getImage() {
115 * Returns true if it is currently busy.
119 public boolean isBusy() {
120 return (busyThread != null);
124 * Process the paint event
126 protected void onPaint(PaintEvent event) {
127 Rectangle rect = getClientArea();
128 if (rect.width == 0 || rect.height == 0)
133 gc.drawImage(image, 2, 2);
137 * Sets the indicators busy count up (true) or down (false) one.
139 * @param busy boolean
141 public synchronized void setBusy(boolean busy) {
143 if (busyThread == null)
146 if (busyThread != null) {
155 * The value <code>null</code> clears it.
157 public void setImage(Image image) {
158 if (image != this.image && !isDisposed()) {