java::awt::event::MouseWheelEvent Class Reference

Inheritance diagram for java::awt::event::MouseWheelEvent:

Inheritance graph
java::awt::event::MouseEventjava::awt::event::InputEventjava::awt::event::ComponentEventjava::awt::AWTEventjava::util::EventObjectjava::lang::Object
[legend]
Collaboration diagram for java::awt::event::MouseWheelEvent:

Collaboration graph
java::awt::event::MouseEventjava::awt::event::InputEventjava::awt::event::ComponentEventjava::awt::AWTEventjava::util::EventObjectjava::lang::Objectjava::lang::ObjectRefjava::lang::Interfacejava::lang::Syncjava::lang::Comparablejava::lang::ScopeAdapterjava::lang::Lock
[legend]

List of all members.


Detailed Description

An event which indicates that the mouse wheel was rotated in a component.

A wheel mouse is a mouse which has a wheel in place of the middle button. This wheel can be rotated towards or away from the user. Mouse wheels are most often used for scrolling, though other uses are possible.

A MouseWheelEvent object is passed to every MouseWheelListener object which registered to receive the "interesting" mouse events using the component's addMouseWheelListener method. Each such listener object gets a MouseEvent containing the mouse event.

Due to the mouse wheel's special relationship to scrolling Components, MouseWheelEvents are delivered somewhat differently than other MouseEvents. This is because while other MouseEvents usually affect a change on the Component directly under the mouse cursor (for instance, when clicking a button), MouseWheelEvents often have an effect away from the mouse cursor (moving the wheel while over a Component inside a ScrollPane should scroll one of the Scrollbars on the ScrollPane).

MouseWheelEvents start delivery from the Component underneath the mouse cursor. If MouseWheelEvents are not enabled on the Component, the event is delivered to the first ancestor Container with MouseWheelEvents enabled. This will usually be a ScrollPane with wheel scrolling enabled. The source Component and x,y coordinates will be relative to the event's final destination (the ScrollPane). This allows a complex GUI to be installed without modification into a ScrollPane, and for all MouseWheelEvents to be delivered to the ScrollPane for scrolling.

Some AWT Components are implemented using native widgets which display their own scrollbars and handle their own scrolling. The particular Components for which this is true will vary from platform to platform. When the mouse wheel is moved over one of these Components, the event is delivered straight to the native widget, and not propagated to ancestors.

Platforms offer customization of the amount of scrolling that should take place when the mouse wheel is moved. The two most common settings are to scroll a certain number of "units" (commonly lines of text in a text-based component) or an entire "block" (similar to page-up/page-down). The MouseWheelEvent offers 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.

Author:
Brent Christian
Version:
1.7 01/23/03
See also:
MouseWheelListener

java.awt.ScrollPane

java.awt.ScrollPane::setWheelScrollingEnabled(boolean)

javax.swing.JScrollPane

javax.swing.JScrollPane::setWheelScrollingEnabled(boolean)

Since:
1.4

Public Types

enum  MOUSE_WHEEL_SCROLL_TYPE { WHEEL_UNIT_SCROLL = 0, WHEEL_BLOCK_SCROLL }

Public Member Functions

 MouseWheelEvent ()
 MouseWheelEvent (const Ref< Component > &source, jint id, jlong when, jint modifiers, jint x, jint y, jint clickCount, jboolean popupTrigger, jint scrollType, jint scrollAmount, jint wheelRotation)
 Constructs a MouseWheelEvent object with the specified source component, type, modifiers, coordinates, scroll type, scroll amount, and wheel rotation.
virtual jint getScrollType () const
 Returns the type of scrolling that should take place in response to this event.
virtual jint getScrollAmount () const
 Returns the number of units that should be scrolled in response to this event.
virtual jint getWheelRotation () const
 Returns the number of "clicks" the mouse wheel was rotated.
virtual jint getUnitsToScroll () const
 This is a convenience method to aid in the implementation of the common-case MouseWheelListener - to scroll a ScrollPane or JScrollPane by an amount which conforms to the platform settings.
virtual String paramString () const
 Returns a parameter string identifying this event.

Protected Attributes

jint scrollType
 Indicates what sort of scrolling should take place in response to this event, based on platform settings.
jint scrollAmount
 Only valid for scrollType WHEEL_UNIT_SCROLL.
jint wheelRotation
 Indicates how far the mouse wheel was rotated.

Member Enumeration Documentation

enum java::awt::event::MouseWheelEvent::MOUSE_WHEEL_SCROLL_TYPE

Enumerator:
WHEEL_UNIT_SCROLL  Constant representing scrolling by "units" (like scrolling with the arrow keys).

See also:
getScrollType
WHEEL_BLOCK_SCROLL  Constant representing scrolling by a "block" (like scrolling with page-up, page-down keys).

See also:
getScrollType


Constructor & Destructor Documentation

java::awt::event::MouseWheelEvent::MouseWheelEvent (  ) 

java::awt::event::MouseWheelEvent::MouseWheelEvent ( const Ref< Component > &  source,
jint  id,
jlong  when,
jint  modifiers,
jint  x,
jint  y,
jint  clickCount,
jboolean  popupTrigger,
jint  scrollType,
jint  scrollAmount,
jint  wheelRotation 
)

Constructs a MouseWheelEvent object with the specified source component, type, modifiers, coordinates, scroll type, scroll amount, and wheel rotation.

Note that passing in an invalid id results in unspecified behavior.

Parameters:
source the Component that originated the event
id the integer that identifies the event
when a long that gives the time the event occurred
modifiers the modifier keys down during event (shift, ctrl, alt, meta)
x the horizontal x coordinate for the mouse location
y the vertical y coordinate for the mouse location
clickCount the number of mouse clicks associated with event
popupTrigger a boolean, true if this event is a trigger for a popup-menu
scrollType the type of scrolling which should take place in response to this event; valid values are WHEEL_UNIT_SCROLL and WHEEL_BLOCK_SCROLL
scrollAmount for scrollType WHEEL_UNIT_SCROLL, the number of units to be scrolled
wheelRotation the amount that the mouse wheel was rotated (the number of "clicks")
See also:
MouseEvent::MouseEvent(java.awt.Component, int, long, int, int, int, int, boolean)


Member Function Documentation

virtual jint java::awt::event::MouseWheelEvent::getScrollType (  )  const [virtual]

Returns the type of scrolling that should take place in response to this event.

This is determined by the native platform. Legal values are:

Returns:
either MouseWheelEvent.WHEEL_UNIT_SCROLL or MouseWheelEvent.WHEEL_BLOCK_SCROLL, depending on the configuration of the native platform.
See also:
java.awt.Adjustable::getUnitIncrement

java.awt.Adjustable::getBlockIncrement

javax.swing.Scrollable::getScrollableUnitIncrement

javax.swing.Scrollable::getScrollableBlockIncrement

virtual jint java::awt::event::MouseWheelEvent::getScrollAmount (  )  const [virtual]

Returns the number of units that should be scrolled in response to this event.

Only valid if getScrollType returns MouseWheelEvent.WHEEL_UNIT_SCROLL

Returns:
number of units to scroll, or an undefined value if getScrollType returns MouseWheelEvent.WHEEL_BLOCK_SCROLL
See also:
getScrollType

virtual jint java::awt::event::MouseWheelEvent::getWheelRotation (  )  const [virtual]

Returns the number of "clicks" the mouse wheel was rotated.

Returns:
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

virtual jint java::awt::event::MouseWheelEvent::getUnitsToScroll (  )  const [virtual]

This is a convenience method to aid in the implementation of the common-case MouseWheelListener - to scroll a ScrollPane or JScrollPane by an amount which conforms to the platform settings.

(Note, however, that ScrollPane and JScrollPane already have this functionality built in.)

This method returns the number of units to scroll when scroll type is MouseWheelEvent.WHEEL_UNIT_SCROLL, and should only be called if getScrollType returns MouseWheelEvent.WHEEL_UNIT_SCROLL.

Direction of scroll, amount of wheel movement, and platform settings for wheel scrolling are all accounted for. This method does not and cannot take into account value of the Adjustable/Scrollable unit increment, as this will vary among scrolling components.

A simplified example of how this method might be used in a listener:

 
  mouseWheelMoved(MouseWheelEvent event) {
      ScrollPane sp = getScrollPaneFromSomewhere(); 
      Adjustable adj = sp.getVAdjustable()
      if (MouseWheelEvent.getScrollType() == WHEEL_UNIT_SCROLL) {
          int totalScrollAmount =
              event.getUnitsToScroll() *
              adj.getUnitIncrement();
          adj.setValue(adj.getValue() + totalScrollAmount);
      }
  }
 

Returns:
the number of units to scroll based on the direction and amount of mouse wheel rotation, and on the wheel scrolling settings of the native platform
See also:
getScrollType

getScrollAmount

MouseWheelListener

java.awt.Adjustable

java.awt.Adjustable::getUnitIncrement

javax.swing.Scrollable

javax.swing.Scrollable::getScrollableUnitIncrement

java.awt.ScrollPane

java.awt.ScrollPane::setWheelScrollingEnabled

javax.swing.JScrollPane

javax.swing.JScrollPane::setWheelScrollingEnabled

virtual String java::awt::event::MouseWheelEvent::paramString (  )  const [virtual]

Returns a parameter string identifying this event.

This method is useful for event-logging and for debugging.

Returns:
a string identifying the event and its attributes

Reimplemented from java::awt::event::MouseEvent.


Member Data Documentation

jint java::awt::event::MouseWheelEvent::scrollType [protected]

Indicates what sort of scrolling should take place in response to this event, based on platform settings.

Legal values are:

See also:
getScrollType

jint java::awt::event::MouseWheelEvent::scrollAmount [protected]

Only valid for scrollType WHEEL_UNIT_SCROLL.

Indicates number of units that should be scrolled per click of mouse wheel rotation, based on platform settings.

See also:
getScrollAmount

getScrollType

jint java::awt::event::MouseWheelEvent::wheelRotation [protected]

Indicates how far the mouse wheel was rotated.

See also:
getWheelRotation


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:18 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3