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 | // Return the gesture
|
---|
576 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ANNOTATION), new ItemSpecificGestureData());
|
---|
577 | }
|
---|
578 | });
|
---|
579 |
|
---|
580 | // Add the F5 -> INSERT_DATE gesture recogniser
|
---|
581 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
582 | {
|
---|
583 | @Override
|
---|
584 | public String details() { return "F5 -> INSERT_DATE"; }
|
---|
585 |
|
---|
586 | @Override
|
---|
587 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
588 | // Cast to keyboard/mouse event
|
---|
589 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
590 |
|
---|
591 | // Must be pressing F5 to insert the date
|
---|
592 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F5) {
|
---|
593 | return null;
|
---|
594 | }
|
---|
595 |
|
---|
596 | // Return the gesture
|
---|
597 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.INSERT_DATE), new ItemSpecificGestureData());
|
---|
598 | }
|
---|
599 | });
|
---|
600 |
|
---|
601 | // Add the F6 -> NEW_FRAMESET gesture recogniser
|
---|
602 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
603 | {
|
---|
604 | @Override
|
---|
605 | public String details() { return "F6 -> NEW_FRAMESET"; }
|
---|
606 |
|
---|
607 | @Override
|
---|
608 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
609 | // Cast to keyboard/mouse event
|
---|
610 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
611 |
|
---|
612 | // Must be pressing F6 to create a new frameset
|
---|
613 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F6) {
|
---|
614 | return null;
|
---|
615 | }
|
---|
616 |
|
---|
617 | // Return the gesture
|
---|
618 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.NEW_FRAMESET), new ItemSpecificGestureData());
|
---|
619 | }
|
---|
620 | });
|
---|
621 |
|
---|
622 | // Add the F7 -> ROTATE_FONT_STYLE gesture recogniser
|
---|
623 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
624 | {
|
---|
625 | @Override
|
---|
626 | public String details() { return "F7 -> ROTATE_FONT_STYLE"; }
|
---|
627 |
|
---|
628 | @Override
|
---|
629 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
630 | // Cast to keyboard/mouse event
|
---|
631 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
632 |
|
---|
633 | // Must be pressing F7 to rotate font style
|
---|
634 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F7) {
|
---|
635 | return null;
|
---|
636 | }
|
---|
637 |
|
---|
638 | // Return the gesture
|
---|
639 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ROTATE_FONT_STYLE), new ItemSpecificGestureData());
|
---|
640 | }
|
---|
641 | });
|
---|
642 |
|
---|
643 | // Add the F8 -> ROTATE_FONT_FAMILY gesture recogniser
|
---|
644 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
645 | {
|
---|
646 | @Override
|
---|
647 | public String details() { return "F8 -> ROTATE_FONT_FAMILY"; }
|
---|
648 |
|
---|
649 | @Override
|
---|
650 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
651 | // Cast to keyboard/mouse event
|
---|
652 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
653 |
|
---|
654 | // Must be pressing F8 to rotate font family
|
---|
655 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F8) {
|
---|
656 | return null;
|
---|
657 | }
|
---|
658 |
|
---|
659 | // Return the gesture
|
---|
660 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ROTATE_FONT_FAMILY), new ItemSpecificGestureData());
|
---|
661 | }
|
---|
662 | });
|
---|
663 |
|
---|
664 | // Add the F9 -> TOGGLE_AUDIENCE_MODE gesture recogniser
|
---|
665 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
666 | {
|
---|
667 | @Override
|
---|
668 | public String details() { return "F9 -> TOGGLE_AUDIENCE_MODE"; }
|
---|
669 |
|
---|
670 | @Override
|
---|
671 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
672 | // Cast to keyboard/mouse event
|
---|
673 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
674 |
|
---|
675 | // Must be pressing F9 to toggle audience mode
|
---|
676 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F9) {
|
---|
677 | return null;
|
---|
678 | }
|
---|
679 |
|
---|
680 | // Return the gesture
|
---|
681 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ROTATE_DISPLAY_MODE), null);
|
---|
682 | }
|
---|
683 | });
|
---|
684 |
|
---|
685 | // Add the F10 -> TOGGLE_XRAY_MODE gesture recogniser
|
---|
686 | addTranslator(new InputEventToGestureTranslator(InputType.KBM) {
|
---|
687 |
|
---|
688 | @Override
|
---|
689 | public String details() { return "F10 -> TOGGLE_XRAY_MODE"; }
|
---|
690 |
|
---|
691 | @Override
|
---|
692 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
693 | // Cast to keyboard/mouse event
|
---|
694 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
695 |
|
---|
696 | // Must be pressing F10 to xray mode
|
---|
697 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F10 || kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
698 | return null;
|
---|
699 | }
|
---|
700 |
|
---|
701 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_XRAY_MODE), null);
|
---|
702 | }
|
---|
703 | });
|
---|
704 |
|
---|
705 | // Add the F10 -> CYCLE_SURROGATE_MODE gesture recogniser
|
---|
706 | addTranslator(new InputEventToGestureTranslator(InputType.KBM) {
|
---|
707 | @Override
|
---|
708 | public String details() { return "F10 -> CYCLE_SURROGATE_MODE"; }
|
---|
709 |
|
---|
710 | @Override
|
---|
711 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
712 | // Case to keyboard/mouse event
|
---|
713 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
714 |
|
---|
715 | // Must be pressing F10 to surrogate mode
|
---|
716 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F10 || !kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
717 | return null;
|
---|
718 | }
|
---|
719 |
|
---|
720 | UndoGestureData data = new UndoGestureData(kbmTranslator.isKeyDown(Key.CTRL));
|
---|
721 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CYCLE_SURROGATE_MODE), data);
|
---|
722 | }
|
---|
723 | });
|
---|
724 |
|
---|
725 | // Add the F11 -> SAVE gesture recogniser
|
---|
726 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
727 | {
|
---|
728 | @Override
|
---|
729 | public String details() { return "F11 -> SAVE"; }
|
---|
730 |
|
---|
731 | @Override
|
---|
732 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
733 | // Cast to keyboard/mouse event
|
---|
734 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
735 |
|
---|
736 | // Must be pressing F11 to save
|
---|
737 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F11) {
|
---|
738 | return null;
|
---|
739 | }
|
---|
740 |
|
---|
741 | // Return the gesture
|
---|
742 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SAVE), null);
|
---|
743 | }
|
---|
744 | });
|
---|
745 |
|
---|
746 | // Add the F12 -> REFRESH gesture recogniser
|
---|
747 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
748 | {
|
---|
749 | @Override
|
---|
750 | public String details() { return "F12 -> REFRESH"; }
|
---|
751 |
|
---|
752 | @Override
|
---|
753 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
754 | // Cast to keyboard/mouse event
|
---|
755 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
756 |
|
---|
757 | // Must be pressing F12 to refresh
|
---|
758 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F12) {
|
---|
759 | return null;
|
---|
760 | }
|
---|
761 |
|
---|
762 | // Decide how to refresh
|
---|
763 | boolean shouldReloadFrameFirst = kbmTranslator.isKeyDown(Key.CTRL);
|
---|
764 | boolean shouldRefreshFrameSize = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
765 |
|
---|
766 | // Return the gesture
|
---|
767 | return standardSingle(StandardGestureType.REFRESH, new RefreshGestureData(shouldReloadFrameFirst, shouldRefreshFrameSize));
|
---|
768 | }
|
---|
769 | });
|
---|
770 |
|
---|
771 | // Add the ESC -> DROP_DOWN gesture recogniser
|
---|
772 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
773 | {
|
---|
774 | @Override
|
---|
775 | public String details() { return "ESC -> DROP_DOWN"; }
|
---|
776 |
|
---|
777 | @Override
|
---|
778 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
779 | // Cast to keyboard/mouse event
|
---|
780 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
781 |
|
---|
782 | // Shift/Ctrl + Esc is calculate
|
---|
783 | if (kbmTranslator.isKeyDown(Key.SHIFT) || kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
784 | return null;
|
---|
785 | }
|
---|
786 |
|
---|
787 | // Must be pressing ESC to drop down
|
---|
788 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.ESC) {
|
---|
789 | return null;
|
---|
790 | }
|
---|
791 |
|
---|
792 | // Return the gesture
|
---|
793 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.DROP_DOWN), null);
|
---|
794 | }
|
---|
795 | });
|
---|
796 |
|
---|
797 | // Add the SHIFT/CTRL + ESC -> CALCULATE gesture recogniser
|
---|
798 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
799 | {
|
---|
800 | @Override
|
---|
801 | public String details() { return "SHIFT/CTRL + ESC -> CALCULATE"; }
|
---|
802 |
|
---|
803 | @Override
|
---|
804 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
805 | // Cast to keyboard/mouse event
|
---|
806 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
807 |
|
---|
808 | // Check that shift or ctrl is down
|
---|
809 | if (!kbmTranslator.isKeyDown(Key.SHIFT) && !kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
810 | return null;
|
---|
811 | }
|
---|
812 |
|
---|
813 | // Must be pressing Esc to calculate
|
---|
814 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.ESC) {
|
---|
815 | return null;
|
---|
816 | }
|
---|
817 |
|
---|
818 | // Return the gesture
|
---|
819 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CALCULATE), new ItemSpecificGestureData());
|
---|
820 | }
|
---|
821 | });
|
---|
822 |
|
---|
823 | // Add the CTRL + TAB -> CALCULATE gesture recogniser
|
---|
824 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
825 | {
|
---|
826 | @Override
|
---|
827 | public String details() { return "CTRL + TAB -> CALCULATE"; }
|
---|
828 |
|
---|
829 | @Override
|
---|
830 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
831 | // Cast to keyboard/mouse event
|
---|
832 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
833 |
|
---|
834 | // Check that ctrl is down
|
---|
835 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
836 | return null;
|
---|
837 | }
|
---|
838 |
|
---|
839 | // Must be pressing tab to calculate
|
---|
840 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.TAB) {
|
---|
841 | return null;
|
---|
842 | }
|
---|
843 |
|
---|
844 | // Return the gesture
|
---|
845 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CALCULATE), new ItemSpecificGestureData());
|
---|
846 | }
|
---|
847 | });
|
---|
848 |
|
---|
849 | // Add the CTRL + L -> LINK gesture recogniser
|
---|
850 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
851 | {
|
---|
852 | @Override
|
---|
853 | public String details() { return "CTRL + L -> LINK"; }
|
---|
854 |
|
---|
855 | @Override
|
---|
856 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
857 | // Cast to keyboard/mouse event
|
---|
858 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
859 |
|
---|
860 | // Check that ctrl is down
|
---|
861 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
862 | return null;
|
---|
863 | }
|
---|
864 |
|
---|
865 | // Must be pressing L to link
|
---|
866 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.L) {
|
---|
867 | return null;
|
---|
868 | }
|
---|
869 |
|
---|
870 | // Return the gesture
|
---|
871 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.LINK), new LinkGestureData(false));
|
---|
872 | }
|
---|
873 | });
|
---|
874 |
|
---|
875 | // Add the CTRL + G -> LINK gesture recogniser
|
---|
876 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
877 | {
|
---|
878 | @Override
|
---|
879 | public String details() { return "CTRL + G -> LINK"; }
|
---|
880 |
|
---|
881 | @Override
|
---|
882 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
883 | // Cast to keyboard/mouse event
|
---|
884 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
885 |
|
---|
886 | // Check that ctrl is down
|
---|
887 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
888 | return null;
|
---|
889 | }
|
---|
890 |
|
---|
891 | // Must be pressing G to link
|
---|
892 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.G) {
|
---|
893 | return null;
|
---|
894 | }
|
---|
895 |
|
---|
896 | // Return the gesture
|
---|
897 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.LINK), new LinkGestureData(true));
|
---|
898 | }
|
---|
899 | });
|
---|
900 |
|
---|
901 | // Add the CTRL + A -> ACTION gesture recogniser
|
---|
902 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
903 | {
|
---|
904 | @Override
|
---|
905 | public String details() { return "CTRL + A -> ACTION"; }
|
---|
906 |
|
---|
907 | @Override
|
---|
908 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
909 | // Cast to keyboard/mouse event
|
---|
910 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
911 |
|
---|
912 | // Check that ctrl is down
|
---|
913 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
914 | return null;
|
---|
915 | }
|
---|
916 |
|
---|
917 | // Must be pressing A to action
|
---|
918 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.A) {
|
---|
919 | return null;
|
---|
920 | }
|
---|
921 |
|
---|
922 | // Return the gesture
|
---|
923 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.ACTION), new ItemSpecificGestureData());
|
---|
924 | }
|
---|
925 | });
|
---|
926 |
|
---|
927 | // Add the CTRL + B -> TOGGLE_BOLD gesture recogniser
|
---|
928 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
929 | {
|
---|
930 | @Override
|
---|
931 | public String details() { return "CTRL + B -> TOGGLE_BOLD"; }
|
---|
932 |
|
---|
933 | @Override
|
---|
934 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
935 | // Cast to keyboard/mouse event
|
---|
936 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
937 |
|
---|
938 | // Check that ctrl is down
|
---|
939 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
940 | return null;
|
---|
941 | }
|
---|
942 |
|
---|
943 | // Must be pressing B to toggle bold
|
---|
944 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.B) {
|
---|
945 | return null;
|
---|
946 | }
|
---|
947 |
|
---|
948 | // Return the gesture
|
---|
949 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_BOLD), new ItemSpecificGestureData());
|
---|
950 | }
|
---|
951 | });
|
---|
952 |
|
---|
953 | // Add the CTRL + I -> TOGGLE_ITALICS gesture recogniser
|
---|
954 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
955 | {
|
---|
956 | @Override
|
---|
957 | public String details() { return "CTRL + I -> TOGGLE_ITALICS"; }
|
---|
958 |
|
---|
959 | @Override
|
---|
960 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
961 | // Cast to keyboard/mouse event
|
---|
962 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
963 |
|
---|
964 | // Check that ctrl is down
|
---|
965 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
966 | return null;
|
---|
967 | }
|
---|
968 |
|
---|
969 | // Must be pressing I to toggle italics
|
---|
970 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.I) {
|
---|
971 | return null;
|
---|
972 | }
|
---|
973 |
|
---|
974 | // Return the gesture
|
---|
975 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ITALICS), new ItemSpecificGestureData());
|
---|
976 | }
|
---|
977 | });
|
---|
978 |
|
---|
979 | // Add the CTRL + V -> PASTE gesture recogniser
|
---|
980 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
981 | {
|
---|
982 | @Override
|
---|
983 | public String details() { return "CTRL + V -> PASTE"; }
|
---|
984 |
|
---|
985 | @Override
|
---|
986 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
987 | // Cast to keyboard/mouse event
|
---|
988 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
989 |
|
---|
990 | // Check that ctrl is down
|
---|
991 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
992 | return null;
|
---|
993 | }
|
---|
994 |
|
---|
995 | // Must be pressing V to paste
|
---|
996 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.V) {
|
---|
997 | return null;
|
---|
998 | }
|
---|
999 |
|
---|
1000 | // Return the gesture
|
---|
1001 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PASTE), null);
|
---|
1002 | }
|
---|
1003 | });
|
---|
1004 |
|
---|
1005 | // Add the CTRL + C -> COPY gesture recogniser
|
---|
1006 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1007 | {
|
---|
1008 | @Override
|
---|
1009 | public String details() { return "CTRL + C -> COPY"; }
|
---|
1010 |
|
---|
1011 | @Override
|
---|
1012 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1013 | // Cast to keyboard/mouse event
|
---|
1014 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1015 |
|
---|
1016 | // Check that ctrl is down
|
---|
1017 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1018 | return null;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | // Must be pressing C to copy
|
---|
1022 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.C) {
|
---|
1023 | return null;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | // Return the gesture
|
---|
1027 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.COPY), new ItemSpecificGestureData());
|
---|
1028 | }
|
---|
1029 | });
|
---|
1030 |
|
---|
1031 | // Add the CTRL + C -> MAKE_CIRCLE gesture recogniser
|
---|
1032 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1033 | {
|
---|
1034 | @Override
|
---|
1035 | public String details() { return "CTRL + C -> MAKE_CIRCLE"; }
|
---|
1036 |
|
---|
1037 | @Override
|
---|
1038 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1039 | // Cast to keyboard/mouse event
|
---|
1040 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1041 |
|
---|
1042 | // Check that ctrl is down
|
---|
1043 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1044 | return null;
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | // Must be pressing C to make circle
|
---|
1048 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.C) {
|
---|
1049 | return null;
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | // Make sure we aren't trying to do a copy-clone
|
---|
1053 | if (FreeItems.hasItemsAttachedToCursor()) {
|
---|
1054 | return null;
|
---|
1055 | }
|
---|
1056 |
|
---|
1057 | // Return the gesture
|
---|
1058 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.MAKE_CIRCLE), new ItemSpecificGestureData());
|
---|
1059 | }
|
---|
1060 | });
|
---|
1061 |
|
---|
1062 | // Add the CTRL + X -> CUT gesture recogniser
|
---|
1063 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1064 | {
|
---|
1065 | @Override
|
---|
1066 | public String details() { return "CTRL + X -> CUT"; }
|
---|
1067 |
|
---|
1068 | @Override
|
---|
1069 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1070 | // Cast to keyboard/mouse event
|
---|
1071 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1072 |
|
---|
1073 | // Check that ctrl is down
|
---|
1074 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1075 | return null;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | // Must be pressing X to cut
|
---|
1079 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.X) {
|
---|
1080 | return null;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | // Return the gesture
|
---|
1084 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CUT), null);
|
---|
1085 | }
|
---|
1086 | });
|
---|
1087 |
|
---|
1088 | // Add the CTRL + M -> TOGGLE_ITEMS_MARK gesture recogniser
|
---|
1089 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1090 | {
|
---|
1091 | @Override
|
---|
1092 | public String details() { return "CTRL + M -> TOGGLE_ITEMS_MARK"; }
|
---|
1093 |
|
---|
1094 | @Override
|
---|
1095 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1096 | // Cast to keyboard/mouse event
|
---|
1097 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1098 |
|
---|
1099 | // Check that ctrl is down
|
---|
1100 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1101 | return null;
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | // Must be pressing M to toggle items mark
|
---|
1105 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.M) {
|
---|
1106 | return null;
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | // Return the gesture
|
---|
1110 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ITEMS_MARK), new ItemSpecificGestureData());
|
---|
1111 | }
|
---|
1112 | });
|
---|
1113 |
|
---|
1114 | // Add the CTRL + Z -> UNDO gesture recogniser
|
---|
1115 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1116 | {
|
---|
1117 | @Override
|
---|
1118 | public String details() { return "CTRL + Z -> UNDO"; }
|
---|
1119 |
|
---|
1120 | @Override
|
---|
1121 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1122 | // Cast to keyboard/mouse event
|
---|
1123 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1124 |
|
---|
1125 | // Check that ctrl is down
|
---|
1126 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1127 | return null;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | // Must be pressing Z to undo
|
---|
1131 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.X) {
|
---|
1132 | return null;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | // Holding shift as well makes this a redo gesture
|
---|
1136 | boolean redo = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1137 |
|
---|
1138 | // Return the gesture
|
---|
1139 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.UNDO), new UndoGestureData(redo));
|
---|
1140 | }
|
---|
1141 | });
|
---|
1142 |
|
---|
1143 | // Add the CTRL + D -> INSERT_STRING gesture recogniser
|
---|
1144 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1145 | {
|
---|
1146 | @Override
|
---|
1147 | public String details() { return "CTRL + D -> INSERT_STRING"; }
|
---|
1148 |
|
---|
1149 | @Override
|
---|
1150 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1151 | // Cast to keyboard/mouse event
|
---|
1152 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1153 |
|
---|
1154 | // Check that ctrl is down
|
---|
1155 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1156 | return null;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | // Must be pressing D to delete character
|
---|
1160 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.D) {
|
---|
1161 | return null;
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | // Return the gesture
|
---|
1165 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.INSERT_STRING), new InsertStringGestureData(Text.DELETE_CHARACTER, false));
|
---|
1166 | }
|
---|
1167 | });
|
---|
1168 |
|
---|
1169 | // Add the CTRL + DELETE -> DELETE gesture recogniser
|
---|
1170 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1171 | {
|
---|
1172 | @Override
|
---|
1173 | public String details() { return "CTRL + DELETE -> DELETE"; }
|
---|
1174 |
|
---|
1175 | @Override
|
---|
1176 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1177 | // Cast to keyboard/mouse event
|
---|
1178 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1179 |
|
---|
1180 | // Check that ctrl is down
|
---|
1181 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1182 | return null;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | // Must be pressing DELETE to delete
|
---|
1186 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.DELETE) {
|
---|
1187 | return null;
|
---|
1188 | }
|
---|
1189 |
|
---|
1190 | // Decide if this is an alternate mode delete
|
---|
1191 | // TODO: What specifically is alternate mode delete? cts16
|
---|
1192 | boolean alternateMode = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1193 |
|
---|
1194 | // Return the gesture
|
---|
1195 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.DELETE), new DeleteGestureData(alternateMode));
|
---|
1196 | }
|
---|
1197 | });
|
---|
1198 |
|
---|
1199 | // Add the CTRL + F -> FORMAT gesture recogniser
|
---|
1200 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1201 | {
|
---|
1202 | @Override
|
---|
1203 | public String details() { return "CTRL + F -> FORMAT"; }
|
---|
1204 |
|
---|
1205 | @Override
|
---|
1206 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1207 | // Cast to keyboard/mouse event
|
---|
1208 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1209 |
|
---|
1210 | // Check that ctrl is down
|
---|
1211 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1212 | return null;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | // Must be pressing F to format
|
---|
1216 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.F) {
|
---|
1217 | return null;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | // Decide if this is an horizontal or vertical format
|
---|
1221 | boolean horizontal = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1222 |
|
---|
1223 | // Return the gesture
|
---|
1224 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.FORMAT), new FormatGestureData(horizontal));
|
---|
1225 | }
|
---|
1226 | });
|
---|
1227 |
|
---|
1228 | // Add the CTRL + J -> JUSTIFY gesture recogniser
|
---|
1229 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1230 | {
|
---|
1231 | @Override
|
---|
1232 | public String details() { return "CTRL + J -> JUSTIFY"; }
|
---|
1233 |
|
---|
1234 | @Override
|
---|
1235 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1236 | // Cast to keyboard/mouse event
|
---|
1237 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1238 |
|
---|
1239 | // Check that ctrl is down
|
---|
1240 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1241 | return null;
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | // Must be pressing J to justify
|
---|
1245 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.J) {
|
---|
1246 | return null;
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | // Return the gesture
|
---|
1250 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.JUSTIFY), new JustifyGestureData(false));
|
---|
1251 | }
|
---|
1252 | });
|
---|
1253 |
|
---|
1254 | // Add the CTRL + R -> JUSTIFY gesture recogniser
|
---|
1255 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1256 | {
|
---|
1257 | @Override
|
---|
1258 | public String details() { return "CTRL + R -> JUSTIFY"; }
|
---|
1259 |
|
---|
1260 | @Override
|
---|
1261 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1262 | // Cast to keyboard/mouse event
|
---|
1263 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1264 |
|
---|
1265 | // Check that ctrl is down
|
---|
1266 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1267 | return null;
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | // Must be pressing R to justify
|
---|
1271 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.R) {
|
---|
1272 | return null;
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | // Return the gesture
|
---|
1276 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.JUSTIFY), new JustifyGestureData(true));
|
---|
1277 | }
|
---|
1278 | });
|
---|
1279 |
|
---|
1280 | // Add the CTRL + S -> SAVE gesture recogniser
|
---|
1281 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1282 | {
|
---|
1283 | @Override
|
---|
1284 | public String details() { return "CTRL + S -> SAVE"; }
|
---|
1285 |
|
---|
1286 | @Override
|
---|
1287 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1288 | // Cast to keyboard/mouse event
|
---|
1289 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1290 |
|
---|
1291 | // Check that ctrl is down
|
---|
1292 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1293 | return null;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | // Ctrl + Shift + S is split text
|
---|
1297 | if (kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1298 | return null;
|
---|
1299 | }
|
---|
1300 |
|
---|
1301 | // Must be pressing S to save
|
---|
1302 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.S) {
|
---|
1303 | return null;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | // Return the gesture
|
---|
1307 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SAVE), null);
|
---|
1308 | }
|
---|
1309 | });
|
---|
1310 |
|
---|
1311 | // Add the CTRL + SHIFT + S -> SPLIT_TEXT gesture recogniser
|
---|
1312 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1313 | {
|
---|
1314 | @Override
|
---|
1315 | public String details() { return "CTRL + SHIFT + S -> SPLIT_TEXT"; }
|
---|
1316 |
|
---|
1317 | @Override
|
---|
1318 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1319 | // Cast to keyboard/mouse event
|
---|
1320 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1321 |
|
---|
1322 | // Check that ctrl is down
|
---|
1323 | if (!kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
1324 | return null;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | // Ctrl + Shift + S is split text
|
---|
1328 | if (!kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1329 | return null;
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | // Must be pressing S to save
|
---|
1333 | if (kbmEvent.getKeyDown() != KBMInputEvent.Key.S) {
|
---|
1334 | return null;
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | // Return the gesture
|
---|
1338 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.SPLIT_TEXT), new ItemSpecificGestureData());
|
---|
1339 | }
|
---|
1340 | });
|
---|
1341 |
|
---|
1342 | // Add the MIDDLE MOUSE + MOUSE_MOVE -> PICK_UP gesture recogniser
|
---|
1343 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1344 | {
|
---|
1345 | private SelectAreaGestureData _draggedFromData = null;
|
---|
1346 |
|
---|
1347 | @Override
|
---|
1348 | public String details() { return "MIDDLE MOUSE + MOUSE_MOVE -> PICK_UP"; }
|
---|
1349 |
|
---|
1350 | @Override
|
---|
1351 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1352 | // Cast to keyboard/mouse event
|
---|
1353 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1354 |
|
---|
1355 | // Check we are holding the middle button only
|
---|
1356 | if (!kbmTranslator.isOnlyMouseButtonDown(MouseButton.MIDDLE)) {
|
---|
1357 | // If we were dragging, reset the dragging tracker and send the drag-finished gesture
|
---|
1358 | if (_draggedFromData != null) {
|
---|
1359 | SelectAreaGestureData finalData = _draggedFromData.finalise();
|
---|
1360 | _draggedFromData = null;
|
---|
1361 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), finalData);
|
---|
1362 |
|
---|
1363 | // Otherwise just return
|
---|
1364 | } else {
|
---|
1365 | return null;
|
---|
1366 | }
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | // Check if it's a mouse movement event
|
---|
1370 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.MOUSE_MOVE) {
|
---|
1371 | return null;
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | // See if we should inherit the attributes of the thing we're picking up
|
---|
1375 | boolean inheritAttributes = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1376 |
|
---|
1377 | // If we are just starting to drag, save the start position of the gesture
|
---|
1378 | if (_draggedFromData == null) {
|
---|
1379 | _draggedFromData = new PickUpGestureData(kbmEvent.getMouseMove().getSecondEnd().clone(), kbmEvent.getMouseMove().getFirstEnd().clone(), false, inheritAttributes);
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | // Wait till we have moved out of no-op range before performing drag-pickup
|
---|
1383 | if (!isMouseDragNoOp()) {
|
---|
1384 | return null;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | // Generate a PICK_UP gesture
|
---|
1388 | _draggedFromData = _draggedFromData.carryOn(kbmEvent.getMouseMove().getSecondEnd().clone());
|
---|
1389 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), _draggedFromData);
|
---|
1390 | }
|
---|
1391 | });
|
---|
1392 |
|
---|
1393 | // Add the MIDDLE MOUSE -> PICK_UP gesture recogniser
|
---|
1394 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1395 | {
|
---|
1396 | private Boolean _pickup = null;
|
---|
1397 | private Item _clickDownOn = null;
|
---|
1398 |
|
---|
1399 | @Override
|
---|
1400 | public String details() { return "MIDDLE MOUSE -> 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 for single middle click
|
---|
1408 | if (_pickup == null && kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1409 | _pickup = true;
|
---|
1410 | _clickDownOn = FrameUtils.getCurrentItem();
|
---|
1411 | return null;
|
---|
1412 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1413 | _pickup = false;
|
---|
1414 | return null;
|
---|
1415 | } else if (Boolean.FALSE.equals(_pickup) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1416 | _pickup = null;
|
---|
1417 | return null;
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 | // Wait for the button up to perform the pickup
|
---|
1421 | if (!Boolean.TRUE.equals(_pickup) || kbmEvent.getMouseButtonUp() != MouseButton.MIDDLE) {
|
---|
1422 | return null;
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 | // Reset pickup for next gesture
|
---|
1426 | _pickup = null;
|
---|
1427 |
|
---|
1428 | // Check we haven't moved too far
|
---|
1429 | if (isMouseDragNoOp()) {
|
---|
1430 | if (!(_clickDownOn instanceof Text)) {
|
---|
1431 | printNoopMessage();
|
---|
1432 | }
|
---|
1433 | return null;
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | // Check we should be picking up (shift forces line creation)
|
---|
1437 | if (FreeItems.hasItemsAttachedToCursor() || kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1438 | return null;
|
---|
1439 | }
|
---|
1440 |
|
---|
1441 | // Check there is something to pick up
|
---|
1442 | if (!FrameUtils.hasCurrentItem() && FrameUtils.getCurrentItems() == null) {
|
---|
1443 | return null;
|
---|
1444 | }
|
---|
1445 |
|
---|
1446 | // Return the gesture
|
---|
1447 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), new PickUpGestureData(false));
|
---|
1448 | }
|
---|
1449 | });
|
---|
1450 |
|
---|
1451 | // Add the RIGHT MOUSE + MOUSE_MOVE -> PICK_UP gesture recogniser
|
---|
1452 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1453 | {
|
---|
1454 | private SelectAreaGestureData _draggedFromData = null;
|
---|
1455 |
|
---|
1456 | @Override
|
---|
1457 | public String details() { return "RIGHT MOUSE + MOUSE_MOVE -> PICK_UP"; }
|
---|
1458 |
|
---|
1459 | @Override
|
---|
1460 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1461 | // Cast to keyboard/mouse event
|
---|
1462 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1463 |
|
---|
1464 | // Check we are holding the middle button only
|
---|
1465 | if (!kbmTranslator.isOnlyMouseButtonDown(MouseButton.RIGHT)) {
|
---|
1466 | // If we were dragging, reset the dragging tracker and send the drag-finished gesture
|
---|
1467 | if (_draggedFromData != null) {
|
---|
1468 | SelectAreaGestureData finalData = _draggedFromData.finalise();
|
---|
1469 | _draggedFromData = null;
|
---|
1470 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), finalData);
|
---|
1471 |
|
---|
1472 | // Otherwise just return
|
---|
1473 | } else {
|
---|
1474 | return null;
|
---|
1475 | }
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | // Check if it's a mouse movement event
|
---|
1479 | if (kbmEvent.getEventType() != KBMInputEvent.EventType.MOUSE_MOVE) {
|
---|
1480 | return null;
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | // See if we should inherit the attributes of the thing we're picking up
|
---|
1484 | boolean inheritAttributes = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1485 |
|
---|
1486 | // If we are just starting to drag, save the start position of the gesture
|
---|
1487 | if (_draggedFromData == null) {
|
---|
1488 | _draggedFromData = new PickUpGestureData(kbmEvent.getMouseMove().getSecondEnd().clone(), kbmEvent.getMouseMove().getFirstEnd().clone(), true, inheritAttributes);
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | // Wait till we have moved out of no-op range before performing drag-pickup
|
---|
1492 | if (!isMouseDragNoOp()) {
|
---|
1493 | return null;
|
---|
1494 | }
|
---|
1495 |
|
---|
1496 | // Generate a PICK_UP gesture
|
---|
1497 | _draggedFromData = _draggedFromData.carryOn(kbmEvent.getMouseMove().getSecondEnd().clone());
|
---|
1498 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), _draggedFromData);
|
---|
1499 | }
|
---|
1500 | });
|
---|
1501 |
|
---|
1502 | // Add the RIGHT MOUSE -> PICK_UP gesture recogniser
|
---|
1503 | addTranslator(new InputEventToGestureTranslator(new InputType[] { InputType.KBM, InputType.TIMEOUT })
|
---|
1504 | {
|
---|
1505 | private final static int EXTRUSION_DELAY_MS = 750;
|
---|
1506 | private final static int PULSE_AMOUNT = 2;
|
---|
1507 | private Boolean _pickup = null;
|
---|
1508 | private Item _clickedItem = null;
|
---|
1509 | private TimeoutHandle _timeoutHandle;
|
---|
1510 | private boolean _extrusionDelayExpired = false;
|
---|
1511 |
|
---|
1512 | @Override
|
---|
1513 | public String details() { return "RIGHT MOUSE -> PICK_UP"; }
|
---|
1514 |
|
---|
1515 | @Override
|
---|
1516 | public List<Gesture> onInputEvent(InputEvent event)
|
---|
1517 | {
|
---|
1518 | if (event == null) {
|
---|
1519 | return null;
|
---|
1520 | } else if (event.getInputType() == InputType.KBM) {
|
---|
1521 | return onKBMInputEvent((KBMInputEvent) event);
|
---|
1522 | } else if (event.getInputType() == InputType.TIMEOUT) {
|
---|
1523 | return onTimeoutInputEvent((TimeoutInputEvent) event);
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | return null;
|
---|
1527 | }
|
---|
1528 |
|
---|
1529 | private List<Gesture> onKBMInputEvent(KBMInputEvent kbmEvent)
|
---|
1530 | {
|
---|
1531 | // Check for single right click
|
---|
1532 | if (_pickup == null && kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1533 | _pickup = true;
|
---|
1534 | _timeoutHandle = EcosystemManager.getInputManager().addTimeout(EXTRUSION_DELAY_MS);
|
---|
1535 | _extrusionDelayExpired = false;
|
---|
1536 | _clickedItem = FrameUtils.getCurrentItem();
|
---|
1537 | return null;
|
---|
1538 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1539 | _pickup = false;
|
---|
1540 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
1541 | return null;
|
---|
1542 | } else if (Boolean.FALSE.equals(_pickup) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1543 | _pickup = null;
|
---|
1544 | return null;
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | // Wait for the button up to perform the pickup
|
---|
1548 | if (!Boolean.TRUE.equals(_pickup) || kbmEvent.getMouseButtonUp() != MouseButton.RIGHT) {
|
---|
1549 | return null;
|
---|
1550 | }
|
---|
1551 |
|
---|
1552 | // Reset pickup for next gesture
|
---|
1553 | _pickup = null;
|
---|
1554 |
|
---|
1555 | // Cancel the extrusion timeout if it's pending
|
---|
1556 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
1557 |
|
---|
1558 | // Reset the line pulse if it occured
|
---|
1559 | if (_extrusionDelayExpired) {
|
---|
1560 | pulseExtrusionLines(false);
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | // Check we haven't moved too far
|
---|
1564 | if (isMouseDragNoOp()) {
|
---|
1565 | printNoopMessage();
|
---|
1566 | return null;
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | // Check we should be picking up (shift forces line creation)
|
---|
1570 | if (FreeItems.hasItemsAttachedToCursor() || kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
1571 | return null;
|
---|
1572 | }
|
---|
1573 |
|
---|
1574 | // Check there is something to pick up
|
---|
1575 | if (!FrameUtils.hasCurrentItem() && FrameUtils.getCurrentItems() == null) {
|
---|
1576 | return null;
|
---|
1577 | }
|
---|
1578 |
|
---|
1579 | // Return the gesture
|
---|
1580 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PICK_UP), new PickUpGestureData(true, _extrusionDelayExpired));
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | private List<Gesture> onTimeoutInputEvent(TimeoutInputEvent event)
|
---|
1584 | {
|
---|
1585 | if (event.getHandle() == _timeoutHandle) {
|
---|
1586 | _extrusionDelayExpired = true;
|
---|
1587 | pulseExtrusionLines(true);
|
---|
1588 | }
|
---|
1589 |
|
---|
1590 | return null;
|
---|
1591 | }
|
---|
1592 |
|
---|
1593 | private void pulseExtrusionLines(boolean pulseOn)
|
---|
1594 | {
|
---|
1595 | int amount = PULSE_AMOUNT;
|
---|
1596 | if (!pulseOn) {
|
---|
1597 | amount *= -1;
|
---|
1598 | }
|
---|
1599 |
|
---|
1600 | if (_clickedItem != null) {
|
---|
1601 | for (Item i : _clickedItem.getAllConnected()) {
|
---|
1602 | if (i instanceof Line) {
|
---|
1603 | Line line = (Line) i;
|
---|
1604 | line.setThickness(line.getThickness() + amount);
|
---|
1605 | }
|
---|
1606 | }
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | DisplayController.requestRefresh(true);
|
---|
1610 | }
|
---|
1611 | });
|
---|
1612 |
|
---|
1613 | // Add the MIDDLE MOUSE -> PLACE gesture recogniser
|
---|
1614 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1615 | {
|
---|
1616 | Boolean _place = null;
|
---|
1617 |
|
---|
1618 | @Override
|
---|
1619 | public String details() { return "MIDDLE MOUSE -> PLACE"; }
|
---|
1620 |
|
---|
1621 | @Override
|
---|
1622 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1623 | // Cast to keyboard/mouse event
|
---|
1624 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1625 |
|
---|
1626 | // Check for single middle click
|
---|
1627 | if (_place == null && kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1628 | _place = true;
|
---|
1629 | return null;
|
---|
1630 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1631 | _place = false;
|
---|
1632 | return null;
|
---|
1633 | } else if (Boolean.FALSE.equals(_place) && isAnyMouseButtonDown() == false) {
|
---|
1634 | _place = null;
|
---|
1635 | return null;
|
---|
1636 | }
|
---|
1637 |
|
---|
1638 | // Wait for the button up to perform the place
|
---|
1639 | if (!Boolean.TRUE.equals(_place) || kbmEvent.getMouseButtonUp() != MouseButton.MIDDLE) {
|
---|
1640 | return null;
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | // Reset place for next gesture
|
---|
1644 | _place = null;
|
---|
1645 |
|
---|
1646 | // Check we haven't moved too far
|
---|
1647 | if (isMouseDragNoOp()) {
|
---|
1648 | printNoopMessage();
|
---|
1649 | return null;
|
---|
1650 | }
|
---|
1651 |
|
---|
1652 | // Check we should be placing
|
---|
1653 | if (!FreeItems.hasItemsAttachedToCursor()) {
|
---|
1654 | return null;
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | // Return the gesture
|
---|
1658 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PLACE), new PickUpGestureData(false));
|
---|
1659 | }
|
---|
1660 | });
|
---|
1661 |
|
---|
1662 | // Add the RIGHT MOUSE -> PLACE gesture recogniser
|
---|
1663 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1664 | {
|
---|
1665 | Boolean _place = null;
|
---|
1666 | @Override
|
---|
1667 | public String details() { return "RIGHT MOUSE -> PLACE"; }
|
---|
1668 |
|
---|
1669 | @Override
|
---|
1670 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1671 | // Cast to keyboard/mouse event
|
---|
1672 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1673 |
|
---|
1674 | // Check for single right click
|
---|
1675 | if (_place == null && kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1676 | _place = true;
|
---|
1677 | return null;
|
---|
1678 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1679 | _place = false;
|
---|
1680 | return null;
|
---|
1681 | } else if (Boolean.FALSE.equals(_place) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1682 | _place = null;
|
---|
1683 | return null;
|
---|
1684 | }
|
---|
1685 |
|
---|
1686 | // Wait for the button up to perform the place
|
---|
1687 | if (!Boolean.TRUE.equals(_place) || kbmEvent.getMouseButtonUp() != MouseButton.RIGHT) {
|
---|
1688 | return null;
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | // Reset place for next gesture
|
---|
1692 | _place = null;
|
---|
1693 |
|
---|
1694 | // Check we haven't moved too far
|
---|
1695 | if (isMouseDragNoOp()) {
|
---|
1696 | printNoopMessage();
|
---|
1697 | return null;
|
---|
1698 | }
|
---|
1699 |
|
---|
1700 | // Check we should be placing
|
---|
1701 | if (!FreeItems.hasItemsAttachedToCursor()) {
|
---|
1702 | return null;
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | // Return the gesture
|
---|
1706 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.PLACE), new PickUpGestureData(true));
|
---|
1707 | }
|
---|
1708 | });
|
---|
1709 |
|
---|
1710 | // Add the MIDDLE + RIGHT MOUSE -> DELETE gesture recogniser
|
---|
1711 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1712 | {
|
---|
1713 | private static final int STATE_NO_MOUSE_BUTTON_DOWN = 0;
|
---|
1714 | private static final int STATE_MIDDLE_MOUSE_BUTTON_DOWN = 1;
|
---|
1715 | private static final int STATE_RIGHT_MOUSE_BUTTON_DOWN = 2;
|
---|
1716 | private static final int STATE_BOTH_MOUSE_BUTTON_DOWN = 3;
|
---|
1717 | private static final int STATE_ERROR = 4;
|
---|
1718 | private int _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1719 |
|
---|
1720 | @Override
|
---|
1721 | public String details() { return "MIDDLE + RIGHT MOUSE -> DELETE"; }
|
---|
1722 |
|
---|
1723 | @Override
|
---|
1724 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1725 | // Cast to keyboard/mouse event
|
---|
1726 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1727 |
|
---|
1728 | // Keep track of mouse button state
|
---|
1729 | if (_state == STATE_NO_MOUSE_BUTTON_DOWN) {
|
---|
1730 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1731 | _state = STATE_RIGHT_MOUSE_BUTTON_DOWN;
|
---|
1732 | } else if (kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1733 | _state = STATE_MIDDLE_MOUSE_BUTTON_DOWN;
|
---|
1734 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1735 | _state = STATE_ERROR;
|
---|
1736 | }
|
---|
1737 | return null;
|
---|
1738 | } else if (_state == STATE_MIDDLE_MOUSE_BUTTON_DOWN) {
|
---|
1739 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1740 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
1741 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.MIDDLE) {
|
---|
1742 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1743 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1744 | _state = STATE_ERROR;
|
---|
1745 | }
|
---|
1746 | return null;
|
---|
1747 | } else if (_state == STATE_RIGHT_MOUSE_BUTTON_DOWN) {
|
---|
1748 | if (kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1749 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
1750 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.RIGHT) {
|
---|
1751 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1752 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1753 | _state = STATE_ERROR;
|
---|
1754 | }
|
---|
1755 | return null;
|
---|
1756 | } else if (_state == STATE_BOTH_MOUSE_BUTTON_DOWN) {
|
---|
1757 | if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1758 | _state = STATE_ERROR;
|
---|
1759 | return null;
|
---|
1760 | }
|
---|
1761 | } else if (kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1762 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1763 | return null;
|
---|
1764 | }
|
---|
1765 |
|
---|
1766 | // Wait for the button up to perform the delete
|
---|
1767 | if (_state != STATE_BOTH_MOUSE_BUTTON_DOWN || kbmTranslator.isAnyMouseButtonDown()) {
|
---|
1768 | return null;
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 | // Reset state for next gesture
|
---|
1772 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
1773 |
|
---|
1774 | // Check we haven't moved too far
|
---|
1775 | if (isMouseDragNoOp()) {
|
---|
1776 | printNoopMessage();
|
---|
1777 | return null;
|
---|
1778 | }
|
---|
1779 |
|
---|
1780 | // Decide if this is an alternate mode delete
|
---|
1781 | // TODO: What specifically is alternate mode delete? cts16
|
---|
1782 | boolean alternateMode = kbmTranslator.isKeyDown(Key.SHIFT);
|
---|
1783 |
|
---|
1784 | // Return the gesture
|
---|
1785 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.DELETE), new DeleteGestureData(alternateMode));
|
---|
1786 | }
|
---|
1787 | });
|
---|
1788 |
|
---|
1789 | // Add the MIDDLE MOUSE -> CREATE_ITEM gesture recogniser
|
---|
1790 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1791 | {
|
---|
1792 | Boolean _create = null;
|
---|
1793 | @Override
|
---|
1794 | public String details() { return "MIDDLE MOUSE -> CREATE_ITEM"; }
|
---|
1795 |
|
---|
1796 | @Override
|
---|
1797 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1798 | // Cast to keyboard/mouse event
|
---|
1799 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1800 |
|
---|
1801 | // Check for single middle click
|
---|
1802 | if (_create == null && kbmEvent.getMouseButtonDown() == MouseButton.MIDDLE) {
|
---|
1803 | _create = true;
|
---|
1804 | return null;
|
---|
1805 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1806 | _create = false;
|
---|
1807 | return null;
|
---|
1808 | } else if (Boolean.FALSE.equals(_create) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1809 | _create = null;
|
---|
1810 | return null;
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | // Wait for the button up to perform the create
|
---|
1814 | if (!Boolean.TRUE.equals(_create) || kbmEvent.getMouseButtonUp() != MouseButton.MIDDLE) {
|
---|
1815 | return null;
|
---|
1816 | }
|
---|
1817 |
|
---|
1818 | // Reset create for next gesture
|
---|
1819 | _create = null;
|
---|
1820 |
|
---|
1821 | // Check we haven't moved too far
|
---|
1822 | if (isMouseDragNoOp()) {
|
---|
1823 | printNoopMessage();
|
---|
1824 | return null;
|
---|
1825 | }
|
---|
1826 |
|
---|
1827 | // Check we can create
|
---|
1828 | if (FreeItems.hasItemsAttachedToCursor()) {
|
---|
1829 | return null;
|
---|
1830 | }
|
---|
1831 |
|
---|
1832 | // Check we're not trying to pick up (shift forces item creation)
|
---|
1833 | if (!kbmTranslator.isKeyDown(Key.SHIFT) && (FrameUtils.hasCurrentItem() || FrameUtils.getCurrentItems() != null)) {
|
---|
1834 | return null;
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 | // Return the gesture
|
---|
1838 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CREATE_ITEM), new CreateItemGestureData(ItemType.LINE));
|
---|
1839 | }
|
---|
1840 | });
|
---|
1841 |
|
---|
1842 | // Add the RIGHT MOUSE -> CREATE_ITEM gesture recogniser
|
---|
1843 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1844 | {
|
---|
1845 | Boolean _create = null;
|
---|
1846 | @Override
|
---|
1847 | public String details() { return "RIGHT MOUSE -> CREATE_ITEM"; }
|
---|
1848 |
|
---|
1849 | @Override
|
---|
1850 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1851 | // Cast to keyboard/mouse event
|
---|
1852 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1853 |
|
---|
1854 | // Check for single middle click
|
---|
1855 | if (_create == null && kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
1856 | _create = true;
|
---|
1857 | return null;
|
---|
1858 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1859 | _create = false;
|
---|
1860 | return null;
|
---|
1861 | } else if (Boolean.FALSE.equals(_create) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1862 | _create = null;
|
---|
1863 | return null;
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | // Wait for the button up to perform the create
|
---|
1867 | if (!Boolean.TRUE.equals(_create) || kbmEvent.getMouseButtonUp() != MouseButton.RIGHT) {
|
---|
1868 | return null;
|
---|
1869 | }
|
---|
1870 |
|
---|
1871 | // Reset create for next gesture
|
---|
1872 | _create = null;
|
---|
1873 |
|
---|
1874 | // Check we haven't moved too far
|
---|
1875 | if (isMouseDragNoOp()) {
|
---|
1876 | printNoopMessage();
|
---|
1877 | return null;
|
---|
1878 | }
|
---|
1879 |
|
---|
1880 | // Check we can create
|
---|
1881 | if (FreeItems.hasItemsAttachedToCursor()) {
|
---|
1882 | return null;
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | // Check we're not trying to pick up (shift forces item creation)
|
---|
1886 | if (!kbmTranslator.isKeyDown(Key.SHIFT) && (FrameUtils.hasCurrentItem() || FrameUtils.getCurrentItems() != null)) {
|
---|
1887 | return null;
|
---|
1888 | }
|
---|
1889 |
|
---|
1890 | // Return the gesture
|
---|
1891 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CREATE_ITEM), new CreateItemGestureData(ItemType.BOX));
|
---|
1892 | }
|
---|
1893 | });
|
---|
1894 |
|
---|
1895 | // Add the LEFT MOUSE -> CLICK gesture recogniser
|
---|
1896 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
1897 | {
|
---|
1898 | private static final int LONG_CLICK_DELAY_MS = 500;
|
---|
1899 | private Boolean _click = null;
|
---|
1900 | private long _clickStartTime;
|
---|
1901 | @Override
|
---|
1902 | public String details() { return "LEFT MOUSE -> CLICK"; }
|
---|
1903 |
|
---|
1904 | @Override
|
---|
1905 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
1906 | // Cast to keyboard/mouse event
|
---|
1907 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
1908 |
|
---|
1909 | // Check for single left click
|
---|
1910 | if (_click == null && kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
1911 | _click = true;
|
---|
1912 | _clickStartTime = System.currentTimeMillis();
|
---|
1913 | return null;
|
---|
1914 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1915 | _click = false;
|
---|
1916 | return null;
|
---|
1917 | } else if (Boolean.FALSE.equals(_click) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1918 | _click = null;
|
---|
1919 | return null;
|
---|
1920 | }
|
---|
1921 |
|
---|
1922 | // Wait for the button up to perform the click
|
---|
1923 | if (!Boolean.TRUE.equals(_click) || kbmEvent.getMouseButtonUp() != MouseButton.LEFT) {
|
---|
1924 | return null;
|
---|
1925 | }
|
---|
1926 |
|
---|
1927 | // Reset click for next gesture
|
---|
1928 | _click = null;
|
---|
1929 |
|
---|
1930 | // Check if this is a long click
|
---|
1931 | boolean longClick = System.currentTimeMillis() >= _clickStartTime + LONG_CLICK_DELAY_MS;
|
---|
1932 |
|
---|
1933 | // Check if we are toggling arrowhead
|
---|
1934 | if (longClick && FrameUtils.getCurrentItem() == null) {
|
---|
1935 | if (FreeItems.getInstance().size() <= 2) {
|
---|
1936 | for (Item i : FreeItems.getInstance()) {
|
---|
1937 | if (i instanceof Line) {
|
---|
1938 | return null;
|
---|
1939 | }
|
---|
1940 | }
|
---|
1941 | }
|
---|
1942 | }
|
---|
1943 |
|
---|
1944 | // Check we haven't moved too far
|
---|
1945 | if (isMouseDragNoOp()) {
|
---|
1946 | printNoopMessage();
|
---|
1947 | return null;
|
---|
1948 | }
|
---|
1949 |
|
---|
1950 | // Return the gesture
|
---|
1951 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.CLICK), new ClickGestureData(longClick));
|
---|
1952 | }
|
---|
1953 | });
|
---|
1954 |
|
---|
1955 | // Add the LEFT MOUSE -> TOGGLE_ARROWHEAD gesture recogniser
|
---|
1956 | addTranslator(new InputEventToGestureTranslator(new InputType[] { InputType.KBM, InputType.TIMEOUT })
|
---|
1957 | {
|
---|
1958 | private static final int LONG_CLICK_DELAY_MS = 500;
|
---|
1959 | private Boolean _click = null;
|
---|
1960 | private TimeoutHandle _timeoutHandle = null;
|
---|
1961 |
|
---|
1962 | @Override
|
---|
1963 | public String details() { return "LEFT MOUSE -> TOGGLE_ARROWHEAD"; }
|
---|
1964 |
|
---|
1965 | @Override
|
---|
1966 | public List<Gesture> onInputEvent(InputEvent event)
|
---|
1967 | {
|
---|
1968 | if (event == null) {
|
---|
1969 | return null;
|
---|
1970 | } else if (event.getInputType() == InputType.KBM) {
|
---|
1971 | return onKBMInputEvent((KBMInputEvent) event);
|
---|
1972 | } else if (event.getInputType() == InputType.TIMEOUT) {
|
---|
1973 | return onTimeoutInputEvent((TimeoutInputEvent) event);
|
---|
1974 | }
|
---|
1975 |
|
---|
1976 | return null;
|
---|
1977 | }
|
---|
1978 |
|
---|
1979 | private List<Gesture> onKBMInputEvent(KBMInputEvent kbmEvent)
|
---|
1980 | {
|
---|
1981 | // Check for single left click
|
---|
1982 | if (_click == null && kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
1983 | _click = true;
|
---|
1984 | _timeoutHandle = EcosystemManager.getInputManager().addTimeout(LONG_CLICK_DELAY_MS);
|
---|
1985 | return null;
|
---|
1986 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
1987 | _click = false;
|
---|
1988 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
1989 | return null;
|
---|
1990 | } else if (Boolean.FALSE.equals(_click) && kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
1991 | _click = null;
|
---|
1992 | return null;
|
---|
1993 | }
|
---|
1994 |
|
---|
1995 | // Wait for the button up to perform the click
|
---|
1996 | if (!Boolean.TRUE.equals(_click) || kbmEvent.getMouseButtonUp() != MouseButton.LEFT) {
|
---|
1997 | return null;
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | // Reset click for next gesture
|
---|
2001 | _click = null;
|
---|
2002 |
|
---|
2003 | // Cancel the timer if it's still pending
|
---|
2004 | EcosystemManager.getInputManager().cancelTimeout(_timeoutHandle);
|
---|
2005 |
|
---|
2006 | return null;
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | private List<Gesture> onTimeoutInputEvent(TimeoutInputEvent event)
|
---|
2010 | {
|
---|
2011 | if (event.getHandle() == _timeoutHandle) {
|
---|
2012 | // Check if we are toggling arrowhead
|
---|
2013 | Item line = null;
|
---|
2014 | if (FrameUtils.getCurrentItem() == null) {
|
---|
2015 | if (FreeItems.getInstance().size() <= 2) {
|
---|
2016 | for (Item i : FreeItems.getInstance()) {
|
---|
2017 | if (i instanceof Line) {
|
---|
2018 | line = i;
|
---|
2019 | }
|
---|
2020 | }
|
---|
2021 | }
|
---|
2022 | }
|
---|
2023 | if (line == null) {
|
---|
2024 | return null;
|
---|
2025 | }
|
---|
2026 |
|
---|
2027 | // Check we haven't moved too far
|
---|
2028 | if (isMouseDragNoOp()) {
|
---|
2029 | printNoopMessage();
|
---|
2030 | return null;
|
---|
2031 | }
|
---|
2032 |
|
---|
2033 | return Gesture.single(StandardGestureActions.getInstance().gestureType(StandardGestureType.TOGGLE_ARROWHEAD), new ItemSpecificGestureData(line));
|
---|
2034 | }
|
---|
2035 |
|
---|
2036 | // Someone else's timeout event
|
---|
2037 | return null;
|
---|
2038 | }
|
---|
2039 | });
|
---|
2040 |
|
---|
2041 | // Add the LEFT + RIGHT MOUSE -> EXTRACT_ATTRIBUTES gesture recogniser
|
---|
2042 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2043 | {
|
---|
2044 | private static final int STATE_NO_MOUSE_BUTTON_DOWN = 0;
|
---|
2045 | private static final int STATE_LEFT_MOUSE_BUTTON_DOWN = 1;
|
---|
2046 | private static final int STATE_RIGHT_MOUSE_BUTTON_DOWN = 2;
|
---|
2047 | private static final int STATE_BOTH_MOUSE_BUTTON_DOWN = 3;
|
---|
2048 | private static final int STATE_ERROR = 4;
|
---|
2049 | private int _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2050 |
|
---|
2051 | @Override
|
---|
2052 | public String details() { return "LEFT + RIGHT MOUSE -> EXTRACT_ATTRIBUTES"; }
|
---|
2053 |
|
---|
2054 | @Override
|
---|
2055 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2056 | // Cast to keyboard/mouse event
|
---|
2057 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2058 |
|
---|
2059 | // Keep track of mouse button state
|
---|
2060 | if (_state == STATE_NO_MOUSE_BUTTON_DOWN) {
|
---|
2061 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2062 | _state = STATE_RIGHT_MOUSE_BUTTON_DOWN;
|
---|
2063 | } else if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2064 | _state = STATE_LEFT_MOUSE_BUTTON_DOWN;
|
---|
2065 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2066 | _state = STATE_ERROR;
|
---|
2067 | }
|
---|
2068 | return null;
|
---|
2069 | } else if (_state == STATE_LEFT_MOUSE_BUTTON_DOWN) {
|
---|
2070 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2071 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2072 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.LEFT) {
|
---|
2073 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2074 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2075 | _state = STATE_ERROR;
|
---|
2076 | }
|
---|
2077 | return null;
|
---|
2078 | } else if (_state == STATE_RIGHT_MOUSE_BUTTON_DOWN) {
|
---|
2079 | if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2080 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2081 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.RIGHT) {
|
---|
2082 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2083 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2084 | _state = STATE_ERROR;
|
---|
2085 | }
|
---|
2086 | return null;
|
---|
2087 | } else if (_state == STATE_BOTH_MOUSE_BUTTON_DOWN) {
|
---|
2088 | if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2089 | _state = STATE_ERROR;
|
---|
2090 | return null;
|
---|
2091 | }
|
---|
2092 | } else if (kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
2093 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2094 | return null;
|
---|
2095 | }
|
---|
2096 |
|
---|
2097 | // Wait for the button up to perform the extraction
|
---|
2098 | if (_state != STATE_BOTH_MOUSE_BUTTON_DOWN || kbmTranslator.isAnyMouseButtonDown()) {
|
---|
2099 | return null;
|
---|
2100 | }
|
---|
2101 |
|
---|
2102 | // Reset state for next gesture
|
---|
2103 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2104 |
|
---|
2105 | // Check we haven't moved too far
|
---|
2106 | if (isMouseDragNoOp()) {
|
---|
2107 | printNoopMessage();
|
---|
2108 | return null;
|
---|
2109 | }
|
---|
2110 |
|
---|
2111 | // Make sure we are over something to extract from
|
---|
2112 | if (!FrameUtils.hasCurrentItem()) {
|
---|
2113 | return null;
|
---|
2114 | }
|
---|
2115 |
|
---|
2116 | // Return the gesture
|
---|
2117 | return standardSingle(StandardGestureType.EXTRACT_ATTRIBUTES, new ItemSpecificGestureData());
|
---|
2118 | }
|
---|
2119 | });
|
---|
2120 |
|
---|
2121 | // Add the LEFT + RIGHT MOUSE -> FORMAT gesture recogniser
|
---|
2122 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2123 | {
|
---|
2124 | private static final int STATE_NO_MOUSE_BUTTON_DOWN = 0;
|
---|
2125 | private static final int STATE_LEFT_MOUSE_BUTTON_DOWN = 1;
|
---|
2126 | private static final int STATE_RIGHT_MOUSE_BUTTON_DOWN = 2;
|
---|
2127 | private static final int STATE_BOTH_MOUSE_BUTTON_DOWN = 3;
|
---|
2128 | private static final int STATE_ERROR = 4;
|
---|
2129 | private int _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2130 |
|
---|
2131 | @Override
|
---|
2132 | public String details() { return "LEFT + RIGHT MOUSE -> FORMAT"; }
|
---|
2133 |
|
---|
2134 | @Override
|
---|
2135 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2136 | // Cast to keyboard/mouse event
|
---|
2137 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2138 |
|
---|
2139 | // Keep track of mouse button state
|
---|
2140 | if (_state == STATE_NO_MOUSE_BUTTON_DOWN) {
|
---|
2141 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2142 | _state = STATE_RIGHT_MOUSE_BUTTON_DOWN;
|
---|
2143 | } else if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2144 | _state = STATE_LEFT_MOUSE_BUTTON_DOWN;
|
---|
2145 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2146 | _state = STATE_ERROR;
|
---|
2147 | }
|
---|
2148 | return null;
|
---|
2149 | } else if (_state == STATE_LEFT_MOUSE_BUTTON_DOWN) {
|
---|
2150 | if (kbmEvent.getMouseButtonDown() == MouseButton.RIGHT) {
|
---|
2151 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2152 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.LEFT) {
|
---|
2153 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2154 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2155 | _state = STATE_ERROR;
|
---|
2156 | }
|
---|
2157 | return null;
|
---|
2158 | } else if (_state == STATE_RIGHT_MOUSE_BUTTON_DOWN) {
|
---|
2159 | if (kbmEvent.getMouseButtonDown() == MouseButton.LEFT) {
|
---|
2160 | _state = STATE_BOTH_MOUSE_BUTTON_DOWN;
|
---|
2161 | } else if (kbmEvent.getMouseButtonUp() == MouseButton.RIGHT) {
|
---|
2162 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2163 | } else if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2164 | _state = STATE_ERROR;
|
---|
2165 | }
|
---|
2166 | return null;
|
---|
2167 | } else if (_state == STATE_BOTH_MOUSE_BUTTON_DOWN) {
|
---|
2168 | if (kbmEvent.getEventType() == EventType.MOUSE_BUTTON_DOWN) {
|
---|
2169 | _state = STATE_ERROR;
|
---|
2170 | return null;
|
---|
2171 | }
|
---|
2172 | } else if (kbmTranslator.isAnyMouseButtonDown() == false) {
|
---|
2173 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2174 | return null;
|
---|
2175 | }
|
---|
2176 |
|
---|
2177 | // Wait for the button up to perform the extraction
|
---|
2178 | if (_state != STATE_BOTH_MOUSE_BUTTON_DOWN || kbmTranslator.isAnyMouseButtonDown()) {
|
---|
2179 | return null;
|
---|
2180 | }
|
---|
2181 |
|
---|
2182 | // Reset state for next gesture
|
---|
2183 | _state = STATE_NO_MOUSE_BUTTON_DOWN;
|
---|
2184 |
|
---|
2185 | // Check we haven't moved too far
|
---|
2186 | if (isMouseDragNoOp()) {
|
---|
2187 | printNoopMessage();
|
---|
2188 | return null;
|
---|
2189 | }
|
---|
2190 |
|
---|
2191 | // Make sure we are not extracting
|
---|
2192 | if (FrameUtils.hasCurrentItem()) {
|
---|
2193 | return null;
|
---|
2194 | }
|
---|
2195 |
|
---|
2196 | // Return the gestures
|
---|
2197 | Gesture hFormat = new Gesture(StandardGestureActions.getInstance().gestureType(StandardGestureType.FORMAT), new FormatGestureData(true));
|
---|
2198 | Gesture vFormat = new Gesture(StandardGestureActions.getInstance().gestureType(StandardGestureType.FORMAT), new FormatGestureData(false));
|
---|
2199 | if (kbmTranslator.isKeyDown(Key.CTRL) && kbmTranslator.isKeyDown(Key.SHIFT)) {
|
---|
2200 | List<Gesture> gestures = Gesture.single(hFormat);
|
---|
2201 | gestures.add(vFormat);
|
---|
2202 | return gestures;
|
---|
2203 | } else if (kbmTranslator.isKeyDown(Key.CTRL)) {
|
---|
2204 | return Gesture.single(hFormat);
|
---|
2205 | } else {
|
---|
2206 | return Gesture.single(vFormat);
|
---|
2207 | }
|
---|
2208 | }
|
---|
2209 | });
|
---|
2210 |
|
---|
2211 | // Add the ENTER_CHAR_TYPED -> ACTIVATE BUTTON -> FORMAT gesture recogniser
|
---|
2212 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2213 | {
|
---|
2214 | @Override
|
---|
2215 | public String details() { return "ENTER_CHAR_TYPED -> ACTIVATE BUTTON"; }
|
---|
2216 |
|
---|
2217 | @Override
|
---|
2218 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2219 | // Cast to keyboard/mouse event
|
---|
2220 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2221 |
|
---|
2222 | if (kbmEvent.getKeyDown() != Key.ENTER) {
|
---|
2223 | return null;
|
---|
2224 | }
|
---|
2225 |
|
---|
2226 | GestureType gestureType = StandardGestureActions.getInstance().gestureType(StandardGestureType.ACTIVATE_BUTTON);
|
---|
2227 | ItemSpecificGestureData data = new ClickGestureData(false);
|
---|
2228 | return Gesture.single(gestureType, data);
|
---|
2229 | }
|
---|
2230 | });
|
---|
2231 |
|
---|
2232 | // TEMPLATE
|
---|
2233 | // Add the DETAILS gesture recogniser
|
---|
2234 | addTranslator(new InputEventToGestureTranslator(InputType.KBM)
|
---|
2235 | {
|
---|
2236 | @Override
|
---|
2237 | public String details() { return "DETAILS"; }
|
---|
2238 |
|
---|
2239 | @Override
|
---|
2240 | public List<Gesture> onInputEvent(InputEvent event) {
|
---|
2241 | // Cast to keyboard/mouse event
|
---|
2242 | KBMInputEvent kbmEvent = (KBMInputEvent) event;
|
---|
2243 |
|
---|
2244 | // TODO Auto-generated method stub
|
---|
2245 | return null;
|
---|
2246 | }
|
---|
2247 | });
|
---|
2248 | }
|
---|
2249 |
|
---|
2250 | public boolean isKeyDown(Key key)
|
---|
2251 | {
|
---|
2252 | return StandardInputEventListeners.kbmStateListener.isKeyDown(key);
|
---|
2253 | }
|
---|
2254 |
|
---|
2255 | public boolean isMouseButtonDown(MouseButton button)
|
---|
2256 | {
|
---|
2257 | return StandardInputEventListeners.kbmStateListener.isMouseButtonDown(button);
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 | public boolean isOnlyMouseButtonDown(MouseButton button)
|
---|
2261 | {
|
---|
2262 | return StandardInputEventListeners.kbmStateListener.isOnlyMouseButtonDown(button);
|
---|
2263 | }
|
---|
2264 |
|
---|
2265 | public boolean isAnyMouseButtonDown()
|
---|
2266 | {
|
---|
2267 | return StandardInputEventListeners.kbmStateListener.isAnyMouseButtonDown();
|
---|
2268 | }
|
---|
2269 |
|
---|
2270 | public static boolean isMouseDragNoOp()
|
---|
2271 | {
|
---|
2272 | return _noop;
|
---|
2273 | }
|
---|
2274 |
|
---|
2275 | public static void printNoopMessage()
|
---|
2276 | {
|
---|
2277 | System.err.println("Exceeded NoOp Threshold of " + UserSettings.NoOpThreshold.get() + " pixels. Reinterpreting origonal Gesture.");
|
---|
2278 | //MessageBay.displayMessage("Gesture cancelled, mouse moved more than " + UserSettings.NoOpThreshold.get() + " pixels.");
|
---|
2279 | }
|
---|
2280 |
|
---|
2281 | public static void trackMouseDragNoop(KBMInputEvent event)
|
---|
2282 | {
|
---|
2283 | if (!StandardInputEventListeners.kbmStateListener.isAnyMouseButtonDown() && (event.getEventType() != EventType.MOUSE_BUTTON_UP)) {
|
---|
2284 | _noop = false;
|
---|
2285 | _mouseDragStart = null;
|
---|
2286 | } else if (_mouseDragStart == null) {
|
---|
2287 | org.expeditee.core.Line mouseMove = event.getMouseMove();
|
---|
2288 | if (mouseMove != null) {
|
---|
2289 | _mouseDragStart = mouseMove.getFirstEnd().clone();
|
---|
2290 | }
|
---|
2291 | } else if (_noop == false) {
|
---|
2292 | org.expeditee.core.Line mouseMove = event.getMouseMove();
|
---|
2293 | if (mouseMove != null) {
|
---|
2294 | mouseMove.setFirstEnd(_mouseDragStart.clone());
|
---|
2295 | if (mouseMove.length() > UserSettings.NoOpThreshold.get()) {
|
---|
2296 | _noop = true;
|
---|
2297 | }
|
---|
2298 | }
|
---|
2299 | }
|
---|
2300 | }
|
---|
2301 |
|
---|
2302 | /** Convenience function to create a single standard gesture. */
|
---|
2303 | public static List<Gesture> standardSingle(StandardGestureType type, GestureData data)
|
---|
2304 | {
|
---|
2305 | return Gesture.single(StandardGestureActions.getInstance().gestureType(type), data);
|
---|
2306 | }
|
---|
2307 | }
|
---|