summaryrefslogtreecommitdiff
path: root/javax/swing/ImageIcon.java
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2005-04-08 18:12:17 +0000
committerRoman Kennke <roman@kennke.org>2005-04-08 18:12:17 +0000
commitfe71d564e62145a0995c6659f09d7dca68ed40a4 (patch)
tree4e71ee1da6d8637fa4186993bb4b88106006f3d6 /javax/swing/ImageIcon.java
parentd17332b9156de61b8d3f21f2b7a8fe784ce6f850 (diff)
downloadclasspath-fe71d564e62145a0995c6659f09d7dca68ed40a4.tar.gz
2005-04-08 Roman Kennke <roman@kennke.org>
* javax/swing/text/ImageIcon.java (ImageIcon): Use setImage instead of direct assignment. (setImage): Call loadImage to make sure that the image is loaded. (loadImage): Waits for the image to complete loading. (getImageLoadStatus): Added. Returns the load status of the image.
Diffstat (limited to 'javax/swing/ImageIcon.java')
-rw-r--r--javax/swing/ImageIcon.java58
1 files changed, 55 insertions, 3 deletions
diff --git a/javax/swing/ImageIcon.java b/javax/swing/ImageIcon.java
index 36bd088ff..e99333318 100644
--- a/javax/swing/ImageIcon.java
+++ b/javax/swing/ImageIcon.java
@@ -40,6 +40,7 @@ package javax.swing;
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 @@ public class ImageIcon
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 class ImageIcon
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 class ImageIcon
public void setImage(Image image)
{
- this.image = Toolkit.getDefaultToolkit().createImage(image.getSource());
+ loadImage(image);
+ this.image = image;
}
public String getDescription()
@@ -143,4 +158,41 @@ public class ImageIcon
{
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 {@link MediaTracker.COMPLETE}
+ * @see {@link MediaTracker.ABORTED}
+ * @see {@link MediaTracker.ERRORED}
+ */
+ public int getImageLoadStatus()
+ {
+ return loadStatus;
+ }
}