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.FlowPanel;
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.TouchEvent;
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 public class TouchPanel extends FlowPanel implements HasTouchHandlers, HasTapHandlers, HasPinchHandlers, HasSwipeHandlers, HasLongTapHandlers {
54
55 private static final TouchWidgetImpl impl = GWT.create(TouchWidgetImpl.class);
56
57 protected final GestureUtility gestureUtility;
58
59
60
61
62 public TouchPanel() {
63 gestureUtility = new GestureUtility(this);
64 }
65
66
67
68
69
70
71 @Override
72 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
73 return impl.addTouchStartHandler(this, handler);
74
75 }
76
77
78
79
80
81
82 @Override
83 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
84 return impl.addTouchMoveHandler(this, handler);
85
86 }
87
88
89
90
91
92
93 @Override
94 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
95 return impl.addTouchCancelHandler(this, handler);
96
97 }
98
99
100
101
102
103
104 @Override
105 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
106 return impl.addTouchEndHandler(this, handler);
107
108 }
109
110
111
112
113
114
115 @Override
116 public HandlerRegistration addTouchHandler(TouchHandler handler) {
117 HandlerRegistrationCollection handlerRegistrationCollection = new HandlerRegistrationCollection();
118
119 handlerRegistrationCollection.addHandlerRegistration(addTouchCancelHandler(handler));
120 handlerRegistrationCollection.addHandlerRegistration(addTouchStartHandler(handler));
121 handlerRegistrationCollection.addHandlerRegistration(addTouchEndHandler(handler));
122 handlerRegistrationCollection.addHandlerRegistration(addTouchMoveHandler(handler));
123 return handlerRegistrationCollection;
124 }
125
126
127
128
129
130 @Override
131 public HandlerRegistration addTapHandler(TapHandler handler) {
132 gestureUtility.ensureTapRecognizer();
133 return addHandler(handler, TapEvent.getType());
134 }
135
136 public HandlerRegistration addSwipeStartHandler(SwipeStartHandler handler) {
137 gestureUtility.ensureSwipeRecognizer();
138 return addHandler(handler, SwipeStartEvent.getType());
139 }
140
141 public HandlerRegistration addSwipeMoveHandler(SwipeMoveHandler handler) {
142 gestureUtility.ensureSwipeRecognizer();
143 return addHandler(handler, SwipeMoveEvent.getType());
144 }
145
146 public HandlerRegistration addSwipeEndHandler(SwipeEndHandler handler) {
147 gestureUtility.ensureSwipeRecognizer();
148 return addHandler(handler, SwipeEndEvent.getType());
149 }
150
151 @Override
152 public HandlerRegistration addPinchHandler(PinchHandler handler) {
153 gestureUtility.ensurePinchRecognizer(this);
154 return addHandler(handler, PinchEvent.getType());
155 }
156
157 @Override
158 public HandlerRegistration addLongTapHandler(LongTapHandler handler) {
159 gestureUtility.ensureLongTapHandler();
160 return addHandler(handler, LongTapEvent.getType());
161 }
162
163 }