Java Bugs - MediaTracker enhancement

Consider the appended diff. It adds a second constructor to MediaTracker, taking a Toolkit instead of a Component. For use in cases where you don't happen to have a Component around - basically, non-GUI applications.

You may ask, well if it's a non-GUI context then why do you have a Toolkit? Well, the Image stuff is pretty inextricably bound up with Toolkits, so when I wanted to write non-GUI Image stuff I just made myself a StubToolkit. But MediaTracker is the only dependency on Component, and it's not a very necessary dependency.

*** Acme/MediaTracker.orig	Sat Mar 23 11:41:07 1996
--- Acme/MediaTracker.java	Sat Mar 23 13:01:31 1996
***************
*** 17,25 ****
--- 17,26 ----
   * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
   */
  
  package java.awt;
  
  import java.awt.Component;
+ import java.awt.Toolkit;
  import java.awt.Image;
  import java.awt.Graphics;
  import java.awt.image.ImageObserver;
***************
*** 125,131 ****
   * @author 	Jim Graham
   */
  public class MediaTracker {
!     Component target;
      MediaEntry head;
  
      /**
--- 126,133 ----
   * @author 	Jim Graham
   */
  public class MediaTracker {
!     Component compTarget;
!     Toolkit tkTarget;
      MediaEntry head;
  
      /**
***************
*** 133,142 ****
       * @param comp the component on which the images will eventually be drawn
       */
      public MediaTracker(Component comp) {
! 	target = comp;
      }
  
      /**
       * Adds an image to the list of images being tracked.  The image
       * will eventually be rendered at its default (unscaled) size.
       * @param image the image to be tracked
--- 135,153 ----
       * @param comp the component on which the images will eventually be drawn
       */
      public MediaTracker(Component comp) {
! 	compTarget = comp;
      }
  
      /**
+      * Creates a Media tracker to track images for a given Toolikit.
+      * @param tk the Toolkit in which the images will eventually be drawn
+      */
+     public MediaTracker(Toolkit tk) {
+ 	compTarget = null;
+ 	tkTarget = tk;
+     }
+ 
+     /**
       * Adds an image to the list of images being tracked.  The image
       * will eventually be rendered at its default (unscaled) size.
       * @param image the image to be tracked
***************
*** 621,629 ****
      }
  
      void startLoad() {
! 	if (tracker.target.prepareImage(image, width, height, this)) {
! 	    setStatus(COMPLETE);
! 	}
      }
  
      public boolean imageUpdate(Image img, int infoflags,
--- 632,645 ----
      }
  
      void startLoad() {
! 	if ( tracker.compTarget != null )
! 	    if (tracker.compTarget.prepareImage(image, width, height, this)) {
! 		setStatus(COMPLETE);
! 	    }
! 	else
! 	    if (tracker.tkTarget.prepareImage(image, width, height, this)) {
! 		setStatus(COMPLETE);
! 	    }
      }
  
      public boolean imageUpdate(Image img, int infoflags,

Back to bugs.
Back to ACME Java.
Back to ACME Labs.