1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.googlecode.mgwt.ui.client.widget.touch;
17
18 import com.google.gwt.user.client.ui.UIObject;
19 import com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers;
20 import com.googlecode.mgwt.dom.client.recognizer.TapRecognizer;
21 import com.googlecode.mgwt.dom.client.recognizer.longtap.LongTapRecognizer;
22 import com.googlecode.mgwt.dom.client.recognizer.pinch.PinchRecognizer;
23 import com.googlecode.mgwt.dom.client.recognizer.pinch.UIObjectToOffsetProvider;
24 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeRecognizer;
25
26
27
28
29
30
31
32 public class GestureUtility {
33 private TapRecognizer tapRecognizer;
34 private final HasTouchHandlers source;
35 private LongTapRecognizer longTapRecognizer;
36 private SwipeRecognizer swipeRecognizer;
37 private PinchRecognizer pinchRecognizer;
38
39
40
41
42
43
44 public GestureUtility(HasTouchHandlers source) {
45 assert source != null;
46 this.source = source;
47 }
48
49
50
51
52 public void ensureTapRecognizer() {
53 if (tapRecognizer != null)
54 return;
55
56 tapRecognizer = new TapRecognizer(source);
57 source.addTouchHandler(tapRecognizer);
58 }
59
60
61
62
63 public void ensureLongTapRecognizer() {
64 if (longTapRecognizer != null) {
65 return;
66 }
67
68 longTapRecognizer = new LongTapRecognizer(source);
69 source.addTouchHandler(longTapRecognizer);
70
71 }
72
73
74
75
76 public void ensureSwipeRecognizer() {
77 if (swipeRecognizer != null) {
78 return;
79 }
80
81 swipeRecognizer = new SwipeRecognizer(source);
82 source.addTouchHandler(swipeRecognizer);
83
84 }
85
86
87
88
89
90
91
92 public void ensurePinchRecognizer(UIObject object) {
93 if (pinchRecognizer != null) {
94 return;
95 }
96
97 pinchRecognizer = new PinchRecognizer(source, new UIObjectToOffsetProvider(object));
98 source.addTouchHandler(pinchRecognizer);
99
100 }
101
102
103
104
105 public void ensureLongTapHandler() {
106 if (longTapRecognizer != null) {
107 return;
108 }
109
110 longTapRecognizer = new LongTapRecognizer(source);
111 source.addTouchHandler(longTapRecognizer);
112
113 }
114 }