Index: javax/swing/ImageIcon.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/ImageIcon.java,v retrieving revision 1.10 diff -u -r1.10 ImageIcon.java --- javax/swing/ImageIcon.java 30 Dec 2004 22:47:25 -0000 1.10 +++ javax/swing/ImageIcon.java 8 Apr 2005 17:48:23 -0000 @@ -40,6 +40,7 @@ import java.awt.Component; import java.awt.Graphics; import java.awt.Image; +import java.awt.MediaTracker; import java.awt.Toolkit; import java.awt.image.ImageObserver; import java.io.Serializable; @@ -50,10 +51,23 @@ implements Icon, Serializable { private static final long serialVersionUID = 532615968316031794L; + + /** A dummy Component that is used in the MediaTracker. */ + protected static Component component = new Component(){}; + + /** The MediaTracker used to monitor the loading of images. */ + protected static MediaTracker tracker = new MediaTracker(component); + + /** The ID that is used in the tracker. */ + private static int id; + Image image; String description; ImageObserver observer; + /** The image loading status. */ + private int loadStatus; + public ImageIcon() { } @@ -95,8 +109,8 @@ public ImageIcon(Image image, String description) { - this.image = Toolkit.getDefaultToolkit().createImage(image.getSource()); - this.description = description; + setImage(image); + setDescription(description); } public ImageObserver getImageObserver() @@ -116,7 +130,8 @@ public void setImage(Image image) { - this.image = Toolkit.getDefaultToolkit().createImage(image.getSource()); + loadImage(image); + this.image = image; } public String getDescription() @@ -143,4 +158,41 @@ { g.drawImage(image, x, y, observer != null ? observer : c); } + + /** + * Loads the image and blocks until the loading operation is finished. + * + * @param image the image to be loaded + */ + protected void loadImage(Image image) + { + try + { + tracker.addImage(image, id); + id++; + tracker.waitForID(id - 1); + } + catch (InterruptedException ex) + { + ; // ignore this for now + } + finally + { + loadStatus = tracker.statusID(id - 1, false); + } + } + + /** + * Returns the load status of the icon image. + * + * @return the load status of the icon image + * + * @see address@hidden MediaTracker.COMPLETE} + * @see address@hidden MediaTracker.ABORTED} + * @see address@hidden MediaTracker.ERRORED} + */ + public int getImageLoadStatus() + { + return loadStatus; + } }