home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / event / InputEvent.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  3.8 KB  |  154 lines

  1. /*
  2.  * @(#)InputEvent.java    1.14 98/03/18
  3.  *
  4.  * Copyright 1996, 1997 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.Event;
  18. import java.awt.Component;
  19.  
  20. /**
  21.  * The root event class for all component-level input events.
  22.  *
  23.  * Input events are delivered to listeners before they are
  24.  * processed normally by the source where they originated.
  25.  * This allows listeners and component subclasses to "consume"
  26.  * the event so that the source will not process them in their
  27.  * default manner.  For example, consuming mousePressed events
  28.  * on a Button component will prevent the Button from being
  29.  * activated.
  30.  *
  31.  * @see KeyEvent
  32.  * @see KeyAdapter
  33.  * @see MouseEvent
  34.  * @see MouseAdapter
  35.  * @see MouseMotionAdapter
  36.  *
  37.  * @version 1.14 03/18/98
  38.  * @author Carl Quinn
  39.  */
  40. public abstract class InputEvent extends ComponentEvent {
  41.  
  42.     /**
  43.      * The shift key modifier constant.
  44.      */
  45.     public static final int SHIFT_MASK = Event.SHIFT_MASK;
  46.  
  47.     /**
  48.      * The control key modifier constant.
  49.      */
  50.     public static final int CTRL_MASK = Event.CTRL_MASK;
  51.  
  52.     /** 
  53.      * The meta key modifier constant.
  54.      */
  55.     public static final int META_MASK = Event.META_MASK;
  56.  
  57.     /** 
  58.      * The alt key modifier constant.
  59.      */
  60.     public static final int ALT_MASK = Event.ALT_MASK;
  61.  
  62.     /**
  63.      * The mouse button1 modifier constant.
  64.      */
  65.     public static final int BUTTON1_MASK = 1 << 4;
  66.  
  67.     /**
  68.      * The mouse button2 modifier constant.
  69.      */
  70.     public static final int BUTTON2_MASK = Event.ALT_MASK;
  71.  
  72.     /** 
  73.      * The mouse button3 modifier constant.
  74.      */
  75.     public static final int BUTTON3_MASK = Event.META_MASK;
  76.  
  77.     long when;
  78.     int modifiers;
  79.  
  80.     /**
  81.      * Constructs an InputEvent object with the specified source component,
  82.      * modifiers, and type.
  83.      * @param source the object where the event originated
  84.      * @id the event type
  85.      * @when the time the event occurred
  86.      * @modifiers the modifier keys down while event occurred
  87.      */
  88.     InputEvent(Component source, int id, long when, int modifiers) {
  89.         super(source, id);
  90.         this.when = when;
  91.         this.modifiers = modifiers;
  92.     }
  93.  
  94.     /**
  95.      * Returns whether or not the Shift modifier is down on this event.
  96.      */
  97.     public boolean isShiftDown() {
  98.         return (modifiers & Event.SHIFT_MASK) != 0;
  99.     }
  100.  
  101.     /**
  102.      * Returns whether or not the Control modifier is down on this event.
  103.      */
  104.     public boolean isControlDown() {
  105.         return (modifiers & Event.CTRL_MASK) != 0;
  106.     }
  107.  
  108.     /**
  109.      * Returns whether or not the Meta modifier is down on this event.
  110.      */ 
  111.     public boolean isMetaDown() {
  112.         return (modifiers & Event.META_MASK) != 0;
  113.     }
  114.  
  115.     /**
  116.      * Returns whether or not the Alt modifier is down on this event.
  117.      */ 
  118.     public boolean isAltDown() {
  119.         return (modifiers & Event.ALT_MASK) != 0;
  120.     }
  121.  
  122.  
  123.     /**
  124.      * Returns the timestamp of when this event occurred.
  125.      */
  126.     public long getWhen() {
  127.         return when;
  128.     }
  129.  
  130.     /**
  131.      * Returns the modifiers flag for this event.
  132.      */
  133.     public int getModifiers() {
  134.         return modifiers;
  135.     }
  136.  
  137.     /**
  138.      * Consumes this event so that it will not be processed
  139.      * in the default manner by the source which originated it.
  140.      */
  141.     public void consume() {
  142.         consumed = true;
  143.     }
  144.  
  145.     /**
  146.      * Returns whether or not this event has been consumed.
  147.      * @see #consume
  148.      */
  149.     public boolean isConsumed() {
  150.         return consumed;
  151.     }
  152.  
  153. }
  154.