01: /*
02: * @(#)ImageWatched.java 1.20 06/10/11
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: *
26: */
27:
28: package sun.awt.image;
29:
30: import java.util.Vector;
31: import java.util.Enumeration;
32: import java.util.NoSuchElementException;
33: import java.awt.Image;
34: import java.awt.image.ImageObserver;
35:
36: public class ImageWatched {
37: public ImageWatched() {
38: }
39:
40: protected Vector watchers;
41:
42: public synchronized void addWatcher(ImageObserver iw) {
43: if (iw != null && !isWatcher(iw)) {
44: if (watchers == null) {
45: watchers = new Vector();
46: }
47: watchers.addElement(iw);
48: }
49: }
50:
51: public synchronized boolean isWatcher(ImageObserver iw) {
52: return (watchers != null && iw != null && watchers.contains(iw));
53: }
54:
55: public synchronized void removeWatcher(ImageObserver iw) {
56: if (iw != null && watchers != null) {
57: watchers.removeElement(iw);
58: if (watchers.size() == 0) {
59: watchers = null;
60: }
61: }
62: }
63:
64: public void newInfo(Image img, int info, int x, int y, int w, int h) {
65: if (watchers != null) {
66: Enumeration enum_ = watchers.elements();
67: Vector uninterested = null;
68: while (enum_.hasMoreElements()) {
69: ImageObserver iw;
70: try {
71: iw = (ImageObserver) enum_.nextElement();
72: } catch (NoSuchElementException e) {
73: break;
74: }
75: if (!iw.imageUpdate(img, info, x, y, w, h)) {
76: if (uninterested == null) {
77: uninterested = new Vector();
78: }
79: uninterested.addElement(iw);
80: }
81: }
82: if (uninterested != null) {
83: enum_ = uninterested.elements();
84: while (enum_.hasMoreElements()) {
85: ImageObserver iw = (ImageObserver) enum_
86: .nextElement();
87: removeWatcher(iw);
88: }
89: }
90: }
91: }
92: }
|