jdk/src/share/classes/java/awt/MediaTracker.java
author jqzuo
Thu, 30 Jan 2014 10:36:40 -0500
changeset 23276 add6f5c93bc6
parent 23256 d71287a532f8
parent 22260 c9185e010e03
child 24865 09b1d992ca72
child 25107 9a16a601de25
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21777
diff changeset
     2
 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.ImageObserver;
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
    31
import sun.awt.image.MultiResolutionToolkitImage;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * The <code>MediaTracker</code> class is a utility class to track
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * the status of a number of media objects. Media objects could
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * include audio clips as well as images, though currently only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * images are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * To use a media tracker, create an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>MediaTracker</code> and call its <code>addImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * method for each image to be tracked. In addition, each image can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * be assigned a unique identifier. This identifier controls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * priority order in which the images are fetched. It can also be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * to identify unique subsets of the images that can be waited on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * independently. Images with a lower ID are loaded in preference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * those with a higher ID number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Tracking an animated image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * might not always be useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * due to the multi-part nature of animated image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * loading and painting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * but it is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>MediaTracker</code> treats an animated image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * as completely loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * when the first frame is completely loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * At that point, the <code>MediaTracker</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * signals any waiters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * that the image is completely loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * If no <code>ImageObserver</code>s are observing the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * when the first frame has finished loading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * the image might flush itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * to conserve resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * (see {@link Image#flush()}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Here is an example of using <code>MediaTracker</code>:
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21777
diff changeset
    69
 *
21777
c0a423e43b0d 8025235: [javadoc] fix some errors in 2D
yan
parents: 21278
diff changeset
    70
 * <hr><blockquote><pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * import java.awt.MediaTracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * public class ImageBlaster extends Applet implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      MediaTracker tracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *      Image bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *      Image anim[] = new Image[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *      int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *      Thread animator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *      // Get the images for the background (id == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *      // and the animation frames (id == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *      // and add them to the MediaTracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *      public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *          tracker = new MediaTracker(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *          bg = getImage(getDocumentBase(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *                  "images/background.gif");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *          tracker.addImage(bg, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *          for (int i = 0; i < 5; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *              anim[i] = getImage(getDocumentBase(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *                      "images/anim"+i+".gif");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *              tracker.addImage(anim[i], 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *      // Start the animation thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *      public void start() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *          animator = new Thread(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *          animator.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *      // Stop the animation thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *      public void stop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *          animator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *      // Run the animation thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *      // First wait for the background image to fully load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *      // and paint.  Then wait for all of the animation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *      // frames to finish loading. Finally, loop and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *      // increment the animation frame index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *          try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *              tracker.waitForID(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *              tracker.waitForID(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *          } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *              return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *          Thread me = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *          while (animator == me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *              try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *                  Thread.sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *              } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *              synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *                  index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *                  if (index >= anim.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *                      index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *              repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *      // The background image fills the frame so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *      // don't need to clear the applet on repaints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *      // Just call the paint method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *      public void update(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *          paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *      // Paint a large red rectangle if there are any errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *      // loading the images.  Otherwise always paint the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *      // background so that it appears incrementally as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *      // is loading.  Finally, only paint the current animation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *      // frame if all of the frames (id == 1) are done loading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *      // so that we don't get partial animations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *      public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *          if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *              g.setColor(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *              g.fillRect(0, 0, size().width, size().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *              return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *          g.drawImage(bg, 0, 0, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *          if (tracker.statusID(1, false) == MediaTracker.COMPLETE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *              g.drawImage(anim[index], 10, 10, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * }
21777
c0a423e43b0d 8025235: [javadoc] fix some errors in 2D
yan
parents: 21278
diff changeset
   164
 * } </pre></blockquote><hr>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
public class MediaTracker implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * A given <code>Component</code> that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * tracked by a media tracker where the image will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * eventually be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @see #MediaTracker(Component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    Component target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * The head of the list of <code>Images</code> that is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * tracked by the <code>MediaTracker</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #addImage(Image, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @see #removeImage(Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    MediaEntry head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static final long serialVersionUID = -483174189758638095L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Creates a media tracker to track images for a given component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param     comp the component on which the images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *                     will eventually be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public MediaTracker(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        target = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Adds an image to the list of images being tracked by this media
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * tracker. The image will eventually be rendered at its default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * (unscaled) size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param     image   the image to be tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param     id      an identifier used to track this image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public void addImage(Image image, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        addImage(image, id, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Adds a scaled image to the list of images being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * by this media tracker. The image will eventually be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * rendered at the indicated width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param     image   the image to be tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param     id   an identifier that can be used to track this image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param     w    the width at which the image is rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param     h    the height at which the image is rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public synchronized void addImage(Image image, int id, int w, int h) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   226
        addImageImpl(image, id, w, h);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   227
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   228
        if (rvImage != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   229
            addImageImpl(rvImage, id, 2 * w, 2 * h);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   230
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   231
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   232
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   233
    private void addImageImpl(Image image, int id, int w, int h) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        head = MediaEntry.insert(head,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                 new ImageMediaEntry(this, image, id, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Flag indicating that media is currently being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public static final int LOADING = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Flag indicating that the downloading of media was aborted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public static final int ABORTED = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Flag indicating that the downloading of media encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public static final int ERRORED = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Flag indicating that the downloading of media was completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public static final int COMPLETE = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    static final int DONE = (ABORTED | ERRORED | COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Checks to see if all images being tracked by this media tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * This method does not start loading the images if they are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * already loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return      <code>true</code> if all images have finished loading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *                       have been aborted, or have encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *                       an error; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see         java.awt.MediaTracker#checkAll(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see         java.awt.MediaTracker#checkID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public boolean checkAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return checkAll(false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Checks to see if all images being tracked by this media tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * If the value of the <code>load</code> flag is <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * then this method starts loading any images that are not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * If there is an error while loading or scaling an image, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <code>isErrorAny</code> and <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param       load   if <code>true</code>, start loading any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *                       images that are not yet being loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return      <code>true</code> if all images have finished loading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *                       have been aborted, or have encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *                       an error; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see         java.awt.MediaTracker#checkID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @see         java.awt.MediaTracker#checkAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see         java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see         java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public boolean checkAll(boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return checkAll(load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    private synchronized boolean checkAll(boolean load, boolean verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        boolean done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if ((cur.getStatus(load, verify) & DONE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Checks the error status of all of the images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @return   <code>true</code> if any of the images tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *                  by this media tracker had an error during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *                  loading; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see      java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see      java.awt.MediaTracker#getErrorsAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public synchronized boolean isErrorAny() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if ((cur.getStatus(false, true) & ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Returns a list of all media that have encountered an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @return       an array of media objects tracked by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *                        media tracker that have encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *                        an error, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *                        there are none with errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see          java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see          java.awt.MediaTracker#getErrorsID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public synchronized Object[] getErrorsAny() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        int numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if ((cur.getStatus(false, true) & ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                numerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (numerrors == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        Object errors[] = new Object[numerrors];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if ((cur.getStatus(false, false) & ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                errors[numerrors++] = cur.getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * Starts loading all images tracked by this media tracker. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * method waits until all the images being tracked have finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see         java.awt.MediaTracker#waitForID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see         java.awt.MediaTracker#waitForAll(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @exception   InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *                                     interrupted this thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void waitForAll() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        waitForAll(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Starts loading all images tracked by this media tracker. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * method waits until all the images being tracked have finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * loading, or until the length of time specified in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * by the <code>ms</code> argument has passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * If there is an error while loading or scaling an image, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * that image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @param       ms       the number of milliseconds to wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *                       for the loading to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return      <code>true</code> if all images were successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *                       loaded; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see         java.awt.MediaTracker#waitForID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see         java.awt.MediaTracker#waitForAll(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @exception   InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *                                     interrupted this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public synchronized boolean waitForAll(long ms)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        long end = System.currentTimeMillis() + ms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            int status = statusAll(first, first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            if ((status & LOADING) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                return (status == COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            long timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            if (ms == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                timeout = end - System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                if (timeout <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Calculates and returns the bitwise inclusive <b>OR</b> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * status of all media that are tracked by this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Possible flags defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <code>MediaTracker</code> class are <code>LOADING</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * <code>ABORTED</code>, <code>ERRORED</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <code>COMPLETE</code>. An image that hasn't started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * loading has zero as its status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * If the value of <code>load</code> is <code>true</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * this method starts loading any images that are not yet being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param        load   if <code>true</code>, start loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *                            any images that are not yet being loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @return       the bitwise inclusive <b>OR</b> of the status of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *                            all of the media being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see          java.awt.MediaTracker#statusID(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see          java.awt.MediaTracker#LOADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see          java.awt.MediaTracker#ABORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @see          java.awt.MediaTracker#ERRORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see          java.awt.MediaTracker#COMPLETE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public int statusAll(boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return statusAll(load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    private synchronized int statusAll(boolean load, boolean verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            status = status | cur.getStatus(load, verify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Checks to see if all images tracked by this media tracker that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * are tagged with the specified identifier have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * This method does not start loading the images if they are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * already loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param       id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @return      <code>true</code> if all images have finished loading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *                       have been aborted, or have encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *                       an error; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @see         java.awt.MediaTracker#checkID(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @see         java.awt.MediaTracker#checkAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see         java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see         java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public boolean checkID(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return checkID(id, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Checks to see if all images tracked by this media tracker that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * are tagged with the specified identifier have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * If the value of the <code>load</code> flag is <code>true</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * then this method starts loading any images that are not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <code>isErrorAny</code> or <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param       id       the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param       load     if <code>true</code>, start loading any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *                       images that are not yet being loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @return      <code>true</code> if all images have finished loading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *                       have been aborted, or have encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *                       an error; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @see         java.awt.MediaTracker#checkID(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @see         java.awt.MediaTracker#checkAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @see         java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see         java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public boolean checkID(int id, boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return checkID(id, load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    private synchronized boolean checkID(int id, boolean load, boolean verify)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        boolean done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                && (cur.getStatus(load, verify) & DONE) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Checks the error status of all of the images tracked by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * media tracker with the specified identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param        id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @return       <code>true</code> if any of the images with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *                          specified identifier had an error during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *                          loading; <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see          java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see          java.awt.MediaTracker#getErrorsID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public synchronized boolean isErrorID(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                && (cur.getStatus(false, true) & ERRORED) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * Returns a list of media with the specified ID that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * have encountered an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @param       id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @return      an array of media objects tracked by this media
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *                       tracker with the specified identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *                       that have encountered an error, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *                       <code>null</code> if there are none with errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @see         java.awt.MediaTracker#getErrorsAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public synchronized Object[] getErrorsID(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        int numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                && (cur.getStatus(false, true) & ERRORED) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                numerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (numerrors == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        Object errors[] = new Object[numerrors];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                && (cur.getStatus(false, false) & ERRORED) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                errors[numerrors++] = cur.getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Starts loading all images tracked by this media tracker with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * specified identifier. This method waits until all the images with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * the specified identifier have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * <code>isErrorAny</code> and <code>isErrorID</code> methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @param         id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @see           java.awt.MediaTracker#waitForAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @see           java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @see           java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @exception     InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *                          interrupted this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    public void waitForID(int id) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        waitForID(id, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Starts loading all images tracked by this media tracker with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * specified identifier. This method waits until all the images with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * the specified identifier have finished loading, or until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * length of time specified in milliseconds by the <code>ms</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * argument has passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * image is considered to have finished loading. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * <code>statusID</code>, <code>isErrorID</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * <code>isErrorAny</code> methods to check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @param         id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param         ms   the length of time, in milliseconds, to wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *                           for the loading to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see           java.awt.MediaTracker#waitForAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see           java.awt.MediaTracker#waitForID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see           java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @see           java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @see           java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @exception     InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *                          interrupted this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    public synchronized boolean waitForID(int id, long ms)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        long end = System.currentTimeMillis() + ms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            int status = statusID(id, first, first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            if ((status & LOADING) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                return (status == COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            long timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            if (ms == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                timeout = end - System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                if (timeout <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * Calculates and returns the bitwise inclusive <b>OR</b> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * status of all media with the specified identifier that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * tracked by this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Possible flags defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <code>MediaTracker</code> class are <code>LOADING</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * <code>ABORTED</code>, <code>ERRORED</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * <code>COMPLETE</code>. An image that hasn't started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * loading has zero as its status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * If the value of <code>load</code> is <code>true</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * this method starts loading any images that are not yet being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @param        id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @param        load   if <code>true</code>, start loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *                            any images that are not yet being loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @return       the bitwise inclusive <b>OR</b> of the status of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *                            all of the media with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *                            identifier that are being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see          java.awt.MediaTracker#statusAll(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @see          java.awt.MediaTracker#LOADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @see          java.awt.MediaTracker#ABORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @see          java.awt.MediaTracker#ERRORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @see          java.awt.MediaTracker#COMPLETE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public int statusID(int id, boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return statusID(id, load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    private synchronized int statusID(int id, boolean load, boolean verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            if (cur.getID() == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                status = status | cur.getStatus(load, verify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Removes the specified image from this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * All instances of the specified image are removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * regardless of scale or ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @param   image     the image to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    public synchronized void removeImage(Image image) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   730
        removeImageImpl(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   731
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   732
        if (rvImage != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   733
            removeImageImpl(rvImage);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   734
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   735
        notifyAll();    // Notify in case remaining images are "done".
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   736
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   737
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   738
    private void removeImageImpl(Image image) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            MediaEntry next = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (cur.getMedia() == image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    head = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    prev.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                cur.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            cur = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Removes the specified image from the specified tracking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * ID of this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * All instances of <code>Image</code> being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * under the specified ID are removed regardless of scale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @param      image the image to be removed
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   763
     * @param      id the tracking ID from which to remove the image
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @see        java.awt.MediaTracker#removeImage(java.awt.Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @see        java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public synchronized void removeImage(Image image, int id) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   769
        removeImageImpl(image, id);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   770
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   771
        if (rvImage != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   772
            removeImageImpl(rvImage, id);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   773
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   774
        notifyAll();    // Notify in case remaining images are "done".
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   775
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   776
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   777
    private void removeImageImpl(Image image, int id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            MediaEntry next = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            if (cur.getID() == id && cur.getMedia() == image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    head = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    prev.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                cur.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            cur = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * Removes the specified image with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * width, height, and ID from this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Only the specified instance (with any duplicates) is removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @param   image the image to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @param   id the tracking ID from which to remove the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @param   width the width to remove (-1 for unscaled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @param   height the height to remove (-1 for unscaled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @since   JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    public synchronized void removeImage(Image image, int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                         int width, int height) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   810
        removeImageImpl(image, id, width, height);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   811
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   812
        if (rvImage != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   813
            removeImageImpl(rvImage, id, 2 * width, 2 * height);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   814
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   815
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   816
        notifyAll();    // Notify in case remaining images are "done".
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   817
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   818
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   819
    private void removeImageImpl(Image image, int id, int width, int height) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            MediaEntry next = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            if (cur.getID() == id && cur instanceof ImageMediaEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                && ((ImageMediaEntry) cur).matches(image, width, height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    head = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    prev.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                cur.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            cur = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    synchronized void setDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   843
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   844
    private static Image getResolutionVariant(Image image) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   845
        if (image instanceof MultiResolutionToolkitImage) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   846
            return ((MultiResolutionToolkitImage) image).getResolutionVariant();
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   847
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   848
        return null;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   849
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
abstract class MediaEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    MediaTracker tracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    int ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    MediaEntry next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    boolean cancelled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    MediaEntry(MediaTracker mt, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        tracker = mt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        ID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    abstract Object getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    static MediaEntry insert(MediaEntry head, MediaEntry me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            if (cur.ID > me.ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        me.next = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            head = me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            prev.next = me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        return head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    int getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        return ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    abstract void startLoad();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    void cancel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        cancelled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    static final int LOADING = MediaTracker.LOADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    static final int ABORTED = MediaTracker.ABORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    static final int ERRORED = MediaTracker.ERRORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    static final int COMPLETE = MediaTracker.COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    static final int LOADSTARTED = (LOADING | ERRORED | COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    static final int DONE = (ABORTED | ERRORED | COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    synchronized int getStatus(boolean doLoad, boolean doVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        if (doLoad && ((status & LOADSTARTED) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            status = (status & ~ABORTED) | LOADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            startLoad();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    void setStatus(int flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            status = flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        tracker.setDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
class ImageMediaEntry extends MediaEntry implements ImageObserver,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    Image image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    private static final long serialVersionUID = 4739377000350280650L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    ImageMediaEntry(MediaTracker mt, Image img, int c, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        super(mt, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        image = img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    boolean matches(Image img, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        return (image == img && width == w && height == h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    Object getMedia() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    synchronized int getStatus(boolean doLoad, boolean doVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if (doVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            int flags = tracker.target.checkImage(image, width, height, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            int s = parseflags(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            if (s == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                if ((status & (ERRORED | COMPLETE)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    setStatus(ABORTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            } else if (s != status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                setStatus(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        return super.getStatus(doLoad, doVerify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    void startLoad() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        if (tracker.target.prepareImage(image, width, height, this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            setStatus(COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    int parseflags(int infoflags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        if ((infoflags & ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            return ERRORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } else if ((infoflags & ABORT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            return ABORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        } else if ((infoflags & (ALLBITS | FRAMEBITS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            return COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    public boolean imageUpdate(Image img, int infoflags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        if (cancelled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        int s = parseflags(infoflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        if (s != 0 && s != status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            setStatus(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        return ((status & LOADING) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
}