Home | History | Annotate | Download | only in awt
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Dmitry A. Durnev, Michael Danilov
     19  * @version $Revision$
     20  */
     21 
     22 package java.awt;
     23 
     24 import java.util.EventObject;
     25 import java.util.Hashtable;
     26 import java.util.EventListener;
     27 
     28 import java.awt.event.*;
     29 
     30 /**
     31  * The abstract class AWTEvent is the base class for all AWT events. This class
     32  * and its subclasses supersede the original java.awt.Event class.
     33  *
     34  * @since Android 1.0
     35  */
     36 public abstract class AWTEvent extends EventObject {
     37 
     38     /**
     39      * The Constant serialVersionUID.
     40      */
     41     private static final long serialVersionUID = -1825314779160409405L;
     42 
     43     /**
     44      * The Constant COMPONENT_EVENT_MASK indicates the event relates to a
     45      * component.
     46      */
     47     public static final long COMPONENT_EVENT_MASK = 1;
     48 
     49     /**
     50      * The Constant CONTAINER_EVENT_MASK indicates the event relates to a
     51      * container.
     52      */
     53     public static final long CONTAINER_EVENT_MASK = 2;
     54 
     55     /**
     56      * The Constant FOCUS_EVENT_MASK indicates the event relates to the focus.
     57      */
     58     public static final long FOCUS_EVENT_MASK = 4;
     59 
     60     /**
     61      * The Constant KEY_EVENT_MASK indicates the event relates to a key.
     62      */
     63     public static final long KEY_EVENT_MASK = 8;
     64 
     65     /**
     66      * The Constant MOUSE_EVENT_MASK indicates the event relates to the mouse.
     67      */
     68     public static final long MOUSE_EVENT_MASK = 16;
     69 
     70     /**
     71      * The Constant MOUSE_MOTION_EVENT_MASK indicates the event relates to a
     72      * mouse motion.
     73      */
     74     public static final long MOUSE_MOTION_EVENT_MASK = 32;
     75 
     76     /**
     77      * The Constant WINDOW_EVENT_MASK indicates the event relates to a window.
     78      */
     79     public static final long WINDOW_EVENT_MASK = 64;
     80 
     81     /**
     82      * The Constant ACTION_EVENT_MASK indicates the event relates to an action.
     83      */
     84     public static final long ACTION_EVENT_MASK = 128;
     85 
     86     /**
     87      * The Constant ADJUSTMENT_EVENT_MASK indicates the event relates to an
     88      * adjustment.
     89      */
     90     public static final long ADJUSTMENT_EVENT_MASK = 256;
     91 
     92     /**
     93      * The Constant ITEM_EVENT_MASK indicates the event relates to an item.
     94      */
     95     public static final long ITEM_EVENT_MASK = 512;
     96 
     97     /**
     98      * The Constant TEXT_EVENT_MASK indicates the event relates to text.
     99      */
    100     public static final long TEXT_EVENT_MASK = 1024;
    101 
    102     /**
    103      * The Constant INPUT_METHOD_EVENT_MASK indicates the event relates to an
    104      * input method.
    105      */
    106     public static final long INPUT_METHOD_EVENT_MASK = 2048;
    107 
    108     /**
    109      * The Constant PAINT_EVENT_MASK indicates the event relates to a paint
    110      * method.
    111      */
    112     public static final long PAINT_EVENT_MASK = 8192;
    113 
    114     /**
    115      * The Constant INVOCATION_EVENT_MASK indicates the event relates to a
    116      * method invocation.
    117      */
    118     public static final long INVOCATION_EVENT_MASK = 16384;
    119 
    120     /**
    121      * The Constant HIERARCHY_EVENT_MASK indicates the event relates to a
    122      * hierarchy.
    123      */
    124     public static final long HIERARCHY_EVENT_MASK = 32768;
    125 
    126     /**
    127      * The Constant HIERARCHY_BOUNDS_EVENT_MASK indicates the event relates to
    128      * hierarchy bounds.
    129      */
    130     public static final long HIERARCHY_BOUNDS_EVENT_MASK = 65536;
    131 
    132     /**
    133      * The Constant MOUSE_WHEEL_EVENT_MASK indicates the event relates to the
    134      * mouse wheel.
    135      */
    136     public static final long MOUSE_WHEEL_EVENT_MASK = 131072;
    137 
    138     /**
    139      * The Constant WINDOW_STATE_EVENT_MASK indicates the event relates to a
    140      * window state.
    141      */
    142     public static final long WINDOW_STATE_EVENT_MASK = 262144;
    143 
    144     /**
    145      * The Constant WINDOW_FOCUS_EVENT_MASK indicates the event relates to a
    146      * window focus.
    147      */
    148     public static final long WINDOW_FOCUS_EVENT_MASK = 524288;
    149 
    150     /**
    151      * The Constant RESERVED_ID_MAX indicates the maximum value for reserved AWT
    152      * event IDs.
    153      */
    154     public static final int RESERVED_ID_MAX = 1999;
    155 
    156     /**
    157      * The Constant eventsMap.
    158      */
    159     private static final Hashtable<Integer, EventDescriptor> eventsMap = new Hashtable<Integer, EventDescriptor>();
    160 
    161     /**
    162      * The converter.
    163      */
    164     private static EventConverter converter;
    165 
    166     /**
    167      * The ID of the event.
    168      */
    169     protected int id;
    170 
    171     /**
    172      * The consumed indicates whether or not the event is sent back down to the
    173      * peer once the source has processed it (false means it's sent to the peer,
    174      * true means it's not).
    175      */
    176     protected boolean consumed;
    177 
    178     /**
    179      * The dispatched by kfm.
    180      */
    181     boolean dispatchedByKFM;
    182 
    183     /**
    184      * The is posted.
    185      */
    186     transient boolean isPosted;
    187 
    188     static {
    189         eventsMap.put(new Integer(KeyEvent.KEY_TYPED), new EventDescriptor(KEY_EVENT_MASK,
    190                 KeyListener.class));
    191         eventsMap.put(new Integer(KeyEvent.KEY_PRESSED), new EventDescriptor(KEY_EVENT_MASK,
    192                 KeyListener.class));
    193         eventsMap.put(new Integer(KeyEvent.KEY_RELEASED), new EventDescriptor(KEY_EVENT_MASK,
    194                 KeyListener.class));
    195         eventsMap.put(new Integer(MouseEvent.MOUSE_CLICKED), new EventDescriptor(MOUSE_EVENT_MASK,
    196                 MouseListener.class));
    197         eventsMap.put(new Integer(MouseEvent.MOUSE_PRESSED), new EventDescriptor(MOUSE_EVENT_MASK,
    198                 MouseListener.class));
    199         eventsMap.put(new Integer(MouseEvent.MOUSE_RELEASED), new EventDescriptor(MOUSE_EVENT_MASK,
    200                 MouseListener.class));
    201         eventsMap.put(new Integer(MouseEvent.MOUSE_MOVED), new EventDescriptor(
    202                 MOUSE_MOTION_EVENT_MASK, MouseMotionListener.class));
    203         eventsMap.put(new Integer(MouseEvent.MOUSE_ENTERED), new EventDescriptor(MOUSE_EVENT_MASK,
    204                 MouseListener.class));
    205         eventsMap.put(new Integer(MouseEvent.MOUSE_EXITED), new EventDescriptor(MOUSE_EVENT_MASK,
    206                 MouseListener.class));
    207         eventsMap.put(new Integer(MouseEvent.MOUSE_DRAGGED), new EventDescriptor(
    208                 MOUSE_MOTION_EVENT_MASK, MouseMotionListener.class));
    209         eventsMap.put(new Integer(MouseEvent.MOUSE_WHEEL), new EventDescriptor(
    210                 MOUSE_WHEEL_EVENT_MASK, MouseWheelListener.class));
    211         eventsMap.put(new Integer(ComponentEvent.COMPONENT_MOVED), new EventDescriptor(
    212                 COMPONENT_EVENT_MASK, ComponentListener.class));
    213         eventsMap.put(new Integer(ComponentEvent.COMPONENT_RESIZED), new EventDescriptor(
    214                 COMPONENT_EVENT_MASK, ComponentListener.class));
    215         eventsMap.put(new Integer(ComponentEvent.COMPONENT_SHOWN), new EventDescriptor(
    216                 COMPONENT_EVENT_MASK, ComponentListener.class));
    217         eventsMap.put(new Integer(ComponentEvent.COMPONENT_HIDDEN), new EventDescriptor(
    218                 COMPONENT_EVENT_MASK, ComponentListener.class));
    219         eventsMap.put(new Integer(FocusEvent.FOCUS_GAINED), new EventDescriptor(FOCUS_EVENT_MASK,
    220                 FocusListener.class));
    221         eventsMap.put(new Integer(FocusEvent.FOCUS_LOST), new EventDescriptor(FOCUS_EVENT_MASK,
    222                 FocusListener.class));
    223         eventsMap.put(new Integer(PaintEvent.PAINT), new EventDescriptor(PAINT_EVENT_MASK, null));
    224         eventsMap.put(new Integer(PaintEvent.UPDATE), new EventDescriptor(PAINT_EVENT_MASK, null));
    225         eventsMap.put(new Integer(WindowEvent.WINDOW_OPENED), new EventDescriptor(
    226                 WINDOW_EVENT_MASK, WindowListener.class));
    227         eventsMap.put(new Integer(WindowEvent.WINDOW_CLOSING), new EventDescriptor(
    228                 WINDOW_EVENT_MASK, WindowListener.class));
    229         eventsMap.put(new Integer(WindowEvent.WINDOW_CLOSED), new EventDescriptor(
    230                 WINDOW_EVENT_MASK, WindowListener.class));
    231         eventsMap.put(new Integer(WindowEvent.WINDOW_DEICONIFIED), new EventDescriptor(
    232                 WINDOW_EVENT_MASK, WindowListener.class));
    233         eventsMap.put(new Integer(WindowEvent.WINDOW_ICONIFIED), new EventDescriptor(
    234                 WINDOW_EVENT_MASK, WindowListener.class));
    235         eventsMap.put(new Integer(WindowEvent.WINDOW_STATE_CHANGED), new EventDescriptor(
    236                 WINDOW_STATE_EVENT_MASK, WindowStateListener.class));
    237         eventsMap.put(new Integer(WindowEvent.WINDOW_LOST_FOCUS), new EventDescriptor(
    238                 WINDOW_FOCUS_EVENT_MASK, WindowFocusListener.class));
    239         eventsMap.put(new Integer(WindowEvent.WINDOW_GAINED_FOCUS), new EventDescriptor(
    240                 WINDOW_FOCUS_EVENT_MASK, WindowFocusListener.class));
    241         eventsMap.put(new Integer(WindowEvent.WINDOW_DEACTIVATED), new EventDescriptor(
    242                 WINDOW_EVENT_MASK, WindowListener.class));
    243         eventsMap.put(new Integer(WindowEvent.WINDOW_ACTIVATED), new EventDescriptor(
    244                 WINDOW_EVENT_MASK, WindowListener.class));
    245         eventsMap.put(new Integer(HierarchyEvent.HIERARCHY_CHANGED), new EventDescriptor(
    246                 HIERARCHY_EVENT_MASK, HierarchyListener.class));
    247         eventsMap.put(new Integer(HierarchyEvent.ANCESTOR_MOVED), new EventDescriptor(
    248                 HIERARCHY_BOUNDS_EVENT_MASK, HierarchyBoundsListener.class));
    249         eventsMap.put(new Integer(HierarchyEvent.ANCESTOR_RESIZED), new EventDescriptor(
    250                 HIERARCHY_BOUNDS_EVENT_MASK, HierarchyBoundsListener.class));
    251         eventsMap.put(new Integer(ContainerEvent.COMPONENT_ADDED), new EventDescriptor(
    252                 CONTAINER_EVENT_MASK, ContainerListener.class));
    253         eventsMap.put(new Integer(ContainerEvent.COMPONENT_REMOVED), new EventDescriptor(
    254                 CONTAINER_EVENT_MASK, ContainerListener.class));
    255         eventsMap.put(new Integer(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED), new EventDescriptor(
    256                 INPUT_METHOD_EVENT_MASK, InputMethodListener.class));
    257         eventsMap.put(new Integer(InputMethodEvent.CARET_POSITION_CHANGED), new EventDescriptor(
    258                 INPUT_METHOD_EVENT_MASK, InputMethodListener.class));
    259         eventsMap.put(new Integer(InvocationEvent.INVOCATION_DEFAULT), new EventDescriptor(
    260                 INVOCATION_EVENT_MASK, null));
    261         eventsMap.put(new Integer(ItemEvent.ITEM_STATE_CHANGED), new EventDescriptor(
    262                 ITEM_EVENT_MASK, ItemListener.class));
    263         eventsMap.put(new Integer(TextEvent.TEXT_VALUE_CHANGED), new EventDescriptor(
    264                 TEXT_EVENT_MASK, TextListener.class));
    265         eventsMap.put(new Integer(ActionEvent.ACTION_PERFORMED), new EventDescriptor(
    266                 ACTION_EVENT_MASK, ActionListener.class));
    267         eventsMap.put(new Integer(AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED), new EventDescriptor(
    268                 ADJUSTMENT_EVENT_MASK, AdjustmentListener.class));
    269         converter = new EventConverter();
    270     }
    271 
    272     /**
    273      * Instantiates a new AWT event from the specified Event object.
    274      *
    275      * @param event
    276      *            the Event object.
    277      */
    278     public AWTEvent(Event event) {
    279         this(event.target, event.id);
    280     }
    281 
    282     /**
    283      * Instantiates a new AWT event with the specified object and type.
    284      *
    285      * @param source
    286      *            the source Object.
    287      * @param id
    288      *            the event's type.
    289      */
    290     public AWTEvent(Object source, int id) {
    291         super(source);
    292         this.id = id;
    293         consumed = false;
    294     }
    295 
    296     /**
    297      * Gets the event's type.
    298      *
    299      * @return the event type ID.
    300      */
    301     public int getID() {
    302         return id;
    303     }
    304 
    305     /**
    306      * Sets a new source for the AWTEvent.
    307      *
    308      * @param newSource
    309      *            the new source Object for the AWTEvent.
    310      */
    311     public void setSource(Object newSource) {
    312         source = newSource;
    313     }
    314 
    315     /**
    316      * Returns a String representation of the AWTEvent.
    317      *
    318      * @return the String representation of the AWTEvent.
    319      */
    320     @Override
    321     public String toString() {
    322         /*
    323          * The format is based on 1.5 release behavior which can be revealed by
    324          * the following code: AWTEvent event = new AWTEvent(new Component(){},
    325          * 1){}; System.out.println(event);
    326          */
    327         String name = ""; //$NON-NLS-1$
    328 
    329         if (source instanceof Component && (source != null)) {
    330             Component comp = (Component)getSource();
    331             name = comp.getName();
    332             if (name == null) {
    333                 name = ""; //$NON-NLS-1$
    334             }
    335         }
    336 
    337         return (getClass().getName() + "[" + paramString() + "]" //$NON-NLS-1$ //$NON-NLS-2$
    338                 + " on " + (name.length() > 0 ? name : source)); //$NON-NLS-1$
    339     }
    340 
    341     /**
    342      * Returns a string representation of the AWTEvent state.
    343      *
    344      * @return a string representation of the AWTEvent state.
    345      */
    346     public String paramString() {
    347         // nothing to implement: all event types must override this method
    348         return ""; //$NON-NLS-1$
    349     }
    350 
    351     /**
    352      * Checks whether or not this AWTEvent has been consumed.
    353      *
    354      * @return true, if this AWTEvent has been consumed, false otherwise.
    355      */
    356     protected boolean isConsumed() {
    357         return consumed;
    358     }
    359 
    360     /**
    361      * Consumes the AWTEvent.
    362      */
    363     protected void consume() {
    364         consumed = true;
    365     }
    366 
    367     /**
    368      * Convert AWTEvent object to a corresponding (deprecated) Event object.
    369      *
    370      * @return new Event object which is a converted AWTEvent object or null if
    371      *         the conversion is not possible
    372      */
    373     Event getEvent() {
    374 
    375         if (id == ActionEvent.ACTION_PERFORMED) {
    376             ActionEvent ae = (ActionEvent)this;
    377             return converter.convertActionEvent(ae);
    378 
    379         } else if (id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
    380             AdjustmentEvent ae = (AdjustmentEvent)this;
    381             return converter.convertAdjustmentEvent(ae);
    382 
    383             // ???AWT
    384             // } else if (id == ComponentEvent.COMPONENT_MOVED
    385             // && source instanceof Window) {
    386             // //the only type of Component events is COMPONENT_MOVED on window
    387             // ComponentEvent ce = (ComponentEvent) this;
    388             // return converter.convertComponentEvent(ce);
    389 
    390         } else if (id >= FocusEvent.FOCUS_FIRST && id <= FocusEvent.FOCUS_LAST) {
    391             // nothing to convert
    392 
    393             // ???AWT
    394             // } else if (id == ItemEvent.ITEM_STATE_CHANGED) {
    395             // ItemEvent ie = (ItemEvent) this;
    396             // return converter.convertItemEvent(ie);
    397 
    398         } else if (id == KeyEvent.KEY_PRESSED || id == KeyEvent.KEY_RELEASED) {
    399             KeyEvent ke = (KeyEvent)this;
    400             return converter.convertKeyEvent(ke);
    401         } else if (id >= MouseEvent.MOUSE_FIRST && id <= MouseEvent.MOUSE_LAST) {
    402             MouseEvent me = (MouseEvent)this;
    403             return converter.convertMouseEvent(me);
    404         } else if (id == WindowEvent.WINDOW_CLOSING || id == WindowEvent.WINDOW_ICONIFIED
    405                 || id == WindowEvent.WINDOW_DEICONIFIED) {
    406             // nothing to convert
    407         } else {
    408             return null;
    409         }
    410         return new Event(source, id, null);
    411     }
    412 
    413     /**
    414      * The class EventDescriptor.
    415      */
    416     static final class EventDescriptor {
    417 
    418         /**
    419          * The event mask.
    420          */
    421         final long eventMask;
    422 
    423         /**
    424          * The listener type.
    425          */
    426         final Class<? extends EventListener> listenerType;
    427 
    428         /**
    429          * Instantiates a new event descriptor.
    430          *
    431          * @param eventMask
    432          *            the event mask.
    433          * @param listenerType
    434          *            the listener type.
    435          */
    436         EventDescriptor(long eventMask, Class<? extends EventListener> listenerType) {
    437             this.eventMask = eventMask;
    438             this.listenerType = listenerType;
    439         }
    440 
    441     }
    442 
    443     /**
    444      * The class EventTypeLookup.
    445      */
    446     static final class EventTypeLookup {
    447 
    448         /**
    449          * The last event.
    450          */
    451         private AWTEvent lastEvent = null;
    452 
    453         /**
    454          * The last event descriptor.
    455          */
    456         private EventDescriptor lastEventDescriptor = null;
    457 
    458         /**
    459          * Gets the event descriptor.
    460          *
    461          * @param event
    462          *            the event.
    463          * @return the event descriptor.
    464          */
    465         EventDescriptor getEventDescriptor(AWTEvent event) {
    466             synchronized (this) {
    467                 if (event != lastEvent) {
    468                     lastEvent = event;
    469                     lastEventDescriptor = eventsMap.get(new Integer(event.id));
    470                 }
    471 
    472                 return lastEventDescriptor;
    473             }
    474         }
    475 
    476         /**
    477          * Gets the event mask.
    478          *
    479          * @param event
    480          *            the event.
    481          * @return the event mask.
    482          */
    483         long getEventMask(AWTEvent event) {
    484             final EventDescriptor ed = getEventDescriptor(event);
    485             return ed == null ? -1 : ed.eventMask;
    486         }
    487     }
    488 
    489     /**
    490      * The class EventConverter.
    491      */
    492     static final class EventConverter {
    493 
    494         /**
    495          * The constant OLD_MOD_MASK.
    496          */
    497         static final int OLD_MOD_MASK = Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK
    498                 | Event.SHIFT_MASK;
    499 
    500         /**
    501          * Convert action event.
    502          *
    503          * @param ae
    504          *            the ae.
    505          * @return the event.
    506          */
    507         Event convertActionEvent(ActionEvent ae) {
    508             Event evt = new Event(ae.getSource(), ae.getID(), ae.getActionCommand());
    509             evt.when = ae.getWhen();
    510             evt.modifiers = ae.getModifiers() & OLD_MOD_MASK;
    511 
    512             /*
    513              * if (source instanceof Button) { arg = ((Button)
    514              * source).getLabel(); } else if (source instanceof Checkbox) { arg
    515              * = new Boolean(((Checkbox) source).getState()); } else if (source
    516              * instanceof CheckboxMenuItem) { arg = ((CheckboxMenuItem)
    517              * source).getLabel(); } else if (source instanceof Choice) { arg =
    518              * ((Choice) source).getSelectedItem(); } else if (source instanceof
    519              * List) { arg = ((List) source).getSelectedItem(); } else if
    520              * (source instanceof MenuItem) { arg = ((MenuItem)
    521              * source).getLabel(); } else if (source instanceof TextField) { arg
    522              * = ((TextField) source).getText(); }
    523              */
    524             return evt;
    525         }
    526 
    527         /**
    528          * Convert adjustment event.
    529          *
    530          * @param ae
    531          *            the ae.
    532          * @return the event.
    533          */
    534         Event convertAdjustmentEvent(AdjustmentEvent ae) {
    535             // TODO: Event.SCROLL_BEGIN/SCROLL_END
    536             return new Event(ae.source, ae.id + ae.getAdjustmentType() - 1, new Integer(ae
    537                     .getValue()));
    538         }
    539 
    540         /**
    541          * Convert component event.
    542          *
    543          * @param ce
    544          *            the ce.
    545          * @return the event.
    546          */
    547         Event convertComponentEvent(ComponentEvent ce) {
    548             Component comp = ce.getComponent();
    549             Event evt = new Event(comp, Event.WINDOW_MOVED, null);
    550             evt.x = comp.getX();
    551             evt.y = comp.getY();
    552             return evt;
    553         }
    554 
    555         // ???AWT
    556         /*
    557          * Event convertItemEvent(ItemEvent ie) { int oldId = ie.id +
    558          * ie.getStateChange() - 1; Object source = ie.source; int idx = -1; if
    559          * (source instanceof List) { List list = (List) source; idx =
    560          * list.getSelectedIndex(); } else if (source instanceof Choice) {
    561          * Choice choice = (Choice) source; idx = choice.getSelectedIndex(); }
    562          * Object arg = idx >= 0 ? new Integer(idx) : null; return new
    563          * Event(source, oldId, arg); }
    564          */
    565 
    566         /**
    567          * Convert key event.
    568          *
    569          * @param ke
    570          *            the ke.
    571          * @return the event.
    572          */
    573         Event convertKeyEvent(KeyEvent ke) {
    574             int oldId = ke.id;
    575             // leave only old Event's modifiers
    576 
    577             int mod = ke.getModifiers() & OLD_MOD_MASK;
    578             Component comp = ke.getComponent();
    579             char keyChar = ke.getKeyChar();
    580             int keyCode = ke.getKeyCode();
    581             int key = convertKey(keyChar, keyCode);
    582             if (key >= Event.HOME && key <= Event.INSERT) {
    583                 oldId += 2; // non-ASCII key -> action key
    584             }
    585             return new Event(comp, ke.getWhen(), oldId, 0, 0, key, mod);
    586         }
    587 
    588         /**
    589          * Convert mouse event.
    590          *
    591          * @param me
    592          *            the me.
    593          * @return the event.
    594          */
    595         Event convertMouseEvent(MouseEvent me) {
    596             int id = me.id;
    597             if (id != MouseEvent.MOUSE_CLICKED) {
    598                 Event evt = new Event(me.source, id, null);
    599                 evt.x = me.getX();
    600                 evt.y = me.getY();
    601                 int mod = me.getModifiers();
    602                 // in Event modifiers mean button number for mouse events:
    603                 evt.modifiers = mod & (Event.ALT_MASK | Event.META_MASK);
    604                 if (id == MouseEvent.MOUSE_PRESSED) {
    605                     evt.clickCount = me.getClickCount();
    606                 }
    607                 return evt;
    608             }
    609             return null;
    610         }
    611 
    612         /**
    613          * Convert key.
    614          *
    615          * @param keyChar
    616          *            the key char.
    617          * @param keyCode
    618          *            the key code.
    619          * @return the int.
    620          */
    621         int convertKey(char keyChar, int keyCode) {
    622             int key;
    623             // F1 - F12
    624             if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) {
    625                 key = Event.F1 + keyCode - KeyEvent.VK_F1;
    626             } else {
    627                 switch (keyCode) {
    628                     default: // non-action key
    629                         key = keyChar;
    630                         break;
    631                     // action keys:
    632                     case KeyEvent.VK_HOME:
    633                         key = Event.HOME;
    634                         break;
    635                     case KeyEvent.VK_END:
    636                         key = Event.END;
    637                         break;
    638                     case KeyEvent.VK_PAGE_UP:
    639                         key = Event.PGUP;
    640                         break;
    641                     case KeyEvent.VK_PAGE_DOWN:
    642                         key = Event.PGDN;
    643                         break;
    644                     case KeyEvent.VK_UP:
    645                         key = Event.UP;
    646                         break;
    647                     case KeyEvent.VK_DOWN:
    648                         key = Event.DOWN;
    649                         break;
    650                     case KeyEvent.VK_LEFT:
    651                         key = Event.LEFT;
    652                         break;
    653                     case KeyEvent.VK_RIGHT:
    654                         key = Event.RIGHT;
    655                         break;
    656                     case KeyEvent.VK_PRINTSCREEN:
    657                         key = Event.PRINT_SCREEN;
    658                         break;
    659                     case KeyEvent.VK_SCROLL_LOCK:
    660                         key = Event.SCROLL_LOCK;
    661                         break;
    662                     case KeyEvent.VK_CAPS_LOCK:
    663                         key = Event.CAPS_LOCK;
    664                         break;
    665                     case KeyEvent.VK_NUM_LOCK:
    666                         key = Event.NUM_LOCK;
    667                         break;
    668                     case KeyEvent.VK_PAUSE:
    669                         key = Event.PAUSE;
    670                         break;
    671                     case KeyEvent.VK_INSERT:
    672                         key = Event.INSERT;
    673                         break;
    674                 }
    675             }
    676             return key;
    677         }
    678 
    679     }
    680 
    681 }
    682