home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- public class MediaTracker {
- Component target;
- MediaEntry head;
- public static final int LOADING = 1;
- public static final int ABORTED = 2;
- public static final int ERRORED = 4;
- public static final int COMPLETE = 8;
- static final int DONE = 14;
-
- public MediaTracker(Component comp) {
- this.target = comp;
- }
-
- public void addImage(Image image, int id) {
- this.addImage(image, id, -1, -1);
- }
-
- public synchronized void addImage(Image image, int id, int w, int h) {
- this.head = MediaEntry.insert(this.head, new ImageMediaEntry(this, image, id, w, h));
- }
-
- public boolean checkAll() {
- return this.checkAll(false);
- }
-
- public synchronized boolean checkAll(boolean load) {
- MediaEntry cur = this.head;
-
- boolean done;
- for(done = true; cur != null; cur = cur.next) {
- if ((cur.getStatus(load) & 14) == 0) {
- done = false;
- }
- }
-
- return done;
- }
-
- public synchronized boolean isErrorAny() {
- for(MediaEntry cur = this.head; cur != null; cur = cur.next) {
- if ((cur.getStatus(false) & 4) != 0) {
- return true;
- }
- }
-
- return false;
- }
-
- public synchronized Object[] getErrorsAny() {
- MediaEntry cur = this.head;
-
- int numerrors;
- for(numerrors = 0; cur != null; cur = cur.next) {
- if ((cur.getStatus(false) & 4) != 0) {
- ++numerrors;
- }
- }
-
- if (numerrors == 0) {
- return null;
- } else {
- Object[] errors = new Object[numerrors];
- cur = this.head;
-
- for(int var5 = 0; cur != null; cur = cur.next) {
- if ((cur.getStatus(false) & 4) != 0) {
- errors[var5++] = cur.getMedia();
- }
- }
-
- return errors;
- }
- }
-
- public void waitForAll() throws InterruptedException {
- this.waitForAll(0L);
- }
-
- public synchronized boolean waitForAll(long ms) throws InterruptedException {
- long end = System.currentTimeMillis() + ms;
- boolean first = true;
-
- while(true) {
- int status = this.statusAll(first);
- if ((status & 1) == 0) {
- if (status != 8) {
- return false;
- }
-
- return true;
- }
-
- first = false;
- long timeout;
- if (ms == 0L) {
- timeout = 0L;
- } else {
- timeout = end - System.currentTimeMillis();
- if (timeout <= 0L) {
- return false;
- }
- }
-
- this.wait(timeout);
- }
- }
-
- public int statusAll(boolean load) {
- MediaEntry cur = this.head;
-
- int status;
- for(status = 0; cur != null; cur = cur.next) {
- status |= cur.getStatus(load);
- }
-
- return status;
- }
-
- public boolean checkID(int id) {
- return this.checkID(id, false);
- }
-
- public synchronized boolean checkID(int id, boolean load) {
- MediaEntry cur = this.head;
-
- boolean done;
- for(done = true; cur != null; cur = cur.next) {
- if (cur.getID() == id && (cur.getStatus(load) & 14) == 0) {
- done = false;
- }
- }
-
- return done;
- }
-
- public synchronized boolean isErrorID(int id) {
- for(MediaEntry cur = this.head; cur != null; cur = cur.next) {
- if (cur.getID() == id && (cur.getStatus(false) & 4) != 0) {
- return true;
- }
- }
-
- return false;
- }
-
- public synchronized Object[] getErrorsID(int id) {
- MediaEntry cur = this.head;
-
- int numerrors;
- for(numerrors = 0; cur != null; cur = cur.next) {
- if (cur.getID() == id && (cur.getStatus(false) & 4) != 0) {
- ++numerrors;
- }
- }
-
- if (numerrors == 0) {
- return null;
- } else {
- Object[] errors = new Object[numerrors];
- cur = this.head;
-
- for(int var6 = 0; cur != null; cur = cur.next) {
- if (cur.getID() == id && (cur.getStatus(false) & 4) != 0) {
- errors[var6++] = cur.getMedia();
- }
- }
-
- return errors;
- }
- }
-
- public void waitForID(int id) throws InterruptedException {
- this.waitForID(id, 0L);
- }
-
- public synchronized boolean waitForID(int id, long ms) throws InterruptedException {
- long end = System.currentTimeMillis() + ms;
- boolean first = true;
-
- while(true) {
- int status = this.statusID(id, first);
- if ((status & 1) == 0) {
- if (status != 8) {
- return false;
- }
-
- return true;
- }
-
- first = false;
- long timeout;
- if (ms == 0L) {
- timeout = 0L;
- } else {
- timeout = end - System.currentTimeMillis();
- if (timeout <= 0L) {
- return false;
- }
- }
-
- this.wait(timeout);
- }
- }
-
- public int statusID(int id, boolean load) {
- MediaEntry cur = this.head;
-
- int status;
- for(status = 0; cur != null; cur = cur.next) {
- if (cur.getID() == id) {
- status |= cur.getStatus(load);
- }
- }
-
- return status;
- }
-
- synchronized void setDone() {
- this.notifyAll();
- }
- }
-