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  
20  /**
21   * A {@link SwipeEndEvent} occurs when the user lifts his finger of the display
22   * 
23   * @author Daniel Kurka
24   * 
25   */
26  public class SwipeEndEvent extends SwipeEvent<SwipeEndHandler> {
27  
28  	private final static GwtEvent.Type<SwipeEndHandler> TYPE = new Type<SwipeEndHandler>();
29  	private final boolean distanceReached;
30  	private final int distance;
31  
32  	public static GwtEvent.Type<SwipeEndHandler> getType() {
33  		return TYPE;
34  	}
35  
36  	/**
37  	 * Construct a swipe end event
38  	 * 
39  	 * @param distanceReached was the minumum distance reached
40  	 * @param distance the distance that was covered by the finger
41  	 * @param direction the direction of the swipe
42  	 */
43  	public SwipeEndEvent(boolean distanceReached, int distance, SwipeEvent.DIRECTION direction) {
44  		super(direction);
45  		this.distanceReached = distanceReached;
46  		this.distance = distance;
47  	}
48  
49  	/*
50  	 * (non-Javadoc)
51  	 * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
52  	 */
53  	@Override
54  	public com.google.gwt.event.shared.GwtEvent.Type<SwipeEndHandler> getAssociatedType() {
55  		return TYPE;
56  	}
57  
58  	/*
59  	 * (non-Javadoc)
60  	 * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
61  	 */
62  	@Override
63  	protected void dispatch(SwipeEndHandler handler) {
64  		handler.onSwipeEnd(this);
65  
66  	}
67  
68  	/**
69  	 * the distance the finger has covered in px
70  	 * 
71  	 * @return the distance in px
72  	 */
73  	public int getDistance() {
74  		return distance;
75  	}
76  
77  	/**
78  	 * is the minimum distance reached by this swipe
79  	 * 
80  	 * @return true if minimum distance was reached
81  	 */
82  	public boolean isDistanceReached() {
83  		return distanceReached;
84  	}
85  
86  }