
//--------------------------------------
// utgb-widget Project
//
// DragListener.java
// Since: May 1, 2008
//
// $URL$ 
// $Author$
//--------------------------------------
package org.utgenome.gwt.widget.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Mouse drag listener support
 * 
 * @author leo
 * 
 */
public class DragListener {

	PopupPanel widgetToMove;
	boolean isDragged = false;
	int dragStartX;
	int dragStartY;

	public DragListener(PopupPanel widgetToMove) {
		this.widgetToMove = widgetToMove;
	}

	public void onMouseDown(Widget sender, int x, int y) {
		isDragged = true;
		dragStartX = x;
		dragStartY = y;
		DOM.setCapture(sender.getElement());
	}

	public void onMouseMove(Widget sender, int x, int y) {
		if (isDragged) {
			widgetToMove.setPopupPosition(widgetToMove.getAbsoluteLeft() + x - dragStartX, widgetToMove.getAbsoluteTop() + y - dragStartY);
		}
	}

	public void onMouseUp(Widget sender, int x, int y) {
		isDragged = false;
		DOM.releaseCapture(sender.getElement());
	}

	public void onMouseEnter(Widget sender) {

	}

	public void onMouseLeave(Widget sender) {

	}

}
