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 / dsapplet.win / src / ds / actions / scaler.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  3.0 KB  |  88 lines

  1. /*
  2.  * quicktime.app: Sample Code for Initial Seeding
  3.  *
  4.  * © 1997 Copyright, Apple Computer
  5.  * All rights reserved
  6.  */
  7. package ds.actions;
  8.  
  9. import quicktime.app.actions.*;
  10. import quicktime.qd.*;
  11. import quicktime.*;
  12. import quicktime.std.image.Matrix;
  13. import quicktime.app.image.Transformable;
  14. import quicktime.app.display.Drawable;
  15.  
  16. import java.awt.Dimension;
  17. import java.awt.event.MouseEvent;
  18.  
  19. /**
  20.  * A class that provides the implementation of where a dragged object will be scaled according
  21.  * to the amount of pixels from the origin the user drags the mouse.
  22.  */
  23. public class Scaler extends Dragger {
  24. //____________________________ CLASS METHODS
  25.     /**
  26.      * Set some parameters that will create DragActions. 
  27.      * @param modifierKeyMask - if specified will determine which modifier keys must
  28.      * be depressed for the action to be invoked.
  29.      */
  30.     public Scaler (int scaleFactor, int modifierKeyMask) {
  31.         this (scaleFactor, modifierKeyMask, MouseResponder.kModifiersExactMatch, MouseResponder.kClickEvents);
  32.     }
  33.  
  34.     /**
  35.      * Set some parameters that will create DragActions. 
  36.      * @param modifierKeyMask - if specified will determine which modifier keys must
  37.      * be depressed for the action to be invoked.
  38.      * @param modifierTestConditions the test conditions under which the modifier mask is tested
  39.      */
  40.     public Scaler (int scaleFactor, int modifierKeyMask, int modifierTestConditions, int eventInvoker) {
  41.         super (modifierKeyMask, modifierTestConditions, eventInvoker);
  42.         this.scaleFactor = scaleFactor;
  43.     }    
  44.     
  45. //____________________________ INSTANCE VARIABLES
  46.     private int xOrigin, yOrigin;    
  47.     private int scaleFactor;
  48.  
  49. //____________________________ INSTANCE METHODS
  50.     /**
  51.      * This method is used by the DragController when the mouse is first pressed down on 
  52.      * the draggable object. If you wish to do anything to your draggable object before it
  53.      * is dragged then you should overide this method. The default implementation does nothing.
  54.      * @param event the mouse down event that may begin the drag action
  55.      * @param space The drawable object is the space within which the event has occured.
  56.      */
  57.     public void mousePressed (MouseEvent event) {
  58.         xOrigin = event.getX();
  59.         yOrigin = event.getY();
  60.     }
  61.  
  62.     /**
  63.      * This method is called by Dragger when an event is received that meets the conditions for 
  64.      * the object to be dragged.
  65.      * <P>
  66.      * This method will allow the user to alter the size of the object by dragging on it.
  67.      * @param event the mouse drag event that triggered the drag action.
  68.      * @param space The drawable object is the space within which the event has occured.
  69.      */
  70.     public void mouseDragged (MouseEvent event) {
  71.         try {
  72.             Matrix mat = target.getMatrix();
  73.  
  74.             float x = (event.getX() - xOrigin) / (float)scaleFactor;
  75.             float y = (event.getY() - yOrigin) / (float)scaleFactor;
  76.             xOrigin = event.getX();
  77.             yOrigin = event.getY();
  78.             
  79.             mat.setSx (mat.getSx() + x);
  80.             mat.setSy (mat.getSy() + y);
  81.             
  82.             target.setMatrix (mat);
  83.         } catch (QTException e) {
  84.             throw new QTRuntimeException (e);
  85.         }
  86.     }
  87. }
  88.