1 /*
2 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
627 * interrupted this thread.
628 */
629 public void waitForID(int id) throws InterruptedException {
630 waitForID(id, 0);
631 }
632
633 /**
634 * Starts loading all images tracked by this media tracker with the
635 * specified identifier. This method waits until all the images with
636 * the specified identifier have finished loading, or until the
637 * length of time specified in milliseconds by the <code>ms</code>
638 * argument has passed.
639 * <p>
640 * If there is an error while loading or scaling an image, then that
641 * image is considered to have finished loading. Use the
642 * <code>statusID</code>, <code>isErrorID</code>, and
643 * <code>isErrorAny</code> methods to check for errors.
644 * @param id the identifier of the images to check
645 * @param ms the length of time, in milliseconds, to wait
646 * for the loading to complete
647 * @see java.awt.MediaTracker#waitForAll
648 * @see java.awt.MediaTracker#waitForID(int)
649 * @see java.awt.MediaTracker#statusID
650 * @see java.awt.MediaTracker#isErrorAny()
651 * @see java.awt.MediaTracker#isErrorID(int)
652 * @exception InterruptedException if any thread has
653 * interrupted this thread.
654 */
655 public synchronized boolean waitForID(int id, long ms)
656 throws InterruptedException
657 {
658 long end = System.currentTimeMillis() + ms;
659 boolean first = true;
660 while (true) {
661 int status = statusID(id, first, first);
662 if ((status & LOADING) == 0) {
663 return (status == COMPLETE);
664 }
665 first = false;
666 long timeout;
|
1 /*
2 * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
627 * interrupted this thread.
628 */
629 public void waitForID(int id) throws InterruptedException {
630 waitForID(id, 0);
631 }
632
633 /**
634 * Starts loading all images tracked by this media tracker with the
635 * specified identifier. This method waits until all the images with
636 * the specified identifier have finished loading, or until the
637 * length of time specified in milliseconds by the <code>ms</code>
638 * argument has passed.
639 * <p>
640 * If there is an error while loading or scaling an image, then that
641 * image is considered to have finished loading. Use the
642 * <code>statusID</code>, <code>isErrorID</code>, and
643 * <code>isErrorAny</code> methods to check for errors.
644 * @param id the identifier of the images to check
645 * @param ms the length of time, in milliseconds, to wait
646 * for the loading to complete
647 * @return {@code true} if the loading completed in time;
648 * otherwise {@code false}
649 * @see java.awt.MediaTracker#waitForAll
650 * @see java.awt.MediaTracker#waitForID(int)
651 * @see java.awt.MediaTracker#statusID
652 * @see java.awt.MediaTracker#isErrorAny()
653 * @see java.awt.MediaTracker#isErrorID(int)
654 * @exception InterruptedException if any thread has
655 * interrupted this thread.
656 */
657 public synchronized boolean waitForID(int id, long ms)
658 throws InterruptedException
659 {
660 long end = System.currentTimeMillis() + ms;
661 boolean first = true;
662 while (true) {
663 int status = statusID(id, first, first);
664 if ((status & LOADING) == 0) {
665 return (status == COMPLETE);
666 }
667 first = false;
668 long timeout;
|