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.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  21.5 KB  |  747 lines

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