src/share/classes/java/awt/MediaTracker.java

Print this page

        

@@ -26,10 +26,11 @@
 package java.awt;
 
 import java.awt.Component;
 import java.awt.Image;
 import java.awt.image.ImageObserver;
+import sun.awt.image.MultiResolutionToolkitImage;
 
 /**
  * The <code>MediaTracker</code> class is a utility class to track
  * the status of a number of media objects. Media objects could
  * include audio clips as well as images, though currently only

@@ -220,14 +221,21 @@
      * @param     id   an identifier that can be used to track this image
      * @param     w    the width at which the image is rendered
      * @param     h    the height at which the image is rendered
      */
     public synchronized void addImage(Image image, int id, int w, int h) {
+        addImageImpl(image, id, w, h);
+        Image rvImage = getResolutionVariant(image);
+        if (rvImage != null) {
+            addImageImpl(rvImage, id, 2 * w, 2 * h);
+        }
+    }
+
+    private void addImageImpl(Image image, int id, int w, int h) {
         head = MediaEntry.insert(head,
                                  new ImageMediaEntry(this, image, id, w, h));
     }
-
     /**
      * Flag indicating that media is currently being loaded.
      * @see         java.awt.MediaTracker#statusAll
      * @see         java.awt.MediaTracker#statusID
      */

@@ -717,10 +725,19 @@
      * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
      * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
      * @since   JDK1.1
      */
     public synchronized void removeImage(Image image) {
+        removeImageImpl(image);
+        Image rvImage = getResolutionVariant(image);
+        if (rvImage != null) {
+            removeImageImpl(rvImage);
+        }
+        notifyAll();    // Notify in case remaining images are "done".
+    }
+
+    private void removeImageImpl(Image image) {
         MediaEntry cur = head;
         MediaEntry prev = null;
         while (cur != null) {
             MediaEntry next = cur.next;
             if (cur.getMedia() == image) {

@@ -733,11 +750,10 @@
             } else {
                 prev = cur;
             }
             cur = next;
         }
-        notifyAll();    // Notify in case remaining images are "done".
     }
 
     /**
      * Removes the specified image from the specified tracking
      * ID of this media tracker.

@@ -748,10 +764,19 @@
      * @see        java.awt.MediaTracker#removeImage(java.awt.Image)
      * @see        java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
      * @since      JDK1.1
      */
     public synchronized void removeImage(Image image, int id) {
+        removeImageImpl(image, id);
+        Image rvImage = getResolutionVariant(image);
+        if (rvImage != null) {
+            removeImageImpl(rvImage, id);
+        }
+        notifyAll();    // Notify in case remaining images are "done".
+    }
+
+    private void removeImageImpl(Image image, int id) {
         MediaEntry cur = head;
         MediaEntry prev = null;
         while (cur != null) {
             MediaEntry next = cur.next;
             if (cur.getID() == id && cur.getMedia() == image) {

@@ -764,11 +789,10 @@
             } else {
                 prev = cur;
             }
             cur = next;
         }
-        notifyAll();    // Notify in case remaining images are "done".
     }
 
     /**
      * Removes the specified image with the specified
      * width, height, and ID from this media tracker.

@@ -781,10 +805,20 @@
      * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
      * @since   JDK1.1
      */
     public synchronized void removeImage(Image image, int id,
                                          int width, int height) {
+        removeImageImpl(image, id, width, height);
+        Image rvImage = getResolutionVariant(image);
+        if (rvImage != null) {
+            removeImageImpl(rvImage, id, 2 * width, 2 * height);
+
+        }
+        notifyAll();    // Notify in case remaining images are "done".
+    }
+
+    private void removeImageImpl(Image image, int id, int width, int height) {
         MediaEntry cur = head;
         MediaEntry prev = null;
         while (cur != null) {
             MediaEntry next = cur.next;
             if (cur.getID() == id && cur instanceof ImageMediaEntry

@@ -799,16 +833,22 @@
             } else {
                 prev = cur;
             }
             cur = next;
         }
-        notifyAll();    // Notify in case remaining images are "done".
     }
 
     synchronized void setDone() {
         notifyAll();
     }
+
+    private static Image getResolutionVariant(Image image) {
+        if (image instanceof MultiResolutionToolkitImage) {
+            return ((MultiResolutionToolkitImage) image).getResolutionVariant();
+        }
+        return null;
+    }
 }
 
 abstract class MediaEntry {
     MediaTracker tracker;
     int ID;