View Javadoc
1   /*
2    * Copyright 2010 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.event.mouse;
17  
18  import com.google.gwt.event.dom.client.MouseDownEvent;
19  import com.google.gwt.event.dom.client.MouseDownHandler;
20  import com.google.gwt.event.dom.client.MouseMoveEvent;
21  import com.google.gwt.event.dom.client.MouseMoveHandler;
22  import com.google.gwt.event.dom.client.MouseUpEvent;
23  import com.google.gwt.event.dom.client.MouseUpHandler;
24  import com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler;
25  
26  /**
27   * Convert TouchMoveHandlers to MouseMoveHandlers for non touch devices or dev
28   * mode
29   *
30   * @author Daniel Kurka
31   * @version $Id: $
32   */
33  public class TouchMoveToMouseMoveHandler implements MouseMoveHandler, MouseDownHandler, MouseUpHandler {
34  
35  	private boolean ignoreEvent;
36  	private final TouchMoveHandler touchMoveHandler;
37  
38  	/**
39  	 * <p>Constructor for TouchMoveToMouseMoveHandler.</p>
40  	 *
41  	 * @param touchMoveHandler a {@link com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler} object.
42  	 */
43  	public TouchMoveToMouseMoveHandler(TouchMoveHandler touchMoveHandler) {
44  		this.touchMoveHandler = touchMoveHandler;
45  		ignoreEvent = true;
46  	}
47  
48  	/** {@inheritDoc} */
49  	@Override
50  	public void onMouseMove(MouseMoveEvent event) {
51  		if (ignoreEvent)
52  			return;
53  		touchMoveHandler.onTouchMove(new SimulatedTouchMoveEvent(event));
54  
55  	}
56  
57  	/* (non-Javadoc)
58  	 * @see com.google.gwt.event.dom.client.MouseUpHandler#onMouseUp(com.google.gwt.event.dom.client.MouseUpEvent)
59  	 */
60  	/** {@inheritDoc} */
61  	@Override
62  	public void onMouseUp(MouseUpEvent event) {
63  		ignoreEvent = true;
64  
65  	}
66  
67  	/* (non-Javadoc)
68  	 * @see com.google.gwt.event.dom.client.MouseDownHandler#onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent)
69  	 */
70  	/** {@inheritDoc} */
71  	@Override
72  	public void onMouseDown(MouseDownEvent event) {
73  		ignoreEvent = false;
74  
75  	}
76  
77  }