home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Event.java < prev    next >
Text File  |  1997-10-01  |  25KB  |  843 lines

  1. /*
  2.  * @(#)Event.java    1.57 97/08/04
  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. package java.awt;
  23.  
  24. import java.awt.event.*;
  25. import java.io.*;
  26.  
  27. /**
  28.  * <code>Event</code> is a platform-independent class that  
  29.  * encapsulates events from the platform's Graphical User 
  30.  * Interface in the Java 1.0 event model. In Java 1.1 
  31.  * and later versions, the <code>Event</code> class is maintained 
  32.  * only for backwards compatibilty. The information in this
  33.  * class description is provided to assist programmers in
  34.  * converting Java 1.0 programs to the new event model.
  35.  * <p>
  36.  * In the Java 1.0 event model, an event contains an 
  37.  * <a href="#id"><code>id</code></a> field 
  38.  * that indicates what type of event it is and which other 
  39.  * <code>Event</code> variables are relevant for the event.
  40.  * <p>
  41.  * For keyboard events, <a href="#key"><code>key</code></a> 
  42.  * contains a value indicating which key was activated, and 
  43.  * <a href="#modifiers"><code>modifiers</code></a> contains the 
  44.  * modifiers for that event.  For the KEY_PRESS and KEY_RELEASE  
  45.  * event ids, the value of <code>key</code> is the unicode 
  46.  * character code for the key. For KEY_ACTION and 
  47.  * KEY_ACTION_RELEASE, the value of <code>key</code> is
  48.  * one of the defined action-key identifiers in the 
  49.  * <code>Event</code> class (<code>PGUP</code>,  
  50.  * <code>PGDN</code>, <code>F1</code>, <code>F2</code>, etc).
  51.  *
  52.  * @version 1.57 08/04/97
  53.  * @author     Sami Shaio
  54.  * @since      JDK1.0
  55.  */
  56. public class Event implements java.io.Serializable {
  57.     private transient int data;
  58.  
  59.     /* Modifier constants */
  60.  
  61.     /**
  62.      * This flag indicates that the Shift key was down when the event 
  63.      * occurred. 
  64.      * @since   JDK1.0
  65.      */
  66.     public static final int SHIFT_MASK        = 1 << 0;
  67.  
  68.     /**
  69.      * This flag indicates that the Control key was down when the event 
  70.      * occurred. 
  71.      * @since   JDK1.0
  72.      */
  73.     public static final int CTRL_MASK        = 1 << 1;
  74.  
  75.     /** 
  76.      * This flag indicates that the Meta key was down when the event 
  77.      * occurred. For mouse events, this flag indicates that the right 
  78.      * button was pressed or released. 
  79.      * @since    JDK1.0
  80.      */
  81.     public static final int META_MASK        = 1 << 2;
  82.  
  83.     /** 
  84.      * This flag indicates that the Alt key was down when 
  85.      * the event occurred. For mouse events, this flag indicates that the 
  86.      * middle mouse button was pressed or released. 
  87.      * @since   JDK1.0
  88.      */
  89.     public static final int ALT_MASK        = 1 << 3;
  90.  
  91.     /* Action keys */
  92.     
  93.     /** 
  94.      * The Home key, a non-ASCII action key. 
  95.      * @since   JDK1.0
  96.      */
  97.     public static final int HOME        = 1000;
  98.  
  99.     /** 
  100.      * The End key, a non-ASCII action key. 
  101.      * @since   JDK1.0
  102.      */
  103.     public static final int END            = 1001;
  104.  
  105.     /**
  106.      * The Page Up key, a non-ASCII action key. 
  107.      * @since   JDK1.0
  108.      */
  109.     public static final int PGUP        = 1002;
  110.  
  111.     /**
  112.      * The Page Down key, a non-ASCII action key. 
  113.      * @since   JDK1.0
  114.      */
  115.     public static final int PGDN        = 1003;
  116.  
  117.     /**
  118.      * The Up Arrow key, a non-ASCII action key. 
  119.      * @since   JDK1.0
  120.      */
  121.     public static final int UP            = 1004;
  122.  
  123.     /**
  124.      * The Down Arrow key, a non-ASCII action key. 
  125.      * @since   JDK1.0
  126.      */
  127.     public static final int DOWN        = 1005;
  128.  
  129.     /**
  130.      * The Left Arrow key, a non-ASCII action key. 
  131.      * @since   JDK1.0
  132.      */
  133.     public static final int LEFT        = 1006;
  134.  
  135.     /**
  136.      * The Right Arrow key, a non-ASCII action key. 
  137.      * @since   JDK1.0
  138.      */
  139.     public static final int RIGHT        = 1007;
  140.  
  141.     /**
  142.      * The F1 function key, a non-ASCII action key.
  143.      * @since   JDK1.0
  144.      */
  145.     public static final int F1            = 1008;
  146.  
  147.     /**
  148.      * The F2 function key, a non-ASCII action key.
  149.      * @since   JDK1.0
  150.      */
  151.     public static final int F2            = 1009;
  152.  
  153.     /**
  154.      * The F3 function key, a non-ASCII action key.
  155.      * @since   JDK1.0
  156.      */
  157.     public static final int F3            = 1010;
  158.  
  159.     /**
  160.      * The F4 function key, a non-ASCII action key.
  161.      * @since   JDK1.0
  162.      */
  163.     public static final int F4            = 1011;
  164.  
  165.     /**
  166.      * The F5 function key, a non-ASCII action key.
  167.      * @since   JDK1.0
  168.      */
  169.     public static final int F5            = 1012;
  170.  
  171.     /**
  172.      * The F6 function key, a non-ASCII action key.
  173.      * @since   JDK1.0
  174.      */
  175.     public static final int F6            = 1013;
  176.  
  177.     /**
  178.      * The F7 function key, a non-ASCII action key.
  179.      * @since   JDK1.0
  180.      */
  181.     public static final int F7            = 1014;
  182.  
  183.     /**
  184.      * The F8 function key, a non-ASCII action key.
  185.      * @since   JDK1.0
  186.      */
  187.     public static final int F8            = 1015;
  188.  
  189.     /**
  190.      * The F9 function key, a non-ASCII action key.
  191.      * @since   JDK1.0
  192.      */
  193.     public static final int F9            = 1016;
  194.  
  195.     /**
  196.      * The F10 function key, a non-ASCII action key.
  197.      * @since   JDK1.0
  198.      */
  199.     public static final int F10            = 1017;
  200.  
  201.     /**
  202.      * The F11 function key, a non-ASCII action key.
  203.      * @since   JDK1.0
  204.      */
  205.     public static final int F11            = 1018;
  206.  
  207.     /**
  208.      * The F12 function key, a non-ASCII action key.
  209.      * @since   JDK1.0
  210.      */
  211.     public static final int F12            = 1019;
  212.  
  213.     /**
  214.      * The Print Screen key, a non-ASCII action key.
  215.      * @since   JDK1.0
  216.      */
  217.     public static final int PRINT_SCREEN    = 1020;
  218.  
  219.     /**
  220.      * The Scroll Lock key, a non-ASCII action key.
  221.      * @since   JDK1.0
  222.      */
  223.     public static final int SCROLL_LOCK        = 1021;
  224.  
  225.     /**
  226.      * The Caps Lock key, a non-ASCII action key.
  227.      * @since   JDK1.0
  228.      */
  229.     public static final int CAPS_LOCK        = 1022;
  230.  
  231.     /**
  232.      * The Num Lock key, a non-ASCII action key.
  233.      * @since   JDK1.0
  234.      */
  235.     public static final int NUM_LOCK        = 1023;
  236.  
  237.     /**
  238.      * The Pause key, a non-ASCII action key.
  239.      * @since   JDK1.0
  240.      */
  241.     public static final int PAUSE        = 1024;
  242.  
  243.     /**
  244.      * The Insert key, a non-ASCII action key.
  245.      * @since   JDK1.0
  246.      */
  247.     public static final int INSERT        = 1025;
  248.  
  249.     /* Non-action keys */
  250.     
  251.     /**
  252.      * The Enter key.
  253.      * @since   JDK1.0
  254.      */
  255.     public static final int ENTER        = '\n';
  256.  
  257.     /**
  258.      * The BackSpace key.
  259.      * @since   JDK1.0
  260.      */
  261.     public static final int BACK_SPACE        = '\b';
  262.  
  263.     /**
  264.      * The Tab key.
  265.      * @since   JDK1.0
  266.      */
  267.     public static final int TAB            = '\t';
  268.  
  269.     /**
  270.      * The Escape key.
  271.      * @since   JDK1.0
  272.      */
  273.     public static final int ESCAPE        = 27;
  274.  
  275.     /**
  276.      * The Delete key.
  277.      * @since   JDK1.0
  278.      */
  279.     public static final int DELETE        = 127;
  280.  
  281.  
  282.     /* Base for all window events. */
  283.     private static final int WINDOW_EVENT     = 200;
  284.  
  285.     /**
  286.      * The user has asked the window manager to kill the window.
  287.      * @since    JDK1.0
  288.      */
  289.     public static final int WINDOW_DESTROY     = 1 + WINDOW_EVENT;
  290.  
  291.     /**
  292.      * The user has asked the window manager to expose the window.
  293.      * @since    JDK1.0
  294.      */
  295.     public static final int WINDOW_EXPOSE     = 2 + WINDOW_EVENT;
  296.  
  297.     /** 
  298.      * The user has asked the window manager to iconify the window.
  299.      * @since    JDK1.0
  300.      */
  301.     public static final int WINDOW_ICONIFY    = 3 + WINDOW_EVENT;
  302.  
  303.     /** 
  304.      * The user has asked the window manager to de-iconify the window.
  305.      * @since    JDK1.0
  306.      */
  307.     public static final int WINDOW_DEICONIFY    = 4 + WINDOW_EVENT;
  308.  
  309.     /**
  310.      * The user has asked the window manager to move the window.
  311.      * @since    JDK1.0
  312.      */
  313.     public static final int WINDOW_MOVED    = 5 + WINDOW_EVENT;
  314.  
  315.     /* Base for all keyboard events. */
  316.     private static final int KEY_EVENT         = 400;
  317.  
  318.     /**
  319.      * The user has pressed a normal key.  
  320.      * @since   JDK1.0
  321.      */
  322.     public static final int KEY_PRESS         = 1 + KEY_EVENT;
  323.  
  324.     /**
  325.      * The user has released a normal key.  
  326.      * @since   JDK1.0
  327.      */
  328.     public static final int KEY_RELEASE     = 2 + KEY_EVENT;
  329.  
  330.     /** 
  331.      * The user has pressed a non-ASCII <em>action</em> key.  
  332.      * The <code>key</code> field contains a value that indicates
  333.      * that the event occurred on one of the action keys, which
  334.      * comprise the 12 function keys, the arrow (cursor) keys,
  335.      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
  336.      * Caps Lock, Num Lock, Pause, and Insert.
  337.      * @since   JDK1.0
  338.      */
  339.     public static final int KEY_ACTION         = 3 + KEY_EVENT;
  340.  
  341.     /** 
  342.      * The user has released a non-ASCII <em>action</em> key.  
  343.      * The <code>key</code> field contains a value that indicates
  344.      * that the event occurred on one of the action keys, which
  345.      * comprise the 12 function keys, the arrow (cursor) keys,
  346.      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
  347.      * Caps Lock, Num Lock, Pause, and Insert.
  348.      * @since   JDK1.0
  349.      */
  350.     public static final int KEY_ACTION_RELEASE    = 4 + KEY_EVENT;
  351.  
  352.     /* Base for all mouse events. */
  353.     private static final int MOUSE_EVENT     = 500;
  354.  
  355.     /**
  356.      * The user has pressed the mouse button. The <code>ALT_MASK</code> 
  357.      * flag indicates that the middle button has been pressed. 
  358.      * The <code>META_MASK</code>flag indicates that the 
  359.      * right button has been pressed. 
  360.      * @see     java.awt.Event#ALT_MASK
  361.      * @see     java.awt.Event#META_MASK
  362.      * @since   JDK1.0
  363.      */
  364.     public static final int MOUSE_DOWN         = 1 + MOUSE_EVENT;
  365.  
  366.     /**
  367.      * The user has released the mouse button. The <code>ALT_MASK</code> 
  368.      * flag indicates that the middle button has been released. 
  369.      * The <code>META_MASK</code>flag indicates that the 
  370.      * right button has been released. 
  371.      * @see     java.awt.Event#ALT_MASK
  372.      * @see     java.awt.Event#META_MASK
  373.      * @since   JDK1.0
  374.      */
  375.     public static final int MOUSE_UP         = 2 + MOUSE_EVENT;
  376.  
  377.     /**
  378.      * The mouse has moved with no button pressed. 
  379.      * @since   JDK1.0
  380.      */
  381.     public static final int MOUSE_MOVE         = 3 + MOUSE_EVENT;
  382.  
  383.     /**
  384.      * The mouse has entered a component. 
  385.      * @since   JDK1.0
  386.      */
  387.     public static final int MOUSE_ENTER     = 4 + MOUSE_EVENT;
  388.  
  389.     /**
  390.      * The mouse has exited a component. 
  391.      * @since   JDK1.0
  392.      */
  393.     public static final int MOUSE_EXIT         = 5 + MOUSE_EVENT;
  394.  
  395.     /** 
  396.      * The user has moved the mouse with a button pressed. The 
  397.      * <code>ALT_MASK</code> flag indicates that the middle 
  398.      * button is being pressed. The <code>META_MASK</code> flag indicates 
  399.      * that the right button is being pressed. 
  400.      * @see     java.awt.Event#ALT_MASK
  401.      * @see     java.awt.Event#META_MASK
  402.      * @since   JDK1.0
  403.      */
  404.     public static final int MOUSE_DRAG         = 6 + MOUSE_EVENT;
  405.  
  406.  
  407.     /* Scrolling events */
  408.     private static final int SCROLL_EVENT     = 600;
  409.  
  410.     /** 
  411.      * The user has activated the <em>line up</em>  
  412.      * area of a scroll bar. 
  413.      * @since   JDK1.0
  414.      */
  415.     public static final int SCROLL_LINE_UP    = 1 + SCROLL_EVENT;
  416.  
  417.     /**
  418.      * The user has activated the <em>line down</em>  
  419.      * area of a scroll bar. 
  420.      * @since   JDK1.0
  421.      */
  422.     public static final int SCROLL_LINE_DOWN    = 2 + SCROLL_EVENT;
  423.  
  424.     /**
  425.      * The user has activated the <em>page up</em>  
  426.      * area of a scroll bar. 
  427.      * @since   JDK1.0
  428.      */
  429.     public static final int SCROLL_PAGE_UP    = 3 + SCROLL_EVENT;
  430.  
  431.     /**
  432.      * The user has activated the <em>page down</em>  
  433.      * area of a scroll bar. 
  434.      * @since   JDK1.0
  435.      */
  436.     public static final int SCROLL_PAGE_DOWN    = 4 + SCROLL_EVENT;
  437.  
  438.     /**
  439.      * The user has moved the bubble (thumb) in a scroll bar,
  440.      * moving to an "absolute" position, rather than to
  441.      * an offset from the last postion.
  442.      * @since   JDK1.0
  443.      */
  444.     public static final int SCROLL_ABSOLUTE    = 5 + SCROLL_EVENT;
  445.  
  446.     /**
  447.      * The scroll begin event.
  448.      * @since   JDK1.0
  449.      */
  450.     public static final int SCROLL_BEGIN    = 6 + SCROLL_EVENT;
  451.  
  452.     /**
  453.      * The scroll end event.
  454.      * @since   JDK1.0
  455.      */
  456.     public static final int SCROLL_END            = 7 + SCROLL_EVENT;
  457.     
  458.     /* List Events */
  459.     private static final int LIST_EVENT        = 700;
  460.  
  461.     /**
  462.      * An item in a list has been selected. 
  463.      * @since   JDK1.0
  464.      */
  465.     public static final int LIST_SELECT        = 1 + LIST_EVENT;
  466.  
  467.     /**
  468.      * An item in a list has been deselected. 
  469.      * @since   JDK1.0
  470.      */
  471.     public static final int LIST_DESELECT    = 2 + LIST_EVENT;
  472.  
  473.     /* Misc Event */
  474.     private static final int MISC_EVENT        = 1000;
  475.  
  476.     /**
  477.      * This event indicates that the user wants some action to occur. 
  478.      * @since   JDK1.0
  479.      */
  480.     public static final int ACTION_EVENT    = 1 + MISC_EVENT;
  481.  
  482.     /**
  483.      * A file loading event.
  484.      * @since   JDK1.0
  485.      */
  486.     public static final int LOAD_FILE        = 2 + MISC_EVENT;
  487.  
  488.     /**
  489.      * A file saving event.
  490.      * @since   JDK1.0
  491.      */
  492.     public static final int SAVE_FILE        = 3 + MISC_EVENT;
  493.  
  494.     /**
  495.      * A component gained the focus.
  496.      * @since   JDK1.0
  497.      */
  498.     public static final int GOT_FOCUS        = 4 + MISC_EVENT;
  499.  
  500.     /**
  501.      * A component lost the focus.
  502.      * @since   JDK1.0
  503.      */
  504.     public static final int LOST_FOCUS        = 5 + MISC_EVENT;
  505.     
  506.     /**
  507.      * The target component. This indicates the component over which the 
  508.      * event occurred or with which the event is associated. 
  509.      * @since   JDK1.0
  510.      */
  511.     public Object target;
  512.  
  513.     /**
  514.      * The time stamp.
  515.      * @since   JDK1.0
  516.      */
  517.     public long when;
  518.  
  519.     /**
  520.      * Indicates which type of event the event is, and which 
  521.      * other <code>Event</code> variables are relevant for the event.
  522.      * @since   JDK1.0
  523.      */
  524.     public int id;
  525.  
  526.     /** 
  527.      * The <i>x</i> coordinate of the event. 
  528.      * @since   JDK1.0
  529.      */
  530.     public int x;
  531.  
  532.     /** 
  533.      * The <i>y</i> coordinate of the event. 
  534.      * @since   JDK1.0
  535.      */
  536.     public int y;
  537.  
  538.     /** 
  539.      * The key code of the key that was pressed in a keyboard event. 
  540.      * @since   JDK1.0
  541.      */
  542.     public int key;
  543.  
  544.     /** 
  545.      * The key character that was pressed in a keyboard event. 
  546.      * @since   JDK1.0
  547.      */
  548. //    public char keyChar;
  549.  
  550.     /** 
  551.      * The state of the modifier keys.
  552.      * <p>
  553.      * NOTE:  changing the modifier keys is not recommended, because many
  554.      * native implementations do not recognize modifier changes.  This is
  555.      * especially true when the shift modifier is changed.
  556.      *
  557.      * @since     JDK1.0
  558.      */
  559.     public int modifiers;
  560.  
  561.     /**
  562.      * For <code>MOUSE_DOWN</code> events, this field indicates the 
  563.      * number of consecutive clicks. For other events, its value is 
  564.      * <code>0</code>. 
  565.      * @since   JDK1.0
  566.      */
  567.     public int clickCount;
  568.  
  569.     /**
  570.      * An arbitrary argument of the event. The value of this field 
  571.      * depends on the type of event. 
  572.      * @since   JDK1.0
  573.      */
  574.     public Object arg;
  575.  
  576.     /**
  577.      * The next event. This field is set when putting events into a 
  578.      * linked list. 
  579.      * @since   JDK1.0
  580.      */
  581.     public Event evt;
  582.  
  583.     /* table for mapping old Event action keys to KeyEvent virtual keys. */
  584.     private static final int actionKeyCodes[][] = {
  585.     /*    virtual key              action key   */
  586.         { KeyEvent.VK_HOME,        Event.HOME         },
  587.         { KeyEvent.VK_END,         Event.END          },
  588.         { KeyEvent.VK_PAGE_UP,     Event.PGUP         },
  589.         { KeyEvent.VK_PAGE_DOWN,   Event.PGDN         },
  590.         { KeyEvent.VK_UP,          Event.UP           },
  591.         { KeyEvent.VK_DOWN,        Event.DOWN         },
  592.         { KeyEvent.VK_LEFT,        Event.LEFT         },
  593.         { KeyEvent.VK_RIGHT,       Event.RIGHT        },
  594.         { KeyEvent.VK_F1,          Event.F1           },
  595.         { KeyEvent.VK_F2,          Event.F2           },
  596.         { KeyEvent.VK_F3,          Event.F3           },
  597.         { KeyEvent.VK_F4,          Event.F4           },
  598.         { KeyEvent.VK_F5,          Event.F5           },
  599.         { KeyEvent.VK_F6,          Event.F6           },
  600.         { KeyEvent.VK_F7,          Event.F7           },
  601.         { KeyEvent.VK_F8,          Event.F8           },
  602.         { KeyEvent.VK_F9,          Event.F9           },
  603.         { KeyEvent.VK_F10,         Event.F10          },
  604.         { KeyEvent.VK_F11,         Event.F11          },
  605.         { KeyEvent.VK_F12,         Event.F12          },
  606.         { KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN },
  607.         { KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK  },
  608.         { KeyEvent.VK_CAPS_LOCK,   Event.CAPS_LOCK    },
  609.         { KeyEvent.VK_NUM_LOCK,    Event.NUM_LOCK     },
  610.         { KeyEvent.VK_PAUSE,       Event.PAUSE        },
  611.         { KeyEvent.VK_INSERT,      Event.INSERT       }
  612.     };
  613.  
  614.     // This field controls whether or not the event is sent back
  615.     // down to the peer once the target has processed it -
  616.     // false means it's sent to the peer, true means it's not.
  617.     private boolean consumed = false;
  618.  
  619.     /*
  620.      * JDK 1.1 serialVersionUID 
  621.      */
  622.     private static final long serialVersionUID = 5488922509400504703L;
  623.  
  624.     /**
  625.      * Creates an instance of <code>Event</code> with the specified target 
  626.      * component, time stamp, event type, <i>x</i> and <i>y</i> 
  627.      * coordinates, keyboard key, state of the modifier keys, and 
  628.      * argument. 
  629.      * @param     target     the target component.
  630.      * @param     when       the time stamp.
  631.      * @param     id         the event type.
  632.      * @param     x          the <i>x</i> coordinate.
  633.      * @param     y          the <i>y</i> coordinate.
  634.      * @param     key        the key pressed in a keyboard event.
  635.      * @param     modifiers  the state of the modifier keys.
  636.      * @param     arg        the specified argument.
  637.      * @since     JDK1.0
  638.      */
  639.     public Event(Object target, long when, int id, int x, int y, int key,
  640.          int modifiers, Object arg) {
  641.     this.target = target;
  642.     this.when = when;
  643.     this.id = id;
  644.     this.x = x;
  645.     this.y = y;
  646.     this.key = key;
  647.     this.modifiers = modifiers;
  648.     this.arg = arg;
  649.     this.data = 0;
  650.     this.clickCount = 0;
  651.         switch(id) {
  652.           case ACTION_EVENT:
  653.           case WINDOW_DESTROY:
  654.           case WINDOW_ICONIFY:
  655.           case WINDOW_DEICONIFY:
  656.           case WINDOW_MOVED:
  657.           case SCROLL_LINE_UP:
  658.           case SCROLL_LINE_DOWN:
  659.           case SCROLL_PAGE_UP:
  660.           case SCROLL_PAGE_DOWN:
  661.           case SCROLL_ABSOLUTE:
  662.           case SCROLL_BEGIN:
  663.           case SCROLL_END:
  664.           case LIST_SELECT:
  665.           case LIST_DESELECT:
  666.             consumed = true; // these types are not passed back to peer
  667.             break;
  668.           default:
  669.         }
  670.     }
  671.  
  672.     /**
  673.      * Creates an instance of <code>Event</code>, with the specified target 
  674.      * component, time stamp, event type, <i>x</i> and <i>y</i> 
  675.      * coordinates, keyboard key, state of the modifier keys, and an 
  676.      * argument set to <code>null</code>. 
  677.      * @param     target     the target component.
  678.      * @param     when       the time stamp.
  679.      * @param     id         the event type.
  680.      * @param     x          the <i>x</i> coordinate.
  681.      * @param     y          the <i>y</i> coordinate.
  682.      * @param     key        the key pressed in a keyboard event.
  683.      * @param     modifiers  the state of the modifier keys.
  684.      * @since    JDK1.0
  685.      */
  686.     public Event(Object target, long when, int id, int x, int y, int key, int modifiers) {
  687.     this(target, when, id, x, y, key, modifiers, null);
  688.     }
  689.  
  690.     /**
  691.      * Creates an instance of <code>Event</code> with the specified  
  692.      * target component, event type, and argument. 
  693.      * @param     target     the target component.
  694.      * @param     id         the event type.
  695.      * @param     arg        the specified argument.
  696.      * @since     JDK1.0
  697.      */
  698.     public Event(Object target, int id, Object arg) {
  699.     this(target, 0, id, 0, 0, 0, 0, arg);
  700.     }
  701.  
  702.     /** 
  703.      * Translates this event so that its <i>x</i> and <i>y</i> 
  704.      * coordinates are increased by <i>dx</i> and <i>dy</i>, 
  705.      * respectively. 
  706.      * <p>
  707.      * This method translates an event relative to the given component. 
  708.      * This involves, at a minimum, translating the coordinates into the
  709.      * local coordinate system of the given component. It may also involve
  710.      * translating a region in the case of an expose event.
  711.      * @param     dx     the distance to translate the <i>x</i> coordinate.
  712.      * @param     dy     the distance to translate the <i>y</i> coordinate.
  713.      * @since     JDK1.0
  714.      */
  715.     public void translate(int x, int y) {
  716.     this.x += x;
  717.     this.y += y;
  718.     }
  719.  
  720.     /**
  721.      * Checks if the Shift key is down.
  722.      * @return    <code>true</code> if the key is down; 
  723.      *            <code>false</code> otherwise.
  724.      * @see       java.awt.Event#modifiers
  725.      * @see       java.awt.Event#controlDown
  726.      * @see       java.awt.Event#metaDown
  727.      * @since     JDK1.0
  728.      */
  729.     public boolean shiftDown() {
  730.     return (modifiers & SHIFT_MASK) != 0;
  731.     }
  732.  
  733.     /**
  734.      * Checks if the Control key is down.
  735.      * @return    <code>true</code> if the key is down; 
  736.      *            <code>false</code> otherwise.
  737.      * @see       java.awt.Event#modifiers
  738.      * @see       java.awt.Event#shiftDown
  739.      * @see       java.awt.Event#metaDown
  740.      * @since     JDK1.0
  741.      */
  742.     public boolean controlDown() {
  743.     return (modifiers & CTRL_MASK) != 0;
  744.     }
  745.  
  746.     /**
  747.      * Checks if the Meta key is down.
  748.      * @return    <code>true</code> if the key is down; 
  749.      *            <code>false</code> otherwise.
  750.      * @see       java.awt.Event#modifiers
  751.      * @see       java.awt.Event#shiftDown
  752.      * @see       java.awt.Event#controlDown
  753.      * @since     JDK1.0
  754.      */
  755.     public boolean metaDown() {
  756.     return (modifiers & META_MASK) != 0;
  757.     }
  758.  
  759.     void consume() {
  760.         switch(id) {
  761.           case KEY_PRESS:
  762.           case KEY_RELEASE:
  763.           case KEY_ACTION:
  764.           case KEY_ACTION_RELEASE:
  765.               consumed = true;
  766.               break;
  767.           default:
  768.               // event type cannot be consumed
  769.         }
  770.     }
  771.  
  772.     boolean isConsumed() {
  773.         return consumed;
  774.     }
  775.  
  776.     /*
  777.      * Returns the integer key-code associated with the key in this event,
  778.      * as described in java.awt.Event.  
  779.      */
  780.     static int getOldEventKey(KeyEvent e) {
  781.         int keyCode = e.getKeyCode();
  782.         for (int i = 0; i < actionKeyCodes.length; i++) {
  783.             if (actionKeyCodes[i][0] == keyCode) {
  784.                 return actionKeyCodes[i][1];
  785.             }
  786.         }
  787.         return (int)e.getKeyChar();
  788.     }
  789.  
  790.     /*
  791.      * Returns a new KeyEvent char which corresponds to the int key
  792.      * of this old event.
  793.      */
  794.     char getKeyEventChar() {
  795.        for (int i = 0; i < actionKeyCodes.length; i++) {
  796.             if (actionKeyCodes[i][1] == key) {
  797.                 return KeyEvent.CHAR_UNDEFINED;
  798.             }
  799.        }
  800.        return (char)key;
  801.     }
  802.  
  803.     /**
  804.      * Returns the parameter string representing this event. 
  805.      * This string is useful for debugging.
  806.      * @return    the parameter string of this event.
  807.      * @since     JDK1.0 
  808.      */
  809.     protected String paramString() {
  810.     String str = "id=" + id + ",x=" + x + ",y=" + y;
  811.     if (key != 0) {
  812.         str += ",key=" + key;
  813.     }
  814.     if (shiftDown()) {
  815.         str += ",shift";
  816.     }
  817.     if (controlDown()) {
  818.         str += ",control";
  819.     }
  820.     if (metaDown()) {
  821.         str += ",meta";
  822.     }
  823.     if (target != null) {
  824.         str += ",target=" + target;
  825.     }
  826.     if (arg != null) {
  827.         str += ",arg=" + arg;
  828.     }
  829.     return str;
  830.     }
  831.  
  832.     /**
  833.      * Returns a representation of this event's values as a string.
  834.      * @return    a string that represents the event and the values
  835.      *                 of its member fields.
  836.      * @see       java.awt.Event#paramString
  837.      * @since     JDK1.1
  838.      */
  839.     public String toString() {
  840.     return getClass().getName() + "[" + paramString() + "]";
  841.     }
  842. }
  843.