home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / MouseEvent.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  4.8 KB  |  171 lines  |  [TEXT/CWIE]

  1. // MouseEvent.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9.  
  10. /** Event subclass used for all mouse events.
  11.   */
  12.  
  13. public class MouseEvent extends netscape.application.Event {
  14.     /** The MouseEvent's X-coordinate, relative to the origin of the View in
  15.       * which the event occurred.
  16.       */
  17.     public int                  x;
  18.  
  19.     /** The MouseEvent's Y-coordinate, relative to the origin of the View in
  20.       * which the event occurred.
  21.       */
  22.     public int                  y;
  23.  
  24.     int                  clickCount, modifiers;
  25.  
  26.     /** Mouse "down" event. */
  27.     public final static int     MOUSE_DOWN = -1;
  28.     /** Mouse "dragged" event. */
  29.     public final static int     MOUSE_DRAGGED = -2;
  30.     /** Mouse "up" event. */
  31.     public final static int     MOUSE_UP = -3;
  32.     /** Mouse "entered" event. */
  33.     public final static int     MOUSE_ENTERED = -4;
  34.     /** Mouse "moved" event. */
  35.     public final static int     MOUSE_MOVED = -5;
  36.     /** Mouse "exited" event. */
  37.     public final static int     MOUSE_EXITED = -6;
  38.  
  39.  
  40.     /** Constructs a MouseEvent.
  41.       */
  42.     public MouseEvent() {
  43.         super();
  44.     }
  45.  
  46.     /** Constructs a MouseEvent of type <b>type</b>, with coordinates
  47.       * (<b>x</b>, <b>y</b>), and the modifier bitmask <b>modifiers</b>,
  48.       * representing the modifier keys the user held down during the
  49.       * mouse event, such as the Shift key.
  50.       */
  51.     public MouseEvent(long timeStamp, int type, int x, int y, int modifiers) {
  52.         this();
  53.  
  54.         this.timeStamp = timeStamp;
  55.  
  56.         if (type < MOUSE_EXITED || type > MOUSE_DOWN) {
  57.             throw new IllegalArgumentException("Invalid MouseEvent type: " +
  58.                                                type);
  59.         }
  60.  
  61.         this.type = type;
  62.         this.x = x;
  63.         this.y = y;
  64.         this.modifiers = modifiers;
  65.     }
  66.  
  67.     /** Sets the MouseEvent's "click" count.  An event type of type MOUSE_DOWN
  68.       * and click count of 2 represents a double-click, for example.
  69.       */
  70.     public void setClickCount(int count) {
  71.         clickCount = count;
  72.     }
  73.  
  74.     /** Returns the MouseEvent's click count.
  75.       * @see #setClickCount
  76.       */
  77.     public int clickCount() {
  78.         return clickCount;
  79.     }
  80.  
  81.     /** Sets the MouseEvent's modifiers, the bitmask describing the keys the
  82.       * user held down when the mouse event occurred. The keyboard modifiers
  83.       * are described in KeyEvent.
  84.       * @see KeyEvent
  85.       */
  86.     public void setModifiers(int modifiers) {
  87.         this.modifiers = modifiers;
  88.     }
  89.  
  90.     /** Returns the MouseEvent's modifier bitmask.
  91.       * @see #setModifiers
  92.       */
  93.     public int modifiers() {
  94.         return modifiers;
  95.     }
  96.  
  97.     /** Returns <b>true</b> if the user held down the Shift key during the
  98.       * mouse event.
  99.       */
  100.     public boolean isShiftKeyDown() {
  101.         return (modifiers & KeyEvent.SHIFT_MASK) != 0;
  102.     }
  103.  
  104.     /** Returns <b>true</b> if the user held down the Control key during the
  105.       * mouse event.
  106.       */
  107.     public boolean isControlKeyDown() {
  108.         return (modifiers & KeyEvent.CONTROL_MASK) != 0;
  109.     }
  110.  
  111.     /** Returns <b>true</b> if the user held down the Meta key during the
  112.       * mouse event.
  113.       */
  114.     public boolean isMetaKeyDown() {
  115.         return (modifiers & KeyEvent.META_MASK) != 0;
  116.     }
  117.  
  118.     /** Returns <b>true</b> if the user held down the Alternate key during the
  119.       * mouse event.
  120.       */
  121.     public boolean isAltKeyDown() {
  122.         return (modifiers & KeyEvent.ALT_MASK) != 0;
  123.     }
  124.  
  125.     /** Sets the RootView in which  the MouseEvent occurred. */
  126.     public void setRootView(RootView rootView) {
  127.         processor = rootView;
  128.     }
  129.  
  130.     /** Returns the RootView in which the MouseEvent occurred.
  131.       * @see #setRootView
  132.       */
  133.     public RootView rootView() {
  134.         return (RootView)processor;
  135.     }
  136.  
  137.     /** Returns the MouseEvent's String representation. */
  138.     public String toString() {
  139.         String typeString;
  140.  
  141.         switch (type) {
  142.             case MOUSE_DOWN:
  143.                 typeString = "Down";
  144.                 break;
  145.             case MOUSE_DRAGGED:
  146.                 typeString = "Dragged";
  147.                 break;
  148.             case MOUSE_UP:
  149.                 typeString = "Up";
  150.                 break;
  151.             case MOUSE_ENTERED:
  152.                 typeString = "Entered";
  153.                 break;
  154.             case MOUSE_MOVED:
  155.                 typeString = "Moved";
  156.                 break;
  157.             case MOUSE_EXITED:
  158.                 typeString = "Exited";
  159.                 break;
  160.             default:
  161.                 typeString = "Unknown Type";
  162.                 break;
  163.         }
  164.  
  165.         return "MouseEvent: " + typeString +
  166.                       " at: (" + x + "," + y + ")" +
  167.                " modifiers: " + modifiers +
  168.                   " clicks: " + clickCount;
  169.     }
  170. }
  171.