Spec-Zone .ru
спецификации, руководства, описания, API
|
public class ScrollEvent extends GestureEvent
When the scrolling is produced by a touch gesture (such as dragging a finger
over a touch screen), it is surrounded by the SCROLL_STARTED
and
SCROLL_FINISHED
events. Changing number of involved touch points during
the scrolling is considered a new gesture, so the pair of
SCROLL_FINISHED
and SCROLL_STARTED
notifications is delivered
each time the touchCount
changes. When the scrolling is caused by a mouse
wheel rotation, only a one-time SCROLL
event is delivered, without
the started/finished surroundings. If scrolling inertia is active on the
given platform, some SCROLL
events with isInertia()
returning
true
can come after SCROLL_FINISHED
.
The event is delivered to the top-most node picked on the gesture coordinates in time of the gesture start - the whole gesture is delivered to the same node even if the coordinates change during the gesture. For mouse wheel rotation the event is delivered to the top-most node picked on mouse cursor location. The delivery is independent of current focus owner.
The event provides two different types of scrolling values: pixel-based and
character/line-based. The basic deltaX
and deltaY
values
give reasonable results when used as number of pixels
to scroll (The totalDeltaX
and totalDeltaY
contain the
cumulative values for the whole gesture, zeros for mouse wheel).
For scrolling text (or other line-based content as tables) the
textDelta
values should be used if they are available. The
textDeltaXUnits
and textDeltaYUnits
determine how to
interpret the textDeltaX
and textDeltaY
values. If the
units are set to NONE
, the text-based values are not available
(not provided by the underlying platform) and the pixel-based values
need to be used.
As all gestures, scrolling can be direct (performed directly at the concrete coordinates as on touch screen - the center point among all the touches is usually used as the gesture coordinates) or indirect (performed indirectly as on track pad or with mouse - the mouse cursor location is usually used as the gesture coordinates).
For example, scrolling a graphical node can be achieved by following code:
node.setOnScroll(new EventHandler
A scroll event handler on text-based component behaving
according to system settings on all platforms should contain following logic:
switch(event.getTextDeltaYUnits()) {
case LINES:
// scroll about event.getTextDeltaY() lines
break;
case PAGES:
// scroll about event.getTextDeltaY() pages
break;
case NONE:
// scroll about event.getDeltaY() pixels
break;
}
Modifier and Type | Class and Description |
---|---|
static class |
ScrollEvent.HorizontalTextScrollUnits
Horizontal text-based scrolling units.
|
static class |
ScrollEvent.VerticalTextScrollUnits
Vertical text-based scrolling units.
|
Modifier and Type | Field and Description |
---|---|
static EventType<ScrollEvent> |
ANY
Common supertype for all scroll event types.
|
static EventType<ScrollEvent> |
SCROLL
This event occurs when user performs a scrolling action such as
rotating mouse wheel or dragging a finger over touch screen.
|
static EventType<ScrollEvent> |
SCROLL_FINISHED
This event occurs when a scrolling gesture ends.
|
static EventType<ScrollEvent> |
SCROLL_STARTED
This event occurs when a scrolling gesture is detected.
|
consumed, eventType, NULL_SOURCE_TARGET, target
Modifier and Type | Method and Description |
---|---|
double |
getDeltaX()
Gets the horizontal scroll amount.
|
double |
getDeltaY()
Gets the vertical scroll amount.
|
double |
getTextDeltaX()
Gets the horizontal text-based scroll amount.
|
ScrollEvent.HorizontalTextScrollUnits |
getTextDeltaXUnits()
Gets the horizontal scrolling units for text-based scrolling.
|
double |
getTextDeltaY()
Gets the vertical text-based scroll amount.
|
ScrollEvent.VerticalTextScrollUnits |
getTextDeltaYUnits()
Gets the vertical scrolling units for text-based scrolling.
|
double |
getTotalDeltaX()
Gets the cumulative horizontal scroll amount for the whole gesture.
|
double |
getTotalDeltaY()
Gets the cumulative vertical scroll amount for the whole gesture.
|
int |
getTouchCount()
Gets number of touch points that caused this event.
|
java.lang.String |
toString()
Returns a string representation of this
ScrollEvent object. |
copyFor, getSceneX, getSceneY, getScreenX, getScreenY, getX, getY, isAltDown, isControlDown, isDirect, isInertia, isMetaDown, isShiftDown, isShortcutDown
clone, consume, fireEvent, getEventType, getTarget, isConsumed
public static final EventType<ScrollEvent> ANY
public static final EventType<ScrollEvent> SCROLL
public static final EventType<ScrollEvent> SCROLL_STARTED
public static final EventType<ScrollEvent> SCROLL_FINISHED
public double getDeltaX()
textDeltaX
and textDeltaXUnits
values should be
considered first.
The sign of the value is reversed compared to the coordinate system
(when you scroll right, the content actually needs to go left). So the
returned value can be simply added to the content's X
coordinate.
public double getDeltaY()
textDeltaY
and textDeltaYUnits
values should be
considered first.
The sign of the value is reversed compared to the coordinate system
(when you scroll down, the content actually needs to go up). So the
returned value can be simply added to the content's Y
coordinate.
public double getTotalDeltaX()
The sign of the value is reversed compared to the coordinate system
(when you scroll right, the content actually needs to go left). So the
returned value can be simply added to the content's X
coordinate.
public double getTotalDeltaY()
The sign of the value is reversed compared to the coordinate system
(when you scroll down, the content actually needs to go up). So the
returned value can be simply added to the content's Y
coordinate.
public ScrollEvent.HorizontalTextScrollUnits getTextDeltaXUnits()
getTextDeltaX()
value. If the returned value is NONE
, the text-based
scrolling value is not available and the pixel-based
getDeltaX()
value needs to be used.public ScrollEvent.VerticalTextScrollUnits getTextDeltaYUnits()
getTextDeltaY()
value. If the returned value is NONE
, the text-based
scrolling value is not available and the pixel-based
getDeltaY()
value needs to be used.public double getTextDeltaX()
getTextDeltaXUnits()
value.getTextDeltaXUnits()
returns NONE
public double getTextDeltaY()
getTextDeltaYUnits()
value.getTextDeltaYUnits()
returns NONE
public int getTouchCount()
public java.lang.String toString()
ScrollEvent
object.toString
in class GestureEvent
ScrollEvent
object.Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. Use is subject to