home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / Source.bin / AnimatorImage.java < prev    next >
Encoding:
Java Source  |  1998-09-14  |  2.0 KB  |  69 lines

  1. package symantec.itools.multimedia;
  2.  
  3. import java.net.URL;
  4. import java.awt.Image;
  5. import java.io.ObjectInputStream;
  6. import java.io.IOException;
  7. import java.awt.MediaTracker;
  8. import java.awt.Component;
  9. import java.util.ResourceBundle;
  10. import java.text.MessageFormat;
  11.  
  12. //    05/30/97    RKM    Moved AnimatorImage class into its own file as the compiler suggested
  13. //  07/15/97    CAR added a default constructor and a constructor which takes a component reference
  14. //                  added a Component reference field and marked fields transient as needed
  15. //                  implemented the Serializable interface
  16. //                  implemented readObject to load the images of the deserialized URLs
  17.  
  18. class AnimatorImage implements java.io.Serializable
  19. {
  20.     URL                    url;
  21.     transient   Image   image;
  22.     transient   boolean    loaded;
  23.     Component           comp = null;
  24.  
  25.     transient protected ResourceBundle errors;
  26.  
  27.     public AnimatorImage() { }
  28.  
  29.     public AnimatorImage(URL u, Image i, boolean l, Component c) {
  30.         this(u, i, l);
  31.         comp = c;
  32.     }
  33.  
  34.     public AnimatorImage(URL u, Image i, boolean l)
  35.     {
  36.         url    = u;
  37.         image  = i;
  38.         loaded = l;
  39.     }
  40.  
  41.     private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  42.         stream.defaultReadObject();
  43.  
  44.         
  45.         try
  46.         {
  47.             errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
  48.         }
  49.         catch(Throwable ex)
  50.         {
  51.             errors = new symantec.itools.resources.ErrorsBundle();
  52.         }
  53.  
  54.         image = comp.getToolkit().getImage(url);
  55.  
  56.         MediaTracker tracker = new MediaTracker(comp);
  57.         tracker.addImage(image, 0);
  58.         try {
  59.             tracker.waitForAll();
  60.         }
  61.         catch(InterruptedException e) {
  62.             Object[] args = { url };
  63.             throw new IOException(MessageFormat.format(errors.getString("ErrorLoadingImageForURL"), args));
  64.         }
  65.  
  66.         loaded = true;
  67.     }
  68. }
  69.