home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / imageproducing / src / ipdrawer.java < prev   
Encoding:
Java Source  |  2000-09-28  |  2.9 KB  |  90 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8.  
  9. import quicktime.app.display.*;
  10. import quicktime.app.image.*;
  11. import quicktime.qd.*;
  12. import quicktime.QTException;
  13. import quicktime.std.image.Matrix;
  14. import java.awt.*;
  15.  
  16. /**
  17.  * This class will present the image that is produced by the given QTImageProducer.
  18.  * If the QTImageProducer is presenting content that has a time or multi-frame element
  19.  * then repaints will be scheduled when the IPDrawer is redrawn.
  20.  * <P>
  21.  * A typical usage of this class is as a client of a QTCanvas that is used within the
  22.  * context of a swing container.
  23.  */
  24. public class IPDrawer extends ImageDrawer {
  25.     /** 
  26.      * Creates an IPDrawer with the given QTImageProducer. The default size of the IPDrawer
  27.      * is the size of the QTImageProducer. 
  28.      */
  29.     public IPDrawer (QTImageProducer ip) {
  30.         super (ip.getSize(), null);
  31.         this.ip = ip;
  32.     }
  33.     
  34. //_________________________ INSTANCE VARIABLES
  35.     private QTImageProducer ip;
  36.     
  37. //_________________________ INSTANCE METHODS
  38.     /**
  39.      * Returns the QTImageProducer that produces the image for this Drawer
  40.      */
  41.     public QTImageProducer getProducer () { return ip; }
  42.  
  43.     /**
  44.      * This method is called by the specified object when the instance of 
  45.      * the class that implements this interface is added to the object
  46.      * that is the source of the interest.
  47.      * @param interest the object that is to be the source of interest for the
  48.      * the object that implements this interface.
  49.      */
  50.     public void addedTo (Object interest) {
  51.         super.addedTo (interest);    //this will set the canv variable
  52.         if (canv != null) {
  53.             im = canv.createImage (ip);
  54.             canv.prepareImage (im, canv);
  55.         }
  56.     }
  57.     
  58.     /**
  59.      * This method is called by the specified object when the instance of 
  60.      * the class that implements this interface is removed from the object
  61.      * that is the source of the interest.
  62.      * @param interest the object that was the source of interest for the
  63.      * the object that implements this interface.
  64.      */
  65.     public void removedFrom (Object interest) {
  66.         super.removedFrom (interest);
  67.         if (canv == null)
  68.             im = null;
  69.     }
  70.  
  71.     /**
  72.      * QTCanvas calls this method when the client should redraw itself.
  73.      * If the canvas is able to discern that only a part of the client's 
  74.      * drawing area needs to be redrawn - then this area shall be passed in
  75.      * using the invalidRgn. Otherwise this will be null in which case the
  76.      * client should redraw itself entirely.
  77.      * @param invalidRgn the invalidRgn that the client should redraw
  78.      */
  79.     public void redraw (Region invalidRgn) throws QTException {
  80.         super.redraw (invalidRgn);
  81.         
  82. // this redraw should be done in another thread to free up the display thread
  83. // so that the app is more repsonsive for the user
  84. // see the sample code
  85.         if (ip.isRedrawing() && canv != null) { 
  86.             ip.redraw(invalidRgn);
  87.         }
  88.     }
  89. }
  90.