diff --git a/src/share/classes/java/awt/Component.java b/src/share/classes/java/awt/Component.java index 5435d9b2599b176c72274f4c4b99fbc83a83c6d7..718cafe0614ef95987de8665945f061dadfb5723 100644 --- a/src/share/classes/java/awt/Component.java +++ b/src/share/classes/java/awt/Component.java @@ -4604,7 +4604,8 @@ public abstract class Component implements ImageObserver, MenuContainer, e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), - e.getWheelRotation()); + e.getWheelRotation(), + e.getPreciseWheelRotation()); ((AWTEvent)e).copyPrivateDataInto(newMWE); // When dispatching a wheel event to // ancestor, there is no need trying to find descendant diff --git a/src/share/classes/java/awt/Container.java b/src/share/classes/java/awt/Container.java index 46164c410c6ccb934818b8f30a0dbf50aabe97f5..4a347f3d5e9fbdbb90b42122286523bc20662ea6 100644 --- a/src/share/classes/java/awt/Container.java +++ b/src/share/classes/java/awt/Container.java @@ -4431,7 +4431,8 @@ class LightweightDispatcher implements java.io.Serializable, AWTEventListener { e.isPopupTrigger(), ((MouseWheelEvent)e).getScrollType(), ((MouseWheelEvent)e).getScrollAmount(), - ((MouseWheelEvent)e).getWheelRotation()); + ((MouseWheelEvent)e).getWheelRotation(), + ((MouseWheelEvent)e).getPreciseWheelRotation()); } else { retargeted = new MouseEvent(target, diff --git a/src/share/classes/java/awt/event/MouseWheelEvent.java b/src/share/classes/java/awt/event/MouseWheelEvent.java index 40af56c44396759633e2c23769e4326e1e329d88..a1c5b2ebb9111eb755c8914f9a42672b12ceef87 100644 --- a/src/share/classes/java/awt/event/MouseWheelEvent.java +++ b/src/share/classes/java/awt/event/MouseWheelEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -74,6 +74,19 @@ import java.awt.Component; * methods for conforming to the underlying platform settings. These * platform settings can be changed at any time by the user. MouseWheelEvents * reflect the most recent settings. + *
+ * The MouseWheelEvent
class includes methods for
+ * getting the number of "clicks" by which the mouse wheel is rotated.
+ * The {@link #getWheelRotation} method returns the integer number
+ * of "clicks" corresponding to the number of notches by which the wheel was
+ * rotated. In addition to this method, the MouseWheelEvent
+ * class provides the {@link #getPreciseWheelRotation} method which returns
+ * a double number of "clicks" in case a partial rotation occurred.
+ * The {@link #getPreciseWheelRotation} method is useful if a mouse supports
+ * a high-resolution wheel, such as a freely rotating wheel with no
+ * notches. Applications can benefit by using this method to process
+ * mouse wheel events more precisely, and thus, making visual perception
+ * smoother.
*
* @author Brent Christian
* @see MouseWheelListener
@@ -131,6 +144,13 @@ public class MouseWheelEvent extends MouseEvent {
*/
int wheelRotation;
+ /**
+ * Indicates how far the mouse wheel was rotated.
+ *
+ * @see #getPreciseWheelRotation
+ */
+ double preciseWheelRotation;
+
/*
* serialVersionUID
*/
@@ -165,8 +185,8 @@ public class MouseWheelEvent extends MouseEvent {
* WHEEL_BLOCK_SCROLL
* @param scrollAmount for scrollType WHEEL_UNIT_SCROLL
,
* the number of units to be scrolled
- * @param wheelRotation the amount that the mouse wheel was rotated (the
- * number of "clicks")
+ * @param wheelRotation the integer number of "clicks" by which the mouse
+ * wheel was rotated
*
* @throws IllegalArgumentException if source
is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
@@ -211,8 +231,8 @@ public class MouseWheelEvent extends MouseEvent {
* WHEEL_BLOCK_SCROLL
* @param scrollAmount for scrollType WHEEL_UNIT_SCROLL
,
* the number of units to be scrolled
- * @param wheelRotation the amount that the mouse wheel was rotated (the
- * number of "clicks")
+ * @param wheelRotation the integer number of "clicks" by which the mouse
+ * wheel was rotated
*
* @throws IllegalArgumentException if source
is null
* @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
@@ -223,12 +243,68 @@ public class MouseWheelEvent extends MouseEvent {
int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
int scrollType, int scrollAmount, int wheelRotation) {
+ this(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger,
+ scrollType, scrollAmount, wheelRotation, wheelRotation);
+
+ }
+
+
+ /**
+ * Constructs a MouseWheelEvent
object with the specified
+ * source component, type, modifiers, coordinates, absolute coordinates,
+ * scroll type, scroll amount, and wheel rotation.
+ *
Note that passing in an invalid id
parameter results
+ * in unspecified behavior. This method throws an
+ * IllegalArgumentException
if source
equals
+ * null
.
+ *
Even if inconsistent values for relative and absolute coordinates
+ * are passed to the constructor, a MouseWheelEvent
instance
+ * is still created and no exception is thrown.
+ *
+ * @param source the Component
that originated the event
+ * @param id the integer value that identifies the event
+ * @param when a long value that gives the time when the event occurred
+ * @param modifiers the modifier keys down during event
+ * (shift, ctrl, alt, meta)
+ * @param x the horizontal x
coordinate for the
+ * mouse location
+ * @param y the vertical y
coordinate for the
+ * mouse location
+ * @param xAbs the absolute horizontal x
coordinate for
+ * the mouse location
+ * @param yAbs the absolute vertical y
coordinate for
+ * the mouse location
+ * @param clickCount the number of mouse clicks associated with the event
+ * @param popupTrigger a boolean value, true
if this event is a trigger
+ * for a popup-menu
+ * @param scrollType the type of scrolling which should take place in
+ * response to this event; valid values are
+ * WHEEL_UNIT_SCROLL
and
+ * WHEEL_BLOCK_SCROLL
+ * @param scrollAmount for scrollType WHEEL_UNIT_SCROLL
,
+ * the number of units to be scrolled
+ * @param wheelRotation the integer number of "clicks" by which the mouse wheel
+ * was rotated
+ * @param preciseWheelRotation the double number of "clicks" by which the mouse wheel
+ * was rotated
+ *
+ * @throws IllegalArgumentException if source
is null
+ * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)
+ * @see MouseEvent#MouseEvent(java.awt.Component, int, long, int, int, int, int, int, int, boolean, int)
+ * @since 1.7
+ */
+ public MouseWheelEvent (Component source, int id, long when, int modifiers,
+ int x, int y, int xAbs, int yAbs, int clickCount, boolean popupTrigger,
+ int scrollType, int scrollAmount, int wheelRotation, double preciseWheelRotation) {
+
super(source, id, when, modifiers, x, y, xAbs, yAbs, clickCount,
popupTrigger, MouseEvent.NOBUTTON);
this.scrollType = scrollType;
this.scrollAmount = scrollAmount;
this.wheelRotation = wheelRotation;
+ this.preciseWheelRotation = preciseWheelRotation;
+
}
/**
@@ -267,16 +343,34 @@ public class MouseWheelEvent extends MouseEvent {
}
/**
- * Returns the number of "clicks" the mouse wheel was rotated.
+ * Returns the number of "clicks" the mouse wheel was rotated, as an integer.
+ * A partial rotation may occur if the mouse supports a high-resolution wheel.
+ * In this case, the method returns zero until a full "click" has been accumulated.
*
* @return negative values if the mouse wheel was rotated up/away from
* the user, and positive values if the mouse wheel was rotated down/
* towards the user
+ * @see #getPreciseWheelRotation
*/
public int getWheelRotation() {
return wheelRotation;
}
+ /**
+ * Returns the number of "clicks" the mouse wheel was rotated, as a double.
+ * A partial rotation may occur if the mouse supports a high-resolution wheel.
+ * In this case, the return value will include a fractional "click".
+ *
+ * @return negative values if the mouse wheel was rotated up or away from
+ * the user, and positive values if the mouse wheel was rotated down or
+ * towards the user
+ * @see #getWheelRotation
+ * @since 1.7
+ */
+ public double getPreciseWheelRotation() {
+ return preciseWheelRotation;
+ }
+
/**
* This is a convenience method to aid in the implementation of
* the common-case MouseWheelListener - to scroll a ScrollPane or
@@ -348,6 +442,6 @@ public class MouseWheelEvent extends MouseEvent {
}
return super.paramString()+",scrollType="+scrollTypeStr+
",scrollAmount="+getScrollAmount()+",wheelRotation="+
- getWheelRotation();
+ getWheelRotation()+",preciseWheelRotation="+getPreciseWheelRotation();
}
}
diff --git a/src/windows/native/sun/windows/awt_Component.cpp b/src/windows/native/sun/windows/awt_Component.cpp
index e1b3a7d1dcdfa42011488cea38bfe18c05405b1d..9a9082b504b3792dac1a5b4f1d8caf7f9dbcd9ea 100644
--- a/src/windows/native/sun/windows/awt_Component.cpp
+++ b/src/windows/native/sun/windows/awt_Component.cpp
@@ -226,6 +226,8 @@ BOOL AwtComponent::m_QueryNewPaletteCalled = FALSE;
CriticalSection windowMoveLock;
BOOL windowMoveLockHeld = FALSE;
+int AwtComponent::sm_wheelRotationAmount = 0;
+
/************************************************************************
* AwtComponent methods
*/
@@ -2074,6 +2076,8 @@ MsgRouting AwtComponent::WmSetFocus(HWND hWndLostFocus)
sm_realFocusOpposite = NULL;
}
+ sm_wheelRotationAmount = 0;
+
SendFocusEvent(java_awt_event_FocusEvent_FOCUS_GAINED, hWndLostFocus);
return mrDoDefault;
@@ -2105,6 +2109,7 @@ MsgRouting AwtComponent::WmKillFocus(HWND hWndGotFocus)
}
sm_focusOwner = NULL;
+ sm_wheelRotationAmount = 0;
SendFocusEvent(java_awt_event_FocusEvent_FOCUS_LOST, hWndGotFocus);
return mrDoDefault;
@@ -2622,9 +2627,13 @@ MsgRouting AwtComponent::WmMouseWheel(UINT flags, int x, int y,
BOOL result;
UINT platformLines;
+ sm_wheelRotationAmount += wheelRotation;
+
// AWT interprets wheel rotation differently than win32, so we need to
// decode wheel amount.
- jint newWheelRotation = wheelRotation / (-1 * WHEEL_DELTA);
+ jint roundedWheelRotation = sm_wheelRotationAmount / (-1 * WHEEL_DELTA);
+ jdouble preciseWheelRotation = (jdouble) wheelRotation / (-1 * WHEEL_DELTA);
+
MSG msg;
if (IS_WIN95 && !IS_WIN98) {
@@ -2657,7 +2666,9 @@ MsgRouting AwtComponent::WmMouseWheel(UINT flags, int x, int y,
SendMouseWheelEvent(java_awt_event_MouseEvent_MOUSE_WHEEL, TimeHelper::getMessageTimeUTC(),
eventPt.x, eventPt.y, GetJavaModifiers(), 0, 0, scrollType,
- scrollLines, newWheelRotation, &msg);
+ scrollLines, roundedWheelRotation, preciseWheelRotation, &msg);
+
+ sm_wheelRotationAmount %= WHEEL_DELTA;
return mrConsume;
}
@@ -4989,8 +5000,8 @@ void
AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
jint modifiers, jint clickCount,
jboolean popupTrigger, jint scrollType,
- jint scrollAmount, jint wheelRotation,
- MSG *pMsg)
+ jint scrollAmount, jint roundedWheelRotation,
+ jdouble preciseWheelRotation, MSG *pMsg)
{
/* Code based not so loosely on AwtComponent::SendMouseEvent */
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
@@ -5018,7 +5029,7 @@ AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
if (mouseWheelEventConst == NULL) {
mouseWheelEventConst =
env->GetMethodID(mouseWheelEventCls, "