[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: swing fixes

Kaffe CVS cvs-commits at kaffe.org
Mon Apr 18 17:09:08 PDT 2005


PatchSet 5704 
Date: 2005/04/19 00:01:47
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: swing fixes

2005-04-18  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-04-08  Roman Kennke  <roman at 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.

Members: 
	ChangeLog:1.3871->1.3872 
	libraries/javalib/javax/swing/ImageIcon.java:1.4->1.5 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3871 kaffe/ChangeLog:1.3872
--- kaffe/ChangeLog:1.3871	Mon Apr 18 23:57:50 2005
+++ kaffe/ChangeLog	Tue Apr 19 00:01:47 2005
@@ -4,6 +4,19 @@
 
 	2005-04-08  Roman Kennke  <roman at 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-18  Dalibor Topic  <robilad at kaffe.org>
+
+        Resynced with GNU Classpath.
+
+	2005-04-08  Roman Kennke  <roman at kennke.org>
+
         * javax/swing/text/JTextComponent.java
         (JTextComponent): Added repaintListener which issues repaint
         requests when the underlying document changes.
Index: kaffe/libraries/javalib/javax/swing/ImageIcon.java
diff -u kaffe/libraries/javalib/javax/swing/ImageIcon.java:1.4 kaffe/libraries/javalib/javax/swing/ImageIcon.java:1.5
--- kaffe/libraries/javalib/javax/swing/ImageIcon.java:1.4	Thu Jan  6 13:08:06 2005
+++ kaffe/libraries/javalib/javax/swing/ImageIcon.java	Tue Apr 19 00:01:53 2005
@@ -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()
@@ -142,5 +157,42 @@
   public void paintIcon(Component c, Graphics g, int x, int y)
   {
     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;
   }
 }




More information about the kaffe mailing list