home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / sun / awt / image / ImageRepresentation.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  5.1 KB  |  440 lines

  1. package sun.awt.image;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Rectangle;
  6. import java.awt.image.ColorModel;
  7. import java.awt.image.ImageConsumer;
  8. import java.awt.image.ImageObserver;
  9. import java.util.Hashtable;
  10.  
  11. public class ImageRepresentation extends ImageWatched implements ImageConsumer {
  12.    int pData;
  13.    InputStreamImageSource src;
  14.    Image image;
  15.    int tag;
  16.    int srcW;
  17.    int srcH;
  18.    public int width;
  19.    public int height;
  20.    int hints;
  21.    int availinfo;
  22.    boolean offscreen;
  23.    Rectangle newbits;
  24.    private boolean consuming = false;
  25.    private int numWaiters;
  26.  
  27.    ImageRepresentation(Image var1, int var2, int var3, int var4) {
  28.       this.image = var1;
  29.       this.tag = var4;
  30.       if (var2 != 0 && var3 != 0) {
  31.          if (var2 > 0) {
  32.             this.width = var2;
  33.             this.availinfo |= 1;
  34.          }
  35.  
  36.          if (var3 > 0) {
  37.             this.height = var3;
  38.             this.availinfo |= 2;
  39.          }
  40.  
  41.          if (this.image.getSource() instanceof InputStreamImageSource) {
  42.             this.src = (InputStreamImageSource)this.image.getSource();
  43.          }
  44.  
  45.       } else {
  46.          throw new IllegalArgumentException();
  47.       }
  48.    }
  49.  
  50.    native void offscreenInit(Color var1);
  51.  
  52.    native void offscreenInit102();
  53.  
  54.    public synchronized void reconstruct(int var1) {
  55.       if (this.src != null) {
  56.          this.src.checkSecurity((Object)null, false);
  57.       }
  58.  
  59.       int var2 = var1 & ~this.availinfo;
  60.       if ((this.availinfo & 64) == 0 && var2 != 0) {
  61.          ++this.numWaiters;
  62.  
  63.          try {
  64.             this.startProduction();
  65.  
  66.             for(int var9 = var1 & ~this.availinfo; (this.availinfo & 64) == 0 && var9 != 0; var9 = var1 & ~this.availinfo) {
  67.                try {
  68.                   this.wait();
  69.                } catch (InterruptedException var7) {
  70.                   Thread.currentThread().interrupt();
  71.                   return;
  72.                }
  73.             }
  74.  
  75.          } finally {
  76.             this.decrementWaiters();
  77.          }
  78.       }
  79.    }
  80.  
  81.    public synchronized void setDimensions(int var1, int var2) {
  82.       if (this.src != null) {
  83.          this.src.checkSecurity((Object)null, false);
  84.       }
  85.  
  86.       this.srcW = var1;
  87.       this.srcH = var2;
  88.       if ((this.availinfo & 1) == 0 && (this.availinfo & 2) == 0) {
  89.          this.width = var1;
  90.          this.height = var2;
  91.       } else if ((this.availinfo & 1) == 0) {
  92.          this.width = var1 * this.height / var2;
  93.       } else {
  94.          if ((this.availinfo & 2) != 0) {
  95.             return;
  96.          }
  97.  
  98.          this.height = var2 * this.width / var1;
  99.       }
  100.  
  101.       if (this.srcW > 0 && this.srcH > 0 && this.width > 0 && this.height > 0) {
  102.          this.availinfo |= 3;
  103.       } else {
  104.          this.imageComplete(1);
  105.       }
  106.    }
  107.  
  108.    public void setProperties(Hashtable var1) {
  109.       if (this.src != null) {
  110.          this.src.checkSecurity((Object)null, false);
  111.       }
  112.  
  113.    }
  114.  
  115.    public void setColorModel(ColorModel var1) {
  116.       if (this.src != null) {
  117.          this.src.checkSecurity((Object)null, false);
  118.       }
  119.  
  120.    }
  121.  
  122.    public void setHints(int var1) {
  123.       if (this.src != null) {
  124.          this.src.checkSecurity((Object)null, false);
  125.       }
  126.  
  127.       this.hints = var1;
  128.    }
  129.  
  130.    private native boolean setBytePixels(int var1, int var2, int var3, int var4, ColorModel var5, byte[] var6, int var7, int var8);
  131.  
  132.    public void setPixels(int var1, int var2, int var3, int var4, ColorModel var5, byte[] var6, int var7, int var8) {
  133.       if (this.src != null) {
  134.          this.src.checkSecurity((Object)null, false);
  135.       }
  136.  
  137.       boolean var9 = false;
  138.       synchronized(this){}
  139.  
  140.       int var10;
  141.       int var11;
  142.       int var12;
  143.       int var13;
  144.       try {
  145.          if (this.newbits == null) {
  146.             this.newbits = new Rectangle(0, 0, this.width, this.height);
  147.          }
  148.  
  149.          if (this.setBytePixels(var1, var2, var3, var4, var5, var6, var7, var8)) {
  150.             this.availinfo |= 8;
  151.             var9 = true;
  152.          }
  153.  
  154.          var10 = this.newbits.x;
  155.          var11 = this.newbits.y;
  156.          var12 = this.newbits.width;
  157.          var13 = this.newbits.height;
  158.       } catch (Throwable var16) {
  159.          throw var16;
  160.       }
  161.  
  162.       if (var9 && !this.offscreen) {
  163.          ((ImageWatched)this).newInfo(this.image, 8, var10, var11, var12, var13);
  164.       }
  165.  
  166.    }
  167.  
  168.    private native boolean setIntPixels(int var1, int var2, int var3, int var4, ColorModel var5, int[] var6, int var7, int var8);
  169.  
  170.    public void setPixels(int var1, int var2, int var3, int var4, ColorModel var5, int[] var6, int var7, int var8) {
  171.       if (this.src != null) {
  172.          this.src.checkSecurity((Object)null, false);
  173.       }
  174.  
  175.       boolean var9 = false;
  176.       synchronized(this){}
  177.  
  178.       int var10;
  179.       int var11;
  180.       int var12;
  181.       int var13;
  182.       try {
  183.          if (this.newbits == null) {
  184.             this.newbits = new Rectangle(0, 0, this.width, this.height);
  185.          }
  186.  
  187.          if (this.setIntPixels(var1, var2, var3, var4, var5, var6, var7, var8)) {
  188.             this.availinfo |= 8;
  189.             var9 = true;
  190.          }
  191.  
  192.          var10 = this.newbits.x;
  193.          var11 = this.newbits.y;
  194.          var12 = this.newbits.width;
  195.          var13 = this.newbits.height;
  196.       } catch (Throwable var16) {
  197.          throw var16;
  198.       }
  199.  
  200.       if (var9 && !this.offscreen) {
  201.          ((ImageWatched)this).newInfo(this.image, 8, var10, var11, var12, var13);
  202.       }
  203.  
  204.    }
  205.  
  206.    private native boolean finish(boolean var1);
  207.  
  208.    public void imageComplete(int var1) {
  209.       if (this.src != null) {
  210.          this.src.checkSecurity((Object)null, false);
  211.       }
  212.  
  213.       boolean var2;
  214.       short var3;
  215.       switch (var1) {
  216.          case 1:
  217.             this.image.addInfo(64);
  218.             var2 = true;
  219.             var3 = 64;
  220.             this.dispose();
  221.             break;
  222.          case 2:
  223.             var2 = false;
  224.             var3 = 16;
  225.             break;
  226.          case 3:
  227.             var2 = true;
  228.             var3 = 32;
  229.             if (this.finish(false)) {
  230.                this.image.getSource().requestTopDownLeftRightResend(this);
  231.                this.finish(true);
  232.             }
  233.             break;
  234.          case 4:
  235.          default:
  236.             var2 = true;
  237.             var3 = 128;
  238.       }
  239.  
  240.       synchronized(this){}
  241.  
  242.       try {
  243.          if (var2) {
  244.             this.image.getSource().removeConsumer(this);
  245.             this.consuming = false;
  246.             this.newbits = null;
  247.          }
  248.  
  249.          this.availinfo |= var3;
  250.          this.notifyAll();
  251.       } catch (Throwable var6) {
  252.          throw var6;
  253.       }
  254.  
  255.       if (!this.offscreen) {
  256.          ((ImageWatched)this).newInfo(this.image, var3, 0, 0, this.width, this.height);
  257.       }
  258.  
  259.    }
  260.  
  261.    void startProduction() {
  262.       if (!this.consuming) {
  263.          this.consuming = true;
  264.          this.image.getSource().startProduction(this);
  265.       }
  266.  
  267.    }
  268.  
  269.    private synchronized void checkConsumption() {
  270.       if (super.watchers == null && this.numWaiters == 0 && (this.availinfo & 32) == 0) {
  271.          this.dispose();
  272.       }
  273.  
  274.    }
  275.  
  276.    public synchronized void removeWatcher(ImageObserver var1) {
  277.       super.removeWatcher(var1);
  278.       this.checkConsumption();
  279.    }
  280.  
  281.    private synchronized void decrementWaiters() {
  282.       --this.numWaiters;
  283.       this.checkConsumption();
  284.    }
  285.  
  286.    public boolean prepare(ImageObserver var1) {
  287.       if (this.src != null) {
  288.          this.src.checkSecurity((Object)null, false);
  289.       }
  290.  
  291.       if ((this.availinfo & 64) != 0) {
  292.          if (var1 != null) {
  293.             var1.imageUpdate(this.image, 192, -1, -1, -1, -1);
  294.          }
  295.  
  296.          return false;
  297.       } else {
  298.          boolean var2 = (this.availinfo & 32) != 0;
  299.          if (!var2) {
  300.             ((ImageWatched)this).addWatcher(var1);
  301.             this.startProduction();
  302.             var2 = (this.availinfo & 32) != 0;
  303.          }
  304.  
  305.          return var2;
  306.       }
  307.    }
  308.  
  309.    public int check(ImageObserver var1) {
  310.       if (this.src != null) {
  311.          this.src.checkSecurity((Object)null, false);
  312.       }
  313.  
  314.       if ((this.availinfo & 96) == 0) {
  315.          ((ImageWatched)this).addWatcher(var1);
  316.       }
  317.  
  318.       return this.availinfo;
  319.    }
  320.  
  321.    synchronized native void imageDraw(Graphics var1, int var2, int var3, Color var4);
  322.  
  323.    synchronized native void imageStretch(Graphics var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, Color var10);
  324.  
  325.    public boolean drawImage(Graphics var1, int var2, int var3, Color var4, ImageObserver var5) {
  326.       if (this.src != null) {
  327.          this.src.checkSecurity((Object)null, false);
  328.       }
  329.  
  330.       if ((this.availinfo & 64) != 0) {
  331.          if (var5 != null) {
  332.             var5.imageUpdate(this.image, 192, -1, -1, -1, -1);
  333.          }
  334.  
  335.          return false;
  336.       } else {
  337.          boolean var6 = (this.availinfo & 32) != 0;
  338.          if (!var6) {
  339.             ((ImageWatched)this).addWatcher(var5);
  340.             this.startProduction();
  341.             var6 = (this.availinfo & 32) != 0;
  342.          }
  343.  
  344.          this.imageDraw(var1, var2, var3, var4);
  345.          return var6;
  346.       }
  347.    }
  348.  
  349.    public boolean drawStretchImage(Graphics var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, Color var10, ImageObserver var11) {
  350.       if (this.src != null) {
  351.          this.src.checkSecurity((Object)null, false);
  352.       }
  353.  
  354.       if ((this.availinfo & 64) != 0) {
  355.          if (var11 != null) {
  356.             var11.imageUpdate(this.image, 192, -1, -1, -1, -1);
  357.          }
  358.  
  359.          return false;
  360.       } else {
  361.          boolean var12 = (this.availinfo & 32) != 0;
  362.          if (!var12) {
  363.             ((ImageWatched)this).addWatcher(var11);
  364.             this.startProduction();
  365.             var12 = (this.availinfo & 32) != 0;
  366.          }
  367.  
  368.          this.imageStretch(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10);
  369.          return var12;
  370.       }
  371.    }
  372.  
  373.    public boolean drawScaledImage(Graphics var1, int var2, int var3, int var4, int var5, Color var6, ImageObserver var7) {
  374.       if (this.src != null) {
  375.          this.src.checkSecurity((Object)null, false);
  376.       }
  377.  
  378.       if ((this.availinfo & 64) != 0) {
  379.          if (var7 != null) {
  380.             var7.imageUpdate(this.image, 192, -1, -1, -1, -1);
  381.          }
  382.  
  383.          return false;
  384.       } else {
  385.          boolean var8 = (this.availinfo & 32) != 0;
  386.          if (!var8) {
  387.             ((ImageWatched)this).addWatcher(var7);
  388.             this.startProduction();
  389.             var8 = (this.availinfo & 32) != 0;
  390.          }
  391.  
  392.          if ((~this.availinfo & 3) != 0) {
  393.             return false;
  394.          } else {
  395.             if (var4 < 0) {
  396.                if (var5 < 0) {
  397.                   var4 = this.width;
  398.                   var5 = this.height;
  399.                } else {
  400.                   var4 = var5 * this.width / this.height;
  401.                }
  402.             } else if (var5 < 0) {
  403.                var5 = var4 * this.height / this.width;
  404.             }
  405.  
  406.             if (var4 == this.width && var5 == this.height) {
  407.                this.imageDraw(var1, var2, var3, var6);
  408.             } else {
  409.                this.imageStretch(var1, var2, var3, var2 + var4, var3 + var5, 0, 0, this.width, this.height, var6);
  410.             }
  411.  
  412.             return var8;
  413.          }
  414.       }
  415.    }
  416.  
  417.    private native void disposeImage();
  418.  
  419.    synchronized void abort() {
  420.       this.image.getSource().removeConsumer(this);
  421.       this.consuming = false;
  422.       this.newbits = null;
  423.       this.disposeImage();
  424.       ((ImageWatched)this).newInfo(this.image, 128, -1, -1, -1, -1);
  425.       this.availinfo &= -121;
  426.    }
  427.  
  428.    synchronized void dispose() {
  429.       this.image.getSource().removeConsumer(this);
  430.       this.consuming = false;
  431.       this.newbits = null;
  432.       this.disposeImage();
  433.       this.availinfo &= -57;
  434.    }
  435.  
  436.    public void finalize() {
  437.       this.dispose();
  438.    }
  439. }
  440.