Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.input; 027 028import javafx.event.EventTarget; 029import javafx.event.EventType; 030 031/** 032 * Zoom event indicates that user performed zooming gesture such as 033 * dragging two fingers apart on track pad, touch screen or other 034 * similar device. 035 * <p> 036 * The event is delivered to the top-most 037 * node picked on the gesture coordinates in time of the gesture start - the 038 * whole gesture is delivered to the same node even if the coordinates change 039 * during the gesture. 040 * <p> 041 * The event provides two values: {@code zoomFactor} is the zooming amount 042 * of this event, {@code totalZoomFactor} is the zooming amount of the whole 043 * gesture. The values work well when multiplied with the node's {@code scale} 044 * properties (values greater than {@code 1} for zooming in). 045 * <p> 046 * As all gestures, zooming can be direct (performed directly at 047 * the concrete coordinates as on touch screen - the center point among all 048 * the touches is usually used as the gesture coordinates) or indirect (performed 049 * indirectly as on track pad - the mouse cursor location is usually used 050 * as the gesture coordinates). 051 * <p> 052 * The gesture's {@code ZOOM} events are surounded by {@code ZOOM_STARTED} 053 * and {@code ZOOM_FINISHED} events. If zooming inertia is active on the 054 * given platform, some {@code ZOOM} events with {@code isInertia()} returning 055 * {@code true} can come after {@code ZOOM_FINISHED}. 056 * 057 * @since 2.2 058 */ 059public final class ZoomEvent extends GestureEvent { 060 061 private static final long serialVersionUID = 20121107L; 062 063 /** 064 * Common supertype for all zoom event types. 065 */ 066 public static final EventType<ZoomEvent> ANY = 067 new EventType<ZoomEvent>(GestureEvent.ANY, "ANY_ZOOM"); 068 069 /** 070 * This event occurs when user performs a zooming gesture such as 071 * dragging two fingers apart. 072 */ 073 public static final EventType<ZoomEvent> ZOOM = 074 new EventType<ZoomEvent>(ZoomEvent.ANY, "ZOOM"); 075 076 /** 077 * This event occurs when a zooming gesture is detected. 078 */ 079 public static final EventType<ZoomEvent> ZOOM_STARTED = 080 new EventType<ZoomEvent>(ZoomEvent.ANY, "ZOOM_STARTED"); 081 082 /** 083 * This event occurs when a zooming gesture ends. 084 */ 085 public static final EventType<ZoomEvent> ZOOM_FINISHED = 086 new EventType<ZoomEvent>(ZoomEvent.ANY, "ZOOM_FINISHED"); 087 088 /** 089 * Constructs new ZoomEvent event. 090 * @param source the source of the event. Can be null. 091 * @param target the target of the event. Can be null. 092 * @param eventType The type of the event. 093 * @param x The x with respect to the scene. 094 * @param y The y with respect to the scene. 095 * @param screenX The x coordinate relative to screen. 096 * @param screenY The y coordinate relative to screen. 097 * @param shiftDown true if shift modifier was pressed. 098 * @param controlDown true if control modifier was pressed. 099 * @param altDown true if alt modifier was pressed. 100 * @param metaDown true if meta modifier was pressed. 101 * @param direct true if the event was caused by direct input device. See {@link #isDirect() } 102 * @param touchCount number of touch points 103 * @param inertia if represents inertia of an already finished gesture. 104 * @param zoomFactor zoom amount 105 * @param totalZoomFactor cumulative zoom amount 106 * @param pickResult pick result. Can be null, in this case a 2D pick result 107 * without any further values is constructed 108 * based on the scene coordinates and the target 109 */ 110 public ZoomEvent(Object source, EventTarget target, final EventType<ZoomEvent> eventType, 111 double x, double y, 112 double screenX, double screenY, 113 boolean shiftDown, 114 boolean controlDown, 115 boolean altDown, 116 boolean metaDown, 117 boolean direct, 118 boolean inertia, 119 double zoomFactor, 120 double totalZoomFactor, 121 PickResult pickResult) { 122 123 super(source, target, eventType, x, y, screenX, screenY, 124 shiftDown, controlDown, altDown, metaDown, direct, inertia, pickResult); 125 this.zoomFactor = zoomFactor; 126 this.totalZoomFactor = totalZoomFactor; 127 } 128 129 /** 130 * Constructs new ZoomEvent event with null source and target. 131 * @param eventType The type of the event. 132 * @param x The x with respect to the scene. 133 * @param y The y with respect to the scene. 134 * @param screenX The x coordinate relative to screen. 135 * @param screenY The y coordinate relative to screen. 136 * @param shiftDown true if shift modifier was pressed. 137 * @param controlDown true if control modifier was pressed. 138 * @param altDown true if alt modifier was pressed. 139 * @param metaDown true if meta modifier was pressed. 140 * @param direct true if the event was caused by direct input device. See {@link #isDirect() } 141 * @param touchCount number of touch points 142 * @param inertia if represents inertia of an already finished gesture. 143 * @param zoomFactor zoom amount 144 * @param totalZoomFactor cumulative zoom amount 145 * @param pickResult pick result. Can be null, in this case a 2D pick result 146 * without any further values is constructed 147 * based on the scene coordinates 148 */ 149 public ZoomEvent(final EventType<ZoomEvent> eventType, 150 double x, double y, 151 double screenX, double screenY, 152 boolean shiftDown, 153 boolean controlDown, 154 boolean altDown, 155 boolean metaDown, 156 boolean direct, 157 boolean inertia, 158 double zoomFactor, 159 double totalZoomFactor, 160 PickResult pickResult) { 161 this(null, null, eventType, x, y, screenX, screenY, shiftDown, controlDown, 162 altDown, metaDown, direct, inertia, zoomFactor, totalZoomFactor, 163 pickResult); 164 } 165 166 private final double zoomFactor; 167 168 /** 169 * Gets the zooming amount of this event. The factor value works well when 170 * multiplied with the node's {@code scale} properties (values greater 171 * than {@code 1} for zooming in, values between {@code 0} and {@code 1} 172 * for zooming out). 173 * @return The zooming amount of this event 174 */ 175 public double getZoomFactor() { 176 return zoomFactor; 177 } 178 179 private final double totalZoomFactor; 180 181 /** 182 * Gets the zooming amount of this gesture. The factor value works well when 183 * multiplied with the node's {@code scale} properties (values greater 184 * than {@code 1} for zooming in, values between {@code 0} and {@code 1} 185 * for zooming out). 186 * @return The cumulative zooming amount of this gesture 187 */ 188 public double getTotalZoomFactor() { 189 return totalZoomFactor; 190 } 191 192 /** 193 * Returns a string representation of this {@code ZoomEvent} object. 194 * @return a string representation of this {@code ZoomEvent} object. 195 */ 196 @Override public String toString() { 197 final StringBuilder sb = new StringBuilder("ZoomEvent ["); 198 199 sb.append("source = ").append(getSource()); 200 sb.append(", target = ").append(getTarget()); 201 sb.append(", eventType = ").append(getEventType()); 202 sb.append(", consumed = ").append(isConsumed()); 203 204 sb.append(", zoomFactor = ").append(getZoomFactor()); 205 sb.append(", totalZoomFactor = ").append(getTotalZoomFactor()); 206 sb.append(", x = ").append(getX()).append(", y = ").append(getY()) 207 .append(", z = ").append(getZ()); 208 sb.append(isDirect() ? ", direct" : ", indirect"); 209 210 if (isInertia()) { 211 sb.append(", inertia"); 212 } 213 214 if (isShiftDown()) { 215 sb.append(", shiftDown"); 216 } 217 if (isControlDown()) { 218 sb.append(", controlDown"); 219 } 220 if (isAltDown()) { 221 sb.append(", altDown"); 222 } 223 if (isMetaDown()) { 224 sb.append(", metaDown"); 225 } 226 if (isShortcutDown()) { 227 sb.append(", shortcutDown"); 228 } 229 sb.append(", pickResult = ").append(getPickResult()); 230 231 return sb.append("]").toString(); 232 } 233 234 @Override 235 public ZoomEvent copyFor(Object newSource, EventTarget newTarget) { 236 return (ZoomEvent) super.copyFor(newSource, newTarget); 237 } 238 239 /** 240 * Creates a copy of the given event with the given fields substituted. 241 * @param source the new source of the copied event 242 * @param target the new target of the copied event 243 * @param eventType the new eventType 244 * @return the event copy with the fields substituted 245 */ 246 public ZoomEvent copyFor(Object newSource, EventTarget newTarget, EventType<ZoomEvent> type) { 247 ZoomEvent e = copyFor(newSource, newTarget); 248 e.eventType = type; 249 return e; 250 } 251 252 @Override 253 public EventType<ZoomEvent> getEventType() { 254 return (EventType<ZoomEvent>) super.getEventType(); 255 } 256 257 258}