0N/A/*
2362N/A * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.event;
0N/A
0N/Aimport java.awt.Component;
0N/Aimport java.awt.GraphicsEnvironment;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.io.IOException;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.awt.IllegalComponentStateException;
870N/Aimport java.awt.MouseInfo;
1224N/Aimport sun.awt.SunToolkit;
0N/A
0N/A/**
0N/A * An event which indicates that a mouse action occurred in a component.
0N/A * A mouse action is considered to occur in a particular component if and only
0N/A * if the mouse cursor is over the unobscured part of the component's bounds
0N/A * when the action happens.
0N/A * For lightweight components, such as Swing's components, mouse events
0N/A * are only dispatched to the component if the mouse event type has been
0N/A * enabled on the component. A mouse event type is enabled by adding the
0N/A * appropriate mouse-based {@code EventListener} to the component
0N/A * ({@link MouseListener} or {@link MouseMotionListener}), or by invoking
0N/A * {@link Component#enableEvents(long)} with the appropriate mask parameter
0N/A * ({@code AWTEvent.MOUSE_EVENT_MASK} or {@code AWTEvent.MOUSE_MOTION_EVENT_MASK}).
0N/A * If the mouse event type has not been enabled on the component, the
0N/A * corresponding mouse events are dispatched to the first ancestor that
0N/A * has enabled the mouse event type.
0N/A *<p>
0N/A * For example, if a {@code MouseListener} has been added to a component, or
0N/A * {@code enableEvents(AWTEvent.MOUSE_EVENT_MASK)} has been invoked, then all
0N/A * the events defined by {@code MouseListener} are dispatched to the component.
0N/A * On the other hand, if a {@code MouseMotionListener} has not been added and
0N/A * {@code enableEvents} has not been invoked with
0N/A * {@code AWTEvent.MOUSE_MOTION_EVENT_MASK}, then mouse motion events are not
0N/A * dispatched to the component. Instead the mouse motion events are
0N/A * dispatched to the first ancestors that has enabled mouse motion
0N/A * events.
0N/A * <P>
0N/A * This low-level event is generated by a component object for:
0N/A * <ul>
0N/A * <li>Mouse Events
0N/A * <ul>
0N/A * <li>a mouse button is pressed
0N/A * <li>a mouse button is released
0N/A * <li>a mouse button is clicked (pressed and released)
0N/A * <li>the mouse cursor enters the unobscured part of component's geometry
0N/A * <li>the mouse cursor exits the unobscured part of component's geometry
0N/A * </ul>
0N/A * <li> Mouse Motion Events
0N/A * <ul>
0N/A * <li>the mouse is moved
0N/A * <li>the mouse is dragged
0N/A * </ul>
0N/A * </ul>
0N/A * <P>
0N/A * A <code>MouseEvent</code> object is passed to every
0N/A * <code>MouseListener</code>
0N/A * or <code>MouseAdapter</code> object which is registered to receive
0N/A * the "interesting" mouse events using the component's
0N/A * <code>addMouseListener</code> method.
0N/A * (<code>MouseAdapter</code> objects implement the
0N/A * <code>MouseListener</code> interface.) Each such listener object
0N/A * gets a <code>MouseEvent</code> containing the mouse event.
0N/A * <P>
0N/A * A <code>MouseEvent</code> object is also passed to every
0N/A * <code>MouseMotionListener</code> or
0N/A * <code>MouseMotionAdapter</code> object which is registered to receive
0N/A * mouse motion events using the component's
0N/A * <code>addMouseMotionListener</code>
0N/A * method. (<code>MouseMotionAdapter</code> objects implement the
0N/A * <code>MouseMotionListener</code> interface.) Each such listener object
0N/A * gets a <code>MouseEvent</code> containing the mouse motion event.
0N/A * <P>
0N/A * When a mouse button is clicked, events are generated and sent to the
0N/A * registered <code>MouseListener</code>s.
0N/A * The state of modal keys can be retrieved using {@link InputEvent#getModifiers}
0N/A * and {@link InputEvent#getModifiersEx}.
0N/A * The button mask returned by {@link InputEvent#getModifiers} reflects
0N/A * only the button that changed state, not the current state of all buttons.
0N/A * (Note: Due to overlap in the values of ALT_MASK/BUTTON2_MASK and
0N/A * META_MASK/BUTTON3_MASK, this is not always true for mouse events involving
0N/A * modifier keys).
0N/A * To get the state of all buttons and modifier keys, use
0N/A * {@link InputEvent#getModifiersEx}.
0N/A * The button which has changed state is returned by {@link MouseEvent#getButton}
0N/A * <P>
0N/A * For example, if the first mouse button is pressed, events are sent in the
0N/A * following order:
0N/A * <PRE>
0N/A * <b >id </b > <b >modifiers </b > <b >button </b >
0N/A * <code>MOUSE_PRESSED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
0N/A * <code>MOUSE_RELEASED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
0N/A * <code>MOUSE_CLICKED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
0N/A * </PRE>
0N/A * When multiple mouse buttons are pressed, each press, release, and click
0N/A * results in a separate event.
0N/A * <P>
0N/A * For example, if the user presses <b>button 1</b> followed by
0N/A * <b>button 2</b>, and then releases them in the same order,
0N/A * the following sequence of events is generated:
0N/A * <PRE>
0N/A * <b >id </b > <b >modifiers </b > <b >button </b >
0N/A * <code>MOUSE_PRESSED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
0N/A * <code>MOUSE_PRESSED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
0N/A * <code>MOUSE_RELEASED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
0N/A * <code>MOUSE_CLICKED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
0N/A * <code>MOUSE_RELEASED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
0N/A * <code>MOUSE_CLICKED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
0N/A * </PRE>
0N/A * If <b>button 2</b> is released first, the
0N/A * <code>MOUSE_RELEASED</code>/<code>MOUSE_CLICKED</code> pair
0N/A * for <code>BUTTON2_MASK</code> arrives first,
0N/A * followed by the pair for <code>BUTTON1_MASK</code>.
0N/A * <p>
870N/A * Some extra mouse buttons are added to extend the standard set of buttons
870N/A * represented by the following constants:{@code BUTTON1}, {@code BUTTON2}, and {@code BUTTON3}.
870N/A * Extra buttons have no assigned {@code BUTTONx}
870N/A * constants as well as their button masks have no assigned {@code BUTTONx_DOWN_MASK}
870N/A * constants. Nevertheless, ordinal numbers starting from 4 may be
870N/A * used as button numbers (button ids). Values obtained by the
870N/A * {@link InputEvent#getMaskForButton(int) getMaskForButton(button)} method may be used
870N/A * as button masks.
870N/A * <p>
0N/A * <code>MOUSE_DRAGGED</code> events are delivered to the <code>Component</code>
0N/A * in which the mouse button was pressed until the mouse button is released
0N/A * (regardless of whether the mouse position is within the bounds of the
0N/A * <code>Component</code>). Due to platform-dependent Drag&Drop implementations,
0N/A * <code>MOUSE_DRAGGED</code> events may not be delivered during a native
0N/A * Drag&Drop operation.
0N/A *
0N/A * In a multi-screen environment mouse drag events are delivered to the
0N/A * <code>Component</code> even if the mouse position is outside the bounds of the
0N/A * <code>GraphicsConfiguration</code> associated with that
0N/A * <code>Component</code>. However, the reported position for mouse drag events
0N/A * in this case may differ from the actual mouse position:
0N/A * <ul>
0N/A * <li>In a multi-screen environment without a virtual device:
0N/A * <br>
0N/A * The reported coordinates for mouse drag events are clipped to fit within the
0N/A * bounds of the <code>GraphicsConfiguration</code> associated with
0N/A * the <code>Component</code>.
0N/A * <li>In a multi-screen environment with a virtual device:
0N/A * <br>
0N/A * The reported coordinates for mouse drag events are clipped to fit within the
0N/A * bounds of the virtual device associated with the <code>Component</code>.
0N/A * </ul>
217N/A * <p>
217N/A * An unspecified behavior will be caused if the {@code id} parameter
217N/A * of any particular {@code MouseEvent} instance is not
217N/A * in the range from {@code MOUSE_FIRST} to {@code MOUSE_LAST}-1
217N/A * ({@code MOUSE_WHEEL} is not acceptable).
0N/A *
0N/A * @author Carl Quinn
0N/A *
0N/A * @see MouseAdapter
0N/A * @see MouseListener
0N/A * @see MouseMotionAdapter
0N/A * @see MouseMotionListener
0N/A * @see MouseWheelListener
0N/A * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/mouselistener.html">Tutorial: Writing a Mouse Listener</a>
0N/A * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/mousemotionlistener.html">Tutorial: Writing a Mouse Motion Listener</a>
0N/A *
0N/A * @since 1.1
0N/A */
0N/Apublic class MouseEvent extends InputEvent {
0N/A
0N/A /**
0N/A * The first number in the range of ids used for mouse events.
0N/A */
0N/A public static final int MOUSE_FIRST = 500;
0N/A
0N/A /**
0N/A * The last number in the range of ids used for mouse events.
0N/A */
0N/A public static final int MOUSE_LAST = 507;
0N/A
0N/A /**
0N/A * The "mouse clicked" event. This <code>MouseEvent</code>
0N/A * occurs when a mouse button is pressed and released.
0N/A */
0N/A public static final int MOUSE_CLICKED = MOUSE_FIRST;
0N/A
0N/A /**
0N/A * The "mouse pressed" event. This <code>MouseEvent</code>
0N/A * occurs when a mouse button is pushed down.
0N/A */
0N/A public static final int MOUSE_PRESSED = 1 + MOUSE_FIRST; //Event.MOUSE_DOWN
0N/A
0N/A /**
0N/A * The "mouse released" event. This <code>MouseEvent</code>
0N/A * occurs when a mouse button is let up.
0N/A */
0N/A public static final int MOUSE_RELEASED = 2 + MOUSE_FIRST; //Event.MOUSE_UP
0N/A
0N/A /**
0N/A * The "mouse moved" event. This <code>MouseEvent</code>
0N/A * occurs when the mouse position changes.
0N/A */
0N/A public static final int MOUSE_MOVED = 3 + MOUSE_FIRST; //Event.MOUSE_MOVE
0N/A
0N/A /**
0N/A * The "mouse entered" event. This <code>MouseEvent</code>
0N/A * occurs when the mouse cursor enters the unobscured part of component's
0N/A * geometry.
0N/A */
0N/A public static final int MOUSE_ENTERED = 4 + MOUSE_FIRST; //Event.MOUSE_ENTER
0N/A
0N/A /**
0N/A * The "mouse exited" event. This <code>MouseEvent</code>
0N/A * occurs when the mouse cursor exits the unobscured part of component's
0N/A * geometry.
0N/A */
0N/A public static final int MOUSE_EXITED = 5 + MOUSE_FIRST; //Event.MOUSE_EXIT
0N/A
0N/A /**
0N/A * The "mouse dragged" event. This <code>MouseEvent</code>
0N/A * occurs when the mouse position changes while a mouse button is pressed.
0N/A */
0N/A public static final int MOUSE_DRAGGED = 6 + MOUSE_FIRST; //Event.MOUSE_DRAG
0N/A
0N/A /**
0N/A * The "mouse wheel" event. This is the only <code>MouseWheelEvent</code>.
0N/A * It occurs when a mouse equipped with a wheel has its wheel rotated.
0N/A * @since 1.4
0N/A */
0N/A public static final int MOUSE_WHEEL = 7 + MOUSE_FIRST;
0N/A
0N/A /**
0N/A * Indicates no mouse buttons; used by {@link #getButton}.
0N/A * @since 1.4
0N/A */
0N/A public static final int NOBUTTON = 0;
0N/A
0N/A /**
0N/A * Indicates mouse button #1; used by {@link #getButton}.
0N/A * @since 1.4
0N/A */
0N/A public static final int BUTTON1 = 1;
0N/A
0N/A /**
0N/A * Indicates mouse button #2; used by {@link #getButton}.
0N/A * @since 1.4
0N/A */
0N/A public static final int BUTTON2 = 2;
0N/A
0N/A /**
0N/A * Indicates mouse button #3; used by {@link #getButton}.
0N/A * @since 1.4
0N/A */
0N/A public static final int BUTTON3 = 3;
0N/A
0N/A /**
0N/A * The mouse event's x coordinate.
0N/A * The x value is relative to the component that fired the event.
0N/A *
0N/A * @serial
0N/A * @see #getX()
0N/A */
0N/A int x;
0N/A
0N/A /**
0N/A * The mouse event's y coordinate.
0N/A * The y value is relative to the component that fired the event.
0N/A *
0N/A * @serial
0N/A * @see #getY()
0N/A */
0N/A int y;
0N/A
0N/A /**
0N/A * The mouse event's x absolute coordinate.
0N/A * In a virtual device multi-screen environment in which the
0N/A * desktop area could span multiple physical screen devices,
0N/A * this coordinate is relative to the virtual coordinate system.
0N/A * Otherwise, this coordinate is relative to the coordinate system
0N/A * associated with the Component's GraphicsConfiguration.
0N/A *
0N/A * @serial
0N/A */
0N/A private int xAbs;
0N/A
0N/A /**
0N/A * The mouse event's y absolute coordinate.
0N/A * In a virtual device multi-screen environment in which the
0N/A * desktop area could span multiple physical screen devices,
0N/A * this coordinate is relative to the virtual coordinate system.
0N/A * Otherwise, this coordinate is relative to the coordinate system
0N/A * associated with the Component's GraphicsConfiguration.
0N/A *
0N/A * @serial
0N/A */
0N/A private int yAbs;
0N/A
0N/A /**
0N/A * Indicates the number of quick consecutive clicks of
0N/A * a mouse button.
0N/A * clickCount will be valid for only three mouse events :<BR>
0N/A * <code>MOUSE_CLICKED</code>,
0N/A * <code>MOUSE_PRESSED</code> and
0N/A * <code>MOUSE_RELEASED</code>.
0N/A * For the above, the <code>clickCount</code> will be at least 1.
0N/A * For all other events the count will be 0.
0N/A *
0N/A * @serial
0N/A * @see #getClickCount().
0N/A */
0N/A int clickCount;
0N/A
0N/A /**
0N/A * Indicates which, if any, of the mouse buttons has changed state.
0N/A *
870N/A * The valid values are ranged from 0 to the value returned by the
870N/A * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()} method.
870N/A * This range already includes constants {@code NOBUTTON}, {@code BUTTON1},
870N/A * {@code BUTTON2}, and {@code BUTTON3}
870N/A * if these buttons are present. So it is allowed to use these constants too.
870N/A * For example, for a mouse with two buttons this field may contain the following values:
870N/A * <ul>
870N/A * <li> 0 ({@code NOBUTTON})
870N/A * <li> 1 ({@code BUTTON1})
870N/A * <li> 2 ({@code BUTTON2})
870N/A * </ul>
870N/A * If a mouse has 5 buttons, this field may contain the following values:
870N/A * <ul>
870N/A * <li> 0 ({@code NOBUTTON})
870N/A * <li> 1 ({@code BUTTON1})
870N/A * <li> 2 ({@code BUTTON2})
870N/A * <li> 3 ({@code BUTTON3})
870N/A * <li> 4
870N/A * <li> 5
870N/A * </ul>
870N/A * If support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled()} disabled by Java
870N/A * then the field may not contain the value larger than {@code BUTTON3}.
0N/A * @serial
870N/A * @see #getButton()
870N/A * @see java.awt.Toolkit#areExtraMouseButtonsEnabled()
0N/A */
0N/A int button;
0N/A
0N/A /**
0N/A * A property used to indicate whether a Popup Menu
0N/A * should appear with a certain gestures.
0N/A * If <code>popupTrigger</code> = <code>false</code>,
0N/A * no popup menu should appear. If it is <code>true</code>
0N/A * then a popup menu should appear.
0N/A *
0N/A * @serial
0N/A * @see java.awt.PopupMenu
0N/A * @see #isPopupTrigger()
0N/A */
0N/A boolean popupTrigger = false;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -991214153494842848L;
0N/A
1224N/A /**
1224N/A * A number of buttons available on the mouse at the {@code Toolkit} machinery startup.
1224N/A */
1224N/A private static int cachedNumberOfButtons;
1224N/A
0N/A static {
0N/A /* ensure that the necessary native libraries are loaded */
0N/A NativeLibLoader.loadLibraries();
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
1224N/A final Toolkit tk = Toolkit.getDefaultToolkit();
1224N/A if (tk instanceof SunToolkit) {
1224N/A cachedNumberOfButtons = ((SunToolkit)tk).getNumberOfButtons();
1224N/A } else {
1224N/A //It's expected that some toolkits (Headless,
1224N/A //whatever besides SunToolkit) could also operate.
1224N/A cachedNumberOfButtons = 3;
1224N/A }
0N/A }
0N/A
0N/A /**
0N/A * Initialize JNI field and method IDs for fields that may be
0N/A accessed from C.
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A /**
0N/A * Returns the absolute x, y position of the event.
0N/A * In a virtual device multi-screen environment in which the
0N/A * desktop area could span multiple physical screen devices,
0N/A * these coordinates are relative to the virtual coordinate system.
0N/A * Otherwise, these coordinates are relative to the coordinate system
0N/A * associated with the Component's GraphicsConfiguration.
0N/A *
0N/A * @return a <code>Point</code> object containing the absolute x
0N/A * and y coordinates.
0N/A *
0N/A * @see java.awt.GraphicsConfiguration
0N/A * @since 1.6
0N/A */
0N/A public Point getLocationOnScreen(){
0N/A return new Point(xAbs, yAbs);
0N/A }
0N/A
0N/A /**
0N/A * Returns the absolute horizontal x position of the event.
0N/A * In a virtual device multi-screen environment in which the
0N/A * desktop area could span multiple physical screen devices,
0N/A * this coordinate is relative to the virtual coordinate system.
0N/A * Otherwise, this coordinate is relative to the coordinate system
0N/A * associated with the Component's GraphicsConfiguration.
0N/A *
0N/A * @return x an integer indicating absolute horizontal position.
0N/A *
0N/A * @see java.awt.GraphicsConfiguration
0N/A * @since 1.6
0N/A */
0N/A public int getXOnScreen() {
0N/A return xAbs;
0N/A }
0N/A
0N/A /**
0N/A * Returns the absolute vertical y position of the event.
0N/A * In a virtual device multi-screen environment in which the
0N/A * desktop area could span multiple physical screen devices,
0N/A * this coordinate is relative to the virtual coordinate system.
0N/A * Otherwise, this coordinate is relative to the coordinate system
0N/A * associated with the Component's GraphicsConfiguration.
0N/A *
0N/A * @return y an integer indicating absolute vertical position.
0N/A *
0N/A * @see java.awt.GraphicsConfiguration
0N/A * @since 1.6
0N/A */
0N/A public int getYOnScreen() {
0N/A return yAbs;
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>MouseEvent</code> object with the
0N/A * specified source component,
870N/A * type, time, modifiers, coordinates, click count, popupTrigger flag,
870N/A * and button number.
0N/A * <p>
217N/A * Creating an invalid event (such
0N/A * as by using more than one of the old _MASKs, or modifier/button
0N/A * values which don't match) results in unspecified behavior.
0N/A * An invocation of the form
0N/A * <tt>MouseEvent(source, id, when, modifiers, x, y, clickCount, popupTrigger, button)</tt>
0N/A * behaves in exactly the same way as the invocation
0N/A * <tt> {@link #MouseEvent(Component, int, long, int, int, int,
0N/A * int, int, int, boolean, int) MouseEvent}(source, id, when, modifiers,
0N/A * x, y, xAbs, yAbs, clickCount, popupTrigger, button)</tt>
0N/A * where xAbs and yAbs defines as source's location on screen plus
0N/A * relative coordinates x and y.
0N/A * xAbs and yAbs are set to zero if the source is not showing.
0N/A * This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A *
217N/A * @param source The <code>Component</code> that originated the event
217N/A * @param id An integer indicating the type of event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link MouseEvent}
217N/A * @param when A long integer that gives the time the event occurred.
217N/A * Passing negative or zero value
217N/A * is not recommended
217N/A * @param modifiers The modifier keys down during event (e.g. shift, ctrl,
0N/A * alt, meta)
217N/A * Passing negative parameter
217N/A * is not recommended.
217N/A * Zero value means that no modifiers were passed.
217N/A * Use either an extended _DOWN_MASK or old _MASK modifiers,
217N/A * however do not mix models in the one event.
217N/A * The extended modifiers are preferred for using
217N/A * @param x The horizontal x coordinate for the mouse location.
217N/A * It is allowed to pass negative values
217N/A * @param y The vertical y coordinate for the mouse location.
217N/A * It is allowed to pass negative values
217N/A * @param clickCount The number of mouse clicks associated with event.
217N/A * Passing negative value
217N/A * is not recommended
217N/A * @param popupTrigger A boolean that equals {@code true} if this event
217N/A * is a trigger for a popup menu
217N/A * @param button An integer that indicates, which of the mouse buttons has
870N/A * changed its state.
870N/A * The following rules are applied to this parameter:
870N/A * <ul>
870N/A * <li>If support for the extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
870N/A * then it is allowed to create {@code MouseEvent} objects only with the standard buttons:
870N/A * {@code NOBUTTON}, {@code BUTTON1}, {@code BUTTON2}, and
870N/A * {@code BUTTON3}.
870N/A * <li> If support for the extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
870N/A * then it is allowed to create {@code MouseEvent} objects with
870N/A * the standard buttons.
870N/A * In case the support for extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java, then
870N/A * in addition to the standard buttons, {@code MouseEvent} objects can be created
870N/A * using buttons from the range starting from 4 to
870N/A * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}
870N/A * if the mouse has more than three buttons.
870N/A * </ul>
870N/A * @throws IllegalArgumentException if {@code button} is less then zero
870N/A * @throws IllegalArgumentException if <code>source</code> is null
870N/A * @throws IllegalArgumentException if {@code button} is greater then BUTTON3 and the support for extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
870N/A * @throws IllegalArgumentException if {@code button} is greater then the
870N/A * {@link java.awt.MouseInfo#getNumberOfButtons() current number of buttons} and the support
870N/A * for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
870N/A * by Java
0N/A * @throws IllegalArgumentException if an invalid <code>button</code>
0N/A * value is passed in
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getWhen()
217N/A * @see #getModifiers()
217N/A * @see #getX()
217N/A * @see #getY()
217N/A * @see #getClickCount()
217N/A * @see #isPopupTrigger()
217N/A * @see #getButton()
0N/A * @since 1.4
0N/A */
0N/A public MouseEvent(Component source, int id, long when, int modifiers,
0N/A int x, int y, int clickCount, boolean popupTrigger,
0N/A int button)
0N/A {
0N/A this(source, id, when, modifiers, x, y, 0, 0, clickCount, popupTrigger, button);
0N/A Point eventLocationOnScreen = new Point(0, 0);
0N/A try {
0N/A eventLocationOnScreen = source.getLocationOnScreen();
0N/A this.xAbs = eventLocationOnScreen.x + x;
0N/A this.yAbs = eventLocationOnScreen.y + y;
0N/A } catch (IllegalComponentStateException e){
0N/A this.xAbs = 0;
0N/A this.yAbs = 0;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>MouseEvent</code> object with the
0N/A * specified source component,
870N/A * type, modifiers, coordinates, click count, and popupTrigger flag.
0N/A * An invocation of the form
0N/A * <tt>MouseEvent(source, id, when, modifiers, x, y, clickCount, popupTrigger)</tt>
0N/A * behaves in exactly the same way as the invocation
0N/A * <tt> {@link #MouseEvent(Component, int, long, int, int, int,
0N/A * int, int, int, boolean, int) MouseEvent}(source, id, when, modifiers,
0N/A * x, y, xAbs, yAbs, clickCount, popupTrigger, MouseEvent.NOBUTTON)</tt>
0N/A * where xAbs and yAbs defines as source's location on screen plus
0N/A * relative coordinates x and y.
0N/A * xAbs and yAbs are set to zero if the source is not showing.
0N/A * This method throws an <code>IllegalArgumentException</code>
0N/A * if <code>source</code> is <code>null</code>.
0N/A *
217N/A * @param source The <code>Component</code> that originated the event
217N/A * @param id An integer indicating the type of event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link MouseEvent}
217N/A * @param when A long integer that gives the time the event occurred.
217N/A * Passing negative or zero value
217N/A * is not recommended
217N/A * @param modifiers The modifier keys down during event (e.g. shift, ctrl,
0N/A * alt, meta)
217N/A * Passing negative parameter
217N/A * is not recommended.
217N/A * Zero value means that no modifiers were passed.
217N/A * Use either an extended _DOWN_MASK or old _MASK modifiers,
217N/A * however do not mix models in the one event.
217N/A * The extended modifiers are preferred for using
217N/A * @param x The horizontal x coordinate for the mouse location.
217N/A * It is allowed to pass negative values
217N/A * @param y The vertical y coordinate for the mouse location.
217N/A * It is allowed to pass negative values
217N/A * @param clickCount The number of mouse clicks associated with event.
217N/A * Passing negative value
217N/A * is not recommended
217N/A * @param popupTrigger A boolean that equals {@code true} if this event
217N/A * is a trigger for a popup menu
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getWhen()
217N/A * @see #getModifiers()
217N/A * @see #getX()
217N/A * @see #getY()
217N/A * @see #getClickCount()
217N/A * @see #isPopupTrigger()
0N/A */
0N/A public MouseEvent(Component source, int id, long when, int modifiers,
0N/A int x, int y, int clickCount, boolean popupTrigger) {
0N/A this(source, id, when, modifiers, x, y, clickCount, popupTrigger, NOBUTTON);
0N/A }
0N/A
0N/A
870N/A /* if the button is an extra button and it is released or clicked then in Xsystem its state
870N/A is not modified. Exclude this button number from ExtModifiers mask.*/
870N/A transient private boolean shouldExcludeButtonFromExtModifiers = false;
870N/A
870N/A /**
870N/A * {@inheritDoc}
870N/A */
870N/A public int getModifiersEx() {
870N/A int tmpModifiers = modifiers;
870N/A if (shouldExcludeButtonFromExtModifiers) {
870N/A tmpModifiers &= ~(InputEvent.getMaskForButton(getButton()));
870N/A }
870N/A return tmpModifiers & ~JDK_1_3_MODIFIERS;
870N/A }
870N/A
0N/A /**
0N/A * Constructs a <code>MouseEvent</code> object with the
0N/A * specified source component,
870N/A * type, time, modifiers, coordinates, absolute coordinates, click count, popupTrigger flag,
870N/A * and button number.
0N/A * <p>
217N/A * Creating an invalid event (such
0N/A * as by using more than one of the old _MASKs, or modifier/button
0N/A * values which don't match) results in unspecified behavior.
0N/A * Even if inconsistent values for relative and absolute coordinates are
0N/A * passed to the constructor, the mouse event instance is still
0N/A * created and no exception is thrown.
0N/A * This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A *
217N/A * @param source The <code>Component</code> that originated the event
217N/A * @param id An integer indicating the type of event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link MouseEvent}
217N/A * @param when A long integer that gives the time the event occurred.
217N/A * Passing negative or zero value
217N/A * is not recommended
217N/A * @param modifiers The modifier keys down during event (e.g. shift, ctrl,
0N/A * alt, meta)
217N/A * Passing negative parameter
217N/A * is not recommended.
217N/A * Zero value means that no modifiers were passed.
217N/A * Use either an extended _DOWN_MASK or old _MASK modifiers,
217N/A * however do not mix models in the one event.
217N/A * The extended modifiers are preferred for using
217N/A * @param x The horizontal x coordinate for the mouse location.
217N/A * It is allowed to pass negative values
217N/A * @param y The vertical y coordinate for the mouse location.
217N/A * It is allowed to pass negative values
217N/A * @param xAbs The absolute horizontal x coordinate for the mouse location
217N/A * It is allowed to pass negative values
217N/A * @param yAbs The absolute vertical y coordinate for the mouse location
217N/A * It is allowed to pass negative values
217N/A * @param clickCount The number of mouse clicks associated with event.
217N/A * Passing negative value
217N/A * is not recommended
217N/A * @param popupTrigger A boolean that equals {@code true} if this event
217N/A * is a trigger for a popup menu
217N/A * @param button An integer that indicates, which of the mouse buttons has
870N/A * changed its state.
870N/A * The following rules are applied to this parameter:
870N/A * <ul>
870N/A * <li>If support for the extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
870N/A * then it is allowed to create {@code MouseEvent} objects only with the standard buttons:
870N/A * {@code NOBUTTON}, {@code BUTTON1}, {@code BUTTON2}, and
870N/A * {@code BUTTON3}.
870N/A * <li> If support for the extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java
870N/A * then it is allowed to create {@code MouseEvent} objects with
870N/A * the standard buttons.
870N/A * In case the support for extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java, then
870N/A * in addition to the standard buttons, {@code MouseEvent} objects can be created
870N/A * using buttons from the range starting from 4 to
870N/A * {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}
870N/A * if the mouse has more than three buttons.
870N/A * </ul>
870N/A * @throws IllegalArgumentException if {@code button} is less then zero
870N/A * @throws IllegalArgumentException if <code>source</code> is null
870N/A * @throws IllegalArgumentException if {@code button} is greater then BUTTON3 and the support for extended mouse buttons is
870N/A * {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
870N/A * @throws IllegalArgumentException if {@code button} is greater then the
870N/A * {@link java.awt.MouseInfo#getNumberOfButtons() current number of buttons} and the support
870N/A * for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled}
870N/A * by Java
0N/A * @throws IllegalArgumentException if an invalid <code>button</code>
0N/A * value is passed in
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getWhen()
217N/A * @see #getModifiers()
217N/A * @see #getX()
217N/A * @see #getY()
217N/A * @see #getXOnScreen()
217N/A * @see #getYOnScreen()
217N/A * @see #getClickCount()
217N/A * @see #isPopupTrigger()
217N/A * @see #getButton()
870N/A * @see #button
870N/A * @see Toolkit#areExtraMouseButtonsEnabled()
870N/A * @see java.awt.MouseInfo#getNumberOfButtons()
870N/A * @see InputEvent#getMaskForButton(int)
0N/A * @since 1.6
0N/A */
0N/A public MouseEvent(Component source, int id, long when, int modifiers,
0N/A int x, int y, int xAbs, int yAbs,
0N/A int clickCount, boolean popupTrigger, int button)
0N/A {
0N/A super(source, id, when, modifiers);
0N/A this.x = x;
0N/A this.y = y;
0N/A this.xAbs = xAbs;
0N/A this.yAbs = yAbs;
0N/A this.clickCount = clickCount;
0N/A this.popupTrigger = popupTrigger;
870N/A if (button < NOBUTTON){
870N/A throw new IllegalArgumentException("Invalid button value :" + button);
0N/A }
870N/A if (button > BUTTON3) {
870N/A if (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
870N/A throw new IllegalArgumentException("Extra mouse events are disabled " + button);
870N/A } else {
870N/A if (button > cachedNumberOfButtons) {
870N/A throw new IllegalArgumentException("Nonexistent button " + button);
870N/A }
870N/A }
870N/A // XToolkit: extra buttons are not reporting about their state correctly.
870N/A // Being pressed they report the state=0 both on the press and on the release.
870N/A // For 1-3 buttons the state value equals zero on press and non-zero on release.
870N/A // Other modifiers like Shift, ALT etc seem report well with extra buttons.
870N/A // The problem reveals as follows: one button is pressed and then another button is pressed and released.
870N/A // So, the getModifiersEx() would not be zero due to a first button and we will skip this modifier.
870N/A // This may have to be moved into the peer code instead if possible.
870N/A
870N/A if (getModifiersEx() != 0) { //There is at least one more button in a pressed state.
870N/A if (id == MouseEvent.MOUSE_RELEASED || id == MouseEvent.MOUSE_CLICKED){
870N/A System.out.println("MEvent. CASE!");
870N/A shouldExcludeButtonFromExtModifiers = true;
870N/A }
870N/A }
870N/A }
870N/A
0N/A this.button = button;
870N/A
0N/A if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
0N/A setNewModifiers();
0N/A } else if ((getModifiers() == 0) &&
870N/A (getModifiersEx() != 0 || button != NOBUTTON) &&
870N/A (button <= BUTTON3))
0N/A {
0N/A setOldModifiers();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the horizontal x position of the event relative to the
0N/A * source component.
0N/A *
0N/A * @return x an integer indicating horizontal position relative to
0N/A * the component
0N/A */
0N/A public int getX() {
0N/A return x;
0N/A }
0N/A
0N/A /**
0N/A * Returns the vertical y position of the event relative to the
0N/A * source component.
0N/A *
0N/A * @return y an integer indicating vertical position relative to
0N/A * the component
0N/A */
0N/A public int getY() {
0N/A return y;
0N/A }
0N/A
0N/A /**
0N/A * Returns the x,y position of the event relative to the source component.
0N/A *
0N/A * @return a <code>Point</code> object containing the x and y coordinates
0N/A * relative to the source component
0N/A *
0N/A */
0N/A public Point getPoint() {
0N/A int x;
0N/A int y;
0N/A synchronized (this) {
0N/A x = this.x;
0N/A y = this.y;
0N/A }
0N/A return new Point(x, y);
0N/A }
0N/A
0N/A /**
0N/A * Translates the event's coordinates to a new position
0N/A * by adding specified <code>x</code> (horizontal) and <code>y</code>
0N/A * (vertical) offsets.
0N/A *
0N/A * @param x the horizontal x value to add to the current x
0N/A * coordinate position
0N/A * @param y the vertical y value to add to the current y
0N/A coordinate position
0N/A */
0N/A public synchronized void translatePoint(int x, int y) {
0N/A this.x += x;
0N/A this.y += y;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of mouse clicks associated with this event.
0N/A *
0N/A * @return integer value for the number of clicks
0N/A */
0N/A public int getClickCount() {
0N/A return clickCount;
0N/A }
0N/A
0N/A /**
0N/A * Returns which, if any, of the mouse buttons has changed state.
870N/A * The returned value is ranged
870N/A * from 0 to the {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}
870N/A * value.
870N/A * The returned value includes at least the following constants:
870N/A * <ul>
870N/A * <li> {@code NOBUTTON}
870N/A * <li> {@code BUTTON1}
870N/A * <li> {@code BUTTON2}
870N/A * <li> {@code BUTTON3}
870N/A * </ul>
870N/A * It is allowed to use those constants to compare with the returned button number in the application.
870N/A * For example,
870N/A * <pre>
870N/A * if (anEvent.getButton() == MouseEvent.BUTTON1) {
870N/A * </pre>
870N/A * In particular, for a mouse with one, two, or three buttons this method may return the following values:
870N/A * <ul>
870N/A * <li> 0 ({@code NOBUTTON})
870N/A * <li> 1 ({@code BUTTON1})
870N/A * <li> 2 ({@code BUTTON2})
870N/A * <li> 3 ({@code BUTTON3})
870N/A * </ul>
870N/A * Button numbers greater then {@code BUTTON3} have no constant identifier. So if a mouse with five buttons is
870N/A * installed, this method may return the following values:
870N/A * <ul>
870N/A * <li> 0 ({@code NOBUTTON})
870N/A * <li> 1 ({@code BUTTON1})
870N/A * <li> 2 ({@code BUTTON2})
870N/A * <li> 3 ({@code BUTTON3})
870N/A * <li> 4
870N/A * <li> 5
870N/A * </ul>
870N/A * <p>
870N/A * Note: If support for extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
870N/A * then the AWT event subsystem does not produce mouse events for the extended mouse
870N/A * buttons. So it is not expected that this method returns anything except {@code NOBUTTON}, {@code BUTTON1},
870N/A * {@code BUTTON2}, {@code BUTTON3}.
0N/A *
870N/A * @return one of the values from 0 to {@link java.awt.MouseInfo#getNumberOfButtons() MouseInfo.getNumberOfButtons()}
870N/A * if support for the extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() enabled} by Java.
870N/A * That range includes {@code NOBUTTON}, {@code BUTTON1}, {@code BUTTON2}, {@code BUTTON3};
870N/A * <br>
870N/A * {@code NOBUTTON}, {@code BUTTON1}, {@code BUTTON2} or {@code BUTTON3}
870N/A * if support for the extended mouse buttons is {@link Toolkit#areExtraMouseButtonsEnabled() disabled} by Java
0N/A * @since 1.4
870N/A * @see Toolkit#areExtraMouseButtonsEnabled()
870N/A * @see java.awt.MouseInfo#getNumberOfButtons()
870N/A * @see #MouseEvent(Component, int, long, int, int, int, int, int, int, boolean, int)
870N/A * @see InputEvent#getMaskForButton(int)
0N/A */
0N/A public int getButton() {
0N/A return button;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether or not this mouse event is the popup menu
0N/A * trigger event for the platform.
0N/A * <p><b>Note</b>: Popup menus are triggered differently
0N/A * on different systems. Therefore, <code>isPopupTrigger</code>
0N/A * should be checked in both <code>mousePressed</code>
0N/A * and <code>mouseReleased</code>
0N/A * for proper cross-platform functionality.
0N/A *
0N/A * @return boolean, true if this event is the popup menu trigger
0N/A * for this platform
0N/A */
0N/A public boolean isPopupTrigger() {
0N/A return popupTrigger;
0N/A }
0N/A
0N/A /**
217N/A * Returns a <code>String</code> instance describing the modifier keys and
0N/A * mouse buttons that were down during the event, such as "Shift",
0N/A * or "Ctrl+Shift". These strings can be localized by changing
0N/A * the <code>awt.properties</code> file.
0N/A * <p>
217N/A * Note that the <code>InputEvent.ALT_MASK</code> and
217N/A * <code>InputEvent.BUTTON2_MASK</code> have equal values,
217N/A * so the "Alt" string is returned for both modifiers. Likewise,
217N/A * the <code>InputEvent.META_MASK</code> and
217N/A * <code>InputEvent.BUTTON3_MASK</code> have equal values,
217N/A * so the "Meta" string is returned for both modifiers.
217N/A * <p>
217N/A * Note that passing negative parameter is incorrect,
217N/A * and will cause the returning an unspecified string.
217N/A * Zero parameter means that no modifiers were passed and will
217N/A * cause the returning an empty string.
870N/A * <p>
217N/A * @param modifiers A modifier mask describing the modifier keys and
0N/A * mouse buttons that were down during the event
217N/A * @return string string text description of the combination of modifier
0N/A * keys and mouse buttons that were down during the event
0N/A * @see InputEvent#getModifiersExText(int)
0N/A * @since 1.4
0N/A */
0N/A public static String getMouseModifiersText(int modifiers) {
0N/A StringBuilder buf = new StringBuilder();
0N/A if ((modifiers & InputEvent.ALT_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.META_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.CTRL_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.button2", "Button2"));
0N/A buf.append("+");
0N/A }
0N/A if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
0N/A buf.append(Toolkit.getProperty("AWT.button3", "Button3"));
0N/A buf.append("+");
0N/A }
870N/A
870N/A int mask;
870N/A
870N/A // TODO: add a toolkit field that holds a number of button on the mouse.
870N/A // As the method getMouseModifiersText() is static and obtain
870N/A // an integer as a parameter then we may not restrict this with the number
870N/A // of buttons installed on the mouse.
870N/A // It's a temporary solution. We need to somehow hold the number of buttons somewhere else.
870N/A for (int i = 1; i <= cachedNumberOfButtons; i++){
870N/A mask = InputEvent.getMaskForButton(i);
870N/A if ((modifiers & mask) != 0 &&
870N/A buf.indexOf(Toolkit.getProperty("AWT.button"+i, "Button"+i)) == -1) //1,2,3 buttons may already be there; so don't duplicate it.
870N/A {
870N/A buf.append(Toolkit.getProperty("AWT.button"+i, "Button"+i));
870N/A buf.append("+");
870N/A }
870N/A }
870N/A
0N/A if (buf.length() > 0) {
0N/A buf.setLength(buf.length()-1); // remove trailing '+'
0N/A }
0N/A return buf.toString();
0N/A }
0N/A
0N/A /**
0N/A * Returns a parameter string identifying this event.
0N/A * This method is useful for event-logging and for debugging.
0N/A *
0N/A * @return a string identifying the event and its attributes
0N/A */
0N/A public String paramString() {
0N/A StringBuilder str = new StringBuilder(80);
0N/A
0N/A switch(id) {
0N/A case MOUSE_PRESSED:
0N/A str.append("MOUSE_PRESSED");
0N/A break;
0N/A case MOUSE_RELEASED:
0N/A str.append("MOUSE_RELEASED");
0N/A break;
0N/A case MOUSE_CLICKED:
0N/A str.append("MOUSE_CLICKED");
0N/A break;
0N/A case MOUSE_ENTERED:
0N/A str.append("MOUSE_ENTERED");
0N/A break;
0N/A case MOUSE_EXITED:
0N/A str.append("MOUSE_EXITED");
0N/A break;
0N/A case MOUSE_MOVED:
0N/A str.append("MOUSE_MOVED");
0N/A break;
0N/A case MOUSE_DRAGGED:
0N/A str.append("MOUSE_DRAGGED");
0N/A break;
0N/A case MOUSE_WHEEL:
0N/A str.append("MOUSE_WHEEL");
0N/A break;
0N/A default:
0N/A str.append("unknown type");
0N/A }
0N/A
0N/A // (x,y) coordinates
0N/A str.append(",(").append(x).append(",").append(y).append(")");
0N/A str.append(",absolute(").append(xAbs).append(",").append(yAbs).append(")");
0N/A
870N/A if (id != MOUSE_DRAGGED && id != MOUSE_MOVED){
870N/A str.append(",button=").append(getButton());
870N/A }
0N/A
0N/A if (getModifiers() != 0) {
0N/A str.append(",modifiers=").append(getMouseModifiersText(modifiers));
0N/A }
0N/A
0N/A if (getModifiersEx() != 0) {
870N/A //Using plain "modifiers" here does show an excluded extended buttons in the string event representation.
870N/A //getModifiersEx() solves the problem.
870N/A str.append(",extModifiers=").append(getModifiersExText(getModifiersEx()));
0N/A }
0N/A
0N/A str.append(",clickCount=").append(clickCount);
0N/A
0N/A return str.toString();
0N/A }
0N/A
0N/A /**
0N/A * Sets new modifiers by the old ones.
0N/A * Also sets button.
0N/A */
0N/A private void setNewModifiers() {
0N/A if ((modifiers & BUTTON1_MASK) != 0) {
0N/A modifiers |= BUTTON1_DOWN_MASK;
0N/A }
0N/A if ((modifiers & BUTTON2_MASK) != 0) {
0N/A modifiers |= BUTTON2_DOWN_MASK;
0N/A }
0N/A if ((modifiers & BUTTON3_MASK) != 0) {
0N/A modifiers |= BUTTON3_DOWN_MASK;
0N/A }
0N/A if (id == MOUSE_PRESSED
0N/A || id == MOUSE_RELEASED
0N/A || id == MOUSE_CLICKED)
0N/A {
0N/A if ((modifiers & BUTTON1_MASK) != 0) {
0N/A button = BUTTON1;
0N/A modifiers &= ~BUTTON2_MASK & ~BUTTON3_MASK;
0N/A if (id != MOUSE_PRESSED) {
0N/A modifiers &= ~BUTTON1_DOWN_MASK;
0N/A }
0N/A } else if ((modifiers & BUTTON2_MASK) != 0) {
0N/A button = BUTTON2;
0N/A modifiers &= ~BUTTON1_MASK & ~BUTTON3_MASK;
0N/A if (id != MOUSE_PRESSED) {
0N/A modifiers &= ~BUTTON2_DOWN_MASK;
0N/A }
0N/A } else if ((modifiers & BUTTON3_MASK) != 0) {
0N/A button = BUTTON3;
0N/A modifiers &= ~BUTTON1_MASK & ~BUTTON2_MASK;
0N/A if (id != MOUSE_PRESSED) {
0N/A modifiers &= ~BUTTON3_DOWN_MASK;
0N/A }
0N/A }
0N/A }
0N/A if ((modifiers & InputEvent.ALT_MASK) != 0) {
0N/A modifiers |= InputEvent.ALT_DOWN_MASK;
0N/A }
0N/A if ((modifiers & InputEvent.META_MASK) != 0) {
0N/A modifiers |= InputEvent.META_DOWN_MASK;
0N/A }
0N/A if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
0N/A modifiers |= InputEvent.SHIFT_DOWN_MASK;
0N/A }
0N/A if ((modifiers & InputEvent.CTRL_MASK) != 0) {
0N/A modifiers |= InputEvent.CTRL_DOWN_MASK;
0N/A }
0N/A if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
0N/A modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets old modifiers by the new ones.
0N/A */
0N/A private void setOldModifiers() {
0N/A if (id == MOUSE_PRESSED
0N/A || id == MOUSE_RELEASED
0N/A || id == MOUSE_CLICKED)
0N/A {
0N/A switch(button) {
0N/A case BUTTON1:
0N/A modifiers |= BUTTON1_MASK;
0N/A break;
0N/A case BUTTON2:
0N/A modifiers |= BUTTON2_MASK;
0N/A break;
0N/A case BUTTON3:
0N/A modifiers |= BUTTON3_MASK;
0N/A break;
0N/A }
0N/A } else {
0N/A if ((modifiers & BUTTON1_DOWN_MASK) != 0) {
0N/A modifiers |= BUTTON1_MASK;
0N/A }
0N/A if ((modifiers & BUTTON2_DOWN_MASK) != 0) {
0N/A modifiers |= BUTTON2_MASK;
0N/A }
0N/A if ((modifiers & BUTTON3_DOWN_MASK) != 0) {
0N/A modifiers |= BUTTON3_MASK;
0N/A }
0N/A }
0N/A if ((modifiers & ALT_DOWN_MASK) != 0) {
0N/A modifiers |= ALT_MASK;
0N/A }
0N/A if ((modifiers & META_DOWN_MASK) != 0) {
0N/A modifiers |= META_MASK;
0N/A }
0N/A if ((modifiers & SHIFT_DOWN_MASK) != 0) {
0N/A modifiers |= SHIFT_MASK;
0N/A }
0N/A if ((modifiers & CTRL_DOWN_MASK) != 0) {
0N/A modifiers |= CTRL_MASK;
0N/A }
0N/A if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) {
0N/A modifiers |= ALT_GRAPH_MASK;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets new modifiers by the old ones.
0N/A * @serial
0N/A */
0N/A private void readObject(ObjectInputStream s)
0N/A throws IOException, ClassNotFoundException {
0N/A s.defaultReadObject();
0N/A if (getModifiers() != 0 && getModifiersEx() == 0) {
0N/A setNewModifiers();
0N/A }
0N/A }
0N/A}