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.longtap;
17  
18  import com.google.gwt.event.shared.GwtEvent;
19  import com.googlecode.mgwt.collection.shared.LightArray;
20  import com.googlecode.mgwt.dom.client.event.touch.Touch;
21  
22  /**
23   * A long tap event is produced if the user touches an area of the display for a
24   * given time without moving his finger(s)
25   * 
26   * @author Daniel Kurka
27   * 
28   */
29  public class LongTapEvent extends GwtEvent<LongTapHandler> {
30  
31  	private static final Type<LongTapHandler> TYPE = new Type<LongTapHandler>();
32  
33  	/**
34  	 * Returns the type of the event
35  	 * 
36  	 * @return the type of the event
37  	 */
38  	public static Type<LongTapHandler> getType() {
39  		return TYPE;
40  	}
41  
42  	private final LightArray<Touch> startPositions;
43  	private final int numberOfFingers;
44  	private final int time;
45  
46  	/**
47  	 * Construct a LongTapEvent
48  	 * 
49  	 * @param source - the source of the event
50  	 * @param numberOfFingers the number of fingers used
51  	 * @param time the time the fingers where touching
52  	 * @param startPositions the start position of each finger
53  	 */
54  	public LongTapEvent(Object source, int numberOfFingers, int time, LightArray<Touch> startPositions) {
55  		this.numberOfFingers = numberOfFingers;
56  		this.time = time;
57  		this.startPositions = startPositions;
58  		setSource(source);
59  
60  	}
61  
62  	/*
63  	 * (non-Javadoc)
64  	 * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
65  	 */
66  	@Override
67  	public com.google.gwt.event.shared.GwtEvent.Type<LongTapHandler> getAssociatedType() {
68  		return TYPE;
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(LongTapHandler handler) {
77  		handler.onLongTap(this);
78  
79  	}
80  
81  	/**
82  	 * the number of fingers that created this event
83  	 * 
84  	 * @return
85  	 */
86  	public int getNumberOfFingers() {
87  		return numberOfFingers;
88  	}
89  
90  	/**
91  	 * the start position of all fingers
92  	 * 
93  	 * @return the array of start positions
94  	 */
95  	public LightArray<Touch> getStartPositions() {
96  		return startPositions;
97  	}
98  
99  	/**
100 	 * the time the user held the fingers
101 	 * 
102 	 * @return the time in milliseconds
103 	 */
104 	public int getTime() {
105 		return time;
106 	}
107 
108 }