src/java.desktop/share/classes/java/awt/MediaTracker.java
author darcy
Tue, 24 Sep 2019 18:25:54 -0700
changeset 58309 c6f8b2c3dc66
parent 52248 2e330da7cbf4
permissions -rw-r--r--
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 1995, 2018, 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
/**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    34
 * The {@code MediaTracker} class is a utility class to track
2
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
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    40
 * {@code MediaTracker} and call its {@code addImage}
2
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.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    55
 * {@code MediaTracker} treats an animated image
2
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.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    58
 * At that point, the {@code MediaTracker}
2
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.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    61
 * If no {@code ImageObserver}s are observing the image
2
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>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    68
 * Here is an example of using {@code MediaTracker}:
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
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23276
diff changeset
   167
 * @since       1.0
2
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
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   172
     * A given {@code Component} that will be
2
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
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   181
     * The head of the list of {@code Images} that is being
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   182
     * tracked by the {@code MediaTracker}.
2
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
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 52248
diff changeset
   188
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    MediaEntry head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private static final long serialVersionUID = -483174189758638095L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Creates a media tracker to track images for a given component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param     comp the component on which the images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *                     will eventually be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public MediaTracker(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        target = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Adds an image to the list of images being tracked by this media
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * tracker. The image will eventually be rendered at its default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * (unscaled) size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param     image   the image to be tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param     id      an identifier used to track this image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public void addImage(Image image, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        addImage(image, id, -1, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Adds a scaled image to the list of images being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * by this media tracker. The image will eventually be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * rendered at the indicated width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param     image   the image to be tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param     id   an identifier that can be used to track this image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param     w    the width at which the image is rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param     h    the height at which the image is rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    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
   227
        addImageImpl(image, id, w, h);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   228
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   229
        if (rvImage != null) {
25107
9a16a601de25 8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents: 23276
diff changeset
   230
            addImageImpl(rvImage, id,
9a16a601de25 8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents: 23276
diff changeset
   231
                    w == -1 ? -1 : 2 * w,
9a16a601de25 8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents: 23276
diff changeset
   232
                    h == -1 ? -1 : 2 * h);
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   233
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   234
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   235
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   236
    private void addImageImpl(Image image, int id, int w, int h) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        head = MediaEntry.insert(head,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                 new ImageMediaEntry(this, image, id, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Flag indicating that media is currently being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public static final int LOADING = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Flag indicating that the downloading of media was aborted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public static final int ABORTED = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Flag indicating that the downloading of media encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public static final int ERRORED = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Flag indicating that the downloading of media was completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @see         java.awt.MediaTracker#statusAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see         java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public static final int COMPLETE = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    static final int DONE = (ABORTED | ERRORED | COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Checks to see if all images being tracked by this media tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * This method does not start loading the images if they are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * already loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   281
     * {@code isErrorAny} or {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * check for errors.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   283
     * @return      {@code true} if all images have finished loading,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *                       have been aborted, or have encountered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   285
     *                       an error; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see         java.awt.MediaTracker#checkAll(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see         java.awt.MediaTracker#checkID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public boolean checkAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return checkAll(false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Checks to see if all images being tracked by this media tracker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   299
     * If the value of the {@code load} flag is {@code true},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * then this method starts loading any images that are not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * If there is an error while loading or scaling an image, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   305
     * {@code isErrorAny} and {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * check for errors.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   307
     * @param       load   if {@code true}, start loading any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *                       images that are not yet being loaded
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   309
     * @return      {@code true} if all images have finished loading,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *                       have been aborted, or have encountered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   311
     *                       an error; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see         java.awt.MediaTracker#checkID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see         java.awt.MediaTracker#checkAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @see         java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @see         java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public boolean checkAll(boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return checkAll(load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    private synchronized boolean checkAll(boolean load, boolean verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        boolean done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if ((cur.getStatus(load, verify) & DONE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Checks the error status of all of the images.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   335
     * @return   {@code true} if any of the images tracked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *                  by this media tracker had an error during
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   337
     *                  loading; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @see      java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @see      java.awt.MediaTracker#getErrorsAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public synchronized boolean isErrorAny() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if ((cur.getStatus(false, true) & ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Returns a list of all media that have encountered an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return       an array of media objects tracked by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *                        media tracker that have encountered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   356
     *                        an error, or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *                        there are none with errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @see          java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @see          java.awt.MediaTracker#getErrorsID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public synchronized Object[] getErrorsAny() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        int numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if ((cur.getStatus(false, true) & ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                numerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (numerrors == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   373
        Object[] errors = new Object[numerrors];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if ((cur.getStatus(false, false) & ERRORED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                errors[numerrors++] = cur.getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Starts loading all images tracked by this media tracker. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * method waits until all the images being tracked have finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   392
     * {@code isErrorAny} or {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see         java.awt.MediaTracker#waitForID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see         java.awt.MediaTracker#waitForAll(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @exception   InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *                                     interrupted this thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public void waitForAll() throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        waitForAll(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Starts loading all images tracked by this media tracker. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * method waits until all the images being tracked have finished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * loading, or until the length of time specified in milliseconds
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   409
     * by the {@code ms} argument has passed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * If there is an error while loading or scaling an image, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * that image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   413
     * {@code isErrorAny} or {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param       ms       the number of milliseconds to wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *                       for the loading to complete
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   417
     * @return      {@code true} if all images were successfully
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   418
     *                       loaded; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see         java.awt.MediaTracker#waitForID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see         java.awt.MediaTracker#waitForAll(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @exception   InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *                                     interrupted this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public synchronized boolean waitForAll(long ms)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        long end = System.currentTimeMillis() + ms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            int status = statusAll(first, first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if ((status & LOADING) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                return (status == COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            long timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            if (ms == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                timeout = end - System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                if (timeout <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Calculates and returns the bitwise inclusive <b>OR</b> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * status of all media that are tracked by this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Possible flags defined by the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   455
     * {@code MediaTracker} class are {@code LOADING},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   456
     * {@code ABORTED}, {@code ERRORED}, and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   457
     * {@code COMPLETE}. An image that hasn't started
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * loading has zero as its status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   460
     * If the value of {@code load} is {@code true}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * this method starts loading any images that are not yet being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   463
     * @param        load   if {@code true}, start loading
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *                            any images that are not yet being loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return       the bitwise inclusive <b>OR</b> of the status of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *                            all of the media being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @see          java.awt.MediaTracker#statusID(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see          java.awt.MediaTracker#LOADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see          java.awt.MediaTracker#ABORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see          java.awt.MediaTracker#ERRORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @see          java.awt.MediaTracker#COMPLETE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public int statusAll(boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return statusAll(load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    private synchronized int statusAll(boolean load, boolean verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            status = status | cur.getStatus(load, verify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Checks to see if all images tracked by this media tracker that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * are tagged with the specified identifier have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * This method does not start loading the images if they are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * already loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   496
     * {@code isErrorAny} or {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @param       id   the identifier of the images to check
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   499
     * @return      {@code true} if all images have finished loading,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *                       have been aborted, or have encountered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   501
     *                       an error; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see         java.awt.MediaTracker#checkID(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see         java.awt.MediaTracker#checkAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see         java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see         java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public boolean checkID(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return checkID(id, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Checks to see if all images tracked by this media tracker that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * are tagged with the specified identifier have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   515
     * If the value of the {@code load} flag is {@code true},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * then this method starts loading any images that are not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   521
     * {@code isErrorAny} or {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param       id       the identifier of the images to check
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   524
     * @param       load     if {@code true}, start loading any
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *                       images that are not yet being loaded
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   526
     * @return      {@code true} if all images have finished loading,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *                       have been aborted, or have encountered
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   528
     *                       an error; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see         java.awt.MediaTracker#checkID(int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @see         java.awt.MediaTracker#checkAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see         java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @see         java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public boolean checkID(int id, boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return checkID(id, load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    private synchronized boolean checkID(int id, boolean load, boolean verify)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        boolean done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                && (cur.getStatus(load, verify) & DONE) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        return done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Checks the error status of all of the images tracked by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * media tracker with the specified identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param        id   the identifier of the images to check
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   557
     * @return       {@code true} if any of the images with the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *                          specified identifier had an error during
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   559
     *                          loading; {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @see          java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @see          java.awt.MediaTracker#getErrorsID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public synchronized boolean isErrorID(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                && (cur.getStatus(false, true) & ERRORED) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Returns a list of media with the specified ID that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * have encountered an error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @param       id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @return      an array of media objects tracked by this media
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *                       tracker with the specified identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *                       that have encountered an error, or
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   583
     *                       {@code null} if there are none with errors
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see         java.awt.MediaTracker#isErrorID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @see         java.awt.MediaTracker#isErrorAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @see         java.awt.MediaTracker#getErrorsAny
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public synchronized Object[] getErrorsID(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        int numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                && (cur.getStatus(false, true) & ERRORED) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                numerrors++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (numerrors == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   602
        Object[] errors = new Object[numerrors];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        numerrors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (cur.getID() == id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                && (cur.getStatus(false, false) & ERRORED) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                errors[numerrors++] = cur.getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return errors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Starts loading all images tracked by this media tracker with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * specified identifier. This method waits until all the images with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * the specified identifier have finished loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   623
     * {@code isErrorAny} and {@code isErrorID} methods to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * check for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @param         id   the identifier of the images to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @see           java.awt.MediaTracker#waitForAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see           java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see           java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @exception     InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *                          interrupted this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    public void waitForID(int id) throws InterruptedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        waitForID(id, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Starts loading all images tracked by this media tracker with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * specified identifier. This method waits until all the images with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * the specified identifier have finished loading, or until the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   640
     * length of time specified in milliseconds by the {@code ms}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * argument has passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * If there is an error while loading or scaling an image, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * image is considered to have finished loading. Use the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   645
     * {@code statusID}, {@code isErrorID}, and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   646
     * {@code isErrorAny} methods to check for errors.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
   647
     * @param  id the identifier of the images to check
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
   648
     * @param  ms the length of time, in milliseconds, to wait
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
   649
     *         for the loading to complete
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
   650
     * @return {@code true} if the loading completed in time;
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 25144
diff changeset
   651
     *         otherwise {@code false}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @see           java.awt.MediaTracker#waitForAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @see           java.awt.MediaTracker#waitForID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @see           java.awt.MediaTracker#statusID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @see           java.awt.MediaTracker#isErrorAny()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @see           java.awt.MediaTracker#isErrorID(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @exception     InterruptedException  if any thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *                          interrupted this thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public synchronized boolean waitForID(int id, long ms)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        throws InterruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        long end = System.currentTimeMillis() + ms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            int status = statusID(id, first, first);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            if ((status & LOADING) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                return (status == COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            long timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            if (ms == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                timeout = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                timeout = end - System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                if (timeout <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            wait(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * Calculates and returns the bitwise inclusive <b>OR</b> of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * status of all media with the specified identifier that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * tracked by this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Possible flags defined by the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   690
     * {@code MediaTracker} class are {@code LOADING},
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   691
     * {@code ABORTED}, {@code ERRORED}, and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   692
     * {@code COMPLETE}. An image that hasn't started
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * loading has zero as its status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   695
     * If the value of {@code load} is {@code true}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * this method starts loading any images that are not yet being loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @param        id   the identifier of the images to check
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   698
     * @param        load   if {@code true}, start loading
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *                            any images that are not yet being loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @return       the bitwise inclusive <b>OR</b> of the status of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *                            all of the media with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *                            identifier that are being tracked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see          java.awt.MediaTracker#statusAll(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @see          java.awt.MediaTracker#LOADING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see          java.awt.MediaTracker#ABORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @see          java.awt.MediaTracker#ERRORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @see          java.awt.MediaTracker#COMPLETE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    public int statusID(int id, boolean load) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        return statusID(id, load, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    private synchronized int statusID(int id, boolean load, boolean verify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        int status = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (cur.getID() == id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                status = status | cur.getStatus(load, verify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Removes the specified image from this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * All instances of the specified image are removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * regardless of scale or ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @param   image     the image to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23276
diff changeset
   732
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    public synchronized void removeImage(Image image) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   735
        removeImageImpl(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   736
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   737
        if (rvImage != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   738
            removeImageImpl(rvImage);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   739
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   740
        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
   741
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   742
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   743
    private void removeImageImpl(Image image) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            MediaEntry next = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (cur.getMedia() == image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                    head = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    prev.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                cur.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            cur = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Removes the specified image from the specified tracking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * ID of this media tracker.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   765
     * All instances of {@code Image} being tracked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * under the specified ID are removed regardless of scale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @param      image the image to be removed
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   768
     * @param      id the tracking ID from which to remove the image
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @see        java.awt.MediaTracker#removeImage(java.awt.Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @see        java.awt.MediaTracker#removeImage(java.awt.Image, int, int, int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23276
diff changeset
   771
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    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
   774
        removeImageImpl(image, id);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   775
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   776
        if (rvImage != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   777
            removeImageImpl(rvImage, id);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   778
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   779
        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
   780
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   781
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   782
    private void removeImageImpl(Image image, int id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            MediaEntry next = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (cur.getID() == id && cur.getMedia() == image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    head = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    prev.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                cur.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            cur = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Removes the specified image with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * width, height, and ID from this media tracker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * Only the specified instance (with any duplicates) is removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @param   image the image to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @param   id the tracking ID from which to remove the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @param   width the width to remove (-1 for unscaled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @param   height the height to remove (-1 for unscaled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @see     java.awt.MediaTracker#removeImage(java.awt.Image, int)
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23276
diff changeset
   811
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    public synchronized void removeImage(Image image, int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                                         int width, int height) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   815
        removeImageImpl(image, id, width, height);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   816
        Image rvImage = getResolutionVariant(image);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   817
        if (rvImage != null) {
25107
9a16a601de25 8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents: 23276
diff changeset
   818
            removeImageImpl(rvImage, id,
9a16a601de25 8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents: 23276
diff changeset
   819
                    width == -1 ? -1 : 2 * width,
9a16a601de25 8040291: [macosx] Http-Images are not fully loaded when using ImageIcon
alexsch
parents: 23276
diff changeset
   820
                    height == -1 ? -1 : 2 * height);
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   821
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   822
        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
   823
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   824
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   825
    private void removeImageImpl(Image image, int id, int width, int height) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            MediaEntry next = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            if (cur.getID() == id && cur instanceof ImageMediaEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                && ((ImageMediaEntry) cur).matches(image, width, height))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    head = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    prev.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                cur.cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            cur = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    synchronized void setDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   849
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   850
    private static Image getResolutionVariant(Image image) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   851
        if (image instanceof MultiResolutionToolkitImage) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   852
            return ((MultiResolutionToolkitImage) image).getResolutionVariant();
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   853
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   854
        return null;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 21777
diff changeset
   855
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
abstract class MediaEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    MediaTracker tracker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    int ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    MediaEntry next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    boolean cancelled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    MediaEntry(MediaTracker mt, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        tracker = mt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        ID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    abstract Object getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    static MediaEntry insert(MediaEntry head, MediaEntry me) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        MediaEntry cur = head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        MediaEntry prev = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        while (cur != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            if (cur.ID > me.ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            prev = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            cur = cur.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        me.next = cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if (prev == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            head = me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            prev.next = me;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    int getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        return ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    abstract void startLoad();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    void cancel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        cancelled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    static final int LOADING = MediaTracker.LOADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    static final int ABORTED = MediaTracker.ABORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    static final int ERRORED = MediaTracker.ERRORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    static final int COMPLETE = MediaTracker.COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    static final int LOADSTARTED = (LOADING | ERRORED | COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    static final int DONE = (ABORTED | ERRORED | COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    synchronized int getStatus(boolean doLoad, boolean doVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (doLoad && ((status & LOADSTARTED) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            status = (status & ~ABORTED) | LOADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            startLoad();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    void setStatus(int flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            status = flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        tracker.setDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 52248
diff changeset
   926
@SuppressWarnings("serial") // MediaEntry does not have a no-arg ctor
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
class ImageMediaEntry extends MediaEntry implements ImageObserver,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
java.io.Serializable {
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 52248
diff changeset
   929
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    Image image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    private static final long serialVersionUID = 4739377000350280650L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    ImageMediaEntry(MediaTracker mt, Image img, int c, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        super(mt, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        image = img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    boolean matches(Image img, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        return (image == img && width == w && height == h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    Object getMedia() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    synchronized int getStatus(boolean doLoad, boolean doVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        if (doVerify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            int flags = tracker.target.checkImage(image, width, height, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            int s = parseflags(flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (s == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                if ((status & (ERRORED | COMPLETE)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    setStatus(ABORTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            } else if (s != status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                setStatus(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        return super.getStatus(doLoad, doVerify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    void startLoad() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        if (tracker.target.prepareImage(image, width, height, this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            setStatus(COMPLETE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    int parseflags(int infoflags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        if ((infoflags & ERROR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            return ERRORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        } else if ((infoflags & ABORT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            return ABORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        } else if ((infoflags & (ALLBITS | FRAMEBITS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            return COMPLETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    public boolean imageUpdate(Image img, int infoflags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        if (cancelled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        int s = parseflags(infoflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        if (s != 0 && s != status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            setStatus(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        return ((status & LOADING) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
}