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