// Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ImageIcon.java

package com.symantec.itools.javax.swing.icons;

import java.awt.*;
import java.awt.image.ImageObserver;
import java.io.*;
import java.net.URL;
import javax.swing.Icon;

public class ImageIcon
    implements Icon, Serializable
{

    public ImageIcon()
    {
        width = -1;
        height = -1;
    }

    public ImageIcon(URL url)
    {
        width = -1;
        height = -1;
        imageLocation = url;
        image = Toolkit.getDefaultToolkit().getImage(url);
        loadImage(image);
    }

    public ImageIcon(Image image1)
    {
        width = -1;
        height = -1;
        image = image1;
        loadImage(image);
    }

    public ImageIcon(InputStream inputstream)
        throws IOException
    {
        width = -1;
        height = -1;
        byte abyte0[] = new byte[1024];
        ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
        int i;
        while((i = inputstream.read(abyte0)) > 0) 
            bytearrayoutputstream.write(abyte0, 0, i);

        inputstream.close();
        bytearrayoutputstream.flush();
        image = Toolkit.getDefaultToolkit().createImage(bytearrayoutputstream.toByteArray());
        loadImage(image);
        bytearrayoutputstream.close();
    }

    public URL getImageLocation()
    {
        return imageLocation;
    }

    public void setImageLocation(URL url)
    {
        imageLocation = url;
        image = Toolkit.getDefaultToolkit().getImage(url);
        loadImage(image);
    }

    public void setImageObserver(ImageObserver imageobserver)
    {
        imageObserver = imageobserver;
    }

    public ImageObserver getImageObserver()
    {
        return imageObserver;
    }

    public synchronized void paintIcon(Component component1, Graphics g, int i, int j)
    {
        if(image != null)
        {
            if(imageObserver == null)
            {
                g.drawImage(image, i, j, component1);
                return;
            }
            g.drawImage(image, i, j, imageObserver);
        }
    }

    public int getIconWidth()
    {
        return width;
    }

    public int getIconHeight()
    {
        return height;
    }

    protected void loadImage(Image image1)
    {
        synchronized(tracker)
        {
            tracker.addImage(image1, 0);
            try
            {
                tracker.waitForID(0, 5000L);
            }
            catch(InterruptedException _ex)
            {
                System.out.println("INTERRUPTED while loading Image");
            }
            loadStatus = tracker.statusID(0, false);
            tracker.removeImage(image1, 0);
            width = image1.getWidth(imageObserver);
            height = image1.getHeight(imageObserver);
        }
    }

    public int getImageLoadStatus()
    {
        return loadStatus;
    }

    public Image getImage()
    {
        return image;
    }

    protected transient Image image;
    protected transient int loadStatus;
    protected ImageObserver imageObserver;
    protected URL imageLocation;
    protected static final Component component;
    protected static final MediaTracker tracker;
    protected int width;
    protected int height;

    static 
    {
        component = new Component() {

        };
        tracker = new MediaTracker(component);
    }
}
