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.pinch;
17  
18  import com.google.gwt.event.shared.GwtEvent;
19  
20  /**
21   * A {@link PinchEvent} is fired when a user moves to finger on the display.
22   * 
23   * A pinch event is fired around a center point which is calculated by looking
24   * at the two fingers producing the event.
25   * 
26   * <p>
27   * if finger one is at x1, y1 and finger two is at x2, y2 the center point is
28   * (x1 + x2) / 2 and (y1 + y2) / 2
29   * </p>
30   * 
31   * 
32   * @author Daniel Kurka
33   * 
34   */
35  public class PinchEvent extends GwtEvent<PinchHandler> {
36  
37  	private static final GwtEvent.Type<PinchHandler> TYPE = new Type<PinchHandler>();
38  	private final int x;
39  	private final int y;
40  	private final double scaleFactor;
41  
42  	public static GwtEvent.Type<PinchHandler> getType() {
43  		return TYPE;
44  	}
45  
46  	/**
47  	 * Construct a pinch event
48  	 * 
49  	 * @param x the mid point of the pinch in x
50  	 * @param y the mid point of the pinch in y
51  	 * @param scaleFactor the new scaling factor
52  	 */
53  	public PinchEvent(int x, int y, double scaleFactor) {
54  		this.x = x;
55  		this.y = y;
56  		this.scaleFactor = scaleFactor;
57  	}
58  
59  	/*
60  	 * (non-Javadoc)
61  	 * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
62  	 */
63  	@Override
64  	public com.google.gwt.event.shared.GwtEvent.Type<PinchHandler> getAssociatedType() {
65  		return TYPE;
66  	}
67  
68  	/*
69  	 * (non-Javadoc)
70  	 * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
71  	 */
72  	@Override
73  	protected void dispatch(PinchHandler handler) {
74  		handler.onPinch(this);
75  
76  	}
77  
78  	/**
79  	 * The x position of the center point of the pinch.
80  	 * 
81  	 * 
82  	 * @return the x position
83  	 */
84  	public int getX() {
85  		return x;
86  	}
87  
88  	/**
89  	 * The y position of the center point of the pinch.
90  	 * 
91  	 * 
92  	 * @return the y position
93  	 */
94  	public int getY() {
95  		return y;
96  	}
97  
98  	/**
99  	 * the new scale factor that can be applied for getting a zoom effect
100 	 * 
101 	 * @return the scale factor
102 	 */
103 	public double getScaleFactor() {
104 		return scaleFactor;
105 	}
106 
107 }