home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / image / ImageWatched.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.4 KB  |  84 lines

  1. /*
  2.  * @(#)ImageWatched.java    1.9 95/12/06 Jim Graham
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt.image;
  21.  
  22. import java.util.Vector;
  23. import java.util.Enumeration;
  24. import java.util.NoSuchElementException;
  25. import java.awt.Image;
  26. import java.awt.image.ImageObserver;
  27.  
  28. public class ImageWatched {
  29.     public ImageWatched() {
  30.     }
  31.  
  32.     protected Vector watchers;
  33.  
  34.     public synchronized void addWatcher(ImageObserver iw) {
  35.     if (iw != null && !isWatcher(iw)) {
  36.         if (watchers == null) {
  37.         watchers = new Vector();
  38.         }
  39.         watchers.addElement(iw);
  40.     }
  41.     }
  42.  
  43.     public synchronized boolean isWatcher(ImageObserver iw) {
  44.     return (watchers != null && iw != null && watchers.contains(iw));
  45.     }
  46.  
  47.     public synchronized void removeWatcher(ImageObserver iw) {
  48.     if (iw != null && watchers != null) {
  49.         watchers.removeElement(iw);
  50.         if (watchers.size() == 0) {
  51.         watchers = null;
  52.         }
  53.     }
  54.     }
  55.  
  56.     public void newInfo(Image img, int info, int x, int y, int w, int h) {
  57.     if (watchers != null) {
  58.         Enumeration enum = watchers.elements();
  59.         Vector uninterested = null;
  60.         while (enum.hasMoreElements()) {
  61.         ImageObserver iw;
  62.         try {
  63.             iw = (ImageObserver) enum.nextElement();
  64.         } catch (NoSuchElementException e) {
  65.             break;
  66.         }
  67.         if (!iw.imageUpdate(img, info, x, y, w, h)) {
  68.             if (uninterested == null) {
  69.             uninterested = new Vector();
  70.             }
  71.             uninterested.addElement(iw);
  72.         }
  73.         }
  74.         if (uninterested != null) {
  75.         enum = uninterested.elements();
  76.         while (enum.hasMoreElements()) {
  77.             ImageObserver iw = (ImageObserver) enum.nextElement();
  78.             removeWatcher(iw);
  79.         }
  80.         }
  81.     }
  82.     }
  83. }
  84.