jdk/src/share/classes/java/awt/event/MouseEvent.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 440 a3dac373f62d
child 1962 6c293d33645b
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
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.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.IllegalComponentStateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * An event which indicates that a mouse action occurred in a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * A mouse action is considered to occur in a particular component if and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * if the mouse cursor is over the unobscured part of the component's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * when the action happens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * For lightweight components, such as Swing's components, mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * are only dispatched to the component if the mouse event type has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * enabled on the component. A mouse event type is enabled by adding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * appropriate mouse-based {@code EventListener} to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * ({@link MouseListener} or {@link MouseMotionListener}), or by invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@link Component#enableEvents(long)} with the appropriate mask parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * ({@code AWTEvent.MOUSE_EVENT_MASK} or {@code AWTEvent.MOUSE_MOTION_EVENT_MASK}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * If the mouse event type has not been enabled on the component, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * corresponding mouse events are dispatched to the first ancestor that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * has enabled the mouse event type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * For example, if a {@code MouseListener} has been added to a component, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * {@code enableEvents(AWTEvent.MOUSE_EVENT_MASK)} has been invoked, then all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * the events defined by {@code MouseListener} are dispatched to the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * On the other hand, if a {@code MouseMotionListener} has not been added and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * {@code enableEvents} has not been invoked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * {@code AWTEvent.MOUSE_MOTION_EVENT_MASK}, then mouse motion events are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * dispatched to the component. Instead the mouse motion events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * dispatched to the first ancestors that has enabled mouse motion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * This low-level event is generated by a component object for:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <li>Mouse Events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *     <li>a mouse button is pressed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *     <li>a mouse button is released
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *     <li>a mouse button is clicked (pressed and released)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *     <li>the mouse cursor enters the unobscured part of component's geometry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *     <li>the mouse cursor exits the unobscured part of component's geometry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *     </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <li> Mouse Motion Events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *     <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *     <li>the mouse is moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *     <li>the mouse is dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *     </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * A <code>MouseEvent</code> object is passed to every
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <code>MouseListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * or <code>MouseAdapter</code> object which is registered to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the "interesting" mouse events using the component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <code>addMouseListener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * (<code>MouseAdapter</code> objects implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <code>MouseListener</code> interface.) Each such listener object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * gets a <code>MouseEvent</code> containing the mouse event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * A <code>MouseEvent</code> object is also passed to every
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>MouseMotionListener</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <code>MouseMotionAdapter</code> object which is registered to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * mouse motion events using the component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <code>addMouseMotionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * method. (<code>MouseMotionAdapter</code> objects implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <code>MouseMotionListener</code> interface.) Each such listener object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * gets a <code>MouseEvent</code> containing the mouse motion event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * When a mouse button is clicked, events are generated and sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * registered <code>MouseListener</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * The state of modal keys can be retrieved using {@link InputEvent#getModifiers}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * and {@link InputEvent#getModifiersEx}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * The button mask returned by {@link InputEvent#getModifiers} reflects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * only the button that changed state, not the current state of all buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * (Note: Due to overlap in the values of ALT_MASK/BUTTON2_MASK and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * META_MASK/BUTTON3_MASK, this is not always true for mouse events involving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * modifier keys).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * To get the state of all buttons and modifier keys, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * {@link InputEvent#getModifiersEx}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * The button which has changed state is returned by {@link MouseEvent#getButton}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * For example, if the first mouse button is pressed, events are sent in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * following order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *    <b   >id           </b   >   <b   >modifiers   </b   > <b   >button </b   >
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *    <code>MOUSE_PRESSED</code>:  <code>BUTTON1_MASK</code> <code>BUTTON1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *    <code>MOUSE_RELEASED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *    <code>MOUSE_CLICKED</code>:  <code>BUTTON1_MASK</code> <code>BUTTON1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * When multiple mouse buttons are pressed, each press, release, and click
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * results in a separate event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * For example, if the user presses <b>button 1</b> followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <b>button 2</b>, and then releases them in the same order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * the following sequence of events is generated:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *    <b   >id           </b   >   <b   >modifiers   </b   > <b   >button </b   >
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *    <code>MOUSE_PRESSED</code>:  <code>BUTTON1_MASK</code> <code>BUTTON1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *    <code>MOUSE_PRESSED</code>:  <code>BUTTON2_MASK</code> <code>BUTTON2</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *    <code>MOUSE_RELEASED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *    <code>MOUSE_CLICKED</code>:  <code>BUTTON1_MASK</code> <code>BUTTON1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *    <code>MOUSE_RELEASED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *    <code>MOUSE_CLICKED</code>:  <code>BUTTON2_MASK</code> <code>BUTTON2</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * If <b>button 2</b> is released first, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <code>MOUSE_RELEASED</code>/<code>MOUSE_CLICKED</code> pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * for <code>BUTTON2_MASK</code> arrives first,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * followed by the pair for <code>BUTTON1_MASK</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <code>MOUSE_DRAGGED</code> events are delivered to the <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * in which the mouse button was pressed until the mouse button is released
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * (regardless of whether the mouse position is within the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <code>Component</code>).  Due to platform-dependent Drag&Drop implementations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <code>MOUSE_DRAGGED</code> events may not be delivered during a native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * Drag&Drop operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * In a multi-screen environment mouse drag events are delivered to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <code>Component</code> even if the mouse position is outside the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <code>GraphicsConfiguration</code> associated with that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <code>Component</code>. However, the reported position for mouse drag events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * in this case may differ from the actual mouse position:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <li>In a multi-screen environment without a virtual device:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * The reported coordinates for mouse drag events are clipped to fit within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * bounds of the <code>GraphicsConfiguration</code> associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <li>In a multi-screen environment with a virtual device:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * The reported coordinates for mouse drag events are clipped to fit within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * bounds of the virtual device associated with the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * </ul>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   162
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   163
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   164
 * of any particular {@code MouseEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   165
 * in the range from {@code MOUSE_FIRST} to {@code MOUSE_LAST}-1
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   166
 * ({@code MOUSE_WHEEL} is not acceptable).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * @see MouseAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * @see MouseListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * @see MouseMotionAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * @see MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * @see MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/mouselistener.html">Tutorial: Writing a Mouse Listener</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/mousemotionlistener.html">Tutorial: Writing a Mouse Motion Listener</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
public class MouseEvent extends InputEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * The first number in the range of ids used for mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public static final int MOUSE_FIRST         = 500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * The last number in the range of ids used for mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static final int MOUSE_LAST          = 507;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * The "mouse clicked" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * occurs when a mouse button is pressed and released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public static final int MOUSE_CLICKED = MOUSE_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * The "mouse pressed" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * occurs when a mouse button is pushed down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static final int MOUSE_PRESSED = 1 + MOUSE_FIRST; //Event.MOUSE_DOWN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * The "mouse released" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * occurs when a mouse button is let up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final int MOUSE_RELEASED = 2 + MOUSE_FIRST; //Event.MOUSE_UP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * The "mouse moved" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * occurs when the mouse position changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public static final int MOUSE_MOVED = 3 + MOUSE_FIRST; //Event.MOUSE_MOVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * The "mouse entered" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * occurs when the mouse cursor enters the unobscured part of component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public static final int MOUSE_ENTERED = 4 + MOUSE_FIRST; //Event.MOUSE_ENTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * The "mouse exited" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * occurs when the mouse cursor exits the unobscured part of component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public static final int MOUSE_EXITED = 5 + MOUSE_FIRST; //Event.MOUSE_EXIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * The "mouse dragged" event. This <code>MouseEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * occurs when the mouse position changes while a mouse button is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public static final int MOUSE_DRAGGED = 6 + MOUSE_FIRST; //Event.MOUSE_DRAG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * The "mouse wheel" event.  This is the only <code>MouseWheelEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * It occurs when a mouse equipped with a wheel has its wheel rotated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public static final int MOUSE_WHEEL = 7 + MOUSE_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Indicates no mouse buttons; used by {@link #getButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public static final int NOBUTTON = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Indicates mouse button #1; used by {@link #getButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public static final int BUTTON1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Indicates mouse button #2; used by {@link #getButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public static final int BUTTON2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Indicates mouse button #3; used by {@link #getButton}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public static final int BUTTON3 = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * The mouse event's x coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * The x value is relative to the component that fired the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see #getX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * The mouse event's y coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * The y value is relative to the component that fired the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see #getY()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * The mouse event's x absolute coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * In a virtual device multi-screen environment in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * desktop area could span multiple physical screen devices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * this coordinate is relative to the virtual coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Otherwise, this coordinate is relative to the coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * associated with the Component's GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private int xAbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * The mouse event's y absolute coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * In a virtual device multi-screen environment in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * desktop area could span multiple physical screen devices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * this coordinate is relative to the virtual coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Otherwise, this coordinate is relative to the coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * associated with the Component's GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private int yAbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Indicates the number of quick consecutive clicks of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * a mouse button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * clickCount will be valid for only three mouse events :<BR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <code>MOUSE_CLICKED</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <code>MOUSE_PRESSED</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * <code>MOUSE_RELEASED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * For the above, the <code>clickCount</code> will be at least 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * For all other events the count will be 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #getClickCount().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    int clickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Indicates which, if any, of the mouse buttons has changed state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * The only legal values are the following constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <code>NOBUTTON</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <code>BUTTON1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <code>BUTTON2</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * <code>BUTTON3</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see #getButton().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    int button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * A property used to indicate whether a Popup Menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * should appear  with a certain gestures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * If <code>popupTrigger</code> = <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * no popup menu should appear.  If it is <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * then a popup menu should appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see java.awt.PopupMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see #isPopupTrigger()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    boolean popupTrigger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private static final long serialVersionUID = -991214153494842848L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        NativeLibLoader.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
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
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
       accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Returns the absolute x, y position of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * In a virtual device multi-screen environment in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * desktop area could span multiple physical screen devices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * these coordinates are relative to the virtual coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Otherwise, these coordinates are relative to the coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * associated with the Component's GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @return a <code>Point</code> object containing the absolute  x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *  and y coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @see java.awt.GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public Point getLocationOnScreen(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      return new Point(xAbs, yAbs);
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 the absolute horizontal x position of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * In a virtual device multi-screen environment in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * desktop area could span multiple physical screen devices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * this coordinate is relative to the virtual coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Otherwise, this coordinate is relative to the coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * associated with the Component's GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @return x  an integer indicating absolute horizontal position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see java.awt.GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public int getXOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return xAbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Returns the absolute vertical y position of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * In a virtual device multi-screen environment in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * desktop area could span multiple physical screen devices,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * this coordinate is relative to the virtual coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Otherwise, this coordinate is relative to the coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * associated with the Component's GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @return y  an integer indicating absolute vertical position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see java.awt.GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public int getYOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return yAbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Constructs a <code>MouseEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * specified source component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * type, modifiers, coordinates, and click count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * <p>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   426
     * Creating an invalid event (such
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * as by using more than one of the old _MASKs, or modifier/button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * values which don't match) results in unspecified behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * An invocation of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * <tt>MouseEvent(source, id, when, modifiers, x, y, clickCount, popupTrigger, button)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * <tt> {@link #MouseEvent(Component, int, long, int, int, int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * int, int, int, boolean, int) MouseEvent}(source, id, when, modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * x, y, xAbs, yAbs, clickCount, popupTrigger, button)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * where xAbs and yAbs defines as source's location on screen plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * relative coordinates x and y.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * xAbs and yAbs are set to zero if the source is not showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * This method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   442
     * @param source       The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   443
     * @param id              An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   444
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   445
     *                     the class description for {@link MouseEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   446
     * @param when         A long integer that gives the time the event occurred.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   447
     *                     Passing negative or zero value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   448
     *                     is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   449
     * @param modifiers    The modifier keys down during event (e.g. shift, ctrl,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *                     alt, meta)
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   451
     *                     Passing negative parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   452
     *                     is not recommended.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   453
     *                     Zero value means that no modifiers were passed.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   454
     *                     Use either an extended _DOWN_MASK or old _MASK modifiers,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   455
     *                     however do not mix models in the one event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   456
     *                     The extended modifiers are preferred for using
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   457
     * @param x            The horizontal x coordinate for the mouse location.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   458
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   459
     * @param y            The vertical y coordinate for the mouse location.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   460
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   461
     * @param clickCount   The number of mouse clicks associated with event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   462
     *                       Passing negative value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   463
     *                       is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   464
     * @param popupTrigger A boolean that equals {@code true} if this event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   465
     *                     is a trigger for a popup menu
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   466
     * @param button       An integer that indicates, which of the mouse buttons has
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   467
     *                     changed its state
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @throws IllegalArgumentException if an invalid <code>button</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *            value is passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   471
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   472
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   473
     * @see #getWhen()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   474
     * @see #getModifiers()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   475
     * @see #getX()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   476
     * @see #getY()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   477
     * @see #getClickCount()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   478
     * @see #isPopupTrigger()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   479
     * @see #getButton()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public MouseEvent(Component source, int id, long when, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                      int x, int y, int clickCount, boolean popupTrigger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                      int button)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        this(source, id, when, modifiers, x, y, 0, 0, clickCount, popupTrigger, button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        Point eventLocationOnScreen = new Point(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
          eventLocationOnScreen = source.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
          this.xAbs = eventLocationOnScreen.x + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
          this.yAbs = eventLocationOnScreen.y + y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        } catch (IllegalComponentStateException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
          this.xAbs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
          this.yAbs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Constructs a <code>MouseEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * specified source component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * type, modifiers, coordinates, and click count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * An invocation of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * <tt>MouseEvent(source, id, when, modifiers, x, y, clickCount, popupTrigger)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * <tt> {@link #MouseEvent(Component, int, long, int, int, int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * int, int, int, boolean, int) MouseEvent}(source, id, when, modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * x, y, xAbs, yAbs, clickCount, popupTrigger, MouseEvent.NOBUTTON)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * where xAbs and yAbs defines as source's location on screen plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * relative coordinates x and y.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * xAbs and yAbs are set to zero if the source is not showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * This method throws an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * if <code>source</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   514
     * @param source       The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   515
     * @param id              An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   516
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   517
     *                     the class description for {@link MouseEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   518
     * @param when         A long integer that gives the time the event occurred.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   519
     *                     Passing negative or zero value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   520
     *                     is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   521
     * @param modifiers    The modifier keys down during event (e.g. shift, ctrl,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *                     alt, meta)
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   523
     *                     Passing negative parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   524
     *                     is not recommended.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   525
     *                     Zero value means that no modifiers were passed.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   526
     *                     Use either an extended _DOWN_MASK or old _MASK modifiers,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   527
     *                     however do not mix models in the one event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   528
     *                     The extended modifiers are preferred for using
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   529
     * @param x            The horizontal x coordinate for the mouse location.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   530
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   531
     * @param y            The vertical y coordinate for the mouse location.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   532
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   533
     * @param clickCount   The number of mouse clicks associated with event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   534
     *                       Passing negative value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   535
     *                       is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   536
     * @param popupTrigger A boolean that equals {@code true} if this event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   537
     *                     is a trigger for a popup menu
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   539
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   540
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   541
     * @see #getWhen()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   542
     * @see #getModifiers()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   543
     * @see #getX()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   544
     * @see #getY()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   545
     * @see #getClickCount()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   546
     * @see #isPopupTrigger()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     public MouseEvent(Component source, int id, long when, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                      int x, int y, int clickCount, boolean popupTrigger) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        this(source, id, when, modifiers, x, y, clickCount, popupTrigger, NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Constructs a <code>MouseEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * specified source component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * type, modifiers, coordinates, absolute coordinates, and click count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <p>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   559
     * Creating an invalid event (such
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * as by using more than one of the old _MASKs, or modifier/button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * values which don't match) results in unspecified behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Even if inconsistent values for relative and absolute coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * passed to the constructor, the mouse event instance is still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * created and no exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * This method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   569
     * @param source       The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   570
     * @param id              An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   571
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   572
     *                     the class description for {@link MouseEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   573
     * @param when         A long integer that gives the time the event occurred.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   574
     *                     Passing negative or zero value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   575
     *                     is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   576
     * @param modifiers    The modifier keys down during event (e.g. shift, ctrl,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *                     alt, meta)
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   578
     *                     Passing negative parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   579
     *                     is not recommended.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   580
     *                     Zero value means that no modifiers were passed.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   581
     *                     Use either an extended _DOWN_MASK or old _MASK modifiers,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   582
     *                     however do not mix models in the one event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   583
     *                     The extended modifiers are preferred for using
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   584
     * @param x            The horizontal x coordinate for the mouse location.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   585
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   586
     * @param y            The vertical y coordinate for the mouse location.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   587
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   588
     * @param xAbs           The absolute horizontal x coordinate for the mouse location
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   589
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   590
     * @param yAbs           The absolute vertical y coordinate for the mouse location
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   591
     *                       It is allowed to pass negative values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   592
     * @param clickCount   The number of mouse clicks associated with event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   593
     *                       Passing negative value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   594
     *                       is not recommended
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   595
     * @param popupTrigger A boolean that equals {@code true} if this event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   596
     *                     is a trigger for a popup menu
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   597
     * @param button       An integer that indicates, which of the mouse buttons has
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   598
     *                     changed its state
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @throws IllegalArgumentException if an invalid <code>button</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *            value is passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   602
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   603
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   604
     * @see #getWhen()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   605
     * @see #getModifiers()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   606
     * @see #getX()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   607
     * @see #getY()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   608
     * @see #getXOnScreen()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   609
     * @see #getYOnScreen()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   610
     * @see #getClickCount()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   611
     * @see #isPopupTrigger()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   612
     * @see #getButton()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public MouseEvent(Component source, int id, long when, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                      int x, int y, int xAbs, int yAbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                      int clickCount, boolean popupTrigger, int button)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        super(source, id, when, modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        this.xAbs = xAbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        this.yAbs = yAbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        this.clickCount = clickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        this.popupTrigger = popupTrigger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        if (button < NOBUTTON || button >BUTTON3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            throw new IllegalArgumentException("Invalid button value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        this.button = button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            setNewModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        } else if ((getModifiers() == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                   (getModifiersEx() != 0 || button != NOBUTTON))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            setOldModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Returns the horizontal x position of the event relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * source component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @return x  an integer indicating horizontal position relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *            the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    public int getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Returns the vertical y position of the event relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * source component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return y  an integer indicating vertical position relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *            the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public int getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Returns the x,y position of the event relative to the source component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @return a <code>Point</code> object containing the x and y coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *         relative to the source component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public Point getPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            x = this.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            y = this.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return new Point(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Translates the event's coordinates to a new position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * by adding specified <code>x</code> (horizontal) and <code>y</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * (vertical) offsets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @param x the horizontal x value to add to the current x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *          coordinate position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @param y the vertical y value to add to the current y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                coordinate position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    public synchronized void translatePoint(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        this.x += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        this.y += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Returns the number of mouse clicks associated with this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @return integer value for the number of clicks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    public int getClickCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return clickCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Returns which, if any, of the mouse buttons has changed state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @return one of the following constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * <code>NOBUTTON</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * <code>BUTTON1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <code>BUTTON2</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * <code>BUTTON3</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    public int getButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Returns whether or not this mouse event is the popup menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * trigger event for the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * <p><b>Note</b>: Popup menus are triggered differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * on different systems. Therefore, <code>isPopupTrigger</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * should be checked in both <code>mousePressed</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * and <code>mouseReleased</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * for proper cross-platform functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @return boolean, true if this event is the popup menu trigger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *         for this platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    public boolean isPopupTrigger() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        return popupTrigger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /**
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   733
     * Returns a <code>String</code> instance describing the modifier keys and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * mouse buttons that were down during the event, such as "Shift",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * or "Ctrl+Shift". These strings can be localized by changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * the <code>awt.properties</code> file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <p>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   738
     * Note that the <code>InputEvent.ALT_MASK</code> and
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   739
     * <code>InputEvent.BUTTON2_MASK</code> have equal values,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   740
     * so the "Alt" string is returned for both modifiers.  Likewise,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   741
     * the <code>InputEvent.META_MASK</code> and
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   742
     * <code>InputEvent.BUTTON3_MASK</code> have equal values,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   743
     * so the "Meta" string is returned for both modifiers.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   744
     * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   745
     * Note that passing negative parameter is incorrect,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   746
     * and will cause the returning an unspecified string.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   747
     * Zero parameter means that no modifiers were passed and will
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   748
     * cause the returning an empty string.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   750
     * @param modifiers A modifier mask describing the modifier keys and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *                  mouse buttons that were down during the event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   752
     * @return string   string text description of the combination of modifier
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *                  keys and mouse buttons that were down during the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @see InputEvent#getModifiersExText(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public static String getMouseModifiersText(int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        if ((modifiers & InputEvent.ALT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if ((modifiers & InputEvent.META_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        if ((modifiers & InputEvent.CTRL_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            buf.append(Toolkit.getProperty("AWT.button2", "Button2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            buf.append(Toolkit.getProperty("AWT.button3", "Button3"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            buf.append("+");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (buf.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            buf.setLength(buf.length()-1); // remove trailing '+'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        StringBuilder str = new StringBuilder(80);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
          case MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
              str.append("MOUSE_PRESSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
          case MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
              str.append("MOUSE_RELEASED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
          case MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
              str.append("MOUSE_CLICKED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
          case MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
              str.append("MOUSE_ENTERED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
          case MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
              str.append("MOUSE_EXITED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
          case MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
              str.append("MOUSE_MOVED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
          case MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
              str.append("MOUSE_DRAGGED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
          case MOUSE_WHEEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
              str.append("MOUSE_WHEEL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
           default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
              str.append("unknown type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        // (x,y) coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        str.append(",(").append(x).append(",").append(y).append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        str.append(",absolute(").append(xAbs).append(",").append(yAbs).append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        str.append(",button=").append(getButton());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (getModifiers() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            str.append(",modifiers=").append(getMouseModifiersText(modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (getModifiersEx() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            str.append(",extModifiers=").append(getModifiersExText(modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        str.append(",clickCount=").append(clickCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        return str.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * Sets new modifiers by the old ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Also sets button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    private void setNewModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if ((modifiers & BUTTON1_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            modifiers |= BUTTON1_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if ((modifiers & BUTTON2_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            modifiers |= BUTTON2_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if ((modifiers & BUTTON3_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            modifiers |= BUTTON3_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (id == MOUSE_PRESSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            || id == MOUSE_RELEASED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            || id == MOUSE_CLICKED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if ((modifiers & BUTTON1_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                button = BUTTON1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                modifiers &= ~BUTTON2_MASK & ~BUTTON3_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                if (id != MOUSE_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    modifiers &= ~BUTTON1_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            } else if ((modifiers & BUTTON2_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                button = BUTTON2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                modifiers &= ~BUTTON1_MASK & ~BUTTON3_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                if (id != MOUSE_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    modifiers &= ~BUTTON2_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            } else if ((modifiers & BUTTON3_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                button = BUTTON3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                modifiers &= ~BUTTON1_MASK & ~BUTTON2_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                if (id != MOUSE_PRESSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                    modifiers &= ~BUTTON3_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        if ((modifiers & InputEvent.ALT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            modifiers |= InputEvent.ALT_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        if ((modifiers & InputEvent.META_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            modifiers |= InputEvent.META_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            modifiers |= InputEvent.SHIFT_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        if ((modifiers & InputEvent.CTRL_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            modifiers |= InputEvent.CTRL_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * Sets old modifiers by the new ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    private void setOldModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (id == MOUSE_PRESSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            || id == MOUSE_RELEASED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            || id == MOUSE_CLICKED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            switch(button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            case BUTTON1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                modifiers |= BUTTON1_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            case BUTTON2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                modifiers |= BUTTON2_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            case BUTTON3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                modifiers |= BUTTON3_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            if ((modifiers & BUTTON1_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                modifiers |= BUTTON1_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            if ((modifiers & BUTTON2_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                modifiers |= BUTTON2_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            if ((modifiers & BUTTON3_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                modifiers |= BUTTON3_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if ((modifiers & ALT_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            modifiers |= ALT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if ((modifiers & META_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            modifiers |= META_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        if ((modifiers & SHIFT_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            modifiers |= SHIFT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        if ((modifiers & CTRL_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            modifiers |= CTRL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            modifiers |= ALT_GRAPH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * Sets new modifiers by the old ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
      throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if (getModifiers() != 0 && getModifiersEx() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            setNewModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
}