home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / awt / image / Image.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  4.5 KB  |  282 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.image.ImageObserver;
  7. import java.awt.image.ImageProducer;
  8. import java.util.Hashtable;
  9.  
  10. public abstract class Image extends java.awt.Image {
  11.    ImageProducer source;
  12.    InputStreamImageSource src;
  13.    ImageRepresentation imagerep;
  14.    private int width = -1;
  15.    private int height = -1;
  16.    private Hashtable properties;
  17.    private int availinfo;
  18.  
  19.    protected Image() {
  20.    }
  21.  
  22.    protected Image(Component var1, int var2, int var3) {
  23.       OffScreenImageSource var4 = new OffScreenImageSource(var1, var2, var3);
  24.       this.source = var4;
  25.       this.width = var2;
  26.       this.height = var3;
  27.       this.properties = new Hashtable();
  28.       this.availinfo |= 7;
  29.       this.imagerep = this.makeImageRep();
  30.       this.imagerep.offscreen = true;
  31.       this.imagerep.setDimensions(var2, var3);
  32.       this.imagerep.offscreenInit(var1.getBackground());
  33.       var4.setImageRep(this.imagerep);
  34.    }
  35.  
  36.    protected Image(ImageProducer var1) {
  37.       this.source = var1;
  38.       if (var1 instanceof InputStreamImageSource) {
  39.          this.src = (InputStreamImageSource)var1;
  40.       }
  41.  
  42.    }
  43.  
  44.    public ImageProducer getSource() {
  45.       if (this.src != null) {
  46.          this.src.checkSecurity((Object)null, false);
  47.       }
  48.  
  49.       return this.source;
  50.    }
  51.  
  52.    protected void initGraphics(Graphics var1) {
  53.       OffScreenImageSource var2 = (OffScreenImageSource)this.source;
  54.       var1.setColor(var2.target.getForeground());
  55.       var1.setFont(var2.target.getFont());
  56.    }
  57.  
  58.    public Color getBackground() {
  59.       OffScreenImageSource var1 = (OffScreenImageSource)this.source;
  60.       return var1.target.getBackground();
  61.    }
  62.  
  63.    public int getWidth() {
  64.       if (this.src != null) {
  65.          this.src.checkSecurity((Object)null, false);
  66.       }
  67.  
  68.       if ((this.availinfo & 1) == 0) {
  69.          this.reconstruct(1);
  70.       }
  71.  
  72.       return this.width;
  73.    }
  74.  
  75.    public synchronized int getWidth(ImageObserver var1) {
  76.       if (this.src != null) {
  77.          this.src.checkSecurity((Object)null, false);
  78.       }
  79.  
  80.       if ((this.availinfo & 1) == 0) {
  81.          this.addWatcher(var1, true);
  82.          if ((this.availinfo & 1) == 0) {
  83.             return -1;
  84.          }
  85.       }
  86.  
  87.       return this.width;
  88.    }
  89.  
  90.    public int getHeight() {
  91.       if (this.src != null) {
  92.          this.src.checkSecurity((Object)null, false);
  93.       }
  94.  
  95.       if ((this.availinfo & 2) == 0) {
  96.          this.reconstruct(2);
  97.       }
  98.  
  99.       return this.height;
  100.    }
  101.  
  102.    public synchronized int getHeight(ImageObserver var1) {
  103.       if (this.src != null) {
  104.          this.src.checkSecurity((Object)null, false);
  105.       }
  106.  
  107.       if ((this.availinfo & 2) == 0) {
  108.          this.addWatcher(var1, true);
  109.          if ((this.availinfo & 2) == 0) {
  110.             return -1;
  111.          }
  112.       }
  113.  
  114.       return this.height;
  115.    }
  116.  
  117.    public Object getProperty(String var1, ImageObserver var2) {
  118.       if (this.src != null) {
  119.          this.src.checkSecurity((Object)null, false);
  120.       }
  121.  
  122.       if (this.properties == null) {
  123.          this.addWatcher(var2, true);
  124.          if (this.properties == null) {
  125.             return null;
  126.          }
  127.       }
  128.  
  129.       Object var3 = this.properties.get(var1);
  130.       if (var3 == null) {
  131.          var3 = java.awt.Image.UndefinedProperty;
  132.       }
  133.  
  134.       return var3;
  135.    }
  136.  
  137.    public boolean hasError() {
  138.       if (this.src != null) {
  139.          this.src.checkSecurity((Object)null, false);
  140.       }
  141.  
  142.       return (this.availinfo & 64) != 0;
  143.    }
  144.  
  145.    public int check(ImageObserver var1) {
  146.       if (this.src != null) {
  147.          this.src.checkSecurity((Object)null, false);
  148.       }
  149.  
  150.       if ((this.availinfo & 64) == 0 && (~this.availinfo & 7) != 0) {
  151.          this.addWatcher(var1, false);
  152.       }
  153.  
  154.       return this.availinfo;
  155.    }
  156.  
  157.    public void preload(ImageObserver var1) {
  158.       if (this.src != null) {
  159.          this.src.checkSecurity((Object)null, false);
  160.       }
  161.  
  162.       if ((this.availinfo & 32) == 0) {
  163.          this.addWatcher(var1, true);
  164.       }
  165.  
  166.    }
  167.  
  168.    private synchronized void addWatcher(ImageObserver var1, boolean var2) {
  169.       if ((this.availinfo & 64) != 0) {
  170.          if (var1 != null) {
  171.             var1.imageUpdate(this, 192, -1, -1, -1, -1);
  172.          }
  173.  
  174.       } else {
  175.          ImageRepresentation var3 = this.getImageRep();
  176.          ((ImageWatched)var3).addWatcher(var1);
  177.          if (var2) {
  178.             var3.startProduction();
  179.          }
  180.  
  181.       }
  182.    }
  183.  
  184.    private synchronized void reconstruct(int var1) {
  185.       if ((var1 & ~this.availinfo) != 0) {
  186.          if ((this.availinfo & 64) != 0) {
  187.             return;
  188.          }
  189.  
  190.          ImageRepresentation var2 = this.getImageRep();
  191.          var2.startProduction();
  192.  
  193.          while((var1 & ~this.availinfo) != 0) {
  194.             try {
  195.                this.wait();
  196.             } catch (InterruptedException var3) {
  197.                Thread.currentThread().interrupt();
  198.                return;
  199.             }
  200.  
  201.             if ((this.availinfo & 64) != 0) {
  202.                return;
  203.             }
  204.          }
  205.       }
  206.  
  207.    }
  208.  
  209.    synchronized void addInfo(int var1) {
  210.       this.availinfo |= var1;
  211.       this.notifyAll();
  212.    }
  213.  
  214.    void setDimensions(int var1, int var2) {
  215.       this.width = var1;
  216.       this.height = var2;
  217.       this.addInfo(3);
  218.    }
  219.  
  220.    void setProperties(Hashtable var1) {
  221.       if (var1 == null) {
  222.          var1 = new Hashtable();
  223.       }
  224.  
  225.       this.properties = var1;
  226.       this.addInfo(4);
  227.    }
  228.  
  229.    synchronized void infoDone(int var1) {
  230.       if (var1 != 1 && (~this.availinfo & 3) == 0) {
  231.          if ((this.availinfo & 4) == 0) {
  232.             this.setProperties((Hashtable)null);
  233.          }
  234.  
  235.       } else {
  236.          this.addInfo(64);
  237.       }
  238.    }
  239.  
  240.    public void flush() {
  241.       if (this.src != null) {
  242.          this.src.checkSecurity((Object)null, false);
  243.       }
  244.  
  245.       if (!(this.source instanceof OffScreenImageSource)) {
  246.          synchronized(this){}
  247.  
  248.          ImageRepresentation var1;
  249.          try {
  250.             this.availinfo &= -65;
  251.             var1 = this.imagerep;
  252.             this.imagerep = null;
  253.          } catch (Throwable var4) {
  254.             throw var4;
  255.          }
  256.  
  257.          if (var1 != null) {
  258.             var1.abort();
  259.          }
  260.  
  261.          if (this.src != null) {
  262.             this.src.flush();
  263.          }
  264.       }
  265.  
  266.    }
  267.  
  268.    protected abstract ImageRepresentation makeImageRep();
  269.  
  270.    protected synchronized ImageRepresentation getImageRep() {
  271.       if (this.src != null) {
  272.          this.src.checkSecurity((Object)null, false);
  273.       }
  274.  
  275.       if (this.imagerep == null) {
  276.          this.imagerep = this.makeImageRep();
  277.       }
  278.  
  279.       return this.imagerep;
  280.    }
  281. }
  282.