home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / ImageIcon.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.8 KB  |  242 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.MediaTracker;
  7. import java.awt.Toolkit;
  8. import java.awt.image.ColorModel;
  9. import java.awt.image.ImageObserver;
  10. import java.awt.image.MemoryImageSource;
  11. import java.awt.image.PixelGrabber;
  12. import java.io.IOException;
  13. import java.io.ObjectInputStream;
  14. import java.io.ObjectOutputStream;
  15. import java.io.Serializable;
  16. import java.net.URL;
  17. import javax.accessibility.Accessible;
  18. import javax.accessibility.AccessibleContext;
  19.  
  20. public class ImageIcon implements Icon, Serializable, Accessible {
  21.    private transient String filename;
  22.    private transient URL location;
  23.    transient Image image;
  24.    transient int loadStatus;
  25.    ImageObserver imageObserver;
  26.    String description;
  27.    protected static final Component component = new 1();
  28.    protected static final MediaTracker tracker;
  29.    int width;
  30.    int height;
  31.    private AccessibleImageIcon accessibleContext;
  32.  
  33.    public ImageIcon(String var1, String var2) {
  34.       this.loadStatus = 0;
  35.       this.description = null;
  36.       this.width = -1;
  37.       this.height = -1;
  38.       this.accessibleContext = null;
  39.       this.image = Toolkit.getDefaultToolkit().getImage(var1);
  40.       if (this.image != null) {
  41.          this.filename = var1;
  42.          this.description = var2;
  43.          this.loadImage(this.image);
  44.       }
  45.    }
  46.  
  47.    public ImageIcon(String var1) {
  48.       this(var1, var1);
  49.    }
  50.  
  51.    public ImageIcon(URL var1, String var2) {
  52.       this.loadStatus = 0;
  53.       this.description = null;
  54.       this.width = -1;
  55.       this.height = -1;
  56.       this.accessibleContext = null;
  57.       this.image = Toolkit.getDefaultToolkit().getImage(var1);
  58.       if (this.image != null) {
  59.          this.location = var1;
  60.          this.description = var2;
  61.          this.loadImage(this.image);
  62.       }
  63.    }
  64.  
  65.    public ImageIcon(URL var1) {
  66.       this(var1, var1.toExternalForm());
  67.    }
  68.  
  69.    public ImageIcon(Image var1, String var2) {
  70.       this(var1);
  71.       this.description = var2;
  72.    }
  73.  
  74.    public ImageIcon(Image var1) {
  75.       this.loadStatus = 0;
  76.       this.description = null;
  77.       this.width = -1;
  78.       this.height = -1;
  79.       this.accessibleContext = null;
  80.       this.image = var1;
  81.       Object var2 = var1.getProperty("comment", this.imageObserver);
  82.       if (var2 instanceof String) {
  83.          this.description = (String)var2;
  84.       }
  85.  
  86.       this.loadImage(var1);
  87.    }
  88.  
  89.    public ImageIcon(byte[] var1, String var2) {
  90.       this.loadStatus = 0;
  91.       this.description = null;
  92.       this.width = -1;
  93.       this.height = -1;
  94.       this.accessibleContext = null;
  95.       this.image = Toolkit.getDefaultToolkit().createImage(var1);
  96.       if (this.image != null) {
  97.          this.description = var2;
  98.          this.loadImage(this.image);
  99.       }
  100.    }
  101.  
  102.    public ImageIcon(byte[] var1) {
  103.       this.loadStatus = 0;
  104.       this.description = null;
  105.       this.width = -1;
  106.       this.height = -1;
  107.       this.accessibleContext = null;
  108.       this.image = Toolkit.getDefaultToolkit().createImage(var1);
  109.       if (this.image != null) {
  110.          Object var2 = this.image.getProperty("comment", this.imageObserver);
  111.          if (var2 instanceof String) {
  112.             this.description = (String)var2;
  113.          }
  114.  
  115.          this.loadImage(this.image);
  116.       }
  117.    }
  118.  
  119.    public ImageIcon() {
  120.       this.loadStatus = 0;
  121.       this.description = null;
  122.       this.width = -1;
  123.       this.height = -1;
  124.       this.accessibleContext = null;
  125.    }
  126.  
  127.    protected void loadImage(Image var1) {
  128.       MediaTracker var2 = tracker;
  129.       synchronized(var2) {
  130.          tracker.addImage(var1, 0);
  131.  
  132.          try {
  133.             tracker.waitForID(0, 0L);
  134.          } catch (InterruptedException var5) {
  135.             System.out.println("INTERRUPTED while loading Image");
  136.          }
  137.  
  138.          this.loadStatus = tracker.statusID(0, false);
  139.          tracker.removeImage(var1, 0);
  140.          this.width = var1.getWidth(this.imageObserver);
  141.          this.height = var1.getHeight(this.imageObserver);
  142.       }
  143.    }
  144.  
  145.    public int getImageLoadStatus() {
  146.       return this.loadStatus;
  147.    }
  148.  
  149.    public Image getImage() {
  150.       return this.image;
  151.    }
  152.  
  153.    public void setImage(Image var1) {
  154.       this.image = var1;
  155.       this.loadImage(var1);
  156.    }
  157.  
  158.    public String getDescription() {
  159.       return this.description;
  160.    }
  161.  
  162.    public void setDescription(String var1) {
  163.       this.description = var1;
  164.    }
  165.  
  166.    public synchronized void paintIcon(Component var1, Graphics var2, int var3, int var4) {
  167.       if (this.imageObserver == null) {
  168.          var2.drawImage(this.image, var3, var4, var1);
  169.       } else {
  170.          var2.drawImage(this.image, var3, var4, this.imageObserver);
  171.       }
  172.  
  173.    }
  174.  
  175.    public int getIconWidth() {
  176.       return this.width;
  177.    }
  178.  
  179.    public int getIconHeight() {
  180.       return this.height;
  181.    }
  182.  
  183.    public void setImageObserver(ImageObserver var1) {
  184.       this.imageObserver = var1;
  185.    }
  186.  
  187.    public ImageObserver getImageObserver() {
  188.       return this.imageObserver;
  189.    }
  190.  
  191.    public String toString() {
  192.       return this.description;
  193.    }
  194.  
  195.    private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
  196.       var1.defaultReadObject();
  197.       int var2 = var1.readInt();
  198.       int var3 = var1.readInt();
  199.       int[] var4 = (int[])var1.readObject();
  200.       if (var4 != null) {
  201.          Toolkit var5 = Toolkit.getDefaultToolkit();
  202.          ColorModel var6 = ColorModel.getRGBdefault();
  203.          this.image = var5.createImage(new MemoryImageSource(var2, var3, var6, var4, 0, var2));
  204.       }
  205.  
  206.    }
  207.  
  208.    private void writeObject(ObjectOutputStream var1) throws IOException {
  209.       var1.defaultWriteObject();
  210.       int var2 = this.getIconWidth();
  211.       int var3 = this.getIconHeight();
  212.       int[] var4 = this.image != null ? new int[var2 * var3] : null;
  213.       if (this.image != null) {
  214.          try {
  215.             PixelGrabber var5 = new PixelGrabber(this.image, 0, 0, var2, var3, var4, 0, var2);
  216.             var5.grabPixels();
  217.             if ((var5.getStatus() & 128) != 0) {
  218.                throw new IOException("failed to load image contents");
  219.             }
  220.          } catch (InterruptedException var6) {
  221.             throw new IOException("image load interrupted");
  222.          }
  223.       }
  224.  
  225.       var1.writeInt(var2);
  226.       var1.writeInt(var3);
  227.       var1.writeObject(var4);
  228.    }
  229.  
  230.    public AccessibleContext getAccessibleContext() {
  231.       if (this.accessibleContext == null) {
  232.          this.accessibleContext = new AccessibleImageIcon(this);
  233.       }
  234.  
  235.       return this.accessibleContext;
  236.    }
  237.  
  238.    static {
  239.       tracker = new MediaTracker(component);
  240.    }
  241. }
  242.