AnimalPane.java


import java.io.IOException;
import java.io.FileNotFoundException;

import quicktime.app.QTFactory;
import quicktime.app.anim.Compositor;
import quicktime.app.image.GraphicsImporterDrawer; 
import quicktime.app.image.ImagePresenter; 
import quicktime.app.image.ImageUtil;
import quicktime.app.players.MoviePresenter;

import quicktime.io.QTFile;
import quicktime.io.OpenMovieFile;

import quicktime.qd.QDRect;
import quicktime.qd.QDGraphics;
import quicktime.qd.QDColor; 
import quicktime.qd.QDConstants; 

import quicktime.qd.QDDrawer;

import quicktime.std.image.Matrix;
import quicktime.std.StdQTConstants;
import quicktime.std.movies.Movie; 
import quicktime.std.image.GraphicsMode;

import quicktime.QTSession;
import quicktime.QTException; 

/**
 * QTZoo Module 3 - Drawing Text Using QTJ
 *
 * @author Michael Hopkins
 * @author Levi Brown
 * @author Apple Computer, Inc.
 * @version 2.0 01/16/2000
 *
 * Revision History
 * ---------------------------------------------------------------------------------
 * 12/02/99 MSH  cleaned up code, added comments
 * 01/16/00 MSH  updated for QuickTime 4.1
 */
public class AnimalPane
{
   /**
    *  Public default constructor
    *  Creates the map button, and sets up the listeners
    */
    public AnimalPane()
    {
        QDRect size = new QDRect(Zoo3.WIDTH, Zoo3.HEIGHT);
        try
        {
            QDGraphics gw = new QDGraphics( size );			// create a new graphics object
            compositor = new Compositor( gw, QDColor.white, 30, 1 );
		
            QTFile imageFile = new QTFile( 
                   QTFactory.findAbsolutePath( "data/zebra/ZebraBackground.jpg" ));
            GraphicsImporterDrawer drawer = new GraphicsImporterDrawer( imageFile );
            ImagePresenter presenter = ImagePresenter.fromGraphicsImporterDrawer( drawer );
            presenter.setLocation( 110, 110 );				// set location of movie within compositor
            compositor.addMember( presenter, 3 );			// add image presenter to compositor in 2nd layer
			
            addText( "data/zebra/Zebra.txt", 2, 15, 160, 415, 220 );

            Movie m = makeMovie( new QTFile( 
                   QTFactory.findAbsolutePath( "data/zebra/Zebra.mov" )));
            md = new MoviePresenter( m );               // create presenter from movie file	
            compositor.addMember( md, 1 );              // add presenter to compositor
            compositor.getTimer().setRate(1);           // start compositor
            md.setRate(1);                              // start movie
        }
        catch ( IOException e )                         // catch any errors
        {
            e.printStackTrace();
        }
        catch ( QTException e )
        {
            e.printStackTrace();
        }
    }
    
    public Compositor getCompositor( ) { return compositor; }	// returns the compositor associated with the animal pane
   
  /**
    * Reads a text file from the disk and displays it in the compositor
    * @param textPath the relative path where the text is located
    * @param layer, the layer of the compositor to add the text to.
    * @param x the x coordinate location.
    * @param y the y coordinate location.
    * @param width the width of the area to display the text.
    * @param height the height of the area to display the text.
    */
    protected void addText( String textPath, int layer, int x, int y, int width, int height )
    {
        try
        {
            TextPresenter text = new TextPresenter( textPath, new Dimension( width, height ));
			
            ImagePresenter presenter = text.getPresenter();
            Matrix theMatrix = new Matrix();
            theMatrix.translate( (float) x, (float) y );
            presenter.setMatrix( theMatrix );
            compositor.addMember( presenter, layer );
        }
        catch( QTException e )
        {
            e.printStackTrace();
        }
        catch( FileNotFoundException e )
        {
            e.printStackTrace();
        }	
    }	// MODULE 3 Addition



		
   /**
    * Opens the movie file and sets it up to be played.
    * @param f a QTFile representing the movie to initialize.
    * @return the movie, ready to play
    */
    protected Movie makeMovie( QTFile f ) throws IOException, QTException
    {
        OpenMovieFile movieFile = OpenMovieFile.asRead(f);
        Movie m = Movie.fromFile( movieFile );
        m.getTimeBase().setFlags( StdQTConstants.loopTimeBase );// we want the movie to loop	
        return m;	
    }
		
    protected Compositor compositor;
    protected MoviePresenter md;
}