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