home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / MouseEvent.java < prev    next >
Text File  |  1998-09-22  |  5KB  |  189 lines

  1. /*
  2.  * @(#)MouseEvent.java    1.13 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.Component;
  18. import java.awt.Event;
  19. import java.awt.Point;
  20.  
  21. /**
  22.  * The mouse event.
  23.  *
  24.  * @version 1.13 07/01/98
  25.  * @author Carl Quinn
  26.  */
  27. public class MouseEvent extends InputEvent {
  28.  
  29.     /**
  30.      * Marks the first integer id for the range of mouse event ids.
  31.      */
  32.     public static final int MOUSE_FIRST     = 500;
  33.  
  34.     /**
  35.      * Marks the last integer id for the range of mouse event ids.
  36.      */
  37.     public static final int MOUSE_LAST          = 506;
  38.  
  39.     /**
  40.      * The mouse clicked event type.
  41.      */
  42.     public static final int MOUSE_CLICKED = MOUSE_FIRST;
  43.  
  44.     /**
  45.      * The mouse pressed event type.
  46.      */
  47.     public static final int MOUSE_PRESSED = 1 + MOUSE_FIRST; //Event.MOUSE_DOWN
  48.  
  49.     /**
  50.      * The mouse released event type.
  51.      */
  52.     public static final int MOUSE_RELEASED = 2 + MOUSE_FIRST; //Event.MOUSE_UP
  53.  
  54.     /**
  55.      * The mouse moved event type.
  56.      */
  57.     public static final int MOUSE_MOVED = 3 + MOUSE_FIRST; //Event.MOUSE_MOVE
  58.  
  59.     /**
  60.      * The mouse entered event type.
  61.      */
  62.     public static final int MOUSE_ENTERED = 4 + MOUSE_FIRST; //Event.MOUSE_ENTER
  63.  
  64.     /**
  65.      * The mouse exited event type.
  66.      */
  67.     public static final int MOUSE_EXITED = 5 + MOUSE_FIRST; //Event.MOUSE_EXIT
  68.  
  69.     /**
  70.      * The mouse dragged event type.
  71.      */
  72.     public static final int MOUSE_DRAGGED = 6 + MOUSE_FIRST; //Event.MOUSE_DRAG
  73.  
  74.     int x;
  75.     int y;
  76.     int clickCount;
  77.     boolean popupTrigger = false;
  78.  
  79.     /*
  80.      * JDK 1.1 serialVersionUID 
  81.      */
  82.     private static final long serialVersionUID = -991214153494842848L;
  83.  
  84.     /**
  85.      * Constructs a MouseEvent object with the specified source component,
  86.      * type, modifiers, coordinates, and click count.
  87.      * @param source the object where the event originated
  88.      * @id the event type
  89.      * @when the time the event occurred
  90.      * @modifiers the modifiers down during event
  91.      * @x the x coordinate location of the mouse
  92.      * @y the y coordinate location of the mouse
  93.      * @clickCount the number of mouse clicks associated with event
  94.      * @popupTrigger whether this event is a popup-menu trigger event
  95.      */
  96.     public MouseEvent(Component source, int id, long when, int modifiers,
  97.                       int x, int y, int clickCount, boolean popupTrigger) {
  98.         super(source, id, when, modifiers);
  99.         this.x = x;
  100.         this.y = y;
  101.         this.clickCount = clickCount;
  102.         this.popupTrigger = popupTrigger;
  103.     }
  104.  
  105.     /**
  106.      * Returns the x position of the event relative to the source component.
  107.      */
  108.     public int getX() {
  109.         return x;
  110.     }
  111.  
  112.     /**
  113.      * Returns the y position of the event relative to the source component.
  114.      */
  115.     public int getY() {
  116.         return y;
  117.     }
  118.  
  119.     /**
  120.      * Returns the x,y position of the event relative to the source component.
  121.      */
  122.     public Point getPoint() {
  123.     int x;
  124.     int y;
  125.     synchronized (this) {
  126.         x = this.x;
  127.         y = this.y;
  128.     }
  129.         return new Point(x, y);
  130.     }
  131.  
  132.     /**
  133.      * Translates the coordinate position of the event by x, y.
  134.      * @param x the x value added to the current x coordinate position
  135.      * @param y the y value added to the current y coordinate position
  136.      */
  137.     public synchronized void translatePoint(int x, int y) {
  138.         this.x += x;
  139.         this.y += y;
  140.     }
  141.  
  142.     /**
  143.      * Return the number of mouse clicks associated with this event.
  144.      */
  145.     public int getClickCount() {
  146.         return clickCount;
  147.     }
  148.  
  149.     /**
  150.      * Returns whether or not this mouse event is the popup-menu
  151.      * trigger event for the platform.
  152.      */
  153.     public boolean isPopupTrigger() {
  154.         return popupTrigger;
  155.     }
  156.  
  157.     public String paramString() {
  158.         String typeStr;
  159.         switch(id) {
  160.           case MOUSE_PRESSED:
  161.               typeStr = "MOUSE_PRESSED";
  162.               break;
  163.           case MOUSE_RELEASED:
  164.               typeStr = "MOUSE_RELEASED";
  165.               break;
  166.           case MOUSE_CLICKED:
  167.               typeStr = "MOUSE_CLICKED";
  168.               break;
  169.           case MOUSE_ENTERED:
  170.               typeStr = "MOUSE_ENTERED";
  171.               break;
  172.           case MOUSE_EXITED:
  173.               typeStr = "MOUSE_EXITED";
  174.               break;
  175.           case MOUSE_MOVED:
  176.               typeStr = "MOUSE_MOVED";
  177.               break;
  178.           case MOUSE_DRAGGED:
  179.               typeStr = "MOUSE_DRAGGED";
  180.               break;
  181.           default:
  182.               typeStr = "unknown type";
  183.         }
  184.         return typeStr + ",("+x+","+y+")"+ ",mods="+getModifiers()+ 
  185.                ",clickCount="+clickCount;
  186.     }
  187.  
  188. }
  189.