View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of 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,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-widget Project
18  //
19  // DragListener.java
20  // Since: May 1, 2008
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.widget.client;
26  
27  import com.google.gwt.user.client.DOM;
28  import com.google.gwt.user.client.ui.PopupPanel;
29  import com.google.gwt.user.client.ui.Widget;
30  
31  /**
32   * Mouse drag listener support
33   * 
34   * @author leo
35   * 
36   */
37  public class DragListener {
38  
39  	PopupPanel widgetToMove;
40  	boolean isDragged = false;
41  	int dragStartX;
42  	int dragStartY;
43  
44  	public DragListener(PopupPanel widgetToMove) {
45  		this.widgetToMove = widgetToMove;
46  	}
47  
48  	public void onMouseDown(Widget sender, int x, int y) {
49  		isDragged = true;
50  		dragStartX = x;
51  		dragStartY = y;
52  		DOM.setCapture(sender.getElement());
53  	}
54  
55  	public void onMouseMove(Widget sender, int x, int y) {
56  		if (isDragged) {
57  			widgetToMove.setPopupPosition(widgetToMove.getAbsoluteLeft() + x - dragStartX, widgetToMove.getAbsoluteTop() + y - dragStartY);
58  		}
59  	}
60  
61  	public void onMouseUp(Widget sender, int x, int y) {
62  		isDragged = false;
63  		DOM.releaseCapture(sender.getElement());
64  	}
65  
66  	public void onMouseEnter(Widget sender) {
67  
68  	}
69  
70  	public void onMouseLeave(Widget sender) {
71  
72  	}
73  
74  }