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