Merge from the pain train
[official-gcc.git] / libjava / java / awt / event / MouseWheelEvent.java
blobc16705759e7324a6318580b5b659ebdee5513531
1 /* MouseWheelEvent.java -- a mouse wheel event
2 Copyright (C) 2002, 2005 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)
9 any later version.
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
19 02111-1307 USA.
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
24 combination.
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;
43 /**
44 * This event is generated for a mouse wheel rotation. The wheel (the middle
45 * mouse button on most modern mice) can be rotated towards or away from the
46 * user, and is ofteh used for scrolling.
48 * <p>Because of the special use for scrolling components, MouseWheelEvents
49 * often affect a different component than the one located at the point of
50 * the event. If the component under the mouse cursor does not accept wheel
51 * events, the event is passed to the first ancestor container which does. This
52 * is often a ScrollPane, which knows how to scroll. If an AWT component is
53 * built from a native widget that knows how to use mouse wheel events, that
54 * component will consume the event.
56 * <p>The two most common scroll types are "units" (lines at a time) or
57 * "blocks" (pages at a time). The initial setting is taken from the platform,
58 * although the user can adjust the setting at any time.
60 * @author Eric Blake (ebb9@email.byu.edu)
61 * @see MouseWheelListener
62 * @see ScrollPane
63 * @see ScrollPane#setWheelScrollingEnabled(boolean)
64 * @see JScrollPane
65 * @see JScrollPane#setWheelScrollingEnabled(boolean)
66 * @since 1.4
67 * @status updated to 1.4
69 public class MouseWheelEvent extends MouseEvent
71 /**
72 * Compatible with JDK 1.4+.
74 private static final long serialVersionUID = 6459879390515399677L;
76 /**
77 * Indicates scrolling by units (lines).
79 * @see #getScrollType()
81 public static final int WHEEL_UNIT_SCROLL = 0;
83 /**
84 * Indicates scrolling by blocks (pages).
86 * @see #getScrollType()
88 public static final int WHEEL_BLOCK_SCROLL = 1;
90 /**
91 * Indicates what scroll type should take place. This should be limited
92 * to {@link #WHEEL_UNIT_SCROLL} and {@link #WHEEL_BLOCK_SCROLL}.
94 * @serial the scroll type
96 private final int scrollType;
98 /**
99 * Indicates the scroll amount. This is only meaningful if scrollType is
100 * WHEEL_UNIT_SCROLL.
102 * @serial the number of lines to scroll
104 private final int scrollAmount;
107 * Indicates how far the mouse wheel was rotated.
109 * @serial the rotation amount
111 private final int wheelRotation;
114 * Initializes a new instance of <code>MouseWheelEvent</code> with the
115 * specified information. Note that an invalid id leads to unspecified
116 * results.
118 * @param source the source of the event
119 * @param id the event id
120 * @param when the timestamp of when the event occurred
121 * @param modifiers any modifier bits for this event
122 * @param x the X coordinate of the mouse point
123 * @param y the Y coordinate of the mouse point
124 * @param clickCount the number of mouse clicks for this event
125 * @param popupTrigger true if this event triggers a popup menu
126 * @param scrollType one of {@link #WHEEL_UNIT_SCROLL},
127 * {@link #WHEEL_BLOCK_SCROLL}
128 * @param scrollAmount the number of units to scroll, ignored for block type
129 * @param wheelRotation the number of rotation "clicks"
130 * @throws IllegalArgumentException if source is null
131 * @see MouseEvent#MouseEvent(Component, int, long, int, int, int, int,
132 * boolean)
134 public MouseWheelEvent(Component source, int id, long when, int modifiers,
135 int x, int y, int clickCount, boolean popupTrigger,
136 int scrollType, int scrollAmount, int wheelRotation)
138 super(source, id, when, modifiers, x, y, clickCount, popupTrigger);
139 this.scrollType = scrollType;
140 this.scrollAmount = scrollAmount;
141 this.wheelRotation = wheelRotation;
145 * This method returns the scrolling pattern this event requests. Legal
146 * values are WHEEL_UNIT_SCROLL and WHEEL_BLOCK_SCROLL.
148 * @return the scroll type
149 * @see Adjustable#getUnitIncrement()
150 * @see Adjustable#getBlockIncrement()
151 * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
152 * @see Scrollable#getScrollableBlockIncrement(Rectangle, int, int)
154 public int getScrollType()
156 return scrollType;
160 * Returns the number of units to scroll in response to this event. This
161 * only makes sense when the scroll type is WHEEL_UNIT_SCROLL.
163 * @return the number of scroll units, if defined
164 * @see #getScrollType()
166 public int getScrollAmount()
168 return scrollAmount;
172 * Gets the number of "clicks" the wheel was rotated. Negative values move
173 * up (away) from the user, positive values move down (towards) the user.
175 * @return the number of rotation clicks
177 public int getWheelRotation()
179 return wheelRotation;
183 * This is a convenience method which aids in a common listener for scrolling
184 * a scrollpane (although this is already built into ScrollPane and
185 * JScrollPane). This method only makes sense when getScrollType() returns
186 * WHEEL_UNIT_SCROLL.
188 * <p>This accounts for direction of scroll and amount of wheel movement, as
189 * interpreted by the platform settings.
191 * @return the number of units to scroll
192 * @see #getScrollType()
193 * @see #getScrollAmount()
194 * @see MouseWheelListener
195 * @see Adjustable
196 * @see Adjustable#getUnitIncrement()
197 * @see Scrollable
198 * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
199 * @see ScrollPane
200 * @see ScrollPane#setWheelScrollingEnabled(boolean)
201 * @see JScrollPane
202 * @see JScrollPane#setWheelScrollingEnabled(boolean)
204 public int getUnitsToScroll()
206 return wheelRotation * scrollAmount;
210 * Returns a string identifying this event. For mouse wheel events, this
211 * is <code>super.paramString() + ",scrollType=WHEEL_" +
212 * (getScrollType() == WHEEL_UNIT_SCROLL ? "UNIT" : "BLOCK")
213 * + "_SCROLL,scrollAmount=" + getScrollAmount() + ",wheelRotation="
214 * + getWheelRotation()</code>.
216 * @return a string identifying this event
218 public String paramString()
220 return super.paramString() + ",scrollType="
221 + (scrollType == WHEEL_UNIT_SCROLL ? "WHEEL_UNIT_SCROLL"
222 : scrollType == WHEEL_BLOCK_SCROLL ? "WHEEL_BLOCK_SCROLL"
223 : "unknown scroll type")
224 + ",scrollAmount=" + scrollAmount + ",wheelRotation=" + wheelRotation;
226 } // class MouseWheelEvent