home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / awt / image / ImageWatched.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  1.8 KB  |  71 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.Image;
  4. import java.awt.image.ImageObserver;
  5. import java.util.Enumeration;
  6. import java.util.NoSuchElementException;
  7. import java.util.Vector;
  8.  
  9. public class ImageWatched {
  10.    protected Vector watchers;
  11.  
  12.    public synchronized void addWatcher(ImageObserver iw) {
  13.       if (iw != null && !this.isWatcher(iw)) {
  14.          if (this.watchers == null) {
  15.             this.watchers = new Vector();
  16.          }
  17.  
  18.          this.watchers.addElement(iw);
  19.       }
  20.  
  21.    }
  22.  
  23.    public synchronized boolean isWatcher(ImageObserver iw) {
  24.       return this.watchers != null && iw != null && this.watchers.contains(iw);
  25.    }
  26.  
  27.    public synchronized void removeWatcher(ImageObserver iw) {
  28.       if (iw != null && this.watchers != null) {
  29.          this.watchers.removeElement(iw);
  30.          if (this.watchers.size() == 0) {
  31.             this.watchers = null;
  32.          }
  33.       }
  34.  
  35.    }
  36.  
  37.    public void newInfo(Image img, int info, int x, int y, int w, int h) {
  38.       if (this.watchers != null) {
  39.          Enumeration enum = this.watchers.elements();
  40.          Vector uninterested = null;
  41.  
  42.          while(enum.hasMoreElements()) {
  43.             ImageObserver iw;
  44.             try {
  45.                iw = (ImageObserver)enum.nextElement();
  46.             } catch (NoSuchElementException var10) {
  47.                break;
  48.             }
  49.  
  50.             if (!iw.imageUpdate(img, info, x, y, w, h)) {
  51.                if (uninterested == null) {
  52.                   uninterested = new Vector();
  53.                }
  54.  
  55.                uninterested.addElement(iw);
  56.             }
  57.          }
  58.  
  59.          if (uninterested != null) {
  60.             enum = uninterested.elements();
  61.  
  62.             while(enum.hasMoreElements()) {
  63.                ImageObserver iw = (ImageObserver)enum.nextElement();
  64.                this.removeWatcher(iw);
  65.             }
  66.          }
  67.       }
  68.  
  69.    }
  70. }
  71.