View Javadoc
1   /*
2    * Copyright 2012 Daniel Kurka
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package com.googlecode.mgwt.dom.client.recognizer.swipe;
17  
18  import com.google.gwt.event.shared.GwtEvent;
19  import com.googlecode.mgwt.dom.client.event.touch.Touch;
20  
21  /**
22   * A {@link SwipeMoveEvent} occurs when the user moves his finger over the
23   * display
24   * 
25   * @author Daniel Kurka
26   * 
27   */
28  public class SwipeMoveEvent extends SwipeEvent<SwipeMoveHandler> {
29  
30  	private final static GwtEvent.Type<SwipeMoveHandler> TYPE = new Type<SwipeMoveHandler>();
31  	private final boolean distanceReached;
32  	private final int distance;
33  	private final Touch touch;
34  
35  	public static GwtEvent.Type<SwipeMoveHandler> getType() {
36  		return TYPE;
37  	}
38  
39  	/**
40  	 * Construct a {@link SwipeMoveEvent}
41  	 * 
42  	 * @param touch
43  	 * 
44  	 * @param distanceReached is the minimum distance reached for this swipe
45  	 * @param distance the distance in px
46  	 * @param direction the direction of the swipe
47  	 */
48  	public SwipeMoveEvent(Touch touch, boolean distanceReached, int distance, SwipeEvent.DIRECTION direction) {
49  		super(direction);
50  		this.touch = touch;
51  		this.distanceReached = distanceReached;
52  		this.distance = distance;
53  	}
54  
55  	/*
56  	 * (non-Javadoc)
57  	 * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
58  	 */
59  	@Override
60  	public com.google.gwt.event.shared.GwtEvent.Type<SwipeMoveHandler> getAssociatedType() {
61  		return TYPE;
62  	}
63  
64  	/*
65  	 * (non-Javadoc)
66  	 * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
67  	 */
68  	@Override
69  	protected void dispatch(SwipeMoveHandler handler) {
70  		handler.onSwipeMove(this);
71  
72  	}
73  
74  	/**
75  	 * the distance of this swipe
76  	 * 
77  	 * @return the distance of this swipe in px
78  	 */
79  	public int getDistance() {
80  		return distance;
81  	}
82  
83  	/**
84  	 * is the minimum distance reached
85  	 * 
86  	 * @return true if the minimum distance reached
87  	 */
88  	public boolean isDistanceReached() {
89  		return distanceReached;
90  	}
91  
92  	public Touch getTouch() {
93  		return touch;
94  	}
95  
96  }