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.core.client.GWT;
19 import com.google.gwt.event.shared.HandlerRegistration;
20 import com.google.gwt.user.client.ui.Widget;
21 import com.googlecode.mgwt.dom.client.event.mouse.HandlerRegistrationCollection;
22 import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers;
23 import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
24 import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
25 import com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers;
26 import com.googlecode.mgwt.dom.client.event.touch.TouchCancelHandler;
27 import com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler;
28 import com.googlecode.mgwt.dom.client.event.touch.TouchHandler;
29 import com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler;
30 import com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler;
31 import com.googlecode.mgwt.dom.client.recognizer.longtap.HasLongTapHandlers;
32 import com.googlecode.mgwt.dom.client.recognizer.longtap.LongTapEvent;
33 import com.googlecode.mgwt.dom.client.recognizer.longtap.LongTapHandler;
34 import com.googlecode.mgwt.dom.client.recognizer.pinch.HasPinchHandlers;
35 import com.googlecode.mgwt.dom.client.recognizer.pinch.PinchEvent;
36 import com.googlecode.mgwt.dom.client.recognizer.pinch.PinchHandler;
37 import com.googlecode.mgwt.dom.client.recognizer.swipe.HasSwipeHandlers;
38 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeEndEvent;
39 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeEndHandler;
40 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeMoveEvent;
41 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeMoveHandler;
42 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeStartEvent;
43 import com.googlecode.mgwt.dom.client.recognizer.swipe.SwipeStartHandler;
44
45
46
47
48
49
50
51
52 public abstract class TouchWidget extends Widget implements HasTouchHandlers, HasTapHandlers, HasSwipeHandlers, HasPinchHandlers, HasLongTapHandlers {
53
54 private static final TouchWidgetImpl impl = GWT.create(TouchWidgetImpl.class);
55
56 protected final GestureUtility gestureUtility;
57
58
59
60
61
62
63 public TouchWidget() {
64 gestureUtility = new GestureUtility(this);
65 }
66
67
68
69
70
71
72 @Override
73 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
74 return impl.addTouchStartHandler(this, handler);
75
76 }
77
78
79
80
81
82
83 @Override
84 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
85 return impl.addTouchMoveHandler(this, handler);
86
87 }
88
89
90
91
92
93
94 @Override
95 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
96 return impl.addTouchCancelHandler(this, handler);
97
98 }
99
100
101
102
103
104
105 @Override
106 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
107 return impl.addTouchEndHandler(this, handler);
108
109 }
110
111
112
113
114
115
116 @Override
117 public HandlerRegistration addTouchHandler(TouchHandler handler) {
118 HandlerRegistrationCollection handlerRegistrationCollection = new HandlerRegistrationCollection();
119
120 handlerRegistrationCollection.addHandlerRegistration(addTouchCancelHandler(handler));
121 handlerRegistrationCollection.addHandlerRegistration(addTouchStartHandler(handler));
122 handlerRegistrationCollection.addHandlerRegistration(addTouchEndHandler(handler));
123 handlerRegistrationCollection.addHandlerRegistration(addTouchMoveHandler(handler));
124 return handlerRegistrationCollection;
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138 public HandlerRegistration addTapHandler(TapHandler handler) {
139 gestureUtility.ensureTapRecognizer();
140 return addHandler(handler, TapEvent.getType());
141 }
142
143 @Override
144 public HandlerRegistration addSwipeStartHandler(SwipeStartHandler handler) {
145 gestureUtility.ensureSwipeRecognizer();
146 return addHandler(handler, SwipeStartEvent.getType());
147 }
148
149 @Override
150 public HandlerRegistration addSwipeMoveHandler(SwipeMoveHandler handler) {
151 gestureUtility.ensureSwipeRecognizer();
152 return addHandler(handler, SwipeMoveEvent.getType());
153 }
154
155 @Override
156 public HandlerRegistration addSwipeEndHandler(SwipeEndHandler handler) {
157 gestureUtility.ensureSwipeRecognizer();
158 return addHandler(handler, SwipeEndEvent.getType());
159 }
160
161 @Override
162 public HandlerRegistration addPinchHandler(PinchHandler handler) {
163 gestureUtility.ensurePinchRecognizer(this);
164 return addHandler(handler, PinchEvent.getType());
165 }
166
167 @Override
168 public HandlerRegistration addLongTapHandler(LongTapHandler handler) {
169 gestureUtility.ensureLongTapHandler();
170 return addHandler(handler, LongTapEvent.getType());
171 }
172
173 }