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;
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 }
|
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;
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 }
|