1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.input; 27 28 import javafx.beans.NamedArg; 29 import javafx.event.EventTarget; 30 import javafx.event.EventType; 31 32 /** 33 * Zoom event indicates that user performed zooming gesture such as 34 * dragging two fingers apart on track pad, touch screen or other 35 * similar device. 36 * <p> 37 * The event is delivered to the top-most 38 * node picked on the gesture coordinates in time of the gesture start - the 39 * whole gesture is delivered to the same node even if the coordinates change 40 * during the gesture. 41 * <p> 42 * The event provides two values: {@code zoomFactor} is the zooming amount 43 * of this event, {@code totalZoomFactor} is the zooming amount of the whole 44 * gesture. The values work well when multiplied with the node's {@code scale} 45 * properties (values greater than {@code 1} for zooming in). 46 * <p> 47 * As all gestures, zooming can be direct (performed directly at 48 * the concrete coordinates as on touch screen - the center point among all 49 * the touches is usually used as the gesture coordinates) or indirect (performed 50 * indirectly as on track pad - the mouse cursor location is usually used 51 * as the gesture coordinates). 52 * <p> 53 * The gesture's {@code ZOOM} events are surounded by {@code ZOOM_STARTED} 54 * and {@code ZOOM_FINISHED} events. If zooming inertia is active on the 55 * given platform, some {@code ZOOM} events with {@code isInertia()} returning 56 * {@code true} can come after {@code ZOOM_FINISHED}. 57 * 58 * @since JavaFX 2.2 59 */ 60 public final class ZoomEvent extends GestureEvent { 61 62 private static final long serialVersionUID = 20121107L; 63 64 /** 65 * Common supertype for all zoom event types. 66 */ 67 public static final EventType<ZoomEvent> ANY = 68 new EventType<ZoomEvent>(GestureEvent.ANY, "ANY_ZOOM"); 69 70 /** 71 * This event occurs when user performs a zooming gesture such as 72 * dragging two fingers apart. 73 */ 74 public static final EventType<ZoomEvent> ZOOM = 75 new EventType<ZoomEvent>(ZoomEvent.ANY, "ZOOM"); 76 77 /** 78 * This event occurs when a zooming gesture is detected. 79 */ 80 public static final EventType<ZoomEvent> ZOOM_STARTED = 81 new EventType<ZoomEvent>(ZoomEvent.ANY, "ZOOM_STARTED"); 82 83 /** 84 * This event occurs when a zooming gesture ends. 85 */ 86 public static final EventType<ZoomEvent> ZOOM_FINISHED = 87 new EventType<ZoomEvent>(ZoomEvent.ANY, "ZOOM_FINISHED"); 88 89 /** 90 * Constructs new ZoomEvent event. 91 * @param source the source of the event. Can be null. 92 * @param target the target of the event. Can be null. 93 * @param eventType The type of the event. 94 * @param x The x with respect to the scene. 95 * @param y The y with respect to the scene. 96 * @param screenX The x coordinate relative to screen. 97 * @param screenY The y coordinate relative to screen. 98 * @param shiftDown true if shift modifier was pressed. 99 * @param controlDown true if control modifier was pressed. 100 * @param altDown true if alt modifier was pressed. 101 * @param metaDown true if meta modifier was pressed. 102 * @param direct true if the event was caused by direct input device. See {@link #isDirect() } 103 * @param touchCount number of touch points 104 * @param inertia if represents inertia of an already finished gesture. 105 * @param zoomFactor zoom amount 106 * @param totalZoomFactor cumulative zoom amount 107 * @param pickResult pick result. Can be null, in this case a 2D pick result 108 * without any further values is constructed 109 * based on the scene coordinates and the target 110 * @since JavaFX 8.0 111 */ 112 public ZoomEvent(@NamedArg("source") Object source, @NamedArg("target") EventTarget target, final @NamedArg("eventType") EventType<ZoomEvent> eventType, 113 @NamedArg("x") double x, @NamedArg("y") double y, 114 @NamedArg("screenX") double screenX, @NamedArg("screenY") double screenY, 115 @NamedArg("shiftDown") boolean shiftDown, 116 @NamedArg("controlDown") boolean controlDown, 117 @NamedArg("altDown") boolean altDown, 118 @NamedArg("metaDown") boolean metaDown, 119 @NamedArg("direct") boolean direct, 120 @NamedArg("inertia") boolean inertia, 121 @NamedArg("zoomFactor") double zoomFactor, 122 @NamedArg("totalZoomFactor") double totalZoomFactor, 123 @NamedArg("pickResult") PickResult pickResult) { 124 125 super(source, target, eventType, x, y, screenX, screenY, 126 shiftDown, controlDown, altDown, metaDown, direct, inertia, pickResult); 127 this.zoomFactor = zoomFactor; 128 this.totalZoomFactor = totalZoomFactor; 129 } 130 131 /** 132 * Constructs new ZoomEvent event with null source and target. 133 * @param eventType The type of the event. 134 * @param x The x with respect to the scene. 135 * @param y The y with respect to the scene. 136 * @param screenX The x coordinate relative to screen. 137 * @param screenY The y coordinate relative to screen. 138 * @param shiftDown true if shift modifier was pressed. 139 * @param controlDown true if control modifier was pressed. 140 * @param altDown true if alt modifier was pressed. 141 * @param metaDown true if meta modifier was pressed. 142 * @param direct true if the event was caused by direct input device. See {@link #isDirect() } 143 * @param touchCount number of touch points 144 * @param inertia if represents inertia of an already finished gesture. 145 * @param zoomFactor zoom amount 146 * @param totalZoomFactor cumulative zoom amount 147 * @param pickResult pick result. Can be null, in this case a 2D pick result 148 * without any further values is constructed 149 * based on the scene coordinates 150 * @since JavaFX 8.0 151 */ 152 public ZoomEvent(final @NamedArg("eventType") EventType<ZoomEvent> eventType, 153 @NamedArg("x") double x, @NamedArg("y") double y, 154 @NamedArg("screenX") double screenX, @NamedArg("screenY") double screenY, 155 @NamedArg("shiftDown") boolean shiftDown, 156 @NamedArg("controlDown") boolean controlDown, 157 @NamedArg("altDown") boolean altDown, 158 @NamedArg("metaDown") boolean metaDown, 159 @NamedArg("direct") boolean direct, 160 @NamedArg("inertia") boolean inertia, 161 @NamedArg("zoomFactor") double zoomFactor, 162 @NamedArg("totalZoomFactor") double totalZoomFactor, 163 @NamedArg("pickResult") PickResult pickResult) { 164 this(null, null, eventType, x, y, screenX, screenY, shiftDown, controlDown, 165 altDown, metaDown, direct, inertia, zoomFactor, totalZoomFactor, 166 pickResult); 167 } 168 169 private final double zoomFactor; 170 171 /** 172 * Gets the zooming amount of this event. The factor value works well when 173 * multiplied with the node's {@code scale} properties (values greater 174 * than {@code 1} for zooming in, values between {@code 0} and {@code 1} 175 * for zooming out). 176 * @return The zooming amount of this event 177 */ 178 public double getZoomFactor() { 179 return zoomFactor; 180 } 181 182 private final double totalZoomFactor; 183 184 /** 185 * Gets the zooming amount of this gesture. The factor value works well when 186 * multiplied with the node's {@code scale} properties (values greater 187 * than {@code 1} for zooming in, values between {@code 0} and {@code 1} 188 * for zooming out). 189 * @return The cumulative zooming amount of this gesture 190 */ 191 public double getTotalZoomFactor() { 192 return totalZoomFactor; 193 } 194 195 /** 196 * Returns a string representation of this {@code ZoomEvent} object. 197 * @return a string representation of this {@code ZoomEvent} object. 198 */ 199 @Override public String toString() { 200 final StringBuilder sb = new StringBuilder("ZoomEvent ["); 201 202 sb.append("source = ").append(getSource()); 203 sb.append(", target = ").append(getTarget()); 204 sb.append(", eventType = ").append(getEventType()); 205 sb.append(", consumed = ").append(isConsumed()); 206 207 sb.append(", zoomFactor = ").append(getZoomFactor()); 208 sb.append(", totalZoomFactor = ").append(getTotalZoomFactor()); 209 sb.append(", x = ").append(getX()).append(", y = ").append(getY()) 210 .append(", z = ").append(getZ()); 211 sb.append(isDirect() ? ", direct" : ", indirect"); 212 213 if (isInertia()) { 214 sb.append(", inertia"); 215 } 216 217 if (isShiftDown()) { 218 sb.append(", shiftDown"); 219 } 220 if (isControlDown()) { 221 sb.append(", controlDown"); 222 } 223 if (isAltDown()) { 224 sb.append(", altDown"); 225 } 226 if (isMetaDown()) { 227 sb.append(", metaDown"); 228 } 229 if (isShortcutDown()) { 230 sb.append(", shortcutDown"); 231 } 232 sb.append(", pickResult = ").append(getPickResult()); 233 234 return sb.append("]").toString(); 235 } 236 237 @Override 238 public ZoomEvent copyFor(Object newSource, EventTarget newTarget) { 239 return (ZoomEvent) super.copyFor(newSource, newTarget); 240 } 241 242 /** 243 * Creates a copy of the given event with the given fields substituted. 244 * @param source the new source of the copied event 245 * @param target the new target of the copied event 246 * @param eventType the new eventType 247 * @return the event copy with the fields substituted 248 * @since JavaFX 8.0 249 */ 250 public ZoomEvent copyFor(Object newSource, EventTarget newTarget, EventType<ZoomEvent> type) { 251 ZoomEvent e = copyFor(newSource, newTarget); 252 e.eventType = type; 253 return e; 254 } 255 256 @Override 257 public EventType<ZoomEvent> getEventType() { 258 return (EventType<ZoomEvent>) super.getEventType(); 259 } 260 261 262 }