jdk/src/share/classes/java/awt/AWTEvent.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8816 29f983feda95
child 11270 d7b0b63bd082
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8816
diff changeset
     2
 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.Field;
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
    33
import sun.awt.AWTAccessor;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
    34
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
    36
import java.security.AccessControlContext;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
    37
import java.security.AccessController;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
    38
import java.io.ObjectInputStream;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
    39
import java.io.IOException;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The root event class for all AWT events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class and its subclasses supercede the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * java.awt.Event class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Subclasses of this root AWTEvent class defined outside of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * java.awt.event package should define event ID values greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the value defined by RESERVED_ID_MAX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The event masks defined in this class are needed by Component subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * which are using Component.enableEvents() to select for event types not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * selected by registered listeners. If a listener is registered on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * component, the appropriate event mask is already set internally by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The masks are also used to specify to which types of events an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * AWTEventListener should listen. The masks are bitwise-ORed together
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * and passed to Toolkit.addAWTEventListener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see Toolkit#addAWTEventListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see java.awt.event.ActionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see java.awt.event.AdjustmentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see java.awt.event.ComponentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see java.awt.event.ContainerEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see java.awt.event.FocusEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see java.awt.event.InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see java.awt.event.InvocationEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @see java.awt.event.ItemEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see java.awt.event.HierarchyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @see java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @see java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see java.awt.event.PaintEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @see java.awt.event.TextEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see java.awt.event.WindowEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
public abstract class AWTEvent extends EventObject {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
    83
    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.AWTEvent");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private byte bdata[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The event's id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see #getID()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see #AWTEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected int id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Controls whether or not the event is sent back down to the peer once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * source has processed it - false means it's sent to the peer; true means
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * it's not. Semantic events always have a 'true' value since they were
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * generated by the peer in response to a low-level event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #consume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #isConsumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected boolean consumed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   105
   /*
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   106
    * The event's AccessControlContext.
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   107
    */
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   108
    private transient volatile AccessControlContext acc =
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   109
        AccessController.getContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   110
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   111
   /*
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   112
    * Returns the acc this event was constructed with.
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   113
    */
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   114
    final AccessControlContext getAccessControlContext() {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   115
        if (acc == null) {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   116
            throw new SecurityException("AWTEvent is missing AccessControlContext");
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   117
        }
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   118
        return acc;
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   119
    }
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    transient boolean focusManagerIsDispatching = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    transient boolean isPosted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   125
     * Indicates whether this AWTEvent was generated by the system as
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   126
     * opposed to by user code.
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   127
     */
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   128
    private transient boolean isSystemGenerated;
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   129
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   130
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The event mask for selecting component events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public final static long COMPONENT_EVENT_MASK = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * The event mask for selecting container events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public final static long CONTAINER_EVENT_MASK = 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * The event mask for selecting focus events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public final static long FOCUS_EVENT_MASK = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The event mask for selecting key events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public final static long KEY_EVENT_MASK = 0x08;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * The event mask for selecting mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public final static long MOUSE_EVENT_MASK = 0x10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * The event mask for selecting mouse motion events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public final static long MOUSE_MOTION_EVENT_MASK = 0x20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * The event mask for selecting window events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public final static long WINDOW_EVENT_MASK = 0x40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * The event mask for selecting action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public final static long ACTION_EVENT_MASK = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * The event mask for selecting adjustment events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public final static long ADJUSTMENT_EVENT_MASK = 0x100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * The event mask for selecting item events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public final static long ITEM_EVENT_MASK = 0x200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * The event mask for selecting text events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public final static long TEXT_EVENT_MASK = 0x400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * The event mask for selecting input method events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public final static long INPUT_METHOD_EVENT_MASK = 0x800;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * The pseudo event mask for enabling input methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * We're using one bit in the eventMask so we don't need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * a separate field inputMethodsEnabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    final static long INPUT_METHODS_ENABLED_MASK = 0x1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The event mask for selecting paint events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public final static long PAINT_EVENT_MASK = 0x2000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * The event mask for selecting invocation events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public final static long INVOCATION_EVENT_MASK = 0x4000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * The event mask for selecting hierarchy events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public final static long HIERARCHY_EVENT_MASK = 0x8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * The event mask for selecting hierarchy bounds events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public final static long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * The event mask for selecting mouse wheel events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public final static long MOUSE_WHEEL_EVENT_MASK = 0x20000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * The event mask for selecting window state events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public final static long WINDOW_STATE_EVENT_MASK = 0x40000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * The event mask for selecting window focus events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public final static long WINDOW_FOCUS_EVENT_MASK = 0x80000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * WARNING: there are more mask defined privately.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * SunToolkit.GRAB_EVENT_MASK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * The maximum value for reserved AWT event IDs. Programs defining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * their own event IDs should use IDs greater than this value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public final static int RESERVED_ID_MAX = 1999;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    // security stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    private static Field inputEvent_CanAccessSystemClipboard_Field = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private static final long serialVersionUID = -1825314779160409405L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   260
        AWTAccessor.setAWTEventAccessor(
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   261
            new AWTAccessor.AWTEventAccessor() {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   262
                public void setPosted(AWTEvent ev) {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   263
                    ev.isPosted = true;
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   264
                }
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   265
                public void setSystemGenerated(AWTEvent ev) {
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   266
                    ev.isSystemGenerated = true;
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   267
                }
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   268
                public boolean isSystemGenerated(AWTEvent ev) {
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   269
                    return ev.isSystemGenerated;
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   270
                }
8816
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   271
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   272
                public AccessControlContext getAccessControlContext(AWTEvent ev) {
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   273
                    return ev.getAccessControlContext();
29f983feda95 6907662: System clipboard should ensure access restrictions
denis
parents: 7668
diff changeset
   274
                }
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2
diff changeset
   275
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static synchronized Field get_InputEvent_CanAccessSystemClipboard() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (inputEvent_CanAccessSystemClipboard_Field == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            inputEvent_CanAccessSystemClipboard_Field =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                (Field)java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                Field field = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                                    field = InputEvent.class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                        getDeclaredField("canAccessSystemClipboard");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                    field.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                    return field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                } catch (SecurityException e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   291
                                    if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   292
                                        log.fine("AWTEvent.get_InputEvent_CanAccessSystemClipboard() got SecurityException ", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                } catch (NoSuchFieldException e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   295
                                    if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   296
                                        log.fine("AWTEvent.get_InputEvent_CanAccessSystemClipboard() got NoSuchFieldException ", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return inputEvent_CanAccessSystemClipboard_Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Constructs an AWTEvent object from the parameters of a 1.0-style event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param event the old-style event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public AWTEvent(Event event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        this(event.target, event.id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Constructs an AWTEvent object with the specified source object and type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @param source the object where the event originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @param id the event type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public AWTEvent(Object source, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        this.id = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
          case ActionEvent.ACTION_PERFORMED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
          case ItemEvent.ITEM_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
          case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
          case TextEvent.TEXT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            consumed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Retargets an event to a new source. This method is typically used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * retarget an event to a lightweight child Component of the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * heavyweight source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * This method is intended to be used only by event targeting subsystems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * such as client-defined KeyboardFocusManagers. It is not for general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * client use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @param newSource the new Object to which the event should be dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public void setSource(Object newSource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (source == newSource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        Component comp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (newSource instanceof Component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            comp = (Component)newSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            while (comp != null && comp.peer != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                   (comp.peer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                comp = comp.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            source = newSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                ComponentPeer peer = comp.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    nativeSetSource(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    private native void nativeSetSource(ComponentPeer peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * Returns the event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public int getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Returns a String representation of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        String srcName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (source instanceof Component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            srcName = ((Component)source).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        } else if (source instanceof MenuComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            srcName = ((MenuComponent)source).getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return getClass().getName() + "[" + paramString() + "] on " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            (srcName != null? srcName : source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Returns a string representing the state of this <code>Event</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return  a string representation of this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Consumes this event, if this event can be consumed. Only low-level,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * system events can be consumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    protected void consume() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
          case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
          case MouseEvent.MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
          case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
          case InputMethodEvent.CARET_POSITION_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
              consumed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
              // event type cannot be consumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Returns whether this event has been consumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    protected boolean isConsumed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return consumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Converts a new event to an old one (used for compatibility).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * If the new event cannot be converted (because no old equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * exists) then this returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Note: this method is here instead of in each individual new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * event class in java.awt.event because we don't want to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * it public and it needs to be called from java.awt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    Event convertToOld() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Object src = getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        int newid = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
          case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
          case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
              KeyEvent ke = (KeyEvent)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
              if (ke.isActionKey()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                  newid = (id == KeyEvent.KEY_PRESSED?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                           Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
              int keyCode = ke.getKeyCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
              if (keyCode == KeyEvent.VK_SHIFT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                  keyCode == KeyEvent.VK_CONTROL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                  keyCode == KeyEvent.VK_ALT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                  return null;  // suppress modifier keys in old event model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
              // no mask for button1 existed in old Event - strip it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
              return new Event(src, ke.getWhen(), newid, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                               Event.getOldEventKey(ke),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                               (ke.getModifiers() & ~InputEvent.BUTTON1_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
          case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
          case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
          case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
          case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
          case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
          case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
              MouseEvent me = (MouseEvent)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
              // no mask for button1 existed in old Event - strip it out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
              Event olde = new Event(src, me.getWhen(), newid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                               me.getX(), me.getY(), 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                               (me.getModifiers() & ~InputEvent.BUTTON1_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
              olde.clickCount = me.getClickCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
              return olde;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
          case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
              return new Event(src, Event.GOT_FOCUS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
          case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
              return new Event(src, Event.LOST_FOCUS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
          case WindowEvent.WINDOW_CLOSING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
          case WindowEvent.WINDOW_ICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
          case WindowEvent.WINDOW_DEICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
              return new Event(src, newid, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
          case ComponentEvent.COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
              if (src instanceof Frame || src instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                  Point p = ((Component)src).getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                  return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
          case ActionEvent.ACTION_PERFORMED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
              ActionEvent ae = (ActionEvent)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
              String cmd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
              if (src instanceof Button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                  cmd = ((Button)src).getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
              } else if (src instanceof MenuItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                  cmd = ((MenuItem)src).getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                  cmd = ae.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
              return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
          case ItemEvent.ITEM_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
              ItemEvent ie = (ItemEvent)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
              Object arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
              if (src instanceof List) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                  newid = (ie.getStateChange() == ItemEvent.SELECTED?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                           Event.LIST_SELECT : Event.LIST_DESELECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                  arg = ie.getItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                  newid = Event.ACTION_EVENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                  if (src instanceof Choice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                      arg = ie.getItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                  } else { // Checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                      arg = Boolean.valueOf(ie.getStateChange() == ItemEvent.SELECTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
              return new Event(src, newid, arg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
          case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
              AdjustmentEvent aje = (AdjustmentEvent)this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
              switch(aje.getAdjustmentType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                case AdjustmentEvent.UNIT_INCREMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                  newid = Event.SCROLL_LINE_DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                case AdjustmentEvent.UNIT_DECREMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                  newid = Event.SCROLL_LINE_UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                case AdjustmentEvent.BLOCK_INCREMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                  newid = Event.SCROLL_PAGE_DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                case AdjustmentEvent.BLOCK_DECREMENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                  newid = Event.SCROLL_PAGE_UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                case AdjustmentEvent.TRACK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                  if (aje.getValueIsAdjusting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                      newid = Event.SCROLL_ABSOLUTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                      newid = Event.SCROLL_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
              return new Event(src, newid, Integer.valueOf(aje.getValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Copies all private data from this event into that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * Space is allocated for the copied data that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * freed when the that is finalized. Upon completion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * this event is not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    void copyPrivateDataInto(AWTEvent that) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        that.bdata = this.bdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        // Copy canAccessSystemClipboard value from this into that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (this instanceof InputEvent && that instanceof InputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            Field field = get_InputEvent_CanAccessSystemClipboard();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            if (field != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    boolean b = field.getBoolean(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    field.setBoolean(that, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                } catch(IllegalAccessException e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   588
                    if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   589
                        log.fine("AWTEvent.copyPrivateDataInto() got IllegalAccessException ", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
   594
        that.isSystemGenerated = this.isSystemGenerated;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    void dispatched() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (this instanceof InputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            Field field = get_InputEvent_CanAccessSystemClipboard();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            if (field != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    field.setBoolean(this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                } catch(IllegalAccessException e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   604
                    if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3084
diff changeset
   605
                        log.fine("AWTEvent.dispatched() got IllegalAccessException ", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
} // class AWTEvent