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 8- transitions / source / zoopane.java < prev   
Encoding:
Java Source  |  2000-06-23  |  7.4 KB  |  232 lines

  1. import java.awt.AWTEventMulticaster;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.MouseListener;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.Point;
  7.  
  8. import quicktime.QTException;
  9. import quicktime.app.anim.Compositor;
  10. import quicktime.app.anim.TwoDSprite;
  11.  
  12. import quicktime.app.event.QTMouseTargetController;
  13. import quicktime.app.event.MouseButtonListener;
  14. import quicktime.app.event.MouseTargetAdapter;
  15. import quicktime.app.event.QTMouseEvent;
  16. import java.awt.Point;
  17. import java.util.Hashtable;
  18.  
  19.  
  20. import quicktime.qd.QDColor;
  21. import quicktime.qd.QDConstants;
  22. import quicktime.std.image.GraphicsMode;
  23.  
  24. /**
  25.  * QTZoo Module 7 - Advanced Compositing and Event Handling
  26.  * This application requires QuickTime for Java
  27.  *
  28.  * @author Levi Brown
  29.  * @author Michael Hopkins
  30.  * @author Apple Computer, Inc.
  31.  * @version 6.0 4/10/2000
  32.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  33.  *    
  34.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  35.  *                ("Apple") in consideration of your agreement to the following terms, and your
  36.  *                use, installation, modification or redistribution of this Apple software
  37.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  38.  *                please do not use, install, modify or redistribute this Apple software.
  39.  *
  40.  *                In consideration of your agreement to abide by the following terms, and subject
  41.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  42.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  43.  *                reproduce, modify and redistribute the Apple Software, with or without
  44.  *                modifications, in source and/or binary forms; provided that if you redistribute
  45.  *                the Apple Software in its entirety and without modifications, you must retain
  46.  *                this notice and the following text and disclaimers in all such redistributions of
  47.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  48.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  49.  *                Apple Software without specific prior written permission from Apple.  Except as
  50.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  51.  *                are granted by Apple herein, including but not limited to any patent rights that
  52.  *                may be infringed by your derivative works or by other works in which the Apple
  53.  *                Software may be incorporated.
  54.  *
  55.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  56.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  57.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  58.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  59.  *                COMBINATION WITH YOUR PRODUCTS.
  60.  *
  61.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  62.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  63.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  64.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  65.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  66.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  67.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  68.  * 
  69.  * 
  70.  */
  71. public abstract class ZooPane
  72. {
  73.     /**
  74.      *    Retrieve the pane's current compositor
  75.      */
  76.     public Compositor getCompositor()
  77.     {
  78.         return compositor;
  79.     }
  80.  
  81.     /**
  82.      * Called to do any setup after being set as the client of the QTCanvas.
  83.      * May be used to start effects running, movies playing, etc.
  84.      */
  85.     abstract public void start();
  86.  
  87.     /**
  88.      * Called to do clean up after being removed as the client of the QTCanvas.
  89.      * Should be used to stop effects running, movies playing, etc.
  90.      */
  91.     abstract public void stop();
  92.     
  93.     /**
  94.      * Sets the command name of the action event fired by this button.
  95.      * @param command The name of the action event command fired by this button
  96.      */
  97.     protected void setActionCommand( String command )
  98.     {
  99.         actionCommand = command;
  100.     }
  101.  
  102.     /**
  103.      * Adds the specified action listener to receive action events
  104.      * from this button.
  105.      * @param l the action listener
  106.      */
  107.     public void addActionListener(ActionListener l)
  108.     {
  109.         actionListener = AWTEventMulticaster.add(actionListener, l);
  110.     }
  111.     
  112.     /**
  113.      * Fire an action event to the listeners.
  114.      */
  115.     protected void fireActionEvent()
  116.     {
  117.         if (actionListener != null)
  118.             actionListener.actionPerformed( new ActionEvent( this, ActionEvent.ACTION_PERFORMED, actionCommand ));
  119.     }
  120.  
  121.     
  122.     /**
  123.      * Responds to mouse events from the animal regions and various buttons
  124.      */
  125.     public class PaneMouseListener extends MouseTargetAdapter implements MouseButtonListener
  126.     {
  127.         public PaneMouseListener( QDColor normalBlend, QDColor rollOverBlend, QDColor clickedBlend )
  128.         { 
  129.             normalGM   = new GraphicsMode( QDConstants.blend, normalBlend   );
  130.             rollOverGM = new GraphicsMode( QDConstants.blend, rollOverBlend );
  131.             clickedGM  = new GraphicsMode( QDConstants.blend, clickedBlend  );
  132.         }
  133.  
  134.         public void mouseTargetEntered( QTMouseEvent e ) // called when the mouse enters a region managed by the controller
  135.         {
  136.             isMouseInside = true;
  137.             try
  138.             {
  139.                 if ( e.getTarget() instanceof TwoDSprite )
  140.                 {
  141.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  142.                     if (isMousePressed)
  143.                         sp.setGraphicsMode( clickedGM );
  144.                     else
  145.                         sp.setGraphicsMode( rollOverGM );
  146.                 }
  147.             }
  148.             catch (QTException exc)
  149.             {    
  150.                 exc.printStackTrace();
  151.             }
  152.         }
  153.         
  154.         public void mouseTargetExited( QTMouseEvent e ) // called when the mouse exits a region managed by the controller
  155.         {
  156.             isMouseInside = false;
  157.             try
  158.             {
  159.                 if ( e.getTarget() instanceof TwoDSprite )
  160.                 {
  161.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  162.                     sp.setGraphicsMode( normalGM );
  163.                 }
  164.             }
  165.             catch (QTException exc)
  166.             {    
  167.                 exc.printStackTrace();
  168.             }
  169.         }
  170.  
  171.         public void mouseClicked(QTMouseEvent e) {}
  172.  
  173.         public void mousePressed( QTMouseEvent e )      // called when the mouse is pressed in a region managed by the controller
  174.         {
  175.             isMousePressed = true;
  176.             try
  177.             {
  178.                 if ( e.getTarget() instanceof TwoDSprite )
  179.                 {
  180.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  181.                     sp.setGraphicsMode( clickedGM );
  182.                 }
  183.             }
  184.             catch (QTException exc)
  185.             {    
  186.                 exc.printStackTrace();
  187.             }
  188.         }
  189.         
  190.         public void mouseReleased( QTMouseEvent e )    // called when the mouse is released in a region managed by the controller
  191.         {
  192.             isMousePressed = false;
  193.             try
  194.             {
  195.                 if ( e.getTarget() instanceof TwoDSprite )
  196.                 {
  197.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  198.                                         
  199.                     if (isMouseInside)
  200.                     {
  201.                         sp.setGraphicsMode( rollOverGM );
  202.  
  203.                         String area = (String) areas.get(sp);
  204.                         setActionCommand(area + ";" + e.getX() + ";" + e.getY());
  205.                         
  206.                         fireActionEvent();
  207.                     }
  208.                     else
  209.                         sp.setGraphicsMode( normalGM );
  210.                 }
  211.             }
  212.             catch (QTException exc)
  213.             {    
  214.                 exc.printStackTrace();
  215.             }
  216.         }
  217.         GraphicsMode rollOverGM = new GraphicsMode( QDConstants.blend, QDColor.darkGray );
  218.         GraphicsMode clickedGM = new GraphicsMode( QDConstants.blend, QDColor.lightGray );
  219.         GraphicsMode normalGM;
  220.     }
  221.     protected Hashtable areas;
  222.  
  223.     protected String actionCommand;
  224.     protected ActionListener actionListener = null;
  225.     
  226.     protected Compositor compositor;
  227.     
  228.     protected QTMouseTargetController ctr;
  229.     protected boolean isMouseInside;
  230.     protected boolean isMousePressed;
  231. }
  232.