1 | package org.expeditee.gio.gesture;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.expeditee.core.Point;
|
---|
7 | import org.expeditee.gio.EcosystemManager;
|
---|
8 | import org.expeditee.gio.TimeoutQueue.TimeoutHandle;
|
---|
9 | import org.expeditee.gio.gesture.Gesture.GestureType;
|
---|
10 | import org.expeditee.gio.gesture.StandardGestureActions.StandardGestureType;
|
---|
11 | import org.expeditee.gio.gesture.data.ChangeColourGestureData;
|
---|
12 | import org.expeditee.gio.gesture.data.ClickGestureData;
|
---|
13 | import org.expeditee.gio.gesture.data.CreateItemGestureData;
|
---|
14 | import org.expeditee.gio.gesture.data.CreateItemGestureData.ItemType;
|
---|
15 | import org.expeditee.gio.gesture.data.DeleteGestureData;
|
---|
16 | import org.expeditee.gio.gesture.data.FormatGestureData;
|
---|
17 | import org.expeditee.gio.gesture.data.GestureData;
|
---|
18 | import org.expeditee.gio.gesture.data.InsertStringGestureData;
|
---|
19 | import org.expeditee.gio.gesture.data.ItemSpecificGestureData;
|
---|
20 | import org.expeditee.gio.gesture.data.JustifyGestureData;
|
---|
21 | import org.expeditee.gio.gesture.data.LinkGestureData;
|
---|
22 | import org.expeditee.gio.gesture.data.NavigateFrameGestureData;
|
---|
23 | import org.expeditee.gio.gesture.data.NavigateTextGestureData;
|
---|
24 | import org.expeditee.gio.gesture.data.PanGestureData;
|
---|
25 | import org.expeditee.gio.gesture.data.PickUpGestureData;
|
---|
26 | import org.expeditee.gio.gesture.data.RefreshGestureData;
|
---|
27 | import org.expeditee.gio.gesture.data.ScaleGestureData;
|
---|
28 | import org.expeditee.gio.gesture.data.SelectAreaGestureData;
|
---|
29 | import org.expeditee.gio.gesture.data.UndoGestureData;
|
---|
30 | import org.expeditee.gio.gesture.data.ZoomGestureData;
|
---|
31 | import org.expeditee.gio.input.InputEvent;
|
---|
32 | import org.expeditee.gio.input.InputEvent.InputType;
|
---|
33 | import org.expeditee.gio.input.InputEventToGestureTranslator;
|
---|
34 | import org.expeditee.gio.input.InputEventToGestureTranslatorSet;
|
---|
35 | import org.expeditee.gio.input.KBMInputEvent;
|
---|
36 | import org.expeditee.gio.input.KBMInputEvent.EventType;
|
---|
37 | import org.expeditee.gio.input.KBMInputEvent.Key;
|
---|
38 | import org.expeditee.gio.input.KBMInputEvent.MouseButton;
|
---|
39 | import org.expeditee.gio.input.StandardInputEventListeners;
|
---|
40 | import org.expeditee.gio.input.TimeoutInputEvent;
|
---|
41 | import org.expeditee.gui.DisplayController;
|
---|
42 | import org.expeditee.gui.FrameUtils;
|
---|
43 | import org.expeditee.gui.FreeItems;
|
---|
44 | import org.expeditee.items.Item;
|
---|
45 | import org.expeditee.items.Line;
|
---|
46 | import org.expeditee.items.Text;
|
---|
47 | import org.expeditee.settings.UserSettings;
|
---|
48 | import org.expeditee.settings.experimental.ExperimentalFeatures;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Class for translating raw keyboard and mouse input into Expeditee gestures.
|
---|
52 | *
|
---|
53 | * @author cts16
|
---|
54 | */
|
---|
55 | public class ExpediteeKBMGestureTranslator extends InputEventToGestureTranslatorSet
|
---|
56 | {
|
---|
57 | /** Convenience definition of this translator's input type. */
|
---|
58 | private static final InputType KBM = InputType.KBM;
|
---|
59 |
|
---|
60 | /** Tracks when the mouse has moved too far away from it's click position and should no-op. */
|
---|
61 | private static boolean _noop = false;
|
---|
62 | /** Tracks the starting position of a mouse drag. */
|
---|
63 | private static Point _mouseDragStart;
|
---|
64 |
|
---|
65 | public ExpediteeKBMGestureTranslator()
|
---|
66 | {
|
---|
67 | // Create the list of sub-translators
|
---|
68 | initialiseExpediteeTranslators();
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public List<Gesture> onInputEvent(InputEvent event)
|
---|
73 | {
|
---|
74 | // Track when the mouse has moved too far and should no-op
|
---|
75 | if (event.getInputType() == KBM) {
|
---|
76 | trackMouseDragNoop((KBMInputEvent) event);
|
---|
77 | }
|
---|
78 |
|
---|
79 | return super.onInputEvent(event);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /** Adds all gesture translators that base Expeditee utilises. */
|
---|
83 | private void initialiseExpediteeTranslators()
|
---|
84 | {
|
---|
85 | // TODO: Remove. Reference automatically falls through. cts16
|
---|
86 | ExpediteeKBMGestureTranslator kbmTranslator = this;
|
---|
87 |
|
---|
88 | // Add the CHAR_TYPED -> INSERT_STRING gesture recogniser
|
---|
89 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
90 | {
|
---|
91 | @Override
|
---|
92 | public String details() { return "CHAR_TYPED -> INSERT_STRING"; }
|
---|
93 |
|
---|
94 | @Override
|
---|
95 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
96 | // Cast to keyboard/mouse event
|
---|
97 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
98 |
|
---|
99 | // Check if it's a typing event
|
---|
100 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.CHAR_TYPED) {
|
---|
101 | return null;
|
---|
102 | }
|
---|
103 |
|
---|
104 | //System.err.println("ExpediteeKBMGestureTranslator::" + details() + ": " + kbmEvent.getCharTyped());
|
---|
105 | // Generate a INSERT_STRING gesture
|
---|
106 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.INSERT_STRING), new InsertStringGestureData(kbmEvent.getCharTyped(), kbmTranslator.isKeyDown(Key.SHIFT)));
|
---|
107 | }
|
---|
108 | });
|
---|
109 |
|
---|
110 | // Add the MOUSE_MOVED -> MOVE_CURSOR gesture recogniser
|
---|
111 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
112 | {
|
---|
113 | @Override
|
---|
114 | public String details() { return "MOUSE_MOVED -> MOVE_CURSOR"; }
|
---|
115 |
|
---|
116 | @Override
|
---|
117 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
118 | // Cast to keyboard/mouse event
|
---|
119 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
120 |
|
---|
121 | // Check if it's a mouse movement event
|
---|
122 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.MOUSE_MOVE) {
|
---|
123 | return null;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // Generate a CURSOR_MOVED gesture
|
---|
127 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.MOVE_CURSOR), new GestureData(kbmEvent.getMouseMove().getSecondEnd().clone()));
|
---|
128 | }
|
---|
129 | });
|
---|
130 |
|
---|
131 | // Add the LEFT CLICK + MOUSE_MOVE -> SELECT_AREA gesture recogniser
|
---|
132 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
133 | {
|
---|
134 | //private static final int NO_CONSTRAINT = 0;
|
---|
135 | private SelectAreaGestureData _draggedFromData = null;
|
---|
136 | //private int _constrainedDirection = NO_CONSTRAINT;
|
---|
137 |
|
---|
138 | @Override
|
---|
139 | public String details() { return "LEFT CLICK + MOUSE_MOVE -> SELECT_AREA"; }
|
---|
140 |
|
---|
141 | @Override
|
---|
142 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
143 | // Cast to keyboard/mouse event
|
---|
144 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
145 |
|
---|
146 | // Check we are holding the left button only
|
---|
147 | if (!kbmTranslator.isOnlyMouseButtonDown(MouseButton.LEFT)) {
|
---|
148 | // If we were dragging, reset the dragging tracker and send the drag-finished gesture
|
---|
149 | if (_draggedFromData != null) {
|
---|
150 | SelectAreaGestureData finalData = _draggedFromData.finalise();
|
---|
151 | _draggedFromData = null;
|
---|
152 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SELECT_AREA), finalData);
|
---|
153 |
|
---|
154 | // Otherwise just return
|
---|
155 | } else {
|
---|
156 | return null;
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | // Check if it's a mouse movement event
|
---|
161 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.MOUSE_MOVE) {
|
---|
162 | return null;
|
---|
163 | }
|
---|
164 |
|
---|
165 | // If we are just starting to drag, save the start position of the gesture
|
---|
166 | if (_draggedFromData == null) {
|
---|
167 | _draggedFromData = new SelectAreaGestureData(kbmEvent.getMouseMove().getSecondEnd().clone(), kbmEvent.getMouseMove().getFirstEnd().clone());
|
---|
168 | }
|
---|
169 |
|
---|
170 | // If holding control, move the mouse cursor to a constrained position
|
---|
171 | Point newMousePos = kbmEvent.getMouseMove().getFirstEnd().clone();
|
---|
172 | /* if (kbmTranslator.isKeyDown(Key.CTRL) && FreeItems.hasItemsAttachedToCursor()) {
|
---|
173 | if (_constrainedDirection == NO_CONSTRAINT) {
|
---|
174 | // Decide the direction of constraint
|
---|
175 | _constrainedDirection = Constraint.DIAGONAL_POS;
|
---|
176 | int absX = kbmEvent.getMouseMove().deltaX();
|
---|
177 | if (absX < 0) {
|
---|
178 | absX = -absX;
|
---|
179 | _constrainedDirection = Constraint.DIAGONAL_NEG;
|
---|
180 | }
|
---|
181 | int absY = kbmEvent.getMouseMove().deltaY();
|
---|
182 | if (absY < 0) {
|
---|
183 | absY = -absY;
|
---|
184 | if (_constrainedDirection == Constraint.DIAGONAL_NEG) {
|
---|
185 | _constrainedDirection = Constraint.DIAGONAL_POS;
|
---|
186 | } else {
|
---|
187 | _constrainedDirection = Constraint.DIAGONAL_NEG;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | if (absY <= absX / 2) {
|
---|
191 | _constrainedDirection = Constraint.HORIZONTAL;
|
---|
192 | } else if (absX <= absY / 2) {
|
---|
193 | _constrainedDirection = Constraint.VERTICAL;
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | int dX, dY;
|
---|
198 | if (_constrainedDirection == Constraint.HORIZONTAL) {
|
---|
199 | dX = kbmEvent.getMouseMove().deltaX();
|
---|
200 | dY = 0;
|
---|
201 | } else if (_constrainedDirection == Constraint.VERTICAL) {
|
---|
202 | dX = 0;
|
---|
203 | dY = kbmEvent.getMouseMove().deltaY();
|
---|
204 | } else if (_constrainedDirection == Constraint.DIAGONAL_POS) {
|
---|
205 | dX = dY = (kbmEvent.getMouseMove().deltaX() + kbmEvent.getMouseMove().deltaY()) / 2;
|
---|
206 | } else {
|
---|
207 | dY = (kbmEvent.getMouseMove().deltaY() - kbmEvent.getMouseMove().deltaX()) / 2;
|
---|
208 | dX = -dY;
|
---|
209 | }
|
---|
210 |
|
---|
211 | // Cause feedback loop by moving the mouse to the calculated position
|
---|
212 | newMousePos.add(1, 1);
|
---|
213 | } else*/ {
|
---|
214 | //_constrainedDirection = NO_CONSTRAINT;
|
---|
215 | newMousePos = kbmEvent.getMouseMove().getSecondEnd().clone();
|
---|
216 | }
|
---|
217 |
|
---|
218 | // Generate a SELECT_AREA gesture
|
---|
219 | _draggedFromData = _draggedFromData.carryOn(newMousePos);
|
---|
220 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SELECT_AREA), _draggedFromData);
|
---|
221 | }
|
---|
222 | });
|
---|
223 |
|
---|
224 | // Add the HOME/END/LEFT/RIGHT/PAGE_UP/PAGE_DOWN -> NAVIGATE_FRAME gesture recogniser
|
---|
225 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
226 | {
|
---|
227 | @Override
|
---|
228 | public String details() { return "HOME/END/LEFT/RIGHT/PAGE_UP/PAGE_DOWN/BACKSPACE -> NAVIGATE_FRAME"; }
|
---|
229 |
|
---|
230 | @Override
|
---|
231 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
232 | // Cast to keyboard/mouse event
|
---|
233 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
234 |
|
---|
235 | // Alt is for mouse emulation
|
---|
236 | if (kbmTranslator.isKeyDown(Key.ALT)) {
|
---|
237 | return null;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // Decide which frame to navigate to
|
---|
241 | NavigateFrameGestureData.NavigateTo navigateTo;
|
---|
242 | if (kbmEvent.getKeyDown() == Key.HOME) {
|
---|
243 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
244 | navigateTo = NavigateFrameGestureData.NavigateTo.EARLIEST_FRAME;
|
---|
245 | } else {
|
---|
246 | navigateTo = NavigateFrameGestureData.NavigateTo.ZERO_FRAME;
|
---|
247 | }
|
---|
248 | } else if(kbmEvent.getKeyDown() == Key.END) {
|
---|
249 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
250 | navigateTo = NavigateFrameGestureData.NavigateTo.LATEST_FRAME;
|
---|
251 | } else {
|
---|
252 | navigateTo = NavigateFrameGestureData.NavigateTo.LAST_FRAME;
|
---|
253 | }
|
---|
254 | } else if(kbmEvent.getKeyDown() == Key.LEFT_ARROW && !kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
255 | navigateTo = NavigateFrameGestureData.NavigateTo.PREVIOUS_FRAME;
|
---|
256 | } else if(kbmEvent.getKeyDown() == Key.RIGHT_ARROW && !kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
257 | navigateTo = NavigateFrameGestureData.NavigateTo.NEXT_FRAME;
|
---|
258 | } else if(kbmEvent.getKeyDown() == Key.PAGE_UP) {
|
---|
259 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
260 | navigateTo = NavigateFrameGestureData.NavigateTo.BACK_FRAME;
|
---|
261 | } else {
|
---|
262 | navigateTo = NavigateFrameGestureData.NavigateTo.NEXT_FRAME;
|
---|
263 | }
|
---|
264 | } else if(kbmEvent.getKeyDown() == Key.PAGE_DOWN) {
|
---|
265 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
266 | navigateTo = NavigateFrameGestureData.NavigateTo.FORWARD_FRAME;
|
---|
267 | } else {
|
---|
268 | navigateTo = NavigateFrameGestureData.NavigateTo.PREVIOUS_FRAME;
|
---|
269 | }
|
---|
270 | } else if(kbmEvent.getKeyDown() == Key.BACKSPACE && kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
271 | navigateTo = NavigateFrameGestureData.NavigateTo.BACK_FRAME;
|
---|
272 | } else {
|
---|
273 | return null;
|
---|
274 | }
|
---|
275 |
|
---|
276 | // Check we aren't over text
|
---|
277 | Item on = FrameUtils.getCurrentItem();
|
---|
278 | if (on != null && on instanceof Text && !on.isFrameName()) {
|
---|
279 | return null;
|
---|
280 | }
|
---|
281 |
|
---|
282 | // Generate a CURSOR_MOVED gesture
|
---|
283 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.NAVIGATE_FRAME), new NavigateFrameGestureData(navigateTo));
|
---|
284 | }
|
---|
285 | });
|
---|
286 |
|
---|
287 | // Add the HOME/END/LEFT/RIGHT/PAGE_UP/PAGE_DOWN -> NAVIGATE_TEXT gesture recogniser
|
---|
288 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
289 | {
|
---|
290 | @Override
|
---|
291 | public String details() { return "HOME/END/LEFT/RIGHT/PAGE_UP/PAGE_DOWN -> NAVIGATE_TEXT"; }
|
---|
292 |
|
---|
293 | @Override
|
---|
294 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
295 | // Cast to keyboard/mouse event
|
---|
296 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
297 |
|
---|
298 | // Alt is for mouse emulation
|
---|
299 | if (kbmTranslator.isKeyDown(Key.ALT)) {
|
---|
300 | return null;
|
---|
301 | }
|
---|
302 |
|
---|
303 | // Decide which frame to navigate to
|
---|
304 | NavigateTextGestureData.NavigateTo navigateTo;
|
---|
305 | if (kbmEvent.getKeyDown() == Key.HOME) {
|
---|
306 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
307 | navigateTo = NavigateTextGestureData.NavigateTo.PARAGRAPH_HOME;
|
---|
308 | } else {
|
---|
309 | navigateTo = NavigateTextGestureData.NavigateTo.LINE_HOME;
|
---|
310 | }
|
---|
311 | } else if(kbmEvent.getKeyDown() == Key.END) {
|
---|
312 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
313 | navigateTo = NavigateTextGestureData.NavigateTo.PARAGRAPH_END;
|
---|
314 | } else {
|
---|
315 | navigateTo = NavigateTextGestureData.NavigateTo.LINE_END;
|
---|
316 | }
|
---|
317 | } else if(kbmEvent.getKeyDown() == Key.LEFT_ARROW) {
|
---|
318 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
319 | navigateTo = NavigateTextGestureData.NavigateTo.PREVIOUS_WORD;
|
---|
320 | } else {
|
---|
321 | navigateTo = NavigateTextGestureData.NavigateTo.PREVIOUS_CHARACTER;
|
---|
322 | }
|
---|
323 | } else if(kbmEvent.getKeyDown() == Key.RIGHT_ARROW) {
|
---|
324 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
325 | navigateTo = NavigateTextGestureData.NavigateTo.NEXT_WORD;
|
---|
326 | } else {
|
---|
327 | navigateTo = NavigateTextGestureData.NavigateTo.NEXT_CHARACTER;
|
---|
328 | }
|
---|
329 | } else if(kbmEvent.getKeyDown() == Key.UP_ARROW) {
|
---|
330 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
331 | navigateTo = NavigateTextGestureData.NavigateTo.PREVIOUS_TEXT_ITEM;
|
---|
332 | } else {
|
---|
333 | navigateTo = NavigateTextGestureData.NavigateTo.ABOVE_LINE;
|
---|
334 | }
|
---|
335 | } else if(kbmEvent.getKeyDown() == Key.DOWN_ARROW) {
|
---|
336 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
337 | navigateTo = NavigateTextGestureData.NavigateTo.NEXT_TEXT_ITEM;
|
---|
338 | } else {
|
---|
339 | navigateTo = NavigateTextGestureData.NavigateTo.BELOW_LINE;
|
---|
340 | }
|
---|
341 | } else {
|
---|
342 | return null;
|
---|
343 | }
|
---|
344 |
|
---|
345 | // Check we are over text
|
---|
346 | Item on = FrameUtils.getCurrentItem();
|
---|
347 | if (on == null || !(on instanceof Text) || on.isFrameName()) {
|
---|
348 | return null;
|
---|
349 | }
|
---|
350 |
|
---|
351 | // See if we are holding shift to select text
|
---|
352 | boolean selecting = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
353 |
|
---|
354 | // Generate a CURSOR_MOVED gesture
|
---|
355 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.NAVIGATE_TEXT), new NavigateTextGestureData(navigateTo, selecting));
|
---|
356 | }
|
---|
357 | });
|
---|
358 |
|
---|
359 | // Add the SHIFT + LEFT_CLICK + MOUSE_MOVE -> PAN gesture recogniser
|
---|
360 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
361 | {
|
---|
362 | private Point _panStart;
|
---|
363 |
|
---|
364 | @Override
|
---|
365 | public String details() { return "SHIFT + LEFT_CLICK + MOUSE_MOVE -> PAN"; }
|
---|
366 |
|
---|
367 | @Override
|
---|
368 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
369 | // Cast to keyboard/mouse event
|
---|
370 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
371 |
|
---|
372 | // See if we are panning
|
---|
373 | if (ExperimentalFeatures.MousePan.get() &&
|
---|
374 | !FrameUtils.hasCurrentItem() &&
|
---|
375 | kbmTranslator.isMouseButtonDown(MouseButton.LEFT) &&
|
---|
376 | kbmTranslator.isKeyDown(Key.SHIFT) &&
|
---|
377 | kbmEvent.getEventType() == KBMInputEvent.EventType.MOUSE_MOVE)
|
---|
378 | {
|
---|
379 | if (_panStart == null) {
|
---|
380 | _panStart = kbmEvent.getMouseMove().getFirstEnd().clone();
|
---|
381 | }
|
---|
382 | } else {
|
---|
383 | _panStart = null;
|
---|
384 | return null;
|
---|
385 | }
|
---|
386 |
|
---|
387 | // Generate a PAN gesture
|
---|
388 | Point panPosition = kbmEvent.getMouseMove().getSecondEnd();
|
---|
389 | Point panDelta = Point.difference(kbmEvent.getMouseMove().getSecondEnd(), kbmEvent.getMouseMove().getFirstEnd());
|
---|
390 |
|
---|
391 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PAN), new PanGestureData(panPosition, _panStart, panDelta));
|
---|
392 | }
|
---|
393 | });
|
---|
394 |
|
---|
395 | // Add the ALT + ARROW_KEYS -> MOVE_CURSOR gesture recogniser
|
---|
396 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
397 | {
|
---|
398 | private final int MACRO_CURSOR_MOVE_DISTANCE = 20;
|
---|
399 | private final int MICRO_CURSOR_MOVE_DISTANCE = 1;
|
---|
400 |
|
---|
401 | @Override
|
---|
402 | public String details() { return "ALT + ARROW_KEYS -> MOVE_CURSOR"; }
|
---|
403 |
|
---|
404 | @Override
|
---|
405 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
406 | // Cast to keyboard/mouse event
|
---|
407 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
408 |
|
---|
409 | // Can return if not pressing any of the arrow keys
|
---|
410 | if ( (kbmEvent.getKeyDown() != Key.UP_ARROW) &&
|
---|
411 | (kbmEvent.getKeyDown() != Key.DOWN_ARROW) &&
|
---|
412 | (kbmEvent.getKeyDown() != Key.LEFT_ARROW) &&
|
---|
413 | (kbmEvent.getKeyDown() != Key.RIGHT_ARROW))
|
---|
414 | {
|
---|
415 | return null;
|
---|
416 | }
|
---|
417 |
|
---|
418 | // Must be holding ALT for mouse emulation
|
---|
419 | if (!kbmTranslator.isKeyDown(Key.ALT)) {
|
---|
420 | return null;
|
---|
421 | }
|
---|
422 |
|
---|
423 | // Decide how far to move
|
---|
424 | int distance = kbmTranslator.isKeyDown(Key.SHIFT) ? MICRO_CURSOR_MOVE_DISTANCE : MACRO_CURSOR_MOVE_DISTANCE;
|
---|
425 |
|
---|
426 | // Calculate the new cursor position
|
---|
427 | Point cursorPosition = EcosystemManager.getInputManager().getCursorPosition();
|
---|
428 | if (kbmEvent.getKeyDown() == Key.UP_ARROW) {
|
---|
429 | cursorPosition.setY(cursorPosition.getY() - distance);
|
---|
430 | }
|
---|
431 | if (kbmEvent.getKeyDown() == Key.DOWN_ARROW) {
|
---|
432 | cursorPosition.setY(cursorPosition.getY() + distance);
|
---|
433 | }
|
---|
434 | if (kbmEvent.getKeyDown() == Key.LEFT_ARROW) {
|
---|
435 | cursorPosition.setX(cursorPosition.getX() - distance);
|
---|
436 | }
|
---|
437 | if (kbmEvent.getKeyDown() == Key.RIGHT_ARROW) {
|
---|
438 | cursorPosition.setX(cursorPosition.getX() + distance);
|
---|
439 | }
|
---|
440 |
|
---|
441 | // Create the MOVE_CURSOR gesture and return it
|
---|
442 | Gesture moveCursorGesture = new Gesture(StandardGestureActions.getInstance().gestureType(StandardGestureType.MOVE_CURSOR), new SelectAreaGestureData(cursorPosition));
|
---|
443 | moveCursorGesture.setRobotic(true);
|
---|
444 | return Gesture.single(moveCursorGesture);
|
---|
445 | }
|
---|
446 | });
|
---|
447 |
|
---|
448 | // Add the F1/F2 -> ZOOM_IN/OUT gesture recogniser
|
---|
449 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
450 | {
|
---|
451 | private final float ZOOM_IN_SCALE_FACTOR = 1.1f;
|
---|
452 | private final float ZOOM_OUT_SCALE_FACTOR = 1f / ZOOM_IN_SCALE_FACTOR;
|
---|
453 |
|
---|
454 | @Override
|
---|
455 | public String details() { return "F1/F2 -> ZOOM_IN/OUT"; }
|
---|
456 |
|
---|
457 | @Override
|
---|
458 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
459 | // Cast to keyboard/mouse event
|
---|
460 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
461 |
|
---|
462 | // Decide on a scale factor
|
---|
463 | float scaleFactor;
|
---|
464 | if (kbmEvent.getKeyDown() == KBMInputEvent.Key.F1) {
|
---|
465 | scaleFactor = ZOOM_IN_SCALE_FACTOR;
|
---|
466 | } else if (kbmEvent.getKeyDown() == KBMInputEvent.Key.F2) {
|
---|
467 | scaleFactor = ZOOM_OUT_SCALE_FACTOR;
|
---|
468 | } else {
|
---|
469 | return null;
|
---|
470 | }
|
---|
471 |
|
---|
472 | // Return if zoom is disabled
|
---|
473 | if (!ExperimentalFeatures.FrameZoom.get()) {
|
---|
474 | return null;
|
---|
475 | }
|
---|
476 |
|
---|
477 | // Make sure we are pointing at free space (or the frame name)
|
---|
478 | Item currentItem = FrameUtils.getCurrentItem();
|
---|
479 | Collection<Item> currentItems = FrameUtils.getCurrentItems(currentItem);
|
---|
480 | if ((currentItem != null && !currentItem.isFrameName()) || (currentItems != null && currentItems.size() > 0)) {
|
---|
481 | return null;
|
---|
482 | }
|
---|
483 |
|
---|
484 | // Decide on where to zoom around
|
---|
485 | Point centreOfZoom;
|
---|
486 | if (ExperimentalFeatures.FrameZoomAroundCursor.get()) {
|
---|
487 | centreOfZoom = EcosystemManager.getInputManager().getCursorPosition();
|
---|
488 | } else {
|
---|
489 | centreOfZoom = new Point(0, 0);
|
---|
490 | }
|
---|
491 |
|
---|
492 | // Return zoom gesture
|
---|
493 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ZOOM), new ZoomGestureData(centreOfZoom, scaleFactor));
|
---|
494 | }
|
---|
495 | });
|
---|
496 |
|
---|
497 | // Add the F1/F2 -> SCALE gesture recogniser
|
---|
498 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
499 | {
|
---|
500 | private final int SCALE_UP_FACTOR = 1;
|
---|
501 | private final int SCALE_DOWN_FACTOR = -1;
|
---|
502 |
|
---|
503 | @Override
|
---|
504 | public String details() { return "F1/F2 -> SCALE"; }
|
---|
505 |
|
---|
506 | @Override
|
---|
507 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
508 | // Cast to keyboard/mouse event
|
---|
509 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
510 |
|
---|
511 | // Decide whether to scale up or down or not at all
|
---|
512 | int scaleFactor;
|
---|
513 | if (kbmEvent.getKeyDown() == KBMInputEvent.Key.F1) {
|
---|
514 | scaleFactor = SCALE_UP_FACTOR;
|
---|
515 | } else if (kbmEvent.getKeyDown() == KBMInputEvent.Key.F2) {
|
---|
516 | scaleFactor = SCALE_DOWN_FACTOR;
|
---|
517 | } else {
|
---|
518 | return null;
|
---|
519 | }
|
---|
520 |
|
---|
521 | // Decide where to scale around
|
---|
522 | ScaleGestureData data;
|
---|
523 | if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
524 | data = new ScaleGestureData(scaleFactor);
|
---|
525 | } else {
|
---|
526 | data = new ScaleGestureData(null, scaleFactor);
|
---|
527 | }
|
---|
528 |
|
---|
529 | // Return scale gestures
|
---|
530 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SCALE), data);
|
---|
531 | }
|
---|
532 | });
|
---|
533 |
|
---|
534 | // Add the F3 -> CHANGE_COLOUR gesture recogniser
|
---|
535 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
536 | {
|
---|
537 | @Override
|
---|
538 | public String details() { return "F3 -> CHANGE_COLOUR"; }
|
---|
539 |
|
---|
540 | @Override
|
---|
541 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
542 | // Cast to keyboard/mouse event
|
---|
543 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
544 |
|
---|
545 | // Must be pressing F3 to change colours
|
---|
546 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F3) {
|
---|
547 | return null;
|
---|
548 | }
|
---|
549 |
|
---|
550 | // Decide how to change the colour
|
---|
551 | boolean shouldSetTransparent = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
552 | boolean shouldSetSecondaryColour = kbmTranslator.isKeyDown(Key.CTRL);
|
---|
553 |
|
---|
554 | // Return the gesture
|
---|
555 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CHANGE_COLOUR), new ChangeColourGestureData(shouldSetTransparent, shouldSetSecondaryColour));
|
---|
556 | }
|
---|
557 | });
|
---|
558 |
|
---|
559 | // Add the F4 -> TOGGLE_ANNOTATION gesture recogniser
|
---|
560 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
561 | {
|
---|
562 | @Override
|
---|
563 | public String details() { return "F4 -> TOGGLE_ANNOTATION"; }
|
---|
564 |
|
---|
565 | @Override
|
---|
566 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
567 | // Cast to keyboard/mouse event
|
---|
568 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
569 |
|
---|
570 | // Must be pressing F4 to toggle annotations
|
---|
571 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F4) {
|
---|
572 | return null;
|
---|
573 | }
|
---|
574 |
|
---|
575 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
576 |
|
---|
577 | // Return the gesture
|
---|
578 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ANNOTATION), new ItemSpecificGestureData(isShiftDown));
|
---|
579 | }
|
---|
580 | });
|
---|
581 |
|
---|
582 | // Add the F5 -> INSERT_DATE gesture recogniser
|
---|
583 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
584 | {
|
---|
585 | @Override
|
---|
586 | public String details() { return "F5 -> INSERT_DATE"; }
|
---|
587 |
|
---|
588 | @Override
|
---|
589 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
590 | // Cast to keyboard/mouse event
|
---|
591 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
592 |
|
---|
593 | // Must be pressing F5 to insert the date
|
---|
594 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F5) {
|
---|
595 | return null;
|
---|
596 | }
|
---|
597 |
|
---|
598 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
599 |
|
---|
600 | // Return the gesture
|
---|
601 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.INSERT_DATE), new ItemSpecificGestureData(isShiftDown));
|
---|
602 | }
|
---|
603 | });
|
---|
604 |
|
---|
605 | // Add the F6 -> NEW_FRAMESET gesture recogniser
|
---|
606 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
607 | {
|
---|
608 | @Override
|
---|
609 | public String details() { return "F6 -> NEW_FRAMESET"; }
|
---|
610 |
|
---|
611 | @Override
|
---|
612 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
613 | // Cast to keyboard/mouse event
|
---|
614 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
615 |
|
---|
616 | // Must be pressing F6 to create a new frameset
|
---|
617 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F6) {
|
---|
618 | return null;
|
---|
619 | }
|
---|
620 |
|
---|
621 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
622 |
|
---|
623 | // Return the gesture
|
---|
624 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.NEW_FRAMESET), new ItemSpecificGestureData(isShiftDown));
|
---|
625 | }
|
---|
626 | });
|
---|
627 |
|
---|
628 | // Add the F7 -> ROTATE_FONT_STYLE gesture recogniser
|
---|
629 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
630 | {
|
---|
631 | @Override
|
---|
632 | public String details() { return "F7 -> ROTATE_FONT_STYLE"; }
|
---|
633 |
|
---|
634 | @Override
|
---|
635 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
636 | // Cast to keyboard/mouse event
|
---|
637 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
638 |
|
---|
639 | // Must be pressing F7 to rotate font style
|
---|
640 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F7) {
|
---|
641 | return null;
|
---|
642 | }
|
---|
643 |
|
---|
644 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
645 |
|
---|
646 | // Return the gesture
|
---|
647 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ROTATE_FONT_STYLE), new ItemSpecificGestureData(isShiftDown));
|
---|
648 | }
|
---|
649 | });
|
---|
650 |
|
---|
651 | // Add the F8 -> ROTATE_FONT_FAMILY gesture recogniser
|
---|
652 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
653 | {
|
---|
654 | @Override
|
---|
655 | public String details() { return "F8 -> ROTATE_FONT_FAMILY"; }
|
---|
656 |
|
---|
657 | @Override
|
---|
658 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
659 | // Cast to keyboard/mouse event
|
---|
660 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
661 |
|
---|
662 | // Must be pressing F8 to rotate font family
|
---|
663 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F8) {
|
---|
664 | return null;
|
---|
665 | }
|
---|
666 |
|
---|
667 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
668 |
|
---|
669 | // Return the gesture
|
---|
670 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ROTATE_FONT_FAMILY), new ItemSpecificGestureData(isShiftDown));
|
---|
671 | }
|
---|
672 | });
|
---|
673 |
|
---|
674 | // Add the F9 -> TOGGLE_AUDIENCE_MODE gesture recogniser
|
---|
675 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
676 | {
|
---|
677 | @Override
|
---|
678 | public String details() { return "F9 -> TOGGLE_AUDIENCE_MODE"; }
|
---|
679 |
|
---|
680 | @Override
|
---|
681 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
682 | // Cast to keyboard/mouse event
|
---|
683 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
684 |
|
---|
685 | // Must be pressing F9 to toggle audience mode
|
---|
686 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F9) {
|
---|
687 | return null;
|
---|
688 | }
|
---|
689 |
|
---|
690 | // Return the gesture
|
---|
691 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ROTATE_DISPLAY_MODE), null);
|
---|
692 | }
|
---|
693 | });
|
---|
694 |
|
---|
695 | // Add the F10 -> TOGGLE_XRAY_MODE gesture recogniser
|
---|
696 | addTranslator(new InputEventToGestureTranslator(InputType.KBM) {
|
---|
697 |
|
---|
698 | @Override
|
---|
699 | public String details() { return "F10 -> TOGGLE_XRAY_MODE"; }
|
---|
700 |
|
---|
701 | @Override
|
---|
702 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
703 | // Cast to keyboard/mouse event
|
---|
704 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
705 |
|
---|
706 | // Must be pressing F10 to xray mode
|
---|
707 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F10 || kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
708 | return null;
|
---|
709 | }
|
---|
710 |
|
---|
711 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_XRAY_MODE), null);
|
---|
712 | }
|
---|
713 | });
|
---|
714 |
|
---|
715 | // Add the F10 -> CYCLE_SURROGATE_MODE gesture recogniser
|
---|
716 | addTranslator(new InputEventToGestureTranslator(InputType.KBM) {
|
---|
717 | @Override
|
---|
718 | public String details() { return "F10 -> CYCLE_SURROGATE_MODE"; }
|
---|
719 |
|
---|
720 | @Override
|
---|
721 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
722 | // Case to keyboard/mouse event
|
---|
723 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
724 |
|
---|
725 | // Must be pressing F10 to surrogate mode
|
---|
726 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F10 || !kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
727 | return null;
|
---|
728 | }
|
---|
729 |
|
---|
730 | UndoGestureData data = new UndoGestureData(kbmTranslator.isKeyDown(Key.CTRL));
|
---|
731 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CYCLE_SURROGATE_MODE), data);
|
---|
732 | }
|
---|
733 | });
|
---|
734 |
|
---|
735 | // Add the F11 -> SAVE gesture recogniser
|
---|
736 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
737 | {
|
---|
738 | @Override
|
---|
739 | public String details() { return "F11 -> SAVE"; }
|
---|
740 |
|
---|
741 | @Override
|
---|
742 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
743 | // Cast to keyboard/mouse event
|
---|
744 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
745 |
|
---|
746 | // Must be pressing F11 to save
|
---|
747 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F11) {
|
---|
748 | return null;
|
---|
749 | }
|
---|
750 |
|
---|
751 | // Return the gesture
|
---|
752 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SAVE), null);
|
---|
753 | }
|
---|
754 | });
|
---|
755 |
|
---|
756 | // Add the F12 -> REFRESH gesture recogniser
|
---|
757 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
758 | {
|
---|
759 | @Override
|
---|
760 | public String details() { return "F12 -> REFRESH"; }
|
---|
761 |
|
---|
762 | @Override
|
---|
763 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
764 | // Cast to keyboard/mouse event
|
---|
765 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
766 |
|
---|
767 | // Must be pressing F12 to refresh
|
---|
768 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F12) {
|
---|
769 | return null;
|
---|
770 | }
|
---|
771 |
|
---|
772 | // Decide how to refresh
|
---|
773 | boolean shouldReloadFrameFirst = kbmTranslator.isKeyDown(Key.CTRL);
|
---|
774 | boolean shouldRefreshFrameSize = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
775 |
|
---|
776 | // Return the gesture
|
---|
777 | return standardSingle(StandardGestureType.REFRESH, new RefreshGestureData(shouldReloadFrameFirst, shouldRefreshFrameSize));
|
---|
778 | }
|
---|
779 | });
|
---|
780 |
|
---|
781 | // Add the ESC -> DROP_DOWN gesture recogniser
|
---|
782 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
783 | {
|
---|
784 | @Override
|
---|
785 | public String details() { return "ESC -> DROP_DOWN"; }
|
---|
786 |
|
---|
787 | @Override
|
---|
788 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
789 | // Cast to keyboard/mouse event
|
---|
790 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
791 |
|
---|
792 | // Shift/Ctrl + Esc is calculate
|
---|
793 | if (kbmTranslator.isKeyDown(Key.SHIFT) || kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
794 | return null;
|
---|
795 | }
|
---|
796 |
|
---|
797 | // Must be pressing ESC to drop down
|
---|
798 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.ESC) {
|
---|
799 | return null;
|
---|
800 | }
|
---|
801 |
|
---|
802 | // Return the gesture
|
---|
803 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.DROP_DOWN), null);
|
---|
804 | }
|
---|
805 | });
|
---|
806 |
|
---|
807 | // Add the SHIFT/CTRL + ESC -> CALCULATE gesture recogniser
|
---|
808 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
809 | {
|
---|
810 | @Override
|
---|
811 | public String details() { return "SHIFT/CTRL + ESC -> CALCULATE"; }
|
---|
812 |
|
---|
813 | @Override
|
---|
814 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
815 | // Cast to keyboard/mouse event
|
---|
816 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
817 |
|
---|
818 | // Check that shift or ctrl is down
|
---|
819 | if (!kbmTranslator.isKeyDown(Key.SHIFT) && !kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
820 | return null;
|
---|
821 | }
|
---|
822 |
|
---|
823 | // Must be pressing Esc to calculate
|
---|
824 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.ESC) {
|
---|
825 | return null;
|
---|
826 | }
|
---|
827 |
|
---|
828 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
829 |
|
---|
830 | // Return the gesture
|
---|
831 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CALCULATE), new ItemSpecificGestureData(isShiftDown));
|
---|
832 | }
|
---|
833 | });
|
---|
834 |
|
---|
835 | // Add the CTRL + TAB -> CALCULATE gesture recogniser
|
---|
836 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
837 | {
|
---|
838 | @Override
|
---|
839 | public String details() { return "CTRL + TAB -> CALCULATE"; }
|
---|
840 |
|
---|
841 | @Override
|
---|
842 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
843 | // Cast to keyboard/mouse event
|
---|
844 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
845 |
|
---|
846 | // Check that ctrl is down
|
---|
847 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
848 | return null;
|
---|
849 | }
|
---|
850 |
|
---|
851 | // Must be pressing tab to calculate
|
---|
852 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.TAB) {
|
---|
853 | return null;
|
---|
854 | }
|
---|
855 |
|
---|
856 | // Return the gesture
|
---|
857 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CALCULATE), new ItemSpecificGestureData(false));
|
---|
858 | }
|
---|
859 | });
|
---|
860 |
|
---|
861 | // Add the CTRL + L -> LINK gesture recogniser
|
---|
862 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
863 | {
|
---|
864 | @Override
|
---|
865 | public String details() { return "CTRL + L -> LINK"; }
|
---|
866 |
|
---|
867 | @Override
|
---|
868 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
869 | // Cast to keyboard/mouse event
|
---|
870 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
871 |
|
---|
872 | // Check that ctrl is down
|
---|
873 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
874 | return null;
|
---|
875 | }
|
---|
876 |
|
---|
877 | // Must be pressing L to link
|
---|
878 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.L) {
|
---|
879 | return null;
|
---|
880 | }
|
---|
881 |
|
---|
882 | // Return the gesture
|
---|
883 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.LINK), new LinkGestureData(false));
|
---|
884 | }
|
---|
885 | });
|
---|
886 |
|
---|
887 | // Add the CTRL + G -> LINK gesture recogniser
|
---|
888 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
889 | {
|
---|
890 | @Override
|
---|
891 | public String details() { return "CTRL + G -> LINK"; }
|
---|
892 |
|
---|
893 | @Override
|
---|
894 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
895 | // Cast to keyboard/mouse event
|
---|
896 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
897 |
|
---|
898 | // Check that ctrl is down
|
---|
899 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
900 | return null;
|
---|
901 | }
|
---|
902 |
|
---|
903 | // Must be pressing G to link
|
---|
904 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.G) {
|
---|
905 | return null;
|
---|
906 | }
|
---|
907 |
|
---|
908 | // Return the gesture
|
---|
909 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.LINK), new LinkGestureData(true));
|
---|
910 | }
|
---|
911 | });
|
---|
912 |
|
---|
913 | // Add the CTRL + A -> ACTION gesture recogniser
|
---|
914 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
915 | {
|
---|
916 | @Override
|
---|
917 | public String details() { return "CTRL + A -> ACTION"; }
|
---|
918 |
|
---|
919 | @Override
|
---|
920 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
921 | // Cast to keyboard/mouse event
|
---|
922 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
923 |
|
---|
924 | // Check that ctrl is down
|
---|
925 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
926 | return null;
|
---|
927 | }
|
---|
928 |
|
---|
929 | // Must be pressing A to action
|
---|
930 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.A) {
|
---|
931 | return null;
|
---|
932 | }
|
---|
933 |
|
---|
934 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
935 |
|
---|
936 | // Return the gesture
|
---|
937 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ACTION), new ItemSpecificGestureData(isShiftDown));
|
---|
938 | }
|
---|
939 | });
|
---|
940 |
|
---|
941 | // Add the CTRL + B -> TOGGLE_BOLD gesture recogniser
|
---|
942 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
943 | {
|
---|
944 | @Override
|
---|
945 | public String details() { return "CTRL + B -> TOGGLE_BOLD"; }
|
---|
946 |
|
---|
947 | @Override
|
---|
948 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
949 | // Cast to keyboard/mouse event
|
---|
950 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
951 |
|
---|
952 | // Check that ctrl is down
|
---|
953 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
954 | return null;
|
---|
955 | }
|
---|
956 |
|
---|
957 | // Must be pressing B to toggle bold
|
---|
958 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.B) {
|
---|
959 | return null;
|
---|
960 | }
|
---|
961 |
|
---|
962 | boolean isShiftDown = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
963 |
|
---|
964 | // Return the gesture
|
---|
965 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_BOLD), new ItemSpecificGestureData(isShiftDown));
|
---|
966 | }
|
---|
967 | });
|
---|
968 |
|
---|
969 | // Add the CTRL + I -> TOGGLE_ITALICS gesture recogniser
|
---|
970 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
971 | {
|
---|
972 | @Override
|
---|
973 | public String details() { return "CTRL + I -> TOGGLE_ITALICS"; }
|
---|
974 |
|
---|
975 | @Override
|
---|
976 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
977 | // Cast to keyboard/mouse event
|
---|
978 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
979 |
|
---|
980 | // Check that ctrl is down
|
---|
981 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
982 | return null;
|
---|
983 | }
|
---|
984 |
|
---|
985 | // Must be pressing I to toggle italics
|
---|
986 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.I) {
|
---|
987 | return null;
|
---|
988 | }
|
---|
989 |
|
---|
990 | // Return the gesture
|
---|
991 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ITALICS), new ItemSpecificGestureData(false));
|
---|
992 | }
|
---|
993 | });
|
---|
994 |
|
---|
995 | // Add the CTRL + V -> PASTE gesture recogniser
|
---|
996 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
997 | {
|
---|
998 | @Override
|
---|
999 | public String details() { return "CTRL + V -> PASTE"; }
|
---|
1000 |
|
---|
1001 | @Override
|
---|
1002 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1003 | // Cast to keyboard/mouse event
|
---|
1004 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1005 |
|
---|
1006 | // Check that ctrl is down
|
---|
1007 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1008 | return null;
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | // Must be pressing V to paste
|
---|
1012 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.V) {
|
---|
1013 | return null;
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | // Return the gesture
|
---|
1017 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PASTE), null);
|
---|
1018 | }
|
---|
1019 | });
|
---|
1020 |
|
---|
1021 | // Add the CTRL + C -> COPY gesture recogniser
|
---|
1022 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1023 | {
|
---|
1024 | @Override
|
---|
1025 | public String details() { return "CTRL + C -> COPY"; }
|
---|
1026 |
|
---|
1027 | @Override
|
---|
1028 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1029 | // Cast to keyboard/mouse event
|
---|
1030 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1031 |
|
---|
1032 | // Check that ctrl is down
|
---|
1033 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1034 | return null;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | // Must be pressing C to copy
|
---|
1038 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.C) {
|
---|
1039 | return null;
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | // Return the gesture
|
---|
1043 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.COPY), new ItemSpecificGestureData(false));
|
---|
1044 | }
|
---|
1045 | });
|
---|
1046 |
|
---|
1047 | // Add the CTRL + C -> MAKE_CIRCLE gesture recogniser
|
---|
1048 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1049 | {
|
---|
1050 | @Override
|
---|
1051 | public String details() { return "CTRL + C -> MAKE_CIRCLE"; }
|
---|
1052 |
|
---|
1053 | @Override
|
---|
1054 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1055 | // Cast to keyboard/mouse event
|
---|
1056 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1057 |
|
---|
1058 | // Check that ctrl is down
|
---|
1059 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1060 | return null;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | // Must be pressing C to make circle
|
---|
1064 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.C) {
|
---|
1065 | return null;
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | // Make sure we aren't trying to do a copy-clone
|
---|
1069 | if (FreeItems.hasItemsAttachedToCursor()) {
|
---|
1070 | return null;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | // Return the gesture
|
---|
1074 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.MAKE_CIRCLE), new ItemSpecificGestureData(false));
|
---|
1075 | }
|
---|
1076 | });
|
---|
1077 |
|
---|
1078 | // Add the CTRL + X -> CUT gesture recogniser
|
---|
1079 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1080 | {
|
---|
1081 | @Override
|
---|
1082 | public String details() { return "CTRL + X -> CUT"; }
|
---|
1083 |
|
---|
1084 | @Override
|
---|
1085 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1086 | // Cast to keyboard/mouse event
|
---|
1087 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1088 |
|
---|
1089 | // Check that ctrl is down
|
---|
1090 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1091 | return null;
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | // Must be pressing X to cut
|
---|
1095 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.X) {
|
---|
1096 | return null;
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | // Return the gesture
|
---|
1100 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CUT), null);
|
---|
1101 | }
|
---|
1102 | });
|
---|
1103 |
|
---|
1104 | // Add the CTRL + M -> TOGGLE_ITEMS_MARK gesture recogniser
|
---|
1105 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1106 | {
|
---|
1107 | @Override
|
---|
1108 | public String details() { return "CTRL + M -> TOGGLE_ITEMS_MARK"; }
|
---|
1109 |
|
---|
1110 | @Override
|
---|
1111 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1112 | // Cast to keyboard/mouse event
|
---|
1113 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1114 |
|
---|
1115 | // Check that ctrl is down
|
---|
1116 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1117 | return null;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | // Must be pressing M to toggle items mark
|
---|
1121 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.M) {
|
---|
1122 | return null;
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | // Return the gesture
|
---|
1126 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ITEMS_MARK), new ItemSpecificGestureData(false));
|
---|
1127 | }
|
---|
1128 | });
|
---|
1129 |
|
---|
1130 | // Add the CTRL + Z -> UNDO gesture recogniser
|
---|
1131 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1132 | {
|
---|
1133 | @Override
|
---|
1134 | public String details() { return "CTRL + Z -> UNDO"; }
|
---|
1135 |
|
---|
1136 | @Override
|
---|
1137 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1138 | // Cast to keyboard/mouse event
|
---|
1139 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1140 |
|
---|
1141 | // Check that ctrl is down
|
---|
1142 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1143 | return null;
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | // Must be pressing Z to undo
|
---|
1147 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.X) {
|
---|
1148 | return null;
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | // Holding shift as well makes this a redo gesture
|
---|
1152 | boolean redo = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1153 |
|
---|
1154 | // Return the gesture
|
---|
1155 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.UNDO), new UndoGestureData(redo));
|
---|
1156 | }
|
---|
1157 | });
|
---|
1158 |
|
---|
1159 | // Add the CTRL + D -> INSERT_STRING gesture recogniser
|
---|
1160 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1161 | {
|
---|
1162 | @Override
|
---|
1163 | public String details() { return "CTRL + D -> INSERT_STRING"; }
|
---|
1164 |
|
---|
1165 | @Override
|
---|
1166 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1167 | // Cast to keyboard/mouse event
|
---|
1168 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1169 |
|
---|
1170 | // Check that ctrl is down
|
---|
1171 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1172 | return null;
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | // Must be pressing D to delete character
|
---|
1176 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.D) {
|
---|
1177 | return null;
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | // Return the gesture
|
---|
1181 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.INSERT_STRING), new InsertStringGestureData(Text.DELETE_CHARACTER, false));
|
---|
1182 | }
|
---|
1183 | });
|
---|
1184 |
|
---|
1185 | // Add the CTRL + DELETE -> DELETE gesture recogniser
|
---|
1186 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1187 | {
|
---|
1188 | @Override
|
---|
1189 | public String details() { return "CTRL + DELETE -> DELETE"; }
|
---|
1190 |
|
---|
1191 | @Override
|
---|
1192 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1193 | // Cast to keyboard/mouse event
|
---|
1194 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1195 |
|
---|
1196 | // Check that ctrl is down
|
---|
1197 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1198 | return null;
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | // Must be pressing DELETE to delete
|
---|
1202 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.DELETE) {
|
---|
1203 | return null;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | // Decide if this is an alternate mode delete
|
---|
1207 | // TODO: What specifically is alternate mode delete? cts16
|
---|
1208 | boolean alternateMode = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1209 |
|
---|
1210 | // Return the gesture
|
---|
1211 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.DELETE), new DeleteGestureData(alternateMode));
|
---|
1212 | }
|
---|
1213 | });
|
---|
1214 |
|
---|
1215 | // Add the CTRL + F -> FORMAT gesture recogniser
|
---|
1216 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1217 | {
|
---|
1218 | @Override
|
---|
1219 | public String details() { return "CTRL + F -> FORMAT"; }
|
---|
1220 |
|
---|
1221 | @Override
|
---|
1222 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1223 | // Cast to keyboard/mouse event
|
---|
1224 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1225 |
|
---|
1226 | // Check that ctrl is down
|
---|
1227 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1228 | return null;
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | // Must be pressing F to format
|
---|
1232 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F) {
|
---|
1233 | return null;
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | // Decide if this is an horizontal or vertical format
|
---|
1237 | boolean horizontal = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1238 |
|
---|
1239 | // Return the gesture
|
---|
1240 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.FORMAT), new FormatGestureData(horizontal));
|
---|
1241 | }
|
---|
1242 | });
|
---|
1243 |
|
---|
1244 | // Add the CTRL + J -> JUSTIFY gesture recogniser
|
---|
1245 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1246 | {
|
---|
1247 | @Override
|
---|
1248 | public String details() { return "CTRL + J -> JUSTIFY"; }
|
---|
1249 |
|
---|
1250 | @Override
|
---|
1251 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1252 | // Cast to keyboard/mouse event
|
---|
1253 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1254 |
|
---|
1255 | // Check that ctrl is down
|
---|
1256 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1257 | return null;
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | // Must be pressing J to justify
|
---|
1261 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.J) {
|
---|
1262 | return null;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | // Return the gesture
|
---|
1266 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.JUSTIFY), new JustifyGestureData(false));
|
---|
1267 | }
|
---|
1268 | });
|
---|
1269 |
|
---|
1270 | // Add the CTRL + R -> JUSTIFY gesture recogniser
|
---|
1271 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1272 | {
|
---|
1273 | @Override
|
---|
1274 | public String details() { return "CTRL + R -> JUSTIFY"; }
|
---|
1275 |
|
---|
1276 | @Override
|
---|
1277 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1278 | // Cast to keyboard/mouse event
|
---|
1279 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1280 |
|
---|
1281 | // Check that ctrl is down
|
---|
1282 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1283 | return null;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | // CTRL + SHIFT + R is the reparse frame body event
|
---|
1287 | if (kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1288 | return null;
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | // Must be pressing R to justify
|
---|
1292 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.R) {
|
---|
1293 | return null;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | // Return the gesture
|
---|
1297 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.JUSTIFY), new JustifyGestureData(true));
|
---|
1298 | }
|
---|
1299 | });
|
---|
1300 |
|
---|
1301 | // Add the CTRL + SHIFT + R -> REPARSE FRAME BODY gesture recogniser
|
---|
1302 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1303 | {
|
---|
1304 | @Override
|
---|
1305 | public String details() { return "CTRL + SHIFT + R -> REPARSE FRAME BODY"; }
|
---|
1306 |
|
---|
1307 | @Override
|
---|
1308 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1309 | // Cast to keyboard/mouse event
|
---|
1310 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1311 |
|
---|
1312 | // Check that ctrl is down
|
---|
1313 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1314 | return null;
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | // CTRL + SHIFT + R is the reparse frame body event
|
---|
1318 | if (!kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1319 | return null;
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | // Must be pressing R to justify
|
---|
1323 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.R) {
|
---|
1324 | return null;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | // Return the gesture
|
---|
1328 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.REPARSE), null);
|
---|
1329 | }
|
---|
1330 | });
|
---|
1331 |
|
---|
1332 | // Add the CTRL + S -> SAVE gesture recogniser
|
---|
1333 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1334 | {
|
---|
1335 | @Override
|
---|
1336 | public String details() { return "CTRL + S -> SAVE"; }
|
---|
1337 |
|
---|
1338 | @Override
|
---|
1339 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1340 | // Cast to keyboard/mouse event
|
---|
1341 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1342 |
|
---|
1343 | // Check that ctrl is down
|
---|
1344 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1345 | return null;
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | // Ctrl + Shift + S is split text
|
---|
1349 | if (kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1350 | return null;
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | // Must be pressing S to save
|
---|
1354 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.S) {
|
---|
1355 | return null;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | // Return the gesture
|
---|
1359 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SAVE), null);
|
---|
1360 | }
|
---|
1361 | });
|
---|
1362 |
|
---|
1363 | // Add the CTRL + SHIFT + S -> SPLIT_TEXT gesture recogniser
|
---|
1364 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1365 | {
|
---|
1366 | @Override
|
---|
1367 | public String details() { return "CTRL + SHIFT + S -> SPLIT_TEXT"; }
|
---|
1368 |
|
---|
1369 | @Override
|
---|
1370 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1371 | // Cast to keyboard/mouse event
|
---|
1372 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1373 |
|
---|
1374 | // Check that ctrl is down
|
---|
1375 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1376 | return null;
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 | // Ctrl + Shift + S is split text
|
---|
1380 | if (!kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1381 | return null;
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | // Must be pressing S to save
|
---|
1385 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.S) {
|
---|
1386 | return null;
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | // Return the gesture
|
---|
1390 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SPLIT_TEXT), new ItemSpecificGestureData(false));
|
---|
1391 | }
|
---|
1392 | });
|
---|
1393 |
|
---|
1394 | // Add the MIDDLE MOUSE + MOUSE_MOVE -> PICK_UP gesture recogniser
|
---|
1395 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1396 | {
|
---|
1397 | private SelectAreaGestureData _draggedFromData = null;
|
---|
1398 |
|
---|
1399 | @Override
|
---|
1400 | public String details() { return "MIDDLE MOUSE + MOUSE_MOVE -> PICK_UP"; }
|
---|
1401 |
|
---|
1402 | @Override
|
---|
1403 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1404 | // Cast to keyboard/mouse event
|
---|
1405 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1406 |
|
---|
1407 | // Check we are holding the middle button only
|
---|
1408 | if (!kbmTranslator.isOnlyMouseButtonDown(MouseButton.MIDDLE)) {
|
---|
1409 | // If we were dragging, reset the dragging tracker and send the drag-finished gesture
|
---|
1410 | if (_draggedFromData != null) {
|
---|
1411 | SelectAreaGestureData finalData = _draggedFromData.finalise();
|
---|
1412 | _draggedFromData = null;
|
---|
1413 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), finalData);
|
---|
1414 |
|
---|
1415 | // Otherwise just return
|
---|
1416 | } else {
|
---|
1417 | return null;
|
---|
1418 | }
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | // Check if it's a mouse movement event
|
---|
1422 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.MOUSE_MOVE) {
|
---|
1423 | return null;
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | // See if we should inherit the attributes of the thing we're picking up
|
---|
1427 | boolean inheritAttributes = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1428 |
|
---|
1429 | // If we are just starting to drag, save the start position of the gesture
|
---|
1430 | if (_draggedFromData == null) {
|
---|
1431 | _draggedFromData = new PickUpGestureData(kbmEvent.getMouseMove().getSecondEnd().clone(), kbmEvent.getMouseMove().getFirstEnd().clone(), false, inheritAttributes);
|
---|
1432 | }
|
---|
1433 |
|
---|
1434 | // Wait till we have moved out of no-op range before performing drag-pickup
|
---|
1435 | if (!isMouseDragNoOp()) {
|
---|
1436 | return null;
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | // Generate a PICK_UP gesture
|
---|
1440 | _draggedFromData = _draggedFromData.carryOn(kbmEvent.getMouseMove().getSecondEnd().clone());
|
---|
1441 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), _draggedFromData);
|
---|
1442 | }
|
---|
1443 | });
|
---|
1444 |
|
---|
1445 | // Add the MIDDLE MOUSE -> PICK_UP gesture recogniser
|
---|
1446 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1447 | {
|
---|
1448 | private Boolean _pickup = null;
|
---|
1449 | private Item _clickDownOn = null;
|
---|
1450 |
|
---|
1451 | @Override
|
---|
1452 | public String details() { return "MIDDLE MOUSE -> PICK_UP"; }
|
---|
1453 |
|
---|
1454 | @Override
|
---|
1455 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1456 | // Cast to keyboard/mouse event
|
---|
1457 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1458 |
|
---|
1459 | // Check for single middle click
|
---|
1460 | if (_pickup == null && kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1461 | _pickup = true;
|
---|
1462 | _clickDownOn = FrameUtils.getCurrentItem();
|
---|
1463 | return null;
|
---|
1464 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1465 | _pickup = false;
|
---|
1466 | return null;
|
---|
1467 | } else if (Boolean.FALSE.equals(_pickup) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1468 | _pickup = null;
|
---|
1469 | return null;
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | // Wait for the button up to perform the pickup
|
---|
1473 | if (!Boolean.TRUE.equals(_pickup) || kbmEvent.getMouseButtonUp() != MouseButton.MIDDLE) {
|
---|
1474 | return null;
|
---|
1475 | }
|
---|
1476 |
|
---|
1477 | // Reset pickup for next gesture
|
---|
1478 | _pickup = null;
|
---|
1479 |
|
---|
1480 | // Check we haven't moved too far
|
---|
1481 | if (isMouseDragNoOp()) {
|
---|
1482 | if (!(_clickDownOn instanceof Text)) {
|
---|
1483 | printNoopMessage();
|
---|
1484 | }
|
---|
1485 | return null;
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 | // Check we should be picking up (shift forces line creation)
|
---|
1489 | if (FreeItems.hasItemsAttachedToCursor() || kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1490 | return null;
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | // Check there is something to pick up
|
---|
1494 | if (!FrameUtils.hasCurrentItem() && FrameUtils.getCurrentItems() == null) {
|
---|
1495 | return null;
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | // Return the gesture
|
---|
1499 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), new PickUpGestureData(false));
|
---|
1500 | }
|
---|
1501 | });
|
---|
1502 |
|
---|
1503 | // Add the RIGHT MOUSE + MOUSE_MOVE -> PICK_UP gesture recogniser
|
---|
1504 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1505 | {
|
---|
1506 | private SelectAreaGestureData _draggedFromData = null;
|
---|
1507 |
|
---|
1508 | @Override
|
---|
1509 | public String details() { return "RIGHT MOUSE + MOUSE_MOVE -> PICK_UP"; }
|
---|
1510 |
|
---|
1511 | @Override
|
---|
1512 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1513 | // Cast to keyboard/mouse event
|
---|
1514 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1515 |
|
---|
1516 | // Check we are holding the middle button only
|
---|
1517 | if (!kbmTranslator.isOnlyMouseButtonDown(MouseButton.RIGHT)) {
|
---|
1518 | // If we were dragging, reset the dragging tracker and send the drag-finished gesture
|
---|
1519 | if (_draggedFromData != null) {
|
---|
1520 | SelectAreaGestureData finalData = _draggedFromData.finalise();
|
---|
1521 | _draggedFromData = null;
|
---|
1522 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), finalData);
|
---|
1523 |
|
---|
1524 | // Otherwise just return
|
---|
1525 | } else {
|
---|
1526 | return null;
|
---|
1527 | }
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | // Check if it's a mouse movement event
|
---|
1531 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.MOUSE_MOVE) {
|
---|
1532 | return null;
|
---|
1533 | }
|
---|
1534 |
|
---|
1535 | // See if we should inherit the attributes of the thing we're picking up
|
---|
1536 | boolean inheritAttributes = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1537 |
|
---|
1538 | // If we are just starting to drag, save the start position of the gesture
|
---|
1539 | if (_draggedFromData == null) {
|
---|
1540 | _draggedFromData = new PickUpGestureData(kbmEvent.getMouseMove().getSecondEnd().clone(), kbmEvent.getMouseMove().getFirstEnd().clone(), true, inheritAttributes);
|
---|
1541 | }
|
---|
1542 |
|
---|
1543 | // Wait till we have moved out of no-op range before performing drag-pickup
|
---|
1544 | if (!isMouseDragNoOp()) {
|
---|
1545 | return null;
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | // Generate a PICK_UP gesture
|
---|
1549 | _draggedFromData = _draggedFromData.carryOn(kbmEvent.getMouseMove().getSecondEnd().clone());
|
---|
1550 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), _draggedFromData);
|
---|
1551 | }
|
---|
1552 | });
|
---|
1553 |
|
---|
1554 | // Add the RIGHT MOUSE -> PICK_UP gesture recogniser
|
---|
1555 | addTranslator(new InputEventToGestureTranslator(new InputType[] { InputType.KBM, InputType.TIMEOUT })
|
---|
1556 | {
|
---|
1557 | private final static int EXTRUSION_DELAY_MS = 750;
|
---|
1558 | private final static int PULSE_AMOUNT = 2;
|
---|
1559 | private Boolean _pickup = null;
|
---|
1560 | private Item _clickedItem = null;
|
---|
1561 | private TimeoutHandle _timeoutHandle;
|
---|
1562 | private boolean _extrusionDelayExpired = false;
|
---|
1563 |
|
---|
1564 | @Override
|
---|
1565 | public String details() { return "RIGHT MOUSE -> PICK_UP"; }
|
---|
1566 |
|
---|
1567 | @Override
|
---|
1568 | public List<Gesture> onInputEvent(InputEvent event)
|
---|
1569 | {
|
---|
1570 | if (event == null) {
|
---|
1571 | return null;
|
---|
1572 | } else if (event.getInputType() == InputType.KBM) {
|
---|
1573 | return onKBMInputEvent((KBMInputEvent) event);
|
---|
1574 | } else if (event.getInputType() == InputType.TIMEOUT) {
|
---|
1575 | return onTimeoutInputEvent((TimeoutInputEvent) event);
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | return null;
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | private List<Gesture> onKBMInputEvent(KBMInputEvent kbmEvent)
|
---|
1582 | {
|
---|
1583 | // Check for single right click
|
---|
1584 | if (_pickup == null && kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1585 | _pickup = true;
|
---|
1586 | _timeoutHandle = EcosystemManager.getInputManager().addTimeout(EXTRUSION_DELAY_MS);
|
---|
1587 | _extrusionDelayExpired = false;
|
---|
1588 | _clickedItem = FrameUtils.getCurrentItem();
|
---|
1589 | return null;
|
---|
1590 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1591 | _pickup = false;
|
---|
1592 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
1593 | return null;
|
---|
1594 | } else if (Boolean.FALSE.equals(_pickup) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1595 | _pickup = null;
|
---|
1596 | return null;
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | // Wait for the button up to perform the pickup
|
---|
1600 | if (!Boolean.TRUE.equals(_pickup) || kbmEvent.getMouseButtonUp() != MouseButton.RIGHT) {
|
---|
1601 | return null;
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 | // Reset pickup for next gesture
|
---|
1605 | _pickup = null;
|
---|
1606 |
|
---|
1607 | // Cancel the extrusion timeout if it's pending
|
---|
1608 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
1609 |
|
---|
1610 | // Reset the line pulse if it occured
|
---|
1611 | if (_extrusionDelayExpired) {
|
---|
1612 | pulseExtrusionLines(false);
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | // Check we haven't moved too far
|
---|
1616 | if (isMouseDragNoOp()) {
|
---|
1617 | printNoopMessage();
|
---|
1618 | return null;
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | // Check we should be picking up (shift forces line creation)
|
---|
1622 | if (FreeItems.hasItemsAttachedToCursor() || kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1623 | return null;
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | // Check there is something to pick up
|
---|
1627 | if (!FrameUtils.hasCurrentItem() && FrameUtils.getCurrentItems() == null) {
|
---|
1628 | return null;
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | // Return the gesture
|
---|
1632 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), new PickUpGestureData(true, _extrusionDelayExpired));
|
---|
1633 | }
|
---|
1634 |
|
---|
1635 | private List<Gesture> onTimeoutInputEvent(TimeoutInputEvent event)
|
---|
1636 | {
|
---|
1637 | if (event.getHandle() == _timeoutHandle) {
|
---|
1638 | _extrusionDelayExpired = true;
|
---|
1639 | pulseExtrusionLines(true);
|
---|
1640 | }
|
---|
1641 |
|
---|
1642 | return null;
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 | private void pulseExtrusionLines(boolean pulseOn)
|
---|
1646 | {
|
---|
1647 | int amount = PULSE_AMOUNT;
|
---|
1648 | if (!pulseOn) {
|
---|
1649 | amount *= -1;
|
---|
1650 | }
|
---|
1651 |
|
---|
1652 | if (_clickedItem != null) {
|
---|
1653 | for (Item i : _clickedItem.getAllConnected()) {
|
---|
1654 | if (i instanceof Line) {
|
---|
1655 | Line line = (Line) i;
|
---|
1656 | line.setThickness(line.getThickness() + amount);
|
---|
1657 | }
|
---|
1658 | }
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | DisplayController.requestRefresh(true);
|
---|
1662 | }
|
---|
1663 | });
|
---|
1664 |
|
---|
1665 | // Add the MIDDLE MOUSE -> PLACE gesture recogniser
|
---|
1666 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1667 | {
|
---|
1668 | Boolean _place = null;
|
---|
1669 |
|
---|
1670 | @Override
|
---|
1671 | public String details() { return "MIDDLE MOUSE -> PLACE"; }
|
---|
1672 |
|
---|
1673 | @Override
|
---|
1674 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1675 | // Cast to keyboard/mouse event
|
---|
1676 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1677 |
|
---|
1678 | // Check for single middle click
|
---|
1679 | if (_place == null && kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1680 | _place = true;
|
---|
1681 | return null;
|
---|
1682 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1683 | _place = false;
|
---|
1684 | return null;
|
---|
1685 | } else if (Boolean.FALSE.equals(_place) && isAnyMouseButtonDown() == false) {
|
---|
1686 | _place = null;
|
---|
1687 | return null;
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 | // Wait for the button up to perform the place
|
---|
1691 | if (!Boolean.TRUE.equals(_place) || kbmEvent.getMouseButtonUp() != MouseButton.MIDDLE) {
|
---|
1692 | return null;
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | // Reset place for next gesture
|
---|
1696 | _place = null;
|
---|
1697 |
|
---|
1698 | // Check we haven't moved too far
|
---|
1699 | if (isMouseDragNoOp()) {
|
---|
1700 | printNoopMessage();
|
---|
1701 | return null;
|
---|
1702 | }
|
---|
1703 |
|
---|
1704 | // Check we should be placing
|
---|
1705 | if (!FreeItems.hasItemsAttachedToCursor()) {
|
---|
1706 | return null;
|
---|
1707 | }
|
---|
1708 |
|
---|
1709 | // Return the gesture
|
---|
1710 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PLACE), new PickUpGestureData(false));
|
---|
1711 | }
|
---|
1712 | });
|
---|
1713 |
|
---|
1714 | // Add the RIGHT MOUSE -> PLACE gesture recogniser
|
---|
1715 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1716 | {
|
---|
1717 | Boolean _place = null;
|
---|
1718 | @Override
|
---|
1719 | public String details() { return "RIGHT MOUSE -> PLACE"; }
|
---|
1720 |
|
---|
1721 | @Override
|
---|
1722 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1723 | // Cast to keyboard/mouse event
|
---|
1724 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1725 |
|
---|
1726 | // Check for single right click
|
---|
1727 | if (_place == null && kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1728 | _place = true;
|
---|
1729 | return null;
|
---|
1730 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1731 | _place = false;
|
---|
1732 | return null;
|
---|
1733 | } else if (Boolean.FALSE.equals(_place) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1734 | _place = null;
|
---|
1735 | return null;
|
---|
1736 | }
|
---|
1737 |
|
---|
1738 | // Wait for the button up to perform the place
|
---|
1739 | if (!Boolean.TRUE.equals(_place) || kbmEvent.getMouseButtonUp() != MouseButton.RIGHT) {
|
---|
1740 | return null;
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | // Reset place for next gesture
|
---|
1744 | _place = null;
|
---|
1745 |
|
---|
1746 | // Check we haven't moved too far
|
---|
1747 | if (isMouseDragNoOp()) {
|
---|
1748 | printNoopMessage();
|
---|
1749 | return null;
|
---|
1750 | }
|
---|
1751 |
|
---|
1752 | // Check we should be placing
|
---|
1753 | if (!FreeItems.hasItemsAttachedToCursor()) {
|
---|
1754 | return null;
|
---|
1755 | }
|
---|
1756 |
|
---|
1757 | // Return the gesture
|
---|
1758 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PLACE), new PickUpGestureData(true));
|
---|
1759 | }
|
---|
1760 | });
|
---|
1761 |
|
---|
1762 | // Add the MIDDLE + RIGHT MOUSE -> DELETE gesture recogniser
|
---|
1763 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1764 | {
|
---|
1765 | private static final int STATE_NO_MOUSE_BUTTON_DOWN = 0;
|
---|
1766 | private static final int STATE_MIDDLE_MOUSE_BUTTON_DOWN = 1;
|
---|
1767 | private static final int STATE_RIGHT_MOUSE_BUTTON_DOWN = 2;
|
---|
1768 | private static final int STATE_BOTH_MOUSE_BUTTON_DOWN = 3;
|
---|
1769 | private static final int STATE_ERROR = 4;
|
---|
1770 | private int _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1771 |
|
---|
1772 | @Override
|
---|
1773 | public String details() { return "MIDDLE + RIGHT MOUSE -> DELETE"; }
|
---|
1774 |
|
---|
1775 | @Override
|
---|
1776 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1777 | // Cast to keyboard/mouse event
|
---|
1778 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1779 |
|
---|
1780 | // Keep track of mouse button state
|
---|
1781 | if (_state == STATE_NO_MOUSE_BUTTON_DOWN) {
|
---|
1782 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1783 | _state = STATE_RIGHT_MOUSE_BUTTON_DOWN;
|
---|
1784 | } else if (kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1785 | _state = STATE_MIDDLE_MOUSE_BUTTON_DOWN;
|
---|
1786 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1787 | _state = STATE_ERROR;
|
---|
1788 | }
|
---|
1789 | return null;
|
---|
1790 | } else if (_state == STATE_MIDDLE_MOUSE_BUTTON_DOWN) {
|
---|
1791 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1792 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
1793 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.MIDDLE) {
|
---|
1794 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1795 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1796 | _state = STATE_ERROR;
|
---|
1797 | }
|
---|
1798 | return null;
|
---|
1799 | } else if (_state == STATE_RIGHT_MOUSE_BUTTON_DOWN) {
|
---|
1800 | if (kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1801 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
1802 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.RIGHT) {
|
---|
1803 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1804 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1805 | _state = STATE_ERROR;
|
---|
1806 | }
|
---|
1807 | return null;
|
---|
1808 | } else if (_state == STATE_BOTH_MOUSE_BUTTON_DOWN) {
|
---|
1809 | if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1810 | _state = STATE_ERROR;
|
---|
1811 | return null;
|
---|
1812 | }
|
---|
1813 | } else if (kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1814 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1815 | return null;
|
---|
1816 | }
|
---|
1817 |
|
---|
1818 | // Wait for the button up to perform the delete
|
---|
1819 | if (_state != STATE_BOTH_MOUSE_BUTTON_DOWN || kbmTranslator.isAnyMouseButtonDown()) {
|
---|
1820 | return null;
|
---|
1821 | }
|
---|
1822 |
|
---|
1823 | // Reset state for next gesture
|
---|
1824 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1825 |
|
---|
1826 | // Check we haven't moved too far
|
---|
1827 | if (isMouseDragNoOp()) {
|
---|
1828 | printNoopMessage();
|
---|
1829 | return null;
|
---|
1830 | }
|
---|
1831 |
|
---|
1832 | // Decide if this is an alternate mode delete
|
---|
1833 | // TODO: What specifically is alternate mode delete? cts16
|
---|
1834 | boolean alternateMode = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1835 |
|
---|
1836 | // Return the gesture
|
---|
1837 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.DELETE), new DeleteGestureData(alternateMode));
|
---|
1838 | }
|
---|
1839 | });
|
---|
1840 |
|
---|
1841 | // Add the MIDDLE MOUSE -> CREATE_ITEM gesture recogniser
|
---|
1842 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1843 | {
|
---|
1844 | Boolean _create = null;
|
---|
1845 | @Override
|
---|
1846 | public String details() { return "MIDDLE MOUSE -> CREATE_ITEM"; }
|
---|
1847 |
|
---|
1848 | @Override
|
---|
1849 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1850 | // Cast to keyboard/mouse event
|
---|
1851 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1852 |
|
---|
1853 | // Check for single middle click
|
---|
1854 | if (_create == null && kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1855 | _create = true;
|
---|
1856 | return null;
|
---|
1857 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1858 | _create = false;
|
---|
1859 | return null;
|
---|
1860 | } else if (Boolean.FALSE.equals(_create) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1861 | _create = null;
|
---|
1862 | return null;
|
---|
1863 | }
|
---|
1864 |
|
---|
1865 | // Wait for the button up to perform the create
|
---|
1866 | if (!Boolean.TRUE.equals(_create) || kbmEvent.getMouseButtonUp() != MouseButton.MIDDLE) {
|
---|
1867 | return null;
|
---|
1868 | }
|
---|
1869 |
|
---|
1870 | // Reset create for next gesture
|
---|
1871 | _create = null;
|
---|
1872 |
|
---|
1873 | // Check we haven't moved too far
|
---|
1874 | if (isMouseDragNoOp()) {
|
---|
1875 | printNoopMessage();
|
---|
1876 | return null;
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 | // Check we can create
|
---|
1880 | if (FreeItems.hasItemsAttachedToCursor()) {
|
---|
1881 | return null;
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 | // Check we're not trying to pick up (shift forces item creation)
|
---|
1885 | if (!kbmTranslator.isKeyDown(Key.SHIFT) && (FrameUtils.hasCurrentItem() || FrameUtils.getCurrentItems() != null)) {
|
---|
1886 | return null;
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | // Return the gesture
|
---|
1890 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CREATE_ITEM), new CreateItemGestureData(ItemType.LINE));
|
---|
1891 | }
|
---|
1892 | });
|
---|
1893 |
|
---|
1894 | // Add the RIGHT MOUSE -> CREATE_ITEM gesture recogniser
|
---|
1895 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1896 | {
|
---|
1897 | Boolean _create = null;
|
---|
1898 | @Override
|
---|
1899 | public String details() { return "RIGHT MOUSE -> CREATE_ITEM"; }
|
---|
1900 |
|
---|
1901 | @Override
|
---|
1902 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1903 | // Cast to keyboard/mouse event
|
---|
1904 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1905 |
|
---|
1906 | // Check for single middle click
|
---|
1907 | if (_create == null && kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1908 | _create = true;
|
---|
1909 | return null;
|
---|
1910 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1911 | _create = false;
|
---|
1912 | return null;
|
---|
1913 | } else if (Boolean.FALSE.equals(_create) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1914 | _create = null;
|
---|
1915 | return null;
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | // Wait for the button up to perform the create
|
---|
1919 | if (!Boolean.TRUE.equals(_create) || kbmEvent.getMouseButtonUp() != MouseButton.RIGHT) {
|
---|
1920 | return null;
|
---|
1921 | }
|
---|
1922 |
|
---|
1923 | // Reset create for next gesture
|
---|
1924 | _create = null;
|
---|
1925 |
|
---|
1926 | // Check we haven't moved too far
|
---|
1927 | if (isMouseDragNoOp()) {
|
---|
1928 | printNoopMessage();
|
---|
1929 | return null;
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 | // Check we can create
|
---|
1933 | if (FreeItems.hasItemsAttachedToCursor()) {
|
---|
1934 | return null;
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | // Check we're not trying to pick up (shift forces item creation)
|
---|
1938 | if (!kbmTranslator.isKeyDown(Key.SHIFT) && (FrameUtils.hasCurrentItem() || FrameUtils.getCurrentItems() != null)) {
|
---|
1939 | return null;
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 | // Return the gesture
|
---|
1943 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CREATE_ITEM), new CreateItemGestureData(ItemType.BOX));
|
---|
1944 | }
|
---|
1945 | });
|
---|
1946 |
|
---|
1947 | // Add the LEFT MOUSE -> CLICK gesture recogniser
|
---|
1948 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1949 | {
|
---|
1950 | private static final int LONG_CLICK_DELAY_MS = 500;
|
---|
1951 | private Boolean _click = null;
|
---|
1952 | private long _clickStartTime;
|
---|
1953 | @Override
|
---|
1954 | public String details() { return "LEFT MOUSE -> CLICK"; }
|
---|
1955 |
|
---|
1956 | @Override
|
---|
1957 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1958 | // Cast to keyboard/mouse event
|
---|
1959 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1960 |
|
---|
1961 | // Check for single left click
|
---|
1962 | if (_click == null && kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
1963 | _click = true;
|
---|
1964 | _clickStartTime = System.currentTimeMillis();
|
---|
1965 | return null;
|
---|
1966 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1967 | _click = false;
|
---|
1968 | return null;
|
---|
1969 | } else if (Boolean.FALSE.equals(_click) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1970 | _click = null;
|
---|
1971 | return null;
|
---|
1972 | }
|
---|
1973 |
|
---|
1974 | // Wait for the button up to perform the click
|
---|
1975 | if (!Boolean.TRUE.equals(_click) || kbmEvent.getMouseButtonUp() != MouseButton.LEFT) {
|
---|
1976 | return null;
|
---|
1977 | }
|
---|
1978 |
|
---|
1979 | // Reset click for next gesture
|
---|
1980 | _click = null;
|
---|
1981 |
|
---|
1982 | // Check if this is a long click
|
---|
1983 | boolean longClick = System.currentTimeMillis() >= _clickStartTime + LONG_CLICK_DELAY_MS;
|
---|
1984 |
|
---|
1985 | // Check if we are toggling arrowhead
|
---|
1986 | if (longClick && FrameUtils.getCurrentItem() == null) {
|
---|
1987 | if (FreeItems.getInstance().size() <= 2) {
|
---|
1988 | for (Item i : FreeItems.getInstance()) {
|
---|
1989 | if (i instanceof Line) {
|
---|
1990 | return null;
|
---|
1991 | }
|
---|
1992 | }
|
---|
1993 | }
|
---|
1994 | }
|
---|
1995 |
|
---|
1996 | // Check we haven't moved too far
|
---|
1997 | if (isMouseDragNoOp()) {
|
---|
1998 | printNoopMessage();
|
---|
1999 | return null;
|
---|
2000 | }
|
---|
2001 |
|
---|
2002 | // Return the gesture
|
---|
2003 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CLICK), new ClickGestureData(longClick));
|
---|
2004 | }
|
---|
2005 | });
|
---|
2006 |
|
---|
2007 | // Add the LEFT MOUSE -> TOGGLE_ARROWHEAD gesture recogniser
|
---|
2008 | addTranslator(new InputEventToGestureTranslator(new InputType[] { InputType.KBM, InputType.TIMEOUT })
|
---|
2009 | {
|
---|
2010 | private static final int LONG_CLICK_DELAY_MS = 500;
|
---|
2011 | private Boolean _click = null;
|
---|
2012 | private TimeoutHandle _timeoutHandle = null;
|
---|
2013 |
|
---|
2014 | @Override
|
---|
2015 | public String details() { return "LEFT MOUSE -> TOGGLE_ARROWHEAD"; }
|
---|
2016 |
|
---|
2017 | @Override
|
---|
2018 | public List<Gesture> onInputEvent(InputEvent event)
|
---|
2019 | {
|
---|
2020 | if (event == null) {
|
---|
2021 | return null;
|
---|
2022 | } else if (event.getInputType() == InputType.KBM) {
|
---|
2023 | return onKBMInputEvent((KBMInputEvent) event);
|
---|
2024 | } else if (event.getInputType() == InputType.TIMEOUT) {
|
---|
2025 | return onTimeoutInputEvent((TimeoutInputEvent) event);
|
---|
2026 | }
|
---|
2027 |
|
---|
2028 | return null;
|
---|
2029 | }
|
---|
2030 |
|
---|
2031 | private List<Gesture> onKBMInputEvent(KBMInputEvent kbmEvent)
|
---|
2032 | {
|
---|
2033 | // Check for single left click
|
---|
2034 | if (_click == null && kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2035 | _click = true;
|
---|
2036 | _timeoutHandle = EcosystemManager.getInputManager().addTimeout(LONG_CLICK_DELAY_MS);
|
---|
2037 | return null;
|
---|
2038 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2039 | _click = false;
|
---|
2040 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
2041 | return null;
|
---|
2042 | } else if (Boolean.FALSE.equals(_click) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
2043 | _click = null;
|
---|
2044 | return null;
|
---|
2045 | }
|
---|
2046 |
|
---|
2047 | // Wait for the button up to perform the click
|
---|
2048 | if (!Boolean.TRUE.equals(_click) || kbmEvent.getMouseButtonUp() != MouseButton.LEFT) {
|
---|
2049 | return null;
|
---|
2050 | }
|
---|
2051 |
|
---|
2052 | // Reset click for next gesture
|
---|
2053 | _click = null;
|
---|
2054 |
|
---|
2055 | // Cancel the timer if it's still pending
|
---|
2056 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
2057 |
|
---|
2058 | return null;
|
---|
2059 | }
|
---|
2060 |
|
---|
2061 | private List<Gesture> onTimeoutInputEvent(TimeoutInputEvent event)
|
---|
2062 | {
|
---|
2063 | if (event.getHandle() == _timeoutHandle) {
|
---|
2064 | // Check if we are toggling arrowhead
|
---|
2065 | Item line = null;
|
---|
2066 | if (FrameUtils.getCurrentItem() == null) {
|
---|
2067 | if (FreeItems.getInstance().size() <= 2) {
|
---|
2068 | for (Item i : FreeItems.getInstance()) {
|
---|
2069 | if (i instanceof Line) {
|
---|
2070 | line = i;
|
---|
2071 | }
|
---|
2072 | }
|
---|
2073 | }
|
---|
2074 | }
|
---|
2075 | if (line == null) {
|
---|
2076 | return null;
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | // Check we haven't moved too far
|
---|
2080 | if (isMouseDragNoOp()) {
|
---|
2081 | printNoopMessage();
|
---|
2082 | return null;
|
---|
2083 | }
|
---|
2084 |
|
---|
2085 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ARROWHEAD), new ItemSpecificGestureData(line, false));
|
---|
2086 | }
|
---|
2087 |
|
---|
2088 | // Someone else's timeout event
|
---|
2089 | return null;
|
---|
2090 | }
|
---|
2091 | });
|
---|
2092 |
|
---|
2093 | // Add the LEFT + RIGHT MOUSE -> EXTRACT_ATTRIBUTES gesture recogniser
|
---|
2094 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2095 | {
|
---|
2096 | private static final int STATE_NO_MOUSE_BUTTON_DOWN = 0;
|
---|
2097 | private static final int STATE_LEFT_MOUSE_BUTTON_DOWN = 1;
|
---|
2098 | private static final int STATE_RIGHT_MOUSE_BUTTON_DOWN = 2;
|
---|
2099 | private static final int STATE_BOTH_MOUSE_BUTTON_DOWN = 3;
|
---|
2100 | private static final int STATE_ERROR = 4;
|
---|
2101 | private int _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2102 |
|
---|
2103 | @Override
|
---|
2104 | public String details() { return "LEFT + RIGHT MOUSE -> EXTRACT_ATTRIBUTES"; }
|
---|
2105 |
|
---|
2106 | @Override
|
---|
2107 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2108 | // Cast to keyboard/mouse event
|
---|
2109 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2110 |
|
---|
2111 | // Keep track of mouse button state
|
---|
2112 | if (_state == STATE_NO_MOUSE_BUTTON_DOWN) {
|
---|
2113 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2114 | _state = STATE_RIGHT_MOUSE_BUTTON_DOWN;
|
---|
2115 | } else if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2116 | _state = STATE_LEFT_MOUSE_BUTTON_DOWN;
|
---|
2117 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2118 | _state = STATE_ERROR;
|
---|
2119 | }
|
---|
2120 | return null;
|
---|
2121 | } else if (_state == STATE_LEFT_MOUSE_BUTTON_DOWN) {
|
---|
2122 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2123 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2124 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.LEFT) {
|
---|
2125 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2126 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2127 | _state = STATE_ERROR;
|
---|
2128 | }
|
---|
2129 | return null;
|
---|
2130 | } else if (_state == STATE_RIGHT_MOUSE_BUTTON_DOWN) {
|
---|
2131 | if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2132 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2133 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.RIGHT) {
|
---|
2134 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2135 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2136 | _state = STATE_ERROR;
|
---|
2137 | }
|
---|
2138 | return null;
|
---|
2139 | } else if (_state == STATE_BOTH_MOUSE_BUTTON_DOWN) {
|
---|
2140 | if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2141 | _state = STATE_ERROR;
|
---|
2142 | return null;
|
---|
2143 | }
|
---|
2144 | } else if (kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
2145 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2146 | return null;
|
---|
2147 | }
|
---|
2148 |
|
---|
2149 | // Wait for the button up to perform the extraction
|
---|
2150 | if (_state != STATE_BOTH_MOUSE_BUTTON_DOWN || kbmTranslator.isAnyMouseButtonDown()) {
|
---|
2151 | return null;
|
---|
2152 | }
|
---|
2153 |
|
---|
2154 | // Reset state for next gesture
|
---|
2155 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2156 |
|
---|
2157 | // Check we haven't moved too far
|
---|
2158 | if (isMouseDragNoOp()) {
|
---|
2159 | printNoopMessage();
|
---|
2160 | return null;
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | // Make sure we are over something to extract from
|
---|
2164 | if (!FrameUtils.hasCurrentItem()) {
|
---|
2165 | return null;
|
---|
2166 | }
|
---|
2167 |
|
---|
2168 | // Return the gesture
|
---|
2169 | return standardSingle(StandardGestureType.EXTRACT_ATTRIBUTES, new ItemSpecificGestureData(false));
|
---|
2170 | }
|
---|
2171 | });
|
---|
2172 |
|
---|
2173 | // Add the LEFT + RIGHT MOUSE -> FORMAT gesture recogniser
|
---|
2174 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2175 | {
|
---|
2176 | private static final int STATE_NO_MOUSE_BUTTON_DOWN = 0;
|
---|
2177 | private static final int STATE_LEFT_MOUSE_BUTTON_DOWN = 1;
|
---|
2178 | private static final int STATE_RIGHT_MOUSE_BUTTON_DOWN = 2;
|
---|
2179 | private static final int STATE_BOTH_MOUSE_BUTTON_DOWN = 3;
|
---|
2180 | private static final int STATE_ERROR = 4;
|
---|
2181 | private int _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2182 |
|
---|
2183 | @Override
|
---|
2184 | public String details() { return "LEFT + RIGHT MOUSE -> FORMAT"; }
|
---|
2185 |
|
---|
2186 | @Override
|
---|
2187 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2188 | // Cast to keyboard/mouse event
|
---|
2189 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2190 |
|
---|
2191 | // Keep track of mouse button state
|
---|
2192 | if (_state == STATE_NO_MOUSE_BUTTON_DOWN) {
|
---|
2193 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2194 | _state = STATE_RIGHT_MOUSE_BUTTON_DOWN;
|
---|
2195 | } else if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2196 | _state = STATE_LEFT_MOUSE_BUTTON_DOWN;
|
---|
2197 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2198 | _state = STATE_ERROR;
|
---|
2199 | }
|
---|
2200 | return null;
|
---|
2201 | } else if (_state == STATE_LEFT_MOUSE_BUTTON_DOWN) {
|
---|
2202 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2203 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2204 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.LEFT) {
|
---|
2205 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2206 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2207 | _state = STATE_ERROR;
|
---|
2208 | }
|
---|
2209 | return null;
|
---|
2210 | } else if (_state == STATE_RIGHT_MOUSE_BUTTON_DOWN) {
|
---|
2211 | if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2212 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2213 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.RIGHT) {
|
---|
2214 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2215 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2216 | _state = STATE_ERROR;
|
---|
2217 | }
|
---|
2218 | return null;
|
---|
2219 | } else if (_state == STATE_BOTH_MOUSE_BUTTON_DOWN) {
|
---|
2220 | if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2221 | _state = STATE_ERROR;
|
---|
2222 | return null;
|
---|
2223 | }
|
---|
2224 | } else if (kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
2225 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2226 | return null;
|
---|
2227 | }
|
---|
2228 |
|
---|
2229 | // Wait for the button up to perform the extraction
|
---|
2230 | if (_state != STATE_BOTH_MOUSE_BUTTON_DOWN || kbmTranslator.isAnyMouseButtonDown()) {
|
---|
2231 | return null;
|
---|
2232 | }
|
---|
2233 |
|
---|
2234 | // Reset state for next gesture
|
---|
2235 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2236 |
|
---|
2237 | // Check we haven't moved too far
|
---|
2238 | if (isMouseDragNoOp()) {
|
---|
2239 | printNoopMessage();
|
---|
2240 | return null;
|
---|
2241 | }
|
---|
2242 |
|
---|
2243 | // Make sure we are not extracting
|
---|
2244 | if (FrameUtils.hasCurrentItem()) {
|
---|
2245 | return null;
|
---|
2246 | }
|
---|
2247 |
|
---|
2248 | // Return the gestures
|
---|
2249 | Gesture hFormat = new Gesture(StandardGestureActions.getInstance().gestureType(StandardGestureType.FORMAT), new FormatGestureData(true));
|
---|
2250 | Gesture vFormat = new Gesture(StandardGestureActions.getInstance().gestureType(StandardGestureType.FORMAT), new FormatGestureData(false));
|
---|
2251 | if (kbmTranslator.isKeyDown(Key.CTRL) && kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
2252 | List<Gesture> gestures = Gesture.single(hFormat);
|
---|
2253 | gestures.add(vFormat);
|
---|
2254 | return gestures;
|
---|
2255 | } else if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
2256 | return Gesture.single(hFormat);
|
---|
2257 | } else {
|
---|
2258 | return Gesture.single(vFormat);
|
---|
2259 | }
|
---|
2260 | }
|
---|
2261 | });
|
---|
2262 |
|
---|
2263 | // Add the ENTER_KEY_HIT -> ACTIVATE BUTTON
|
---|
2264 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2265 | {
|
---|
2266 | @Override
|
---|
2267 | public String details() { return "ENTER_CHAR_TYPED -> ACTIVATE BUTTON"; }
|
---|
2268 |
|
---|
2269 | @Override
|
---|
2270 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2271 | // Cast to keyboard/mouse event
|
---|
2272 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2273 |
|
---|
2274 | List<Gesture> ret_gesture = null;
|
---|
2275 |
|
---|
2276 | if ((kbmEvent.getEventType() == EventType.CHAR_TYPED) && (kbmEvent.getCharTyped() == '\n')) {
|
---|
2277 |
|
---|
2278 | GestureType gestureType = StandardGestureActions.getInstance().gestureType(StandardGestureType.ACTIVATE_BUTTON);
|
---|
2279 | ItemSpecificGestureData data = new ClickGestureData(false);
|
---|
2280 | ret_gesture = Gesture.single(gestureType, data);
|
---|
2281 | }
|
---|
2282 |
|
---|
2283 | return ret_gesture;
|
---|
2284 |
|
---|
2285 | /*
|
---|
2286 | if (kbmEvent.getKeyDown() != Key.ENTER) {
|
---|
2287 | return null;
|
---|
2288 | }
|
---|
2289 |
|
---|
2290 | GestureType gestureType = StandardGestureActions.getInstance().gestureType(StandardGestureType.ACTIVATE_BUTTON);
|
---|
2291 | ItemSpecificGestureData data = new ClickGestureData(false);
|
---|
2292 | return Gesture.single(gestureType, data);
|
---|
2293 | */
|
---|
2294 |
|
---|
2295 | }
|
---|
2296 | });
|
---|
2297 |
|
---|
2298 | // TEMPLATE
|
---|
2299 | // Add the DETAILS gesture recogniser
|
---|
2300 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2301 | {
|
---|
2302 | @Override
|
---|
2303 | public String details() { return "DETAILS"; }
|
---|
2304 |
|
---|
2305 | @Override
|
---|
2306 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2307 | // Cast to keyboard/mouse event
|
---|
2308 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2309 |
|
---|
2310 | // TODO Auto-generated method stub
|
---|
2311 | return null;
|
---|
2312 | }
|
---|
2313 | });
|
---|
2314 | }
|
---|
2315 |
|
---|
2316 | public boolean isKeyDown(Key key)
|
---|
2317 | {
|
---|
2318 | return StandardInputEventListeners.kbmStateListener.isKeyDown(key);
|
---|
2319 | }
|
---|
2320 |
|
---|
2321 | public boolean isMouseButtonDown(MouseButton button)
|
---|
2322 | {
|
---|
2323 | return StandardInputEventListeners.kbmStateListener.isMouseButtonDown(button);
|
---|
2324 | }
|
---|
2325 |
|
---|
2326 | public boolean isOnlyMouseButtonDown(MouseButton button)
|
---|
2327 | {
|
---|
2328 | return StandardInputEventListeners.kbmStateListener.isOnlyMouseButtonDown(button);
|
---|
2329 | }
|
---|
2330 |
|
---|
2331 | public boolean isAnyMouseButtonDown()
|
---|
2332 | {
|
---|
2333 | return StandardInputEventListeners.kbmStateListener.isAnyMouseButtonDown();
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | public static boolean isMouseDragNoOp()
|
---|
2337 | {
|
---|
2338 | return _noop;
|
---|
2339 | }
|
---|
2340 |
|
---|
2341 | public static void printNoopMessage()
|
---|
2342 | {
|
---|
2343 | System.err.println("Exceeded NoOp Threshold of " + UserSettings.NoOpThreshold.get() + " pixels. Reinterpreting origonal Gesture.");
|
---|
2344 | //MessageBay.displayMessage("Gesture cancelled, mouse moved more than " + UserSettings.NoOpThreshold.get() + " pixels.");
|
---|
2345 | }
|
---|
2346 |
|
---|
2347 | public static void trackMouseDragNoop(KBMInputEvent event)
|
---|
2348 | {
|
---|
2349 | if (!StandardInputEventListeners.kbmStateListener.isAnyMouseButtonDown() && (event.getEventType() != EventType.MOUSE_BUTTON_UP)) {
|
---|
2350 | _noop = false;
|
---|
2351 | _mouseDragStart = null;
|
---|
2352 | } else if (_mouseDragStart == null) {
|
---|
2353 | org.expeditee.core.Line mouseMove = event.getMouseMove();
|
---|
2354 | if (mouseMove != null) {
|
---|
2355 | _mouseDragStart = mouseMove.getFirstEnd().clone();
|
---|
2356 | }
|
---|
2357 | } else if (_noop == false) {
|
---|
2358 | org.expeditee.core.Line mouseMove = event.getMouseMove();
|
---|
2359 | if (mouseMove != null) {
|
---|
2360 | mouseMove.setFirstEnd(_mouseDragStart.clone());
|
---|
2361 | if (mouseMove.length() > UserSettings.NoOpThreshold.get()) {
|
---|
2362 | _noop = true;
|
---|
2363 | }
|
---|
2364 | }
|
---|
2365 | }
|
---|
2366 | }
|
---|
2367 |
|
---|
2368 | /** Convenience function to create a single standard gesture. */
|
---|
2369 | public static List<Gesture> standardSingle(StandardGestureType type, GestureData data)
|
---|
2370 | {
|
---|
2371 | return Gesture.single(StandardGestureActions.getInstance().gestureType(type), data);
|
---|
2372 | }
|
---|
2373 | }
|
---|