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