/[classpath]/classpath/javax/swing/ImageIcon.java
ViewVC logotype

Diff of /classpath/javax/swing/ImageIcon.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by mkoch, Thu Dec 30 22:47:25 2004 UTC revision 1.11 by rabbit78, Fri Apr 8 18:12:17 2005 UTC
# Line 40  package javax.swing; Line 40  package javax.swing;
40  import java.awt.Component;  import java.awt.Component;
41  import java.awt.Graphics;  import java.awt.Graphics;
42  import java.awt.Image;  import java.awt.Image;
43    import java.awt.MediaTracker;
44  import java.awt.Toolkit;  import java.awt.Toolkit;
45  import java.awt.image.ImageObserver;  import java.awt.image.ImageObserver;
46  import java.io.Serializable;  import java.io.Serializable;
# Line 50  public class ImageIcon Line 51  public class ImageIcon
51    implements Icon, Serializable    implements Icon, Serializable
52  {  {
53    private static final long serialVersionUID = 532615968316031794L;    private static final long serialVersionUID = 532615968316031794L;
54    
55      /** A dummy Component that is used in the MediaTracker. */
56      protected static Component component = new Component(){};
57    
58      /** The MediaTracker used to monitor the loading of images. */
59      protected static MediaTracker tracker = new MediaTracker(component);
60    
61      /** The ID that is used in the tracker. */
62      private static int id;
63    
64    Image image;    Image image;
65    String description;    String description;
66    ImageObserver observer;    ImageObserver observer;
67    
68      /** The image loading status. */
69      private int loadStatus;
70    
71    public ImageIcon()    public ImageIcon()
72    {    {
73    }    }
# Line 95  public class ImageIcon Line 109  public class ImageIcon
109    
110    public ImageIcon(Image image, String description)    public ImageIcon(Image image, String description)
111    {    {
112      this.image = Toolkit.getDefaultToolkit().createImage(image.getSource());      setImage(image);
113      this.description = description;      setDescription(description);
114    }    }
115            
116    public ImageObserver getImageObserver()    public ImageObserver getImageObserver()
# Line 116  public class ImageIcon Line 130  public class ImageIcon
130    
131    public void setImage(Image image)    public void setImage(Image image)
132    {    {
133      this.image = Toolkit.getDefaultToolkit().createImage(image.getSource());      loadImage(image);
134        this.image = image;
135    }    }
136    
137    public String getDescription()    public String getDescription()
# Line 143  public class ImageIcon Line 158  public class ImageIcon
158    {    {
159      g.drawImage(image, x, y, observer != null ? observer : c);      g.drawImage(image, x, y, observer != null ? observer : c);
160    }    }
161    
162      /**
163       * Loads the image and blocks until the loading operation is finished.
164       *
165       * @param image the image to be loaded
166       */
167      protected void loadImage(Image image)
168      {
169        try
170          {
171            tracker.addImage(image, id);
172            id++;
173            tracker.waitForID(id - 1);
174          }
175        catch (InterruptedException ex)
176          {
177            ; // ignore this for now
178          }
179        finally
180          {
181            loadStatus = tracker.statusID(id - 1, false);
182          }
183      }
184    
185      /**
186       * Returns the load status of the icon image.
187       *
188       * @return the load status of the icon image
189       *
190       * @see {@link MediaTracker.COMPLETE}
191       * @see {@link MediaTracker.ABORTED}
192       * @see {@link MediaTracker.ERRORED}
193       */
194      public int getImageLoadStatus()
195      {
196        return loadStatus;
197      }
198  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26