home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / MouseEvent.java < prev    next >
Text File  |  1997-05-20  |  6KB  |  197 lines

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