1 /* MouseWheelEvent.java -- a mouse wheel event
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java
.awt
.event
;
41 import java
.awt
.Component
;
42 import java
.awt
.Point
;
45 * This event is generated for a mouse wheel rotation. The wheel (the middle
46 * mouse button on most modern mice) can be rotated towards or away from the
47 * user, and is ofteh used for scrolling.
49 * <p>Because of the special use for scrolling components, MouseWheelEvents
50 * often affect a different component than the one located at the point of
51 * the event. If the component under the mouse cursor does not accept wheel
52 * events, the event is passed to the first ancestor container which does. This
53 * is often a ScrollPane, which knows how to scroll. If an AWT component is
54 * built from a native widget that knows how to use mouse wheel events, that
55 * component will consume the event.
57 * <p>The two most common scroll types are "units" (lines at a time) or
58 * "blocks" (pages at a time). The initial setting is taken from the platform,
59 * although the user can adjust the setting at any time.
61 * @author Eric Blake <ebb9@email.byu.edu>
62 * @see MouseWheelListener
64 * @see ScrollPane#setWheelScrollingEnabled(boolean)
66 * @see JScrollPane#setWheelScrollingEnabled(boolean)
68 * @status updated to 1.4
70 public class MouseWheelEvent
extends MouseEvent
73 * Compatible with JDK 1.4+.
75 private static final long serialVersionUID
= 6459879390515399677L;
78 * Indicates scrolling by units (lines).
80 * @see #getScrollType()
82 public static final int WHEEL_UNIT_SCROLL
= 0;
85 * Indicates scrolling by blocks (pages).
87 * @see #getScrollType()
89 public static final int WHEEL_BLOCK_SCROLL
= 1;
92 * Indicates what scroll type should take place. This should be limited
93 * to {@link #WHEEL_UNIT_SCROLL} and {@link #WHEEL_BLOCK_SCROLL}.
95 * @serial the scroll type
97 private final int scrollType
;
100 * Indicates the scroll amount. This is only meaningful if scrollType is
103 * @serial the number of lines to scroll
105 private final int scrollAmount
;
108 * Indicates how far the mouse wheel was rotated.
110 * @serial the rotation amount
112 private final int wheelRotation
;
115 * Initializes a new instance of <code>MouseWheelEvent</code> with the
116 * specified information. Note that an invalid id leads to unspecified
119 * @param source the source of the event
120 * @param id the event id
121 * @param when the timestamp of when the event occurred
122 * @param modifiers any modifier bits for this event
123 * @param x the X coordinate of the mouse point
124 * @param y the Y coordinate of the mouse point
125 * @param clickCount the number of mouse clicks for this event
126 * @param popupTrigger true if this event triggers a popup menu
127 * @param scrollType one of {@link #WHEEL_UNIT_SCROLL},
128 * {@link #WHEEL_BLOCK_SCROLL}
129 * @param scrollAmount the number of units to scroll, ignored for block type
130 * @param wheelRotation the number of rotation "clicks"
131 * @throws IllegalArgumentException if source is null
132 * @see MouseEvent#MouseEvent(Component, int, long, int, int, int, int,
135 public MouseWheelEvent(Component source
, int id
, long when
, int modifiers
,
136 int x
, int y
, int clickCount
, boolean popupTrigger
,
137 int scrollType
, int scrollAmount
, int wheelRotation
)
139 super(source
, id
, when
, modifiers
, x
, y
, clickCount
, popupTrigger
);
140 this.scrollType
= scrollType
;
141 this.scrollAmount
= scrollAmount
;
142 this.wheelRotation
= wheelRotation
;
146 * This method returns the scrolling pattern this event requests. Legal
147 * values are WHEEL_UNIT_SCROLL and WHEEL_BLOCK_SCROLL.
149 * @return the scroll type
150 * @see Adjustable#getUnitIncrement()
151 * @see Adjustable#getBlockIncrement()
152 * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
153 * @see Scrollable#getScrollableBlockIncrement(Rectangle, int, int)
155 public int getScrollType()
161 * Returns the number of units to scroll in response to this event. This
162 * only makes sense when the scroll type is WHEEL_UNIT_SCROLL.
164 * @return the number of scroll units, if defined
165 * @see #getScrollType()
167 public int getScrollAmount()
173 * Gets the number of "clicks" the wheel was rotated. Negative values move
174 * up (away) from the user, positive values move down (towards) the user.
176 * @return the number of rotation clicks
178 public int getWheelRotation()
180 return wheelRotation
;
184 * This is a convenience method which aids in a common listener for scrolling
185 * a scrollpane (although this is already built into ScrollPane and
186 * JScrollPane). This method only makes sense when getScrollType() returns
189 * <p>This accounts for direction of scroll and amount of wheel movement, as
190 * interpreted by the platform settings.
192 * @return the number of units to scroll
193 * @see #getScrollType()
194 * @see #getScrollAmount()
195 * @see MouseWheelListener
197 * @see Adjustable#getUnitIncrement()
199 * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
201 * @see ScrollPane#setWheelScrollingEnabled(boolean)
203 * @see JScrollPane#setWheelScrollingEnabled(boolean)
205 public int getUnitsToScroll()
207 return wheelRotation
* scrollAmount
;
211 * Returns a string identifying this event. For mouse wheel events, this
212 * is <code>super.paramString() + ",scrollType=WHEEL_" +
213 * (getScrollType() == WHEEL_UNIT_SCROLL ? "UNIT" : "BLOCK")
214 * + "_SCROLL,scrollAmount=" + getScrollAmount() + ",wheelRotation="
215 * + getWheelRotation()</code>.
217 * @return a string identifying this event
219 public String
paramString()
221 return super.paramString() + ",scrollType="
222 + (scrollType
== WHEEL_UNIT_SCROLL ?
"WHEEL_UNIT_SCROLL"
223 : scrollType
== WHEEL_BLOCK_SCROLL ?
"WHEEL_BLOCK_SCROLL"
224 : "unknown scroll type")
225 + ",scrollAmount=" + scrollAmount
+ ",wheelRotation=" + wheelRotation
;
227 } // class MouseWheelEvent