jdk/src/share/classes/java/awt/event/MouseWheelEvent.java
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 12813 c10ab96dcf41
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    30
import java.lang.annotation.Native;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    31
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * An event which indicates that the mouse wheel was rotated in a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A wheel mouse is a mouse which has a wheel in place of the middle button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This wheel can be rotated towards or away from the user.  Mouse wheels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * most often used for scrolling, though other uses are possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A MouseWheelEvent object is passed to every <code>MouseWheelListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * object which registered to receive the "interesting" mouse events using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * component's <code>addMouseWheelListener</code> method.  Each such listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * object gets a <code>MouseEvent</code> containing the mouse event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Due to the mouse wheel's special relationship to scrolling Components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * MouseWheelEvents are delivered somewhat differently than other MouseEvents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This is because while other MouseEvents usually affect a change on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the Component directly under the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * cursor (for instance, when clicking a button), MouseWheelEvents often have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * an effect away from the mouse cursor (moving the wheel while
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * over a Component inside a ScrollPane should scroll one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Scrollbars on the ScrollPane).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * MouseWheelEvents start delivery from the Component underneath the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * mouse cursor.  If MouseWheelEvents are not enabled on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Component, the event is delivered to the first ancestor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Container with MouseWheelEvents enabled.  This will usually be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * a ScrollPane with wheel scrolling enabled.  The source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Component and x,y coordinates will be relative to the event's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * final destination (the ScrollPane).  This allows a complex
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * GUI to be installed without modification into a ScrollPane, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * for all MouseWheelEvents to be delivered to the ScrollPane for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Some AWT Components are implemented using native widgets which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * display their own scrollbars and handle their own scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * The particular Components for which this is true will vary from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * platform to platform.  When the mouse wheel is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * moved over one of these Components, the event is delivered straight to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the native widget, and not propagated to ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Platforms offer customization of the amount of scrolling that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * should take place when the mouse wheel is moved.  The two most
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * common settings are to scroll a certain number of "units"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * (commonly lines of text in a text-based component) or an entire "block"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * (similar to page-up/page-down).  The MouseWheelEvent offers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * methods for conforming to the underlying platform settings.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * platform settings can be changed at any time by the user.  MouseWheelEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * reflect the most recent settings.
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    79
 * <P>
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    80
 * The <code>MouseWheelEvent</code> class includes methods for
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    81
 * getting the number of "clicks" by which the mouse wheel is rotated.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    82
 * The {@link #getWheelRotation} method returns the integer number
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    83
 * of "clicks" corresponding to the number of notches by which the wheel was
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    84
 * rotated. In addition to this method, the <code>MouseWheelEvent</code>
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    85
 * class provides the {@link #getPreciseWheelRotation} method which returns
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    86
 * a double number of "clicks" in case a partial rotation occurred.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    87
 * The {@link #getPreciseWheelRotation} method is useful if a mouse supports
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    88
 * a high-resolution wheel, such as a freely rotating wheel with no
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    89
 * notches. Applications can benefit by using this method to process
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    90
 * mouse wheel events more precisely, and thus, making visual perception
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
    91
 * smoother.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @author Brent Christian
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @see MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @see java.awt.ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @see java.awt.ScrollPane#setWheelScrollingEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @see javax.swing.JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @see javax.swing.JScrollPane#setWheelScrollingEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
public class MouseWheelEvent extends MouseEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Constant representing scrolling by "units" (like scrolling with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * arrow keys)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #getScrollType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   110
    @Native public static final int WHEEL_UNIT_SCROLL = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Constant representing scrolling by a "block" (like scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * with page-up, page-down keys)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see #getScrollType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   118
    @Native public static final int WHEEL_BLOCK_SCROLL = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Indicates what sort of scrolling should take place in response to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * event, based on platform settings.  Legal values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <li> WHEEL_UNIT_SCROLL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <li> WHEEL_BLOCK_SCROLL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see #getScrollType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    int scrollType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Only valid for scrollType WHEEL_UNIT_SCROLL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Indicates number of units that should be scrolled per
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * click of mouse wheel rotation, based on platform settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #getScrollAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #getScrollType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    int scrollAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Indicates how far the mouse wheel was rotated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @see #getWheelRotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    int wheelRotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   149
    /**
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   150
     * Indicates how far the mouse wheel was rotated.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   151
     *
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   152
     * @see #getPreciseWheelRotation
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   153
     */
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   154
    double preciseWheelRotation;
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   155
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private static final long serialVersionUID = 6459879390515399677L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Constructs a <code>MouseWheelEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * specified source component, type, modifiers, coordinates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * scroll type, scroll amount, and wheel rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p>Absolute coordinates xAbs and yAbs are set to source's location on screen plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * relative coordinates x and y. xAbs and yAbs are set to zero if the source is not showing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <p>Note that passing in an invalid <code>id</code> results in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * unspecified behavior. This method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param source         the <code>Component</code> that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *                       the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param id             the integer that identifies the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param when           a long that gives the time the event occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param modifiers      the modifier keys down during event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *                       (shift, ctrl, alt, meta)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param x              the horizontal x coordinate for the mouse location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param y              the vertical y coordinate for the mouse location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param clickCount     the number of mouse clicks associated with event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param popupTrigger   a boolean, true if this event is a trigger for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *                       popup-menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param scrollType     the type of scrolling which should take place in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *                       response to this event;  valid values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *                       <code>WHEEL_UNIT_SCROLL</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *                       <code>WHEEL_BLOCK_SCROLL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *                       the number of units to be scrolled
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   190
     * @param wheelRotation  the integer number of "clicks" by which the mouse
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   191
     *                       wheel was rotated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @throws IllegalArgumentException if <code>source</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public MouseWheelEvent (Component source, int id, long when, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                      int x, int y, int clickCount, boolean popupTrigger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                      int scrollType, int scrollAmount, int wheelRotation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        this(source, id, when, modifiers, x, y, 0, 0, clickCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
             popupTrigger, scrollType, scrollAmount, wheelRotation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Constructs a <code>MouseWheelEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * specified source component, type, modifiers, coordinates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * absolute coordinates, scroll type, scroll amount, and wheel rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p>Note that passing in an invalid <code>id</code> results in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * unspecified behavior. This method throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * is <code>null</code>.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Even if inconsistent values for relative and absolute coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * passed to the constructor, the MouseWheelEvent instance is still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * created and no exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param source         the <code>Component</code> that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *                       the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param id             the integer that identifies the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param when           a long that gives the time the event occurred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param modifiers      the modifier keys down during event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *                       (shift, ctrl, alt, meta)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param x              the horizontal x coordinate for the mouse location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param y              the vertical y coordinate for the mouse location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param xAbs           the absolute horizontal x coordinate for the mouse location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param yAbs           the absolute vertical y coordinate for the mouse location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param clickCount     the number of mouse clicks associated with event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param popupTrigger   a boolean, true if this event is a trigger for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *                       popup-menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param scrollType     the type of scrolling which should take place in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *                       response to this event;  valid values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *                       <code>WHEEL_UNIT_SCROLL</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *                       <code>WHEEL_BLOCK_SCROLL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *                       the number of units to be scrolled
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   236
     * @param wheelRotation  the integer number of "clicks" by which the mouse
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   237
     *                       wheel was rotated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @throws IllegalArgumentException if <code>source</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public MouseWheelEvent (Component source, int id, long when, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            int scrollType, int scrollAmount, int wheelRotation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   248
        this(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger,
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   249
             scrollType, scrollAmount, wheelRotation, wheelRotation);
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   250
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   251
    }
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   252
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   253
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   254
    /**
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   255
     * Constructs a <code>MouseWheelEvent</code> object with the specified
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   256
     * source component, type, modifiers, coordinates, absolute coordinates,
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   257
     * scroll type, scroll amount, and wheel rotation.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   258
     * <p>Note that passing in an invalid <code>id</code> parameter results
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   259
     * in unspecified behavior. This method throws an
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   260
     * <code>IllegalArgumentException</code> if <code>source</code> equals
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   261
     * <code>null</code>.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   262
     * <p>Even if inconsistent values for relative and absolute coordinates
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   263
     * are passed to the constructor, a <code>MouseWheelEvent</code> instance
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   264
     * is still created and no exception is thrown.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   265
     *
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   266
     * @param source         the <code>Component</code> that originated the event
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   267
     * @param id             the integer value that identifies the event
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   268
     * @param when           a long value that gives the time when the event occurred
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   269
     * @param modifiers      the modifier keys down during event
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   270
     *                       (shift, ctrl, alt, meta)
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   271
     * @param x              the horizontal <code>x</code> coordinate for the
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   272
     *                       mouse location
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   273
     * @param y              the vertical <code>y</code> coordinate for the
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   274
     *                       mouse location
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   275
     * @param xAbs           the absolute horizontal <code>x</code> coordinate for
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   276
     *                       the mouse location
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   277
     * @param yAbs           the absolute vertical <code>y</code> coordinate for
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   278
     *                       the mouse location
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   279
     * @param clickCount     the number of mouse clicks associated with the event
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   280
     * @param popupTrigger   a boolean value, <code>true</code> if this event is a trigger
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   281
     *                       for a popup-menu
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   282
     * @param scrollType     the type of scrolling which should take place in
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   283
     *                       response to this event;  valid values are
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   284
     *                       <code>WHEEL_UNIT_SCROLL</code> and
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   285
     *                       <code>WHEEL_BLOCK_SCROLL</code>
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   286
     * @param  scrollAmount  for scrollType <code>WHEEL_UNIT_SCROLL</code>,
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   287
     *                       the number of units to be scrolled
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   288
     * @param wheelRotation  the integer number of "clicks" by which the mouse wheel
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   289
     *                       was rotated
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   290
     * @param preciseWheelRotation the double number of "clicks" by which the mouse wheel
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   291
     *                       was rotated
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   292
     *
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   293
     * @throws IllegalArgumentException if <code>source</code> is null
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   294
     * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   295
     * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   296
     * @since 1.7
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   297
     */
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   298
    public MouseWheelEvent (Component source, int id, long when, int modifiers,
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   299
                            int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   300
                            int scrollType, int scrollAmount, int wheelRotation, double preciseWheelRotation) {
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   301
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
              popupTrigger, MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        this.scrollType = scrollType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        this.scrollAmount = scrollAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        this.wheelRotation = wheelRotation;
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   308
        this.preciseWheelRotation = preciseWheelRotation;
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   309
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Returns the type of scrolling that should take place in response to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * event.  This is determined by the native platform.  Legal values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * <li> MouseWheelEvent.WHEEL_UNIT_SCROLL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <li> MouseWheelEvent.WHEEL_BLOCK_SCROLL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @return either MouseWheelEvent.WHEEL_UNIT_SCROLL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *  MouseWheelEvent.WHEEL_BLOCK_SCROLL, depending on the configuration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *  the native platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see java.awt.Adjustable#getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see java.awt.Adjustable#getBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see javax.swing.Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @see javax.swing.Scrollable#getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public int getScrollType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return scrollType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Returns the number of units that should be scrolled per
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * click of mouse wheel rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Only valid if <code>getScrollType</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <code>MouseWheelEvent.WHEEL_UNIT_SCROLL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return number of units to scroll, or an undefined value if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *  <code>getScrollType</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *  <code>MouseWheelEvent.WHEEL_BLOCK_SCROLL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #getScrollType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public int getScrollAmount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return scrollAmount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   348
     * Returns the number of "clicks" the mouse wheel was rotated, as an integer.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   349
     * A partial rotation may occur if the mouse supports a high-resolution wheel.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   350
     * In this case, the method returns zero until a full "click" has been accumulated.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return negative values if the mouse wheel was rotated up/away from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * the user, and positive values if the mouse wheel was rotated down/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * towards the user
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   355
     * @see #getPreciseWheelRotation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public int getWheelRotation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return wheelRotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   362
     * Returns the number of "clicks" the mouse wheel was rotated, as a double.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   363
     * A partial rotation may occur if the mouse supports a high-resolution wheel.
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   364
     * In this case, the return value will include a fractional "click".
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   365
     *
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   366
     * @return negative values if the mouse wheel was rotated up or away from
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   367
     * the user, and positive values if the mouse wheel was rotated down or
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   368
     * towards the user
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   369
     * @see #getWheelRotation
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   370
     * @since 1.7
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   371
     */
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   372
    public double getPreciseWheelRotation() {
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   373
        return preciseWheelRotation;
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   374
    }
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   375
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   376
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * This is a convenience method to aid in the implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * the common-case MouseWheelListener - to scroll a ScrollPane or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * JScrollPane by an amount which conforms to the platform settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * (Note, however, that <code>ScrollPane</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * <code>JScrollPane</code> already have this functionality built in.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * This method returns the number of units to scroll when scroll type is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * MouseWheelEvent.WHEEL_UNIT_SCROLL, and should only be called if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <code>getScrollType</code> returns MouseWheelEvent.WHEEL_UNIT_SCROLL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Direction of scroll, amount of wheel movement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * and platform settings for wheel scrolling are all accounted for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * This method does not and cannot take into account value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Adjustable/Scrollable unit increment, as this will vary among
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * scrolling components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * A simplified example of how this method might be used in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * listener:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *  mouseWheelMoved(MouseWheelEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *      ScrollPane sp = getScrollPaneFromSomewhere();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *      Adjustable adj = sp.getVAdjustable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *      if (MouseWheelEvent.getScrollType() == WHEEL_UNIT_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *          int totalScrollAmount =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *              event.getUnitsToScroll() *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *              adj.getUnitIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     *          adj.setValue(adj.getValue() + totalScrollAmount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return the number of units to scroll based on the direction and amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *  of mouse wheel rotation, and on the wheel scrolling settings of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *  native platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see #getScrollType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @see #getScrollAmount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see java.awt.Adjustable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see java.awt.Adjustable#getUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see javax.swing.Scrollable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see javax.swing.Scrollable#getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see java.awt.ScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see java.awt.ScrollPane#setWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see javax.swing.JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see javax.swing.JScrollPane#setWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public int getUnitsToScroll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return scrollAmount * wheelRotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        String scrollTypeStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (getScrollType() == WHEEL_UNIT_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            scrollTypeStr = "WHEEL_UNIT_SCROLL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        else if (getScrollType() == WHEEL_BLOCK_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            scrollTypeStr = "WHEEL_BLOCK_SCROLL";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            scrollTypeStr = "unknown scroll type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return super.paramString()+",scrollType="+scrollTypeStr+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
         ",scrollAmount="+getScrollAmount()+",wheelRotation="+
121
c43b2dfab9ac 6524352: support for high-resolution mouse wheel
dcherepanov
parents: 2
diff changeset
   447
         getWheelRotation()+",preciseWheelRotation="+getPreciseWheelRotation();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
}