⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mediatracker.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  {    long start = System.currentTimeMillis();    boolean result = checkAll(true);    synchronized (this)    {      while (result == false)        {          wait(ms);          result = checkAll(true);          if ((System.currentTimeMillis() - start) > ms)            break;        }    }    return result;  }  /**   * Returns the status flags of all registered media objects ORed together.   * If <code>load</code> is <code>true</code> then media objects that   * are not already loading will be started to load.   *   * @param load if set to <code>true</code> then media objects that are   *        not already loading are started   *   * @return the status flags of all tracked media objects ORed together   */  public int statusAll(boolean load)  {    int result = 0;    MediaEntry e = head;    while (e != null)      {        if (load && e.status == 0)          {            if (target.prepareImage(e.image, e))              e.status = COMPLETE;            else	      {                e.status = LOADING;                int flags = target.checkImage(e.image, e);		if ((flags & ImageObserver.ABORT) != 0)		  e.status = ABORTED;		else if ((flags & ImageObserver.ERROR) != 0)		  e.status = ERRORED;		else if ((flags & ImageObserver.ALLBITS) != 0)		  e.status = COMPLETE;	      }          }        result |= e.status;        e = e.next;      }    return result;  }  /**   * Checks if the media objects with <code>ID</code> have completed loading.   *   * @param id the ID of the media objects to check   *   * @return <code>true</code> if all media objects with <code>ID</code>   *         have successfully finished   */  public boolean checkID(int id)  {    return checkID(id, false);  }  /**   * Checks if the media objects with <code>ID</code> have completed loading.   * If <code>load</code> is <code>true</code> then media objects that   * are not already loading will be started to load.   *   * @param id the ID of the media objects to check   * @param load if set to <code>true</code> then media objects that are   *        not already loading are started   *   * @return <code>true</code> if all media objects with <code>ID</code>   *         have successfully finished   */  public boolean checkID(int id, boolean load)  {    MediaEntry e = head;    boolean result = true;        while (e != null)      {        if (e.id == id && ((e.status & (COMPLETE | ABORTED | ERRORED)) == 0))          {            if (load && ((e.status & LOADING) == 0))              {                e.status = LOADING;		if (target.prepareImage(e.image, e))		  e.status = COMPLETE;		else		  {		    int flags = target.checkImage(e.image, e);		    if ((flags & ImageObserver.ABORT) != 0)		      e.status = ABORTED;		    else if ((flags & ImageObserver.ERROR) != 0)		      e.status = ERRORED;		    else if ((flags & ImageObserver.ALLBITS) != 0)		      e.status = COMPLETE;		  }		boolean complete = (e.status				    & (COMPLETE | ABORTED | ERRORED)) != 0;		if (!complete)		  result = false;              }            else              result = false;          }        e = e.next;      }    return result;  }  /**   * Returns <code>true</code> if any of the media objects with <code>ID</code>   * have encountered errors during loading, false otherwise.   *   * @param id the ID of the media objects to check   *   * @return <code>true</code> if any of the media objects with <code>ID</code>   *         have encountered errors during loading, false otherwise   */  public boolean isErrorID(int id)  {    MediaEntry e = head;        while (e != null)      {        if (e.id == id && ((e.status & ERRORED) != 0))          return true;        e = e.next;      }    return false;  }  /**   * Returns all media objects with the specified ID that have encountered   * an error.   *   * @param id the ID of the media objects to check   *   * @return an array of all media objects  with the specified ID that   *         have encountered an error   */  public Object[] getErrorsID(int id)  {    MediaEntry e = head;    ArrayList result = null;    while (e != null)      {        if (e.id == id && ((e.status & ERRORED) != 0))          {            if (result == null)              result = new ArrayList();            result.add(e.image);          }        e = e.next;      }    if (result == null)      return null;    else      return result.toArray();  }  /**   * Waits for all media objects with the specified ID to finish loading,   * either by completing successfully or by aborting or encountering an error.   *   * @param id the ID of the media objects to wait for   *   * @throws InterruptedException if another thread interrupted the   *         current thread while waiting   */  public void waitForID(int id) throws InterruptedException  {    MediaEntry e = head;    synchronized (this)    {      while (checkID (id, true) == false)        wait();    }  }  /**   * Waits for all media objects with the specified ID to finish loading,   * either by completing successfully or by aborting or encountering an error.   *   * This method waits at most <code>ms</code> milliseconds. If the   * media objects have not completed loading within this timeframe, this   * method returns <code>false</code>, otherwise <code>true</code>.   *   * @param id the ID of the media objects to wait for   * @param ms timeframe in milliseconds to wait for the media objects to   *        finish   *   * @return <code>true</code> if all media objects have successfully loaded   *         within the timeframe, <code>false</code> otherwise   *   * @throws InterruptedException if another thread interrupted the   *         current thread while waiting   */  public boolean waitForID(int id, long ms) throws InterruptedException  {    MediaEntry e = head;    long start = System.currentTimeMillis();    boolean result = checkID(id, true);    synchronized (this)    {      while (result == false)        {          wait(ms);          result = checkID(id, true);          if ((System.currentTimeMillis() - start) > ms)            break;        }    }    return result;  }  /**   * Returns the status flags of the media objects with the specified ID   * ORed together.   *   * If <code>load</code> is <code>true</code> then media objects that   * are not already loading will be started to load.   *   * @param load if set to <code>true</code> then media objects that are   *        not already loading are started   *   * @return the status flags of all tracked media objects ORed together   */  public int statusID(int id, boolean load)  {    int result = 0;    MediaEntry e = head;    while (e != null)      {        if (e.id == id)          {            if (load && e.status == 0)              {		if (target.prepareImage(e.image, e))                  e.status = COMPLETE;		else		  {		    e.status = LOADING;		    int flags = target.checkImage(e.image, e);		    if ((flags & ImageObserver.ABORT) != 0)		      e.status = ABORTED;		    else if ((flags & ImageObserver.ERROR) != 0)		      e.status = ERRORED;		    else if ((flags & ImageObserver.ALLBITS) != 0)		      e.status = COMPLETE;		  }              }            result |= e.status;          }        e = e.next;      }    return result;  }  /**   * Removes an image from this MediaTracker.   *   * @param image the image to be removed   */  public void removeImage(Image image)  {    synchronized (this)      {        MediaEntry e = head;        MediaEntry prev = null;        while (e != null)          {            if (e.image == image)              {                if (prev == null)                  head = e.next;                else                  prev.next = e.next;              }            prev = e;            e = e.next;          }      }  }  /**   * Removes an image with the specified ID from this MediaTracker.   *   * @param image the image to be removed   */  public void removeImage(Image image, int id)  {    synchronized (this)      {        MediaEntry e = head;        MediaEntry prev = null;        while (e != null)          {            if (e.id == id && e.image == image)              {                if (prev == null)                  head = e.next;                else                  prev.next = e.next;              }            else              prev = e;            e = e.next;          }      }  }  /**   * Removes an image with the specified ID and scale from this MediaTracker.   *   * @param image the image to be removed   */  public void removeImage(Image image, int id, int width, int height)  {    synchronized (this)      {        MediaEntry e = head;        MediaEntry prev = null;        while (e != null)          {            if (e.id == id && e.image == image                && e.width == width && e.height == height)              {                if (prev == null)                  head = e.next;                else                  prev.next = e.next;              }            else              prev = e;            e = e.next;          }      }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -