home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / BitmapObserver.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.7 KB  |  82 lines  |  [TEXT/CWIE]

  1. // Bitmap.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import java.awt.image.ImageObserver;
  8.  
  9.  
  10. /** This class exists to assist with incremental bitmap loading, as well as
  11.   * getting a Bitmap's size information without having to have all of the
  12.   * Bitmap's data present.
  13.   */
  14. class BitmapObserver implements ImageObserver {
  15.     Application         application;
  16.     Bitmap              bitmap;
  17.     int                 lastInfo;
  18.  
  19.     BitmapObserver(Application application, Bitmap bitmap) {
  20.         super();
  21.  
  22.         this.application = application;
  23.         this.bitmap = bitmap;
  24.     }
  25.  
  26.     public synchronized boolean imageUpdate(java.awt.Image image,
  27.                                             int infoflags, int x, int y,
  28.                                             int width, int height) {
  29.         Target          updateTarget;
  30.  
  31.         lastInfo = infoflags;
  32.         if (image == null) {
  33.             return true;
  34.         }
  35.  
  36.         /* inform waiting bitmap that its width, height or data might
  37.          * be available
  38.          */
  39.         if ((infoflags & ImageObserver.WIDTH) != 0 ||
  40.             (infoflags & ImageObserver.HEIGHT) != 0 ||
  41.             (infoflags & ImageObserver.PROPERTIES) != 0 ||
  42.             (infoflags & ImageObserver.ALLBITS) != 0 ||
  43.             (infoflags & ImageObserver.ERROR) != 0 ||
  44.             (infoflags & ImageObserver.ABORT) != 0) {
  45.             notifyAll();
  46.             return true;
  47.         }
  48.  
  49.         if (!bitmap.loadsIncrementally()) {
  50.             return true;
  51.         }
  52.  
  53.         if ((infoflags & ImageObserver.SOMEBITS) != 0) {
  54.             bitmap.unionWithUpdateRect(x, y, width, height);
  55.             updateTarget = bitmap.updateTarget();
  56.             if (updateTarget != null && application != null) {
  57.                 application.performCommandLater(updateTarget,
  58.                                                 bitmap.updateCommand(),
  59.                                                 bitmap, true);
  60.             }
  61.         } else if ((infoflags & ImageObserver.FRAMEBITS) != 0) {
  62.             updateTarget = bitmap.updateTarget();
  63.             if (updateTarget != null && application != null) {
  64.                 application.performCommandLater(updateTarget,
  65.                                                 bitmap.updateCommand(),
  66.                                                 bitmap, true);
  67.             }
  68.         }
  69.  
  70.         return true;
  71.     }
  72.  
  73.     synchronized boolean allBitsPresent() {
  74.         return (lastInfo & ImageObserver.ALLBITS) != 0;
  75.     }
  76.  
  77.     synchronized boolean imageHasProblem() {
  78.         return ((lastInfo & ImageObserver.ERROR) != 0 ||
  79.                 (lastInfo & ImageObserver.ABORT) != 0);
  80.     }
  81. }
  82.