home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / NETSCAP4.06 / CP32E406.EXE / nav40.z / java40.jar / sun / awt / image / Image.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-08-13  |  4.7 KB  |  284 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.                SecurityManager.enablePrivilege("UniversalThreadAccess");
  198.                Thread.currentThread().interrupt();
  199.                SecurityManager.revertPrivilege();
  200.                return;
  201.             }
  202.  
  203.             if ((this.availinfo & 64) != 0) {
  204.                return;
  205.             }
  206.          }
  207.       }
  208.  
  209.    }
  210.  
  211.    synchronized void addInfo(int var1) {
  212.       this.availinfo |= var1;
  213.       this.notifyAll();
  214.    }
  215.  
  216.    void setDimensions(int var1, int var2) {
  217.       this.width = var1;
  218.       this.height = var2;
  219.       this.addInfo(3);
  220.    }
  221.  
  222.    void setProperties(Hashtable var1) {
  223.       if (var1 == null) {
  224.          var1 = new Hashtable();
  225.       }
  226.  
  227.       this.properties = var1;
  228.       this.addInfo(4);
  229.    }
  230.  
  231.    synchronized void infoDone(int var1) {
  232.       if (var1 != 1 && (~this.availinfo & 3) == 0) {
  233.          if ((this.availinfo & 4) == 0) {
  234.             this.setProperties((Hashtable)null);
  235.          }
  236.  
  237.       } else {
  238.          this.addInfo(64);
  239.       }
  240.    }
  241.  
  242.    public void flush() {
  243.       if (this.src != null) {
  244.          this.src.checkSecurity((Object)null, false);
  245.       }
  246.  
  247.       if (!(this.source instanceof OffScreenImageSource)) {
  248.          synchronized(this){}
  249.  
  250.          ImageRepresentation var1;
  251.          try {
  252.             this.availinfo &= -65;
  253.             var1 = this.imagerep;
  254.             this.imagerep = null;
  255.          } catch (Throwable var4) {
  256.             throw var4;
  257.          }
  258.  
  259.          if (var1 != null) {
  260.             var1.abort();
  261.          }
  262.  
  263.          if (this.src != null) {
  264.             this.src.flush();
  265.          }
  266.       }
  267.  
  268.    }
  269.  
  270.    protected abstract ImageRepresentation makeImageRep();
  271.  
  272.    protected synchronized ImageRepresentation getImageRep() {
  273.       if (this.src != null) {
  274.          this.src.checkSecurity((Object)null, false);
  275.       }
  276.  
  277.       if (this.imagerep == null) {
  278.          this.imagerep = this.makeImageRep();
  279.       }
  280.  
  281.       return this.imagerep;
  282.    }
  283. }
  284.