home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 9- full screen mode / source / mainframe.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  7.6 KB  |  241 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import java.util.Vector;
  5. import java.util.StringTokenizer;
  6.  
  7. import quicktime.QTException;
  8. import quicktime.QTSession;
  9. import quicktime.app.display.QTCanvas;
  10. import quicktime.app.anim.Compositor;
  11. import quicktime.app.image.QTTransition;
  12. import quicktime.std.movies.Atom;
  13. import quicktime.std.movies.AtomContainer;
  14. import quicktime.std.StdQTConstants;
  15. import quicktime.qd.QDDimension;
  16.  
  17. import quicktime.util.EndianOrder;
  18.  
  19.  
  20. /**
  21.  * QTZoo Module 8 - Using QuickTime Transitions
  22.  * This application requires QuickTime for Java
  23.  *
  24.  * @author Levi Brown
  25.  * @author Michael Hopkins
  26.  * @author Apple Computer, Inc.
  27.  * @version 8.0 4/10/2000
  28.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  29.  *    
  30.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  31.  *                ("Apple") in consideration of your agreement to the following terms, and your
  32.  *                use, installation, modification or redistribution of this Apple software
  33.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  34.  *                please do not use, install, modify or redistribute this Apple software.
  35.  *
  36.  *                In consideration of your agreement to abide by the following terms, and subject
  37.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  38.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  39.  *                reproduce, modify and redistribute the Apple Software, with or without
  40.  *                modifications, in source and/or binary forms; provided that if you redistribute
  41.  *                the Apple Software in its entirety and without modifications, you must retain
  42.  *                this notice and the following text and disclaimers in all such redistributions of
  43.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  44.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  45.  *                Apple Software without specific prior written permission from Apple.  Except as
  46.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  47.  *                are granted by Apple herein, including but not limited to any patent rights that
  48.  *                may be infringed by your derivative works or by other works in which the Apple
  49.  *                Software may be incorporated.
  50.  *
  51.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  52.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  53.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  54.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  55.  *                COMBINATION WITH YOUR PRODUCTS.
  56.  *
  57.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  58.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  59.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  60.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  61.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  62.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  63.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64.  * 
  65.  * 
  66.  */
  67.  
  68.  
  69. public class MainFrame extends Frame 
  70. {
  71.     public static final int WIDTH  = 640;
  72.     public static final int HEIGHT = 480;
  73.  
  74.     /**
  75.      * Creates the QTCanvas, loads media, and displays window contents
  76.      */
  77.     public MainFrame( String s )
  78.     {
  79.         super( s );
  80.         setResizable( false );
  81.         setBounds( 0, 0, WIDTH, HEIGHT );
  82.         
  83.         myQTCanvas = new QTCanvas( QTCanvas.kInitialSize, 0.5F, 0.5F );     // Create new QT Canvas
  84.         add( myQTCanvas );
  85.         
  86.         loadPanes( );    
  87.         
  88.         try
  89.         {
  90.             myQTCanvas.setClient (mapPane.getCompositor(), true);                //Set the canvas to display the map pane
  91.         }
  92.         catch (QTException exc)
  93.         {
  94.             exc.printStackTrace();
  95.         }                                                                    
  96.         
  97.         addWindowListener( new WindowAdapter() 
  98.         {
  99.             public void windowClosing( WindowEvent we )
  100.             {
  101.                 QTSession.close();
  102.                 dispose();
  103.             }
  104.             public void windowClosed( WindowEvent we )
  105.             {
  106.                 System.exit( 0 );
  107.             }
  108.         });
  109.         
  110.         show();
  111.         toFront();
  112.     }
  113.     
  114.     /**
  115.      * Loads the data displayed in each of the animal panes
  116.      */
  117.     public void loadPanes()
  118.     {
  119.         actionListener = new Action();
  120.  
  121.         mapPane = new MapPane( );
  122.         mapPane.addActionListener(actionListener);
  123.         
  124.         zebraPane = new AnimalPane( );
  125.         zebraPane.addActionListener(actionListener);
  126.     }
  127.     
  128.     protected void transition(ZooPane fromPane, ZooPane toPane, Point effectLoc )
  129.     {
  130.         Compositor fromComp = fromPane.getCompositor();
  131.         Compositor toComp = toPane.getCompositor();
  132.         try
  133.         {
  134.             //Make sure the compositor has had a chance to drawn itself
  135.             toComp.setGWorld(quicktime.qd.QDGraphics.validScratch);
  136.             toComp.redraw(null);
  137.             
  138.             QTTransition transition = new QTTransition(new QDDimension(MainFrame.WIDTH, MainFrame.HEIGHT));
  139.             transition.setTime(1000);
  140.             transition.setSourceImage(fromComp);
  141.             transition.setDestinationImage(toComp);
  142.             transition.setProfiled(false);
  143.             myQTCanvas.setClient (transition, true);
  144.  
  145.             AtomContainer effectSample = new AtomContainer();
  146.  
  147.             if (effectLoc == null)
  148.             {
  149.                 // We are using SMPTE Effects so set the what atom to smpt
  150.                 effectSample.insertChild (Atom.kParentIsContainer, StdQTConstants.kEffectWhatAtom, 1, 0, EndianOrder.flipNativeToBigEndian32(StdQTConstants.kWipeTransitionType));        
  151.                 // We are using SMPTE effect number 74    - start at 0%, stop at 100%
  152.                 effectSample.insertChild(Atom.kParentIsContainer, StdQTConstants.kEffectWipe, 1, 0, EndianOrder.flipNativeToBigEndian32(StdQTConstants.kRandomWipeTransitionType));
  153.             }
  154.             else
  155.             {
  156.                 effectSample.insertChild(Atom.kParentIsContainer, StdQTConstants.kEffectWhatAtom, 1, 0, EndianOrder.flipNativeToBigEndian32(StdQTConstants.kExplodeTransitionType));        
  157.                 effectSample.insertChild(Atom.kParentIsContainer, StdQTConstants.kExplodeTransitionType, 1, 0, EndianOrder.flipNativeToBigEndian32(StdQTConstants.kExplodeTransitionType));
  158.             }
  159.             transition.setEffect(effectSample);
  160.             transition.doTransition();
  161.  
  162.             myQTCanvas.setClient (toComp, true);
  163.  
  164.             toPane.start();
  165.             fromPane.stop();
  166.         }
  167.         catch (QTException exc)
  168.         {
  169.             exc.printStackTrace();
  170.         }
  171.     }
  172.  
  173.     
  174.     /**
  175.      * Responds to actions targeting the MainFrame
  176.      * Responsible for handling clicks in the animal regions in the Map Pane
  177.      */
  178.     class Action implements ActionListener
  179.     {
  180.         public void actionPerformed(ActionEvent event)
  181.         {
  182.             Object source = event.getSource();
  183.             String command = event.getActionCommand();
  184.             StringTokenizer st = new StringTokenizer(command, ";");
  185.             Vector params = new Vector();
  186.             
  187.             while (st.hasMoreTokens())
  188.             {
  189.                 params.addElement(st.nextToken());
  190.             }
  191.  
  192.             //Minimalistic error checking...
  193.             if (params.size() < 3)
  194.             {
  195.                 System.err.println("Not enough parameters in command");
  196.                 return;
  197.             }
  198.             
  199.             //Parse our action command for pertinate info    
  200.             String area = (String)params.elementAt(0);
  201.             int xLoc = 0;
  202.             int yLoc = 0;
  203.             
  204.             try
  205.             {
  206.                 xLoc = Integer.parseInt((String)params.elementAt(1));
  207.             } catch (NumberFormatException exc)
  208.             {
  209.                 exc.printStackTrace();
  210.             }
  211.             try
  212.             {
  213.                 yLoc = Integer.parseInt((String)params.elementAt(2));
  214.             } catch (NumberFormatException exc)
  215.             {
  216.                 exc.printStackTrace();
  217.             }
  218.                 
  219.             //Distribute appropriately
  220.             
  221.             if (source.equals(mapPane))
  222.             {
  223.                 zebraPane.playSound();
  224.                 transition(mapPane, zebraPane, new Point(xLoc, yLoc));
  225.             }
  226.             else if (source instanceof AnimalPane)
  227.             {
  228.                 if (area.equals("map"))
  229.                 {
  230.                     transition((AnimalPane)source, mapPane, null );
  231.                 }
  232.             }
  233.         }
  234.     }
  235.  
  236.     protected ActionListener actionListener;
  237.     protected QTCanvas myQTCanvas;
  238.     protected MapPane mapPane;
  239.     protected AnimalPane zebraPane;
  240. }
  241.