Spec-Zone.ru › OpenJavaFX 21

Class TouchEvent

java.lang.Object
java.util.EventObject
javafx.event.Event
javafx.scene.input.InputEvent
javafx.scene.input.TouchEvent
All Implemented Interfaces:
Serializable, Cloneable
public final class TouchEvent extends InputEvent
Touch event indicates a touch screen action. It contains detailed information about each particular touch point.

Touch point represents a single touched finger and has its location, state (pressed/moved/released/stationary) and an ID unique in scope of a single gesture. For detailed reference see TouchPoint.

For each multi-touch action a set of touch events is generated - for each touch point one. The event has type corresponds to its touch point's state. Each of the events also contain list of all the touch points. This design allows for handling complicated multi-touch actions from one place while keeping it possible to filter/consume each touch point separately. To recognize which events belong into a single set there is getEventSetId() method.

Each touch point is - similarly to mouse dragging - delivered to a single node on which it was pressed, regardless of where it moves then. It is possible to change this behavior by using a grabbing mechanism described in TouchPoint documentation.

Since:
JavaFX 2.2
See Also:
  • Serialized Form

Field Summary

Modifier and Type Field Description
static final EventType<TouchEvent> ANY
Common supertype for all touch event types.
static final EventType<TouchEvent> TOUCH_MOVED
This event occurs when the touch point is moved.
static final EventType<TouchEvent> TOUCH_PRESSED
This event occurs when the touch point is pressed (touched for the first time).
static final EventType<TouchEvent> TOUCH_RELEASED
This event occurs when the touch point is released.
static final EventType<TouchEvent> TOUCH_STATIONARY
This event occurs when the touch point is pressed and still (doesn't move).

Fields declared in class javafx.event.Event

consumed, eventType, NULL_SOURCE_TARGET, target

Fields declared in class java.util.EventObject

source

Constructor Summary

Constructor Description
TouchEvent(Object source, EventTarget target, EventType<TouchEvent> eventType, TouchPoint touchPoint, List<TouchPoint> touchPoints, int eventSetId, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown)
Constructs new TouchEvent event.
TouchEvent(EventType<TouchEvent> eventType, TouchPoint touchPoint, List<TouchPoint> touchPoints, int eventSetId, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown)
Constructs new TouchEvent event with null source and target.

Method Summary

Modifier and Type Method Description
TouchEvent copyFor(Object newSource, EventTarget newTarget)
Creates and returns a copy of this event with the specified event source and target.
TouchEvent copyFor(Object newSource, EventTarget newTarget, EventType<TouchEvent> type)
Creates a copy of the given event with the given fields substituted.
final int getEventSetId()
Gets sequential number of the set of touch events representing the same multi-touch action.
EventType<TouchEvent> getEventType()
Gets the event type of this event.
int getTouchCount()
Returns number of touch points represented by this touch event set.
TouchPoint getTouchPoint()
Gets the touch point of this event.
List<TouchPoint> getTouchPoints()
Gets all the touch points represented by this set of touch events, including the touch point of this event.
final boolean isAltDown()
Whether or not the Alt modifier is down on this event.
final boolean isControlDown()
Whether or not the Control modifier is down on this event.
final boolean isMetaDown()
Whether or not the Meta modifier is down on this event.
final boolean isShiftDown()
Whether or not the Shift modifier is down on this event.
String toString()
Returns a string representation of this TouchEvent object.

Methods declared in class javafx.event.Event

clone, consume, fireEvent, getTarget, isConsumed

Methods declared in class java.util.EventObject

getSource

Methods declared in class java.lang.Object

equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Details

ANY

public static final EventType<TouchEvent> ANY
Common supertype for all touch event types.

TOUCH_PRESSED

public static final EventType<TouchEvent> TOUCH_PRESSED
This event occurs when the touch point is pressed (touched for the first time).

TOUCH_MOVED

public static final EventType<TouchEvent> TOUCH_MOVED
This event occurs when the touch point is moved.

TOUCH_RELEASED

public static final EventType<TouchEvent> TOUCH_RELEASED
This event occurs when the touch point is released.

TOUCH_STATIONARY

public static final EventType<TouchEvent> TOUCH_STATIONARY
This event occurs when the touch point is pressed and still (doesn't move).

Constructor Details

TouchEvent

public TouchEvent(Object source, EventTarget target, EventType<TouchEvent> eventType, TouchPoint touchPoint, List<TouchPoint> touchPoints, int eventSetId, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown)
Constructs new TouchEvent event.
Parameters:
source - the source of the event. Can be null.
target - the target of the event. Can be null.
eventType - The type of the event.
touchPoint - the touch point of this event
touchPoints - set of touch points for the multi-touch action
eventSetId - set id of the multi-touch action
shiftDown - true if shift modifier was pressed.
controlDown - true if control modifier was pressed.
altDown - true if alt modifier was pressed.
metaDown - true if meta modifier was pressed.
Since:
JavaFX 8.0

TouchEvent

public TouchEvent(EventType<TouchEvent> eventType, TouchPoint touchPoint, List<TouchPoint> touchPoints, int eventSetId, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown)
Constructs new TouchEvent event with null source and target.
Parameters:
eventType - The type of the event.
touchPoint - the touch point of this event
touchPoints - set of touch points for the multi-touch action
eventSetId - set id of the multi-touch action
shiftDown - true if shift modifier was pressed.
controlDown - true if control modifier was pressed.
altDown - true if alt modifier was pressed.
metaDown - true if meta modifier was pressed.
Since:
JavaFX 8.0

Method Details

getTouchCount

public int getTouchCount()
Returns number of touch points represented by this touch event set. The returned number matches the size of the touchPoints list.
Returns:
The number of touch points represented by this touch event set.

copyFor

public TouchEvent copyFor(Object newSource, EventTarget newTarget)
Creates and returns a copy of this event with the specified event source and target. If the source or target is set to null, it is replaced by the NULL_SOURCE_TARGET value.
Overrides:
copyFor in class Event
Parameters:
newSource - the new source of the copied event
newTarget - the new target of the copied event
Returns:
the event copy with the new source and target

copyFor

public TouchEvent copyFor(Object newSource, EventTarget newTarget, EventType<TouchEvent> type)
Creates a copy of the given event with the given fields substituted.
Parameters:
newSource - the new source of the copied event
newTarget - the new target of the copied event
type - the new eventType
Returns:
the event copy with the fields substituted
Since:
JavaFX 8.0

getEventType

public EventType<TouchEvent> getEventType()
Description copied from class: Event
Gets the event type of this event. Objects of the same Event class can have different event types. These event types further specify what kind of event occurred.
Overrides:
getEventType in class Event
Returns:
the event type

getEventSetId

public final int getEventSetId()
Gets sequential number of the set of touch events representing the same multi-touch action. For a multi-touch user action, number of touch points may exist; each of them produces a touch event, each of those touch events carry the same list of touch points - and all of them return the same number from this method. Then state of some of the touch points changes and the new set of events has new id. The id is guaranteed to be sequential and unique in scope of one gesture (is reset when all touch points are released).
Returns:
Sequential id of event set unique in scope of a gesture

isShiftDown

public final boolean isShiftDown()
Whether or not the Shift modifier is down on this event.
Returns:
true if the Shift modifier is down on this event

isControlDown

public final boolean isControlDown()
Whether or not the Control modifier is down on this event.
Returns:
true if the Control modifier is down on this event

isAltDown

public final boolean isAltDown()
Whether or not the Alt modifier is down on this event.
Returns:
true if the Alt modifier is down on this event

isMetaDown

public final boolean isMetaDown()
Whether or not the Meta modifier is down on this event.
Returns:
true if the Meta modifier is down on this event

getTouchPoint

public TouchPoint getTouchPoint()
Gets the touch point of this event.
Returns:
Touch point of this event

getTouchPoints

public List<TouchPoint> getTouchPoints()
Gets all the touch points represented by this set of touch events, including the touch point of this event. The list is unmodifiable and is sorted by their IDs, which means it is also sorted by the time they were pressed. To distinguish between touch points belonging to a node and unrelated touch points, TouchPoint's belongsTo method can be used.
Returns:
All current touch points in an unmodifiable list

toString

public String toString()
Returns a string representation of this TouchEvent object.
Overrides:
toString in class EventObject
Returns:
a string representation of this TouchEvent object.

© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API