home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Internet / Javadraw / DATA.Z / InputEvent.java < prev    next >
Text File  |  1997-08-30  |  4KB  |  156 lines

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