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

Print this page




 209      * @param     id      an identifier used to track this image
 210      */
 211     public void addImage(Image image, int id) {
 212         addImage(image, id, -1, -1);
 213     }
 214 
 215     /**
 216      * Adds a scaled image to the list of images being tracked
 217      * by this media tracker. The image will eventually be
 218      * rendered at the indicated width and height.
 219      *
 220      * @param     image   the image to be tracked
 221      * @param     id   an identifier that can be used to track this image
 222      * @param     w    the width at which the image is rendered
 223      * @param     h    the height at which the image is rendered
 224      */
 225     public synchronized void addImage(Image image, int id, int w, int h) {
 226         addImageImpl(image, id, w, h);
 227         Image rvImage = getResolutionVariant(image);
 228         if (rvImage != null) {
 229             addImageImpl(rvImage, id, 2 * w, 2 * h);


 230         }
 231     }
 232 
 233     private void addImageImpl(Image image, int id, int w, int h) {
 234         head = MediaEntry.insert(head,
 235                                  new ImageMediaEntry(this, image, id, w, h));
 236     }
 237     /**
 238      * Flag indicating that media is currently being loaded.
 239      * @see         java.awt.MediaTracker#statusAll
 240      * @see         java.awt.MediaTracker#statusID
 241      */
 242     public static final int LOADING = 1;
 243 
 244     /**
 245      * Flag indicating that the downloading of media was aborted.
 246      * @see         java.awt.MediaTracker#statusAll
 247      * @see         java.awt.MediaTracker#statusID
 248      */
 249     public static final int ABORTED = 2;


 793         }
 794     }
 795 
 796     /**
 797      * Removes the specified image with the specified
 798      * width, height, and ID from this media tracker.
 799      * Only the specified instance (with any duplicates) is removed.
 800      * @param   image the image to be removed
 801      * @param   id the tracking ID from which to remove the image
 802      * @param   width the width to remove (-1 for unscaled)
 803      * @param   height the height to remove (-1 for unscaled)
 804      * @see     java.awt.MediaTracker#removeImage(java.awt.Image)
 805      * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
 806      * @since   JDK1.1
 807      */
 808     public synchronized void removeImage(Image image, int id,
 809                                          int width, int height) {
 810         removeImageImpl(image, id, width, height);
 811         Image rvImage = getResolutionVariant(image);
 812         if (rvImage != null) {
 813             removeImageImpl(rvImage, id, 2 * width, 2 * height);
 814 

 815         }
 816         notifyAll();    // Notify in case remaining images are "done".
 817     }
 818 
 819     private void removeImageImpl(Image image, int id, int width, int height) {
 820         MediaEntry cur = head;
 821         MediaEntry prev = null;
 822         while (cur != null) {
 823             MediaEntry next = cur.next;
 824             if (cur.getID() == id && cur instanceof ImageMediaEntry
 825                 && ((ImageMediaEntry) cur).matches(image, width, height))
 826             {
 827                 if (prev == null) {
 828                     head = next;
 829                 } else {
 830                     prev.next = next;
 831                 }
 832                 cur.cancel();
 833             } else {
 834                 prev = cur;




 209      * @param     id      an identifier used to track this image
 210      */
 211     public void addImage(Image image, int id) {
 212         addImage(image, id, -1, -1);
 213     }
 214 
 215     /**
 216      * Adds a scaled image to the list of images being tracked
 217      * by this media tracker. The image will eventually be
 218      * rendered at the indicated width and height.
 219      *
 220      * @param     image   the image to be tracked
 221      * @param     id   an identifier that can be used to track this image
 222      * @param     w    the width at which the image is rendered
 223      * @param     h    the height at which the image is rendered
 224      */
 225     public synchronized void addImage(Image image, int id, int w, int h) {
 226         addImageImpl(image, id, w, h);
 227         Image rvImage = getResolutionVariant(image);
 228         if (rvImage != null) {
 229             addImageImpl(rvImage, id,
 230                     w == -1 ? -1 : 2 * w,
 231                     h == -1 ? -1 : 2 * h);
 232         }
 233     }
 234 
 235     private void addImageImpl(Image image, int id, int w, int h) {
 236         head = MediaEntry.insert(head,
 237                                  new ImageMediaEntry(this, image, id, w, h));
 238     }
 239     /**
 240      * Flag indicating that media is currently being loaded.
 241      * @see         java.awt.MediaTracker#statusAll
 242      * @see         java.awt.MediaTracker#statusID
 243      */
 244     public static final int LOADING = 1;
 245 
 246     /**
 247      * Flag indicating that the downloading of media was aborted.
 248      * @see         java.awt.MediaTracker#statusAll
 249      * @see         java.awt.MediaTracker#statusID
 250      */
 251     public static final int ABORTED = 2;


 795         }
 796     }
 797 
 798     /**
 799      * Removes the specified image with the specified
 800      * width, height, and ID from this media tracker.
 801      * Only the specified instance (with any duplicates) is removed.
 802      * @param   image the image to be removed
 803      * @param   id the tracking ID from which to remove the image
 804      * @param   width the width to remove (-1 for unscaled)
 805      * @param   height the height to remove (-1 for unscaled)
 806      * @see     java.awt.MediaTracker#removeImage(java.awt.Image)
 807      * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
 808      * @since   JDK1.1
 809      */
 810     public synchronized void removeImage(Image image, int id,
 811                                          int width, int height) {
 812         removeImageImpl(image, id, width, height);
 813         Image rvImage = getResolutionVariant(image);
 814         if (rvImage != null) {
 815             removeImageImpl(rvImage, id,
 816                     width == -1 ? -1 : 2 * width,
 817                     height == -1 ? -1 : 2 * height);
 818         }
 819         notifyAll();    // Notify in case remaining images are "done".
 820     }
 821 
 822     private void removeImageImpl(Image image, int id, int width, int height) {
 823         MediaEntry cur = head;
 824         MediaEntry prev = null;
 825         while (cur != null) {
 826             MediaEntry next = cur.next;
 827             if (cur.getID() == id && cur instanceof ImageMediaEntry
 828                 && ((ImageMediaEntry) cur).matches(image, width, height))
 829             {
 830                 if (prev == null) {
 831                     head = next;
 832                 } else {
 833                     prev.next = next;
 834                 }
 835                 cur.cancel();
 836             } else {
 837                 prev = cur;