Commit b9d896d6 by Roman Kennke Committed by Michael Koch

2005-04-19 Roman Kennke <roman@kennke.org>

	* javax/swing/ImageIcon.java
	Added API documentation.

2005-04-19  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.

From-SVN: r98384
parent 3419f465
2005-04-19 Roman Kennke <roman@kennke.org>
* javax/swing/ImageIcon.java
Added API documentation.
2005-04-19 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.
2005-04-19 Audrius Meskauskas <audriusa@bluewin.ch> 2005-04-19 Audrius Meskauskas <audriusa@bluewin.ch>
* javax/swing/JTextArea.java (replaceRange): * javax/swing/JTextArea.java (replaceRange):
......
/* ImageIcon.java -- /* ImageIcon.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc. Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -40,6 +40,7 @@ package javax.swing; ...@@ -40,6 +40,7 @@ package javax.swing;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Image; import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.image.ImageObserver; import java.awt.image.ImageObserver;
import java.io.Serializable; import java.io.Serializable;
...@@ -50,10 +51,23 @@ public class ImageIcon ...@@ -50,10 +51,23 @@ public class ImageIcon
implements Icon, Serializable implements Icon, Serializable
{ {
private static final long serialVersionUID = 532615968316031794L; 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; Image image;
String description; String description;
ImageObserver observer; ImageObserver observer;
/** The image loading status. */
private int loadStatus;
public ImageIcon() public ImageIcon()
{ {
} }
...@@ -95,8 +109,8 @@ public class ImageIcon ...@@ -95,8 +109,8 @@ public class ImageIcon
public ImageIcon(Image image, String description) public ImageIcon(Image image, String description)
{ {
this.image = Toolkit.getDefaultToolkit().createImage(image.getSource()); setImage(image);
this.description = description; setDescription(description);
} }
public ImageObserver getImageObserver() public ImageObserver getImageObserver()
...@@ -116,7 +130,8 @@ public class ImageIcon ...@@ -116,7 +130,8 @@ public class ImageIcon
public void setImage(Image image) public void setImage(Image image)
{ {
this.image = Toolkit.getDefaultToolkit().createImage(image.getSource()); loadImage(image);
this.image = image;
} }
public String getDescription() public String getDescription()
...@@ -143,4 +158,41 @@ public class ImageIcon ...@@ -143,4 +158,41 @@ public class ImageIcon
{ {
g.drawImage(image, x, y, observer != null ? observer : c); 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;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment