01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ImageWaiter.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.tools;
09:
10: import java.awt.Canvas;
11: import java.awt.Component;
12: import java.awt.Image;
13: import java.awt.MediaTracker;
14: import java.awt.image.ImageObserver;
15:
16: public class ImageWaiter {
17: private static Canvas mWaitComponent = null;
18:
19: public static void wait(Image image) {
20: if (mWaitComponent == null) {
21: mWaitComponent = new Canvas();
22: }
23: wait(image, mWaitComponent);
24: }
25:
26: public static void wait(Image image, Component component) {
27: MediaTracker tracker = new MediaTracker(component);
28: tracker.addImage(image, 0);
29: try {
30: tracker.waitForAll();
31: } catch (InterruptedException e) {
32: // do nothing
33: }
34: }
35:
36: public static void wait(final Image image,
37: final Component component, final ImageObserver imageobserver) {
38: final MediaTracker tracker = new MediaTracker(component);
39:
40: new Thread(new Runnable() {
41: public void run() {
42: tracker.addImage(image, 0);
43: try {
44: tracker.waitForAll();
45: } catch (InterruptedException e) {
46: // do nothing
47: }
48:
49: imageobserver.imageUpdate(image, 0, 0, 0, image
50: .getWidth(null), image.getHeight(null));
51: }
52: }).start();
53:
54: return;
55:
56: }
57:
58: }
|