< prev index next >

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

Print this page

        

*** 23,36 **** * questions. */ package java.awt; - import java.awt.Component; - import java.awt.Image; import java.awt.image.ImageObserver; import sun.awt.image.MultiResolutionToolkitImage; /** * 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 --- 23,37 ---- * questions. */ package java.awt; import java.awt.image.ImageObserver; + import java.awt.image.ResolutionVariantItem; import sun.awt.image.MultiResolutionToolkitImage; + import java.util.List; + import java.util.stream.Stream; /** * 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,237 **** * @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)); --- 223,250 ---- * @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.getValue(), id, ! scale(w, rvItem.getScaleX()), ! scale(h, rvItem.getScaleY()) ! )); ! } ! } ! ! ! private static Stream<ResolutionVariantItem<Image>> getRVItems(Image image) { ! return ((MultiResolutionToolkitImage) image) ! .getResolutionVariantItems().stream(); } + + private static int scale(int size, double scale) { + return size == -1 ? -1 : (int) Math.floor(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,743 **** * @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) { MediaEntry cur = head; --- 743,757 ---- * @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.getValue())); } + notifyAll(); // Notify in case remaining images are "done". } private void removeImageImpl(Image image) { MediaEntry cur = head;
*** 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) { --- 783,796 ---- * @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.getValue(), 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) { --- 825,842 ---- * @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.getValue(), 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) {
*** 843,859 **** } 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; --- 861,870 ----
< prev index next >