src/share/classes/java/awt/MediaTracker.java
Print this page
*** 26,35 ****
--- 26,36 ----
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,233 ****
* @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) {
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
*/
--- 221,241 ----
* @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,726 ****
--- 725,743 ----
* @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,743 ****
} 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.
--- 750,759 ----
*** 748,757 ****
--- 764,782 ----
* @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,774 ****
} 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.
--- 789,798 ----
*** 781,790 ****
--- 805,824 ----
* @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,814 ****
} else {
prev = cur;
}
cur = next;
}
- notifyAll(); // Notify in case remaining images are "done".
}
synchronized void setDone() {
notifyAll();
}
}
abstract class MediaEntry {
MediaTracker tracker;
int ID;
--- 833,854 ----
} else {
prev = cur;
}
cur = next;
}
}
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;