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 33 import com.sun.javafx.tk.FocusCause; 34 import javafx.scene.input.InputEvent; 35 import javafx.scene.input.ScrollEvent; 36 37 /** 38 * An utility class to translate input events between embedded 39 * application and FX. 40 * 41 */ 42 public class AbstractEvents { 43 44 public final static int MOUSEEVENT_PRESSED = 0; 45 public final static int MOUSEEVENT_RELEASED = 1; 46 public final static int MOUSEEVENT_CLICKED = 2; 47 public final static int MOUSEEVENT_ENTERED = 3; 48 public final static int MOUSEEVENT_EXITED = 4; 49 public final static int MOUSEEVENT_MOVED = 5; 50 public final static int MOUSEEVENT_DRAGGED = 6; 51 public final static int MOUSEEVENT_VERTICAL_WHEEL = 7; 52 public final static int MOUSEEVENT_HORIZONTAL_WHEEL = 8; 53 54 public final static int MOUSEEVENT_NONE_BUTTON = 0; 55 public final static int MOUSEEVENT_PRIMARY_BUTTON = 1; 56 public final static int MOUSEEVENT_SECONDARY_BUTTON = 2; 57 public final static int MOUSEEVENT_MIDDLE_BUTTON = 4; 58 59 public final static int KEYEVENT_PRESSED = 0; 60 public final static int KEYEVENT_RELEASED = 1; 61 public final static int KEYEVENT_TYPED = 2; 62 63 public final static int FOCUSEVENT_ACTIVATED = 0; 64 public final static int FOCUSEVENT_TRAVERSED_FORWARD = 1; 65 public final static int FOCUSEVENT_TRAVERSED_BACKWARD = 2; 66 public final static int FOCUSEVENT_DEACTIVATED = 3; 67 68 public final static int MODIFIER_SHIFT = 1; 69 public final static int MODIFIER_CONTROL = 2; 70 public final static int MODIFIER_ALT = 4; 71 public final static int MODIFIER_META = 8; 72 73 public static EventType<MouseEvent> mouseIDToFXEventID(int embedMouseID) { 74 switch (embedMouseID) { 75 case MOUSEEVENT_PRESSED: 76 return MouseEvent.MOUSE_PRESSED; 77 case MOUSEEVENT_RELEASED: 78 return MouseEvent.MOUSE_RELEASED; 79 case MOUSEEVENT_CLICKED: 80 return MouseEvent.MOUSE_CLICKED; 81 case MOUSEEVENT_ENTERED: 82 return MouseEvent.MOUSE_ENTERED; 83 case MOUSEEVENT_EXITED: 84 return MouseEvent.MOUSE_EXITED; 85 case MOUSEEVENT_MOVED: 86 return MouseEvent.MOUSE_MOVED; 87 case MOUSEEVENT_DRAGGED: 88 return MouseEvent.MOUSE_DRAGGED; 89 } 90 // Should never reach here 91 return MouseEvent.MOUSE_MOVED; 92 } 93 94 public static MouseButton mouseButtonToFXMouseButton(int embedButton) { 95 switch (embedButton) { 96 case MOUSEEVENT_PRIMARY_BUTTON: 97 return MouseButton.PRIMARY; 98 case MOUSEEVENT_SECONDARY_BUTTON: 99 return MouseButton.SECONDARY; 100 case MOUSEEVENT_MIDDLE_BUTTON: 101 return MouseButton.MIDDLE; 102 } 103 // Should never reach here 104 return MouseButton.NONE; 105 } 106 107 public static EventType<KeyEvent> keyIDToFXEventType(int embedKeyID) { 108 switch (embedKeyID) { 109 case KEYEVENT_PRESSED: 110 return KeyEvent.KEY_PRESSED; 111 case KEYEVENT_RELEASED: 112 return KeyEvent.KEY_RELEASED; 113 case KEYEVENT_TYPED: 114 return KeyEvent.KEY_TYPED; 115 } 116 // Should never reach here 117 return KeyEvent.KEY_TYPED; 118 } 119 120 public static FocusCause focusCauseToPeerFocusCause(int focusCause) { 121 switch (focusCause) { 122 case FOCUSEVENT_ACTIVATED: 123 return FocusCause.ACTIVATED; 124 case FOCUSEVENT_TRAVERSED_FORWARD: 125 return FocusCause.TRAVERSED_FORWARD; 126 case FOCUSEVENT_TRAVERSED_BACKWARD: 127 return FocusCause.TRAVERSED_BACKWARD; 128 case FOCUSEVENT_DEACTIVATED: 129 return FocusCause.DEACTIVATED; 130 } 131 // Should never reach here 132 return FocusCause.ACTIVATED; 133 } 134 }