jdk/src/share/classes/java/awt/event/InputEvent.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6910 4acdf8b6df2f
child 11814 aeabedb76db2
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6910
diff changeset
     2
 * Copyright (c) 1996, 2010, 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.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Toolkit;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    32
import java.util.Arrays;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    33
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    34
import sun.awt.AWTAccessor;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    35
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The root event class for all component-level input events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Input events are delivered to listeners before they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * processed normally by the source where they originated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This allows listeners and component subclasses to "consume"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the event so that the source will not process them in their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * default manner.  For example, consuming mousePressed events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * on a Button component will prevent the Button from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see KeyAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see MouseAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see MouseMotionAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public abstract class InputEvent extends ComponentEvent {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
    59
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
    60
    private static final PlatformLogger logger = PlatformLogger.getLogger("java.awt.event.InputEvent");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The Shift key modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * It is recommended that SHIFT_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static final int SHIFT_MASK = Event.SHIFT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The Control key modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * It is recommended that CTRL_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final int CTRL_MASK = Event.CTRL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The Meta key modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * It is recommended that META_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int META_MASK = Event.META_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * The Alt key modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * It is recommended that ALT_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final int ALT_MASK = Event.ALT_MASK;
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 AltGraph key modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final int ALT_GRAPH_MASK = 1 << 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * The Mouse Button1 modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * It is recommended that BUTTON1_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final int BUTTON1_MASK = 1 << 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * The Mouse Button2 modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * It is recommended that BUTTON2_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Note that BUTTON2_MASK has the same value as ALT_MASK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static final int BUTTON2_MASK = Event.ALT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The Mouse Button3 modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * It is recommended that BUTTON3_DOWN_MASK be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Note that BUTTON3_MASK has the same value as META_MASK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static final int BUTTON3_MASK = Event.META_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The Shift key extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static final int SHIFT_DOWN_MASK = 1 << 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The Control key extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public static final int CTRL_DOWN_MASK = 1 << 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * The Meta key extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static final int META_DOWN_MASK = 1 << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * The Alt key extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final int ALT_DOWN_MASK = 1 << 9;
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 Mouse Button1 extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final int BUTTON1_DOWN_MASK = 1 << 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The Mouse Button2 extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final int BUTTON2_DOWN_MASK = 1 << 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * The Mouse Button3 extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public static final int BUTTON3_DOWN_MASK = 1 << 12;
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 AltGraph key extended modifier constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static final int ALT_GRAPH_DOWN_MASK = 1 << 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   159
    /**
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   160
     * An array of extended modifiers for additional buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   161
     * @see getButtonDownMasks
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   162
     * There are twenty buttons fit into 4byte space.
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   163
     * one more bit is reserved for FIRST_HIGH_BIT.
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   164
     * @since 7.0
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   165
     */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   166
    private static final int [] BUTTON_DOWN_MASK = new int [] { BUTTON1_DOWN_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   167
                                                               BUTTON2_DOWN_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   168
                                                               BUTTON3_DOWN_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   169
                                                               1<<14, //4th phisical button (this is not a wheel!)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   170
                                                               1<<15, //(this is not a wheel!)
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   171
                                                               1<<16,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   172
                                                               1<<17,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   173
                                                               1<<18,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   174
                                                               1<<19,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   175
                                                               1<<20,
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   176
                                                               1<<21,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   177
                                                               1<<22,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   178
                                                               1<<23,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   179
                                                               1<<24,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   180
                                                               1<<25,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   181
                                                               1<<26,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   182
                                                               1<<27,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   183
                                                               1<<28,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   184
                                                               1<<29,
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   185
                                                               1<<30};
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   186
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   187
    /**
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   188
     * A method to access an array of extended modifiers for additional buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   189
     * @since 7.0
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   190
     */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   191
    private static int [] getButtonDownMasks(){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   192
        return Arrays.copyOf(BUTTON_DOWN_MASK, BUTTON_DOWN_MASK.length);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   193
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   194
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   195
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   196
    /**
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   197
     * A method to obtain a mask for any existing mouse button.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   198
     * The returned mask may be used for different purposes. Following are some of them:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   199
     * <ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   200
     * <li> {@link java.awt.Robot#mousePress(int) mousePress(buttons)} and
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   201
     *      {@link java.awt.Robot#mouseRelease(int) mouseRelease(buttons)}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   202
     * <li> as a {@code modifiers} parameter when creating a new {@link MouseEvent} instance
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   203
     * <li> to check {@link MouseEvent#getModifiersEx() modifiersEx} of existing {@code MouseEvent}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   204
     * </ul>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   205
     * @param button is a number to represent a button starting from 1.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   206
     * For example,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   207
     * <pre>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   208
     * int button = InputEvent.getMaskForButton(1);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   209
     * </pre>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   210
     * will have the same meaning as
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   211
     * <pre>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   212
     * int button = InputEvent.getMaskForButton(MouseEvent.BUTTON1);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   213
     * </pre>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   214
     * because {@link MouseEvent#BUTTON1 MouseEvent.BUTTON1} equals to 1.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   215
     * If a mouse has three enabled buttons(see {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()})
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   216
     * then the values from the left column passed into the method will return
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   217
     * corresponding values from the right column:
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   218
     * <PRE>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   219
     *    <b>button </b>   <b>returned mask</b>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   220
     *    {@link MouseEvent#BUTTON1 BUTTON1}  {@link MouseEvent#BUTTON1_DOWN_MASK BUTTON1_DOWN_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   221
     *    {@link MouseEvent#BUTTON2 BUTTON2}  {@link MouseEvent#BUTTON2_DOWN_MASK BUTTON2_DOWN_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   222
     *    {@link MouseEvent#BUTTON3 BUTTON3}  {@link MouseEvent#BUTTON3_DOWN_MASK BUTTON3_DOWN_MASK}
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   223
     * </PRE>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   224
     * If a mouse has more than three enabled buttons then more values
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   225
     * are admissible (4, 5, etc.). There is no assigned constants for these extended buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   226
     * The button masks for the extra buttons returned by this method have no assigned names like the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   227
     * first three button masks.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   228
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   229
     * This method has the following implementation restriction.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   230
     * It returns masks for a limited number of buttons only. The maximum number is
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   231
     * implementation dependent and may vary.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   232
     * This limit is defined by the relevant number
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   233
     * of buttons that may hypothetically exist on the mouse but it is greater than the
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   234
     * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   235
     * <p>
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   236
     * @throws IllegalArgumentException if {@code button} is less than zero or greater than the number
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   237
     *         of button masks reserved for buttons
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   238
     * @since 7.0
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   239
     * @see java.awt.MouseInfo#getNumberOfButtons()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   240
     * @see Toolkit#areExtraMouseButtonsEnabled()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   241
     * @see MouseEvent#getModifiers()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   242
     * @see MouseEvent#getModifiersEx()
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   243
     */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   244
    public static int getMaskForButton(int button) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   245
        if (button <= 0 || button > BUTTON_DOWN_MASK.length) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   246
            throw new IllegalArgumentException("button doesn\'t exist " + button);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   247
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   248
        return BUTTON_DOWN_MASK[button - 1];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   249
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   250
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    // the constant below MUST be updated if any extra modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    // bits are to be added!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    // in fact, it is undesirable to add modifier bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    // to the same field as this may break applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    // see bug# 5066958
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 1962
diff changeset
   256
    static final int FIRST_HIGH_BIT = 1 << 31;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    static final int JDK_1_3_MODIFIERS = SHIFT_DOWN_MASK - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    static final int HIGH_MODIFIERS = ~( FIRST_HIGH_BIT - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * The input event's Time stamp in UTC format.  The time stamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * indicates when the input event was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #getWhen()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    long when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * The state of the modifier mask at the time the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * event was fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see #getModifiers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #getModifiersEx()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @see java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    int modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * A flag that indicates that this instance can be used to access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the system clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private transient boolean canAccessSystemClipboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        NativeLibLoader.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   294
        AWTAccessor.setInputEventAccessor(
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   295
            new AWTAccessor.InputEventAccessor() {
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   296
                public int[] getButtonDownMasks() {
6910
4acdf8b6df2f 6993984: PIT: b116 - Many of the swing test are failing on Solaris
lana
parents: 6825
diff changeset
   297
                    return InputEvent.getButtonDownMasks();
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   298
                }
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   299
            });
2
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
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
       accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Constructs an InputEvent object with the specified source component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * modifiers, and type.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   311
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param source the object where the event originated
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   316
     * @param id           the integer that identifies the event type.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   317
     *                     It is allowed to pass as parameter any value that
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   318
     *                     allowed for some subclass of {@code InputEvent} class.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   319
     *                     Passing in the value different from those values result
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   320
     *                     in unspecified behavior
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   321
     * @param when         a long int that gives the time the event occurred.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   322
     *                     Passing negative or zero value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   323
     *                     is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   324
     * @param modifiers    the modifier keys down during event (e.g. shift, ctrl,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   325
     *                     alt, meta)
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   326
     *                     Passing negative parameter is not recommended.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   327
     *                     Zero value means no modifiers.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   328
     *                     Either extended _DOWN_MASK or old _MASK modifiers
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   329
     *                     should be used, but both models should not be mixed
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   330
     *                     in one event. Use of the extended modifiers is
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   331
     *                     preferred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   333
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   334
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   335
     * @see #getWhen()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   336
     * @see #getModifiers()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    InputEvent(Component source, int id, long when, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        this.when = when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        canAccessSystemClipboard = canAccessSystemClipboard();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private boolean canAccessSystemClipboard() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        boolean b = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    sm.checkSystemClipboardAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    b = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                } catch (SecurityException se) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
   355
                    if (logger.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2810
diff changeset
   356
                        logger.fine("InputEvent.canAccessSystemClipboard() got SecurityException ", se);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                b = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * Returns whether or not the Shift modifier is down on this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public boolean isShiftDown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return (modifiers & SHIFT_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Returns whether or not the Control modifier is down on this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public boolean isControlDown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return (modifiers & CTRL_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Returns whether or not the Meta modifier is down on this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public boolean isMetaDown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return (modifiers & META_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Returns whether or not the Alt modifier is down on this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public boolean isAltDown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        return (modifiers & ALT_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Returns whether or not the AltGraph modifier is down on this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public boolean isAltGraphDown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return (modifiers & ALT_GRAPH_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   403
     * Returns the difference in milliseconds between the timestamp of when this event occurred and
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   404
     * midnight, January 1, 1970 UTC.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public long getWhen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Returns the modifier mask for this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return modifiers & (JDK_1_3_MODIFIERS | HIGH_MODIFIERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Returns the extended modifier mask for this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Extended modifiers represent the state of all modal keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * such as ALT, CTRL, META, and the mouse buttons just after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * the event occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * For example, if the user presses <b>button 1</b> followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * <b>button 2</b>, and then releases them in the same order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * the following sequence of events is generated:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *    <code>MOUSE_PRESSED</code>:  <code>BUTTON1_DOWN_MASK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *    <code>MOUSE_PRESSED</code>:  <code>BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *    <code>MOUSE_RELEASED</code>: <code>BUTTON2_DOWN_MASK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *    <code>MOUSE_CLICKED</code>:  <code>BUTTON2_DOWN_MASK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *    <code>MOUSE_RELEASED</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *    <code>MOUSE_CLICKED</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * It is not recommended to compare the return value of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * using <code>==</code> because new modifiers can be added in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * For example, the appropriate way to check that SHIFT and BUTTON1 are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * down, but CTRL is up is demonstrated by the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *    int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *    int offmask = CTRL_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *    if ((event.getModifiersEx() & (onmask | offmask)) == onmask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *        ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * The above code will work even if new modifiers are added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public int getModifiersEx() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return modifiers & ~JDK_1_3_MODIFIERS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Consumes this event so that it will not be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * in the default manner by the source which originated it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public void consume() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        consumed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Returns whether or not this event has been consumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see #consume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public boolean isConsumed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return consumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    // state serialization compatibility with JDK 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    static final long serialVersionUID = -2482525981698309786L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Returns a String describing the extended modifier keys and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * mouse buttons, such as "Shift", "Button1", or "Ctrl+Shift".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * These strings can be localized by changing the
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   477
     * <code>awt.properties</code> file.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   478
     * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   479
     * Note that passing negative parameter is incorrect,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   480
     * and will cause the returning an unspecified string.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   481
     * Zero parameter means that no modifiers were passed and will
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   482
     * cause the returning an empty string.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param modifiers a modifier mask describing the extended
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   485
     *                modifier keys and mouse buttons for the event
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @return a text description of the combination of extended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *         modifier keys and mouse buttons that were held down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *         during the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public static String getModifiersExText(int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   513
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   514
        int buttonNumber = 1;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   515
        for (int mask : InputEvent.BUTTON_DOWN_MASK){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   516
            if ((modifiers & mask) != 0) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   517
                buf.append(Toolkit.getProperty("AWT.button"+buttonNumber, "Button"+buttonNumber));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   518
                buf.append("+");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   519
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 715
diff changeset
   520
            buttonNumber++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (buf.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            buf.setLength(buf.length()-1); // remove trailing '+'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
}