< prev index next >
src/java.desktop/share/classes/java/awt/MediaTracker.java
Print this page
*** 27,36 ****
--- 27,39 ----
import java.awt.Component;
import java.awt.Image;
import java.awt.image.ImageObserver;
import sun.awt.image.MultiResolutionToolkitImage;
+ import java.util.stream.Stream;
+ import java.util.List;
+ import sun.awt.image.MultiResolutionToolkitImage.ResolutionVariantItem;
/**
* The {@code MediaTracker} 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
*** 222,239 ****
* @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,
! w == -1 ? -1 : 2 * w,
! h == -1 ? -1 : 2 * h);
}
}
private void addImageImpl(Image image, int id, int w, int h) {
head = MediaEntry.insert(head,
new ImageMediaEntry(this, image, id, w, h));
}
/**
--- 225,248 ----
* @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);
!
! if (image instanceof MultiResolutionToolkitImage) {
! getRVItems(image).forEach(rvItem ->
! addImageImpl(rvItem.getImage(), id,
! scale(w, rvItem.getScaleX()),
! scale(h, rvItem.getScaleY())
! ));
}
}
+ private static int scale(int size, double scale) {
+ return (size == -1 || scale == 1) ? size : (int) Math.ceil(scale * size);
+ }
+
private void addImageImpl(Image image, int id, int w, int h) {
head = MediaEntry.insert(head,
new ImageMediaEntry(this, image, id, w, h));
}
/**
*** 730,742 ****
* @see java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
* @since 1.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) {
--- 739,751 ----
* @see java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
* @since 1.1
*/
public synchronized void removeImage(Image image) {
removeImageImpl(image);
! if (image instanceof MultiResolutionToolkitImage) {
! getRVItems(image).forEach(rvItem ->
! removeImageImpl(rvItem.getImage()));
}
notifyAll(); // Notify in case remaining images are "done".
}
private void removeImageImpl(Image image) {
*** 769,781 ****
* @see java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
* @since 1.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) {
--- 778,791 ----
* @see java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
* @since 1.1
*/
public synchronized void removeImage(Image image, int id) {
removeImageImpl(image, id);
!
! if (image instanceof MultiResolutionToolkitImage) {
! getRVItems(image).forEach(rvItem ->
! removeImageImpl(rvItem.getImage(), id));
}
notifyAll(); // Notify in case remaining images are "done".
}
private void removeImageImpl(Image image, int id) {
*** 810,824 ****
* @since 1.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,
! width == -1 ? -1 : 2 * width,
! height == -1 ? -1 : 2 * height);
}
notifyAll(); // Notify in case remaining images are "done".
}
private void removeImageImpl(Image image, int id, int width, int height) {
--- 820,837 ----
* @since 1.1
*/
public synchronized void removeImage(Image image, int id,
int width, int height) {
removeImageImpl(image, id, width, height);
!
! if (image instanceof MultiResolutionToolkitImage) {
!
! getRVItems(image).forEach(rvItem ->
! removeImageImpl(rvItem.getImage(), id,
! scale(width, rvItem.getScaleX()),
! scale(height, rvItem.getScaleY())
! ));
}
notifyAll(); // Notify in case remaining images are "done".
}
private void removeImageImpl(Image image, int id, int width, int height) {
*** 844,858 ****
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;
--- 857,869 ----
synchronized void setDone() {
notifyAll();
}
! private static Stream<ResolutionVariantItem> getRVItems(Image image) {
! return ((MultiResolutionToolkitImage) image)
! .getResolutionVariantItems().stream();
}
}
abstract class MediaEntry {
MediaTracker tracker;
< prev index next >