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 SwipeStartEvent} is fired when the user moves his finger over a
23   * certain amount on the display
24   * 
25   * @author Daniel Kurka
26   * 
27   */
28  public class SwipeStartEvent extends SwipeEvent<SwipeStartHandler> {
29  
30  	private final static GwtEvent.Type<SwipeStartHandler> TYPE = new Type<SwipeStartHandler>();
31  	private final int distance;
32  	private final Touch touch;
33  
34  	public static GwtEvent.Type<SwipeStartHandler> getType() {
35  		return TYPE;
36  	}
37  
38  	/**
39  	 * Construct a {@link SwipeStartEvent}
40  	 * 
41  	 * @param distance the distance the finger already moved
42  	 * @param j
43  	 * @param i
44  	 * @param direction the direction of the finger
45  	 */
46  	public SwipeStartEvent(Touch touch, int distance, SwipeEvent.DIRECTION direction) {
47  		super(direction);
48  		this.touch = touch;
49  		this.distance = distance;
50  
51  	}
52  
53  	/*
54  	 * (non-Javadoc)
55  	 * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
56  	 */
57  	@Override
58  	public com.google.gwt.event.shared.GwtEvent.Type<SwipeStartHandler> getAssociatedType() {
59  		return TYPE;
60  	}
61  
62  	/**
63  	 * The distance the finger moved before the event occured
64  	 * 
65  	 * @return the distance in px
66  	 */
67  	public int getDistance() {
68  		return distance;
69  	}
70  
71  	/*
72  	 * (non-Javadoc)
73  	 * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
74  	 */
75  	@Override
76  	protected void dispatch(SwipeStartHandler handler) {
77  		handler.onSwipeStart(this);
78  
79  	}
80  
81  	public Touch getTouch() {
82  		return touch;
83  	}
84  
85  }