/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2014 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the Apache
 * License, Version 2.0. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.graphics.client.controller.drag;

import com.google.gwt.event.dom.client.MouseMoveEvent;
import org.geomajas.geometry.Coordinate;
import org.geomajas.graphics.client.controller.UpdateHandlerGraphicsController;
import org.geomajas.graphics.client.object.role.Draggable;
import org.geomajas.graphics.client.object.GraphicsObject;
import org.geomajas.graphics.client.operation.DragOperation;
import org.geomajas.graphics.client.operation.GraphicsOperation;
import org.geomajas.graphics.client.service.GraphicsService;
import org.vaadin.gwtgraphics.client.VectorObject;

/**
 * Extension of {@link AbstractDragHandler}
 * 
 * @author Jan De Moerloose
 * @author Jan Venstermans
 * 
 */
public class GraphicsObjectDragHandler extends AbstractDragHandler {
	
	private GraphicsObject invisbleMaskGraphicsObject;

	public GraphicsObjectDragHandler(GraphicsObject object, GraphicsService service,
			UpdateHandlerGraphicsController graphicsController) {
		super(object, service, graphicsController);
	}

	public Draggable getDraggable() {
		return getObject().getRole(Draggable.TYPE);
	}

	public void update() {
		invisbleMaskGraphicsObject.getRole(Draggable.TYPE).setPosition(getDraggable().getPosition());
	}

	@Override
	protected VectorObject createInvisibleMask() {
		invisbleMaskGraphicsObject = (GraphicsObject) getObject().cloneObject();
		invisbleMaskGraphicsObject.setOpacity(0);
		return invisbleMaskGraphicsObject.getRole(Draggable.TYPE).asObject();
	}

	@Override
	protected GraphicsObject createDraggingMask() {
		GraphicsObject maskObject = (GraphicsObject) getObject().cloneObject();
		maskObject.setOpacity(0.5);
		maskObject.getRole(Draggable.TYPE).setPosition(getBeginPositionUser());
		return maskObject;
	}

	@Override
	protected Coordinate getObjectPosition() {
		return getDraggable().getPosition();
	}

	@Override
	protected GraphicsOperation createGraphicsOperation(Coordinate before,
			Coordinate after) {
		return new DragOperation(getObject(), before, after);
	}

	@Override
	protected void mouseMoveContent(MouseMoveEvent event) {
		getDraggingMask().getRole(Draggable.TYPE).setPosition(
				getNewPosition(event.getClientX(), event.getClientY()));
	}

	public GraphicsObject getInvisbleMaskGraphicsObject() {
		return invisbleMaskGraphicsObject;
	}

}



@@ -516,16 +516,51 @@
 eEvent;%0A
+import org.geomajas.geometry.Bbox;%0A
 import o
@@ -672,16 +672,79 @@
 roller;%0A
+import org.geomajas.graphics.client.object.base.BaseRectangle;%0A
 import o
@@ -1139,16 +1139,68 @@
 Handler%7D
+ with a %7B@link BaseRectangle%7D for an invisible mask.
 %0A * %0A * 
@@ -1339,30 +1339,29 @@
 private 
-GraphicsObject
+BaseRectangle
  invisbl
@@ -1576,91 +1576,17 @@
 %7D%0A%0A%09
-public Draggable getDraggable() %7B%0A%09%09return getObject().getRole(Draggable.TYPE);%0A%09%7D%0A
+@Override
 %0A%09pu
@@ -1771,79 +1771,237 @@
 %7B%0A%09%09
+// make an 
 invis
+i
 ble
-MaskGraphicsObject = (GraphicsObject) getObject().cloneObjec
+ mask that is a rectangle of the bounds of the draggable.%0A%09%09Bbox bbox = getDraggable().getBounds();%0A%09%09invisbleMaskGraphicsObject = new BaseRectangle(bbox.getX(), bbox.getY(), bbox.getWidth(), bbox.getHeigh
 t()
+)
 ;%0A%09%09
@@ -2082,32 +2082,8 @@
 ect.
-getRole(Draggable.TYPE).
 asOb
@@ -2909,12 +2909,97 @@
 ct;%0A%09%7D%0A%0A
+%09public Draggable getDraggable() %7B%0A%09%09return getObject().getRole(Draggable.TYPE);%0A%09%7D%0A%0A
 %7D%0A%0A%0A

simplify draghandler controller