1 /*******************************************************************************
2 * Copyright (c) 2010, 2018 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.events;
17 import org.eclipse.swt.widgets.*;
20 * Instances of this class are sent in response to
21 * touch-based gestures that are triggered by the user.
23 * @see GestureListener
24 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
28 public class GestureEvent extends TypedEvent {
31 * The state of the keyboard modifier keys and mouse masks
32 * at the time the event was generated.
34 * @see org.eclipse.swt.SWT#MODIFIER_MASK
35 * @see org.eclipse.swt.SWT#BUTTON_MASK
42 * <li>{@link org.eclipse.swt.SWT#GESTURE_BEGIN}</li>
43 * <li>{@link org.eclipse.swt.SWT#GESTURE_END}</li>
44 * <li>{@link org.eclipse.swt.SWT#GESTURE_MAGNIFY}</li>
45 * <li>{@link org.eclipse.swt.SWT#GESTURE_PAN}</li>
46 * <li>{@link org.eclipse.swt.SWT#GESTURE_ROTATE}</li>
47 * <li>{@link org.eclipse.swt.SWT#GESTURE_SWIPE}</li>
50 * This field determines the <code>GestureEvent</code> fields that contain valid data.
55 * The meaning of this field is dependent on the value of the <code>detail</code> field
56 * and the platform. It can represent either the x coordinate of the centroid of the
57 * touches that make up the gesture, or the x coordinate of the cursor at the time the
58 * gesture was performed.
63 * The meaning of this field is dependent on the value of the <code>detail</code> field
64 * and the platform. It can represent either the y coordinate of the centroid of the
65 * touches that make up the gesture, or the y coordinate of the cursor at the time the
66 * gesture was performed.
71 * This field is valid when the <code>detail</code> field is set to <code>GESTURE_ROTATE</code>.
72 * It specifies the number of degrees rotated on the device since the gesture started. Positive
73 * values indicate counter-clockwise rotation, and negative values indicate clockwise rotation.
75 public double rotation;
78 * This field is valid when the <code>detail</code> field is set to <code>GESTURE_SWIPE</code>
79 * or <code>GESTURE_PAN</code>. Both <code>xDirection</code> and <code>yDirection</code>
80 * can be valid for an individual gesture. The meaning of this field is dependent on the value
81 * of the <code>detail</code> field.
83 * If <code>detail</code> is <code>GESTURE_SWIPE</code> then a positive value indicates a swipe
84 * to the right and a negative value indicates a swipe to the left.
86 * If <code>detail</code> is <code>GESTURE_PAN</code> then a positive value indicates a pan to
87 * the right by this field's count of points and a negative value indicates a pan to the left
88 * by this field's count of points.
90 public int xDirection;
93 * This field is valid when the <code>detail</code> field is set to <code>GESTURE_SWIPE</code>
94 * or <code>GESTURE_PAN</code>. Both <code>xDirection</code> and <code>yDirection</code>
95 * can be valid for an individual gesture. The meaning of this field is dependent on the value
96 * of the <code>detail</code> field.
98 * If <code>detail</code> is <code>GESTURE_SWIPE</code> then a positive value indicates a downward
99 * swipe and a negative value indicates an upward swipe.
101 * If <code>detail</code> is <code>GESTURE_PAN</code> then a positive value indicates a downward
102 * pan by this field's count of points and a negative value indicates an upward pan by this
103 * field's count of points.
105 public int yDirection;
108 * This field is valid when the <code>detail</code> field is set to <code>GESTURE_MAGNIFY</code>.
109 * This is the scale factor to be applied. This value will be 1.0 in the first received event with
110 * <code>GESTURE_MAGNIFY</code>, and will then fluctuate in subsequent events as the user moves
113 public double magnification;
116 * This flag indicates whether the operation should be allowed.
117 * Setting it to <code>false</code> will cancel the operation.
121 static final long serialVersionUID = -8348741538373572182L;
124 * Constructs a new instance of this class based on the
125 * information in the given untyped event.
127 * @param e the untyped event containing the information
129 public GestureEvent(Event e) {
131 this.stateMask = e.stateMask;
134 this.detail = e.detail;
135 this.rotation = e.rotation;
136 this.xDirection = e.xDirection;
137 this.yDirection = e.yDirection;
138 this.magnification = e.magnification;
143 * Returns a string containing a concise, human-readable
144 * description of the receiver.
146 * @return a string representation of the event
149 public String toString() {
150 String string = super.toString ();
151 return string.substring (0, string.length() - 1) // remove trailing '}'
152 + " stateMask=0x" + Integer.toHexString(stateMask)
153 + " detail=" + detail
156 + " rotation=" + rotation
157 + " xDirection=" + xDirection
158 + " yDirection=" + yDirection
159 + " magnification=" + magnification