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 * Rotate event indicates that user performed rotating gesture such as
033 * dragging two fingers around each other on track pad,
034 * touch screen or other 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 angle} is the rotation angle of this
042 * event, {@code totalAngle} is the rotation angle of the whole gesture. Both
043 * values are in degrees and work well when added to the node's {@code rotate}
044 * property value (positive values for clockwise rotation).
045 * <p>
046 * As all gestures, rotation 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 ROTATE} events are surounded by {@code ROTATION_STARTED}
053 * and {@code ROTATION_FINISHED} events. If rotation inertia is active on the
054 * given platform, some {@code ROTATE} events with {@code isInertia()} returning
055 * {@code true} can come after {@code ROTATION_FINISHED}.
056 *
057 * @since 2.2
058 */
059public final class RotateEvent extends GestureEvent {
060
061    private static final long serialVersionUID = 20121107L;
062
063    /**
064     * Common supertype for all rotate event types.
065     */
066    public static final EventType<RotateEvent> ANY =
067            new EventType<RotateEvent>(GestureEvent.ANY, "ANY_ROTATE");
068
069    /**
070     * This event occurs when user performs a rotating gesture such as
071     * dragging two fingers around each other.
072     */
073    public static final EventType<RotateEvent> ROTATE =
074            new EventType<RotateEvent>(RotateEvent.ANY, "ROTATE");
075
076    /**
077     * This event occurs when a rotating gesture is detected.
078     */
079    public static final EventType<RotateEvent> ROTATION_STARTED =
080            new EventType<RotateEvent>(RotateEvent.ANY, "ROTATION_STARTED");
081
082    /**
083     * This event occurs when a rotating gesture ends.
084     */
085    public static final EventType<RotateEvent> ROTATION_FINISHED =
086            new EventType<RotateEvent>(RotateEvent.ANY, "ROTATION_FINISHED");
087
088    /**
089     * Constructs new RotateEvent 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 inertia if represents inertia of an already finished gesture.
103     * @param angle the rotational angle
104     * @param totalAngle the cumulative rotational angle
105     * @param pickResult pick result. Can be null, in this case a 2D pick result
106     *                   without any further values is constructed
107     *                   based on the scene coordinates and the target
108     */
109    public RotateEvent(Object source, EventTarget target,
110            final EventType<RotateEvent> 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, double angle, double totalAngle,
119            PickResult pickResult) {
120
121        super(source, target, eventType, x, y, screenX, screenY,
122                shiftDown, controlDown, altDown, metaDown, direct, inertia,
123                pickResult);
124        this.angle = angle;
125        this.totalAngle = totalAngle;
126    }
127
128    /**
129     * Constructs new RotateEvent event with null source and target
130     * @param eventType The type of the event.
131     * @param x The x with respect to the scene.
132     * @param y The y with respect to the scene.
133     * @param screenX The x coordinate relative to screen.
134     * @param screenY The y coordinate relative to screen.
135     * @param shiftDown true if shift modifier was pressed.
136     * @param controlDown true if control modifier was pressed.
137     * @param altDown true if alt modifier was pressed.
138     * @param metaDown true if meta modifier was pressed.
139     * @param direct true if the event was caused by direct input device. See {@link #isDirect() }
140     * @param inertia if represents inertia of an already finished gesture.
141     * @param angle the rotational angle
142     * @param totalAngle the cumulative rotational angle
143     * @param pickResult pick result. Can be null, in this case a 2D pick result
144     *                   without any further values is constructed
145     *                   based on the scene coordinates
146     */
147    public RotateEvent(final EventType<RotateEvent> eventType,
148            double x, double y,
149            double screenX, double screenY,
150            boolean shiftDown,
151            boolean controlDown,
152            boolean altDown,
153            boolean metaDown,
154            boolean direct,
155            boolean inertia, double angle, double totalAngle,
156            PickResult pickResult) {
157        this(null, null, eventType, x, y, screenX, screenY, shiftDown, controlDown,
158                altDown, metaDown, direct, inertia, angle, totalAngle, pickResult);
159    }
160
161    private final double angle;
162
163    /**
164     * Gets the rotation angle of this event.
165     * The angle is in degrees and work well when added to the node's
166     * {@code rotate} property value (positive values for clockwise rotation).
167     * @return The rotation angle of this event
168     */
169    public double getAngle() {
170        return angle;
171    }
172
173    private final double totalAngle;
174
175    /**
176     * Gets the cumulative rotation angle of this gesture.
177     * The angle is in degrees and work well when added to the node's
178     * {@code rotate} property value (positive values for clockwise rotation).
179     * @return The cumulative rotation angle of this gesture
180     */
181    public double getTotalAngle() {
182        return totalAngle;
183    }
184
185    /**
186     * Returns a string representation of this {@code RotateEvent} object.
187     * @return a string representation of this {@code RotateEvent} object.
188     */
189    @Override public String toString() {
190        final StringBuilder sb = new StringBuilder("RotateEvent [");
191
192        sb.append("source = ").append(getSource());
193        sb.append(", target = ").append(getTarget());
194        sb.append(", eventType = ").append(getEventType());
195        sb.append(", consumed = ").append(isConsumed());
196
197        sb.append(", angle = ").append(getAngle());
198        sb.append(", totalAngle = ").append(getTotalAngle());
199        sb.append(", x = ").append(getX()).append(", y = ").append(getY())
200                .append(", z = ").append(getZ());
201        sb.append(isDirect() ? ", direct" : ", indirect");
202
203        if (isInertia()) {
204            sb.append(", inertia");
205        }
206
207        if (isShiftDown()) {
208            sb.append(", shiftDown");
209        }
210        if (isControlDown()) {
211            sb.append(", controlDown");
212        }
213        if (isAltDown()) {
214            sb.append(", altDown");
215        }
216        if (isMetaDown()) {
217            sb.append(", metaDown");
218        }
219        if (isShortcutDown()) {
220            sb.append(", shortcutDown");
221        }
222        sb.append(", pickResult = ").append(getPickResult());
223
224        return sb.append("]").toString();
225    }
226
227    @Override
228    public RotateEvent copyFor(Object newSource, EventTarget newTarget) {
229        return (RotateEvent) super.copyFor(newSource, newTarget);
230    }
231
232    /**
233     * Creates a copy of the given event with the given fields substituted.
234     * @param source the new source of the copied event
235     * @param target the new target of the copied event
236     * @param eventType the new eventType
237     * @return the event copy with the fields substituted
238     */
239    public RotateEvent copyFor(Object newSource, EventTarget newTarget, EventType<RotateEvent> type) {
240        RotateEvent e = copyFor(newSource, newTarget);
241        e.eventType = type;
242        return e;
243    }
244    
245    @Override
246    public EventType<RotateEvent> getEventType() {
247        return (EventType<RotateEvent>) super.getEventType();
248    }
249    
250    
251}