1 /* 2 * Copyright (c) 2010, 2016, 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 com.sun.javafx.embed; 27 28 import javafx.event.EventType; 29 import javafx.scene.input.KeyEvent; 30 import javafx.scene.input.MouseButton; 31 import javafx.scene.input.MouseEvent; 32 import javafx.scene.input.RotateEvent; 33 import javafx.scene.input.ScrollEvent; 34 import javafx.scene.input.SwipeEvent; 35 import javafx.scene.input.ZoomEvent; 36 37 import com.sun.javafx.tk.FocusCause; 38 39 /** 40 * An utility class to translate input events between embedded 41 * application and FX. 42 * 43 */ 44 public class AbstractEvents { 45 46 public final static int MOUSEEVENT_PRESSED = 0; 47 public final static int MOUSEEVENT_RELEASED = 1; 48 public final static int MOUSEEVENT_CLICKED = 2; 49 public final static int MOUSEEVENT_ENTERED = 3; 50 public final static int MOUSEEVENT_EXITED = 4; 51 public final static int MOUSEEVENT_MOVED = 5; 52 public final static int MOUSEEVENT_DRAGGED = 6; 53 public final static int MOUSEEVENT_VERTICAL_WHEEL = 7; 54 public final static int MOUSEEVENT_HORIZONTAL_WHEEL = 8; 55 56 public final static int MOUSEEVENT_NONE_BUTTON = 0; 57 public final static int MOUSEEVENT_PRIMARY_BUTTON = 1; 58 public final static int MOUSEEVENT_SECONDARY_BUTTON = 2; 59 public final static int MOUSEEVENT_MIDDLE_BUTTON = 4; 60 61 public final static int KEYEVENT_PRESSED = 0; 62 public final static int KEYEVENT_RELEASED = 1; 63 public final static int KEYEVENT_TYPED = 2; 64 65 public final static int ZOOMEVENT_STARTED = 0; 66 public final static int ZOOMEVENT_ZOOM = 1; 67 public final static int ZOOMEVENT_FINISHED = 2; 68 69 public final static int ROTATEEVENT_STARTED = 0; 70 public final static int ROTATEEVENT_ROTATE = 1; 71 public final static int ROTATEEVENT_FINISHED = 2; 72 73 public final static int SCROLLEVENT_STARTED = 0; 74 public final static int SCROLLEVENT_SCROLL = 1; 75 public final static int SCROLLEVENT_FINISHED = 2; 76 77 public final static int SWIPEEVENT_DOWN = 0; 78 public final static int SWIPEEVENT_UP = 1; 79 public final static int SWIPEEVENT_LEFT = 2; 80 public final static int SWIPEEVENT_RIGHT = 3; 81 82 public final static int FOCUSEVENT_ACTIVATED = 0; 83 public final static int FOCUSEVENT_TRAVERSED_FORWARD = 1; 84 public final static int FOCUSEVENT_TRAVERSED_BACKWARD = 2; 85 public final static int FOCUSEVENT_DEACTIVATED = 3; 86 87 public final static int MODIFIER_SHIFT = 1; 88 public final static int MODIFIER_CONTROL = 2; 89 public final static int MODIFIER_ALT = 4; 90 public final static int MODIFIER_META = 8; 91 92 public static EventType<MouseEvent> mouseIDToFXEventID(int embedMouseID) { 93 switch (embedMouseID) { 94 case MOUSEEVENT_PRESSED: 95 return MouseEvent.MOUSE_PRESSED; 96 case MOUSEEVENT_RELEASED: 97 return MouseEvent.MOUSE_RELEASED; 98 case MOUSEEVENT_CLICKED: 99 return MouseEvent.MOUSE_CLICKED; 100 case MOUSEEVENT_ENTERED: 101 return MouseEvent.MOUSE_ENTERED; 102 case MOUSEEVENT_EXITED: 103 return MouseEvent.MOUSE_EXITED; 104 case MOUSEEVENT_MOVED: 105 return MouseEvent.MOUSE_MOVED; 106 case MOUSEEVENT_DRAGGED: 107 return MouseEvent.MOUSE_DRAGGED; 108 } 109 // Should never reach here 110 return MouseEvent.MOUSE_MOVED; 111 } 112 113 public static MouseButton mouseButtonToFXMouseButton(int embedButton) { 114 switch (embedButton) { 115 case MOUSEEVENT_PRIMARY_BUTTON: 116 return MouseButton.PRIMARY; 117 case MOUSEEVENT_SECONDARY_BUTTON: 118 return MouseButton.SECONDARY; 119 case MOUSEEVENT_MIDDLE_BUTTON: 120 return MouseButton.MIDDLE; 121 } 122 // Should never reach here 123 return MouseButton.NONE; 124 } 125 126 public static EventType<KeyEvent> keyIDToFXEventType(int embedKeyID) { 127 switch (embedKeyID) { 128 case KEYEVENT_PRESSED: 129 return KeyEvent.KEY_PRESSED; 130 case KEYEVENT_RELEASED: 131 return KeyEvent.KEY_RELEASED; 132 case KEYEVENT_TYPED: 133 return KeyEvent.KEY_TYPED; 134 } 135 // Should never reach here 136 return KeyEvent.KEY_TYPED; 137 } 138 139 public static EventType<ZoomEvent> zoomIDToFXEventType(int zoomID) { 140 switch(zoomID) { 141 case ZOOMEVENT_STARTED: 142 return ZoomEvent.ZOOM_STARTED; 143 case ZOOMEVENT_ZOOM: 144 return ZoomEvent.ZOOM; 145 case ZOOMEVENT_FINISHED: 146 return ZoomEvent.ZOOM_FINISHED; 147 } 148 // Should never reach here 149 return ZoomEvent.ZOOM; 150 } 151 152 public static EventType<RotateEvent> rotateIDToFXEventType(int rotateID) { 153 switch(rotateID) { 154 case ROTATEEVENT_STARTED: 155 return RotateEvent.ROTATION_STARTED; 156 case ROTATEEVENT_ROTATE: 157 return RotateEvent.ROTATE; 158 case ROTATEEVENT_FINISHED: 159 return RotateEvent.ROTATION_FINISHED; 160 } 161 // Should never reach here 162 return RotateEvent.ROTATE; 163 } 164 165 public static EventType<SwipeEvent> swipeIDToFXEventType(int swipeID) { 166 switch(swipeID) { 167 case SWIPEEVENT_UP: 168 return SwipeEvent.SWIPE_UP; 169 case SWIPEEVENT_DOWN: 170 return SwipeEvent.SWIPE_DOWN; 171 case SWIPEEVENT_LEFT: 172 return SwipeEvent.SWIPE_LEFT; 173 case SWIPEEVENT_RIGHT: 174 return SwipeEvent.SWIPE_RIGHT; 175 } 176 // Should never reach here 177 return SwipeEvent.SWIPE_DOWN; 178 } 179 180 public static EventType<ScrollEvent> scrollIDToFXEventType(int scrollID) { 181 switch(scrollID) { 182 case SCROLLEVENT_STARTED: 183 return ScrollEvent.SCROLL_STARTED; 184 case SCROLLEVENT_FINISHED: 185 return ScrollEvent.SCROLL_FINISHED; 186 case MOUSEEVENT_VERTICAL_WHEEL: 187 case MOUSEEVENT_HORIZONTAL_WHEEL: 188 case SCROLLEVENT_SCROLL: 189 return ScrollEvent.SCROLL; 190 } 191 // Should never reach here 192 return ScrollEvent.SCROLL; 193 } 194 195 public static FocusCause focusCauseToPeerFocusCause(int focusCause) { 196 switch (focusCause) { 197 case FOCUSEVENT_ACTIVATED: 198 return FocusCause.ACTIVATED; 199 case FOCUSEVENT_TRAVERSED_FORWARD: 200 return FocusCause.TRAVERSED_FORWARD; 201 case FOCUSEVENT_TRAVERSED_BACKWARD: 202 return FocusCause.TRAVERSED_BACKWARD; 203 case FOCUSEVENT_DEACTIVATED: 204 return FocusCause.DEACTIVATED; 205 } 206 // Should never reach here 207 return FocusCause.ACTIVATED; 208 } 209 }