List of usage examples for com.vaadin.shared MouseEventDetails getClientY
public int getClientY()
From source file:com.foc.vaadin.gui.layouts.FVGrid_WYSIWYG_DropHandler.java
License:Apache License
@Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails(); DDGridLayout layout = (DDGridLayout) details.getTarget(); Component source = event.getTransferable().getSourceComponent(); Component comp = transferable.getComponent(); ComponentContainer sourceLayout = null; if (comp != null) { if (comp == layout) { // Dropping myself on myself, if parent is absolute layout then // move if (comp.getParent() instanceof DDAbsoluteLayout) { MouseEventDetails mouseDown = transferable.getMouseDownEvent(); MouseEventDetails mouseUp = details.getMouseEvent(); int movex = mouseUp.getClientX() - mouseDown.getClientX(); int movey = mouseUp.getClientY() - mouseDown.getClientY(); DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent(); ComponentPosition position = parent.getPosition(comp); sourceLayout = parent;//ww w . j a v a2s. co m float x = position.getLeftValue() + movex; float y = position.getTopValue() + movey; position.setLeft(x, Sizeable.Unit.PIXELS); position.setTop(y, Sizeable.Unit.PIXELS); return; } } else { // Check that we are not dragging an outer layout into an inner // layout Component parent = layout.getParent(); while (parent != null) { if (parent == comp) { return; } parent = parent.getParent(); } // Remove component from its source if (source instanceof ComponentContainer) { sourceLayout = (ComponentContainer) source; sourceLayout.removeComponent(comp); } } int row = details.getOverRow(); int column = details.getOverColumn(); AttributesImpl newAttributes = removeNotNeededAttributes(((FocXMLGuiComponent) comp).getAttributes(), (FVLayout) sourceLayout); if (newAttributes.getValue(FXML.ATT_COL) != null) { newAttributes.setValue(newAttributes.getIndex(FXML.ATT_COL), column + ""); } else { newAttributes.addAttribute("", FXML.ATT_COL, FXML.ATT_COL, "CDATA", column + ""); } if (newAttributes.getValue(FXML.ATT_ROW) != null) { newAttributes.setValue(newAttributes.getIndex(FXML.ATT_ROW), row + ""); } else { newAttributes.addAttribute("", FXML.ATT_ROW, FXML.ATT_ROW, "CDATA", row + ""); } ((FocXMLGuiComponent) comp).setAttributes(newAttributes); addComponent(event, comp, column, row); } }
From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler.java
License:Apache License
/** * Handles a drop by a component which has an absolute layout as parent. In * this case the component is moved.// ww w. ja v a 2s . c o m * * @param event * The drag and drop event */ protected void handleDropFromAbsoluteParentLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); TargetDetails details = event.getTargetDetails(); MouseEventDetails mouseDown = transferable.getMouseDownEvent(); MouseEventDetails mouseUp = MouseEventDetails .deSerialize((String) details.getData(Constants.DROP_DETAIL_MOUSE_EVENT)); int movex = mouseUp.getClientX() - mouseDown.getClientX(); int movey = mouseUp.getClientY() - mouseDown.getClientY(); Component comp = transferable.getComponent(); DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent(); ComponentPosition position = parent.getPosition(comp); if (position.getLeftValue() != null) { float x = position.getLeftValue() + movex; position.setLeft(x, Sizeable.UNITS_PIXELS); } if (position.getRightValue() != null) { float x = position.getRightValue() - movex; position.setRight(x, Sizeable.UNITS_PIXELS); } if (position.getTopValue() != null) { float y = position.getTopValue() + movey; position.setTop(y, Sizeable.UNITS_PIXELS); } if (position.getBottomValue() != null) { float y = position.getBottomValue() - movey; position.setBottom(y, Sizeable.UNITS_PIXELS); } }
From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.DefaultGridLayoutDropHandler.java
License:Apache License
@Override protected void handleDropFromLayout(DragAndDropEvent event) { LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable(); GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails(); DDGridLayout layout = (DDGridLayout) details.getTarget(); Component source = event.getTransferable().getSourceComponent(); Component comp = transferable.getComponent(); if (comp == layout) { // Dropping myself on myself, if parent is absolute layout then // move/*from w w w . j a v a2 s. co m*/ if (comp.getParent() instanceof DDAbsoluteLayout) { MouseEventDetails mouseDown = transferable.getMouseDownEvent(); MouseEventDetails mouseUp = details.getMouseEvent(); int movex = mouseUp.getClientX() - mouseDown.getClientX(); int movey = mouseUp.getClientY() - mouseDown.getClientY(); DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent(); ComponentPosition position = parent.getPosition(comp); float x = position.getLeftValue() + movex; float y = position.getTopValue() + movey; position.setLeft(x, Sizeable.UNITS_PIXELS); position.setTop(y, Sizeable.UNITS_PIXELS); return; } } else { // Check that we are not dragging an outer layout into an inner // layout Component parent = layout.getParent(); while (parent != null) { if (parent == comp) { return; } parent = parent.getParent(); } // Detach from old source if (source instanceof ComponentContainer) { ((ComponentContainer) source).removeComponent(comp); } else if (source instanceof SingleComponentContainer) { ((SingleComponentContainer) source).setContent(null); } } int row = details.getOverRow(); int column = details.getOverColumn(); addComponent(event, comp, column, row); }
From source file:org.peergreen.vaadin.diagram.DiagramDropHandler.java
License:Apache License
@Override public void drop(final DragAndDropEvent event) { TargetDetails targetDetails = event.getTargetDetails(); Transferable transferable = event.getTransferable(); MouseEventDetails mouseEventDetails = MouseEventDetails .deSerialize((String) targetDetails.getData("mouseEvent")); Integer absoluteLeft = (Integer) targetDetails.getData("absoluteLeft"); Integer absoluteTop = (Integer) targetDetails.getData("absoluteTop"); diagram.drop(mouseEventDetails.getClientX() - absoluteLeft, mouseEventDetails.getClientY() - absoluteTop, (String) transferable.getData("component-type")); }
From source file:org.semanticsoft.vaaclipse.widgets.client.ui.stackwidget.VStackWidget.java
License:Open Source License
public boolean updateRegion(VDragEvent event) { //VConsole.log("updateDropDetails: start"); Element element = event.getElementOver(); Widget targetWidget = Util.findWidget(element, null); if (targetWidget == null) { //VConsole.log("updateDropDetails: targetWidget is null. return."); return false; }// ww w . j a v a2 s . co m if (targetWidget != this) { //VConsole.log("updateDropDetails: targetWidget != this"); Widget parent = targetWidget.getParent(); while (parent != null && parent != this) { parent = parent.getParent(); } if (parent == null) { //VConsole.log("updateDropDetails: parent not finded"); return false; } targetWidget = parent; //VConsole.log("updateDropDetails: parent finded"); } MouseEventDetails details1 = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement()); int mouseX = details1.getClientX(); int mouseY = details1.getClientY(); int barLeft = tabBar.getAbsoluteLeft(); int barTop = tabBar.getAbsoluteTop(); int barWidth = tabBar.getOffsetWidth(); int barHeight = tabBar.getOffsetHeight(); boolean overBar = mouseX > barLeft && mouseX < barLeft + barWidth && mouseY > barTop && mouseY < barTop + barHeight; if (overBar) { //VConsole.log("updateDropDetails: over bar"); removeDockZone(); event.getDropDetails().put("targetWidgetClassName", targetWidget.getClass().getName()); event.getDropDetails().put("dropType", "DropToTabsheetBar"); event.getDropDetails().put("targetWidgetAbsoluteLeft", targetWidget.getAbsoluteLeft()); event.getDropDetails().put("targetWidgetAbsoluteTop", targetWidget.getAbsoluteTop()); event.getDropDetails().put("targetWidgetOffsetWidth", targetWidget.getOffsetWidth()); event.getDropDetails().put("targetWidgetOffsetHeight", targetWidget.getOffsetHeight()); } else { //VConsole.log("updateDropDetails: not over bar"); Object sourceWidget = event.getTransferable().getDragSource(); if (!(sourceWidget instanceof VStackWidget) && !(sourceWidget instanceof StackWidgetConnector)) { //VConsole.log("updateDropDetails: return, because the sourceWidget is " + sourceWidget.getClass().getName()); return false; } if (sourceWidget instanceof StackWidgetConnector) sourceWidget = ((StackWidgetConnector) sourceWidget).getWidget(); //VConsole.log("updateDropDetails: sourceWidget is VStackWidget or StackWidgetConnector"); VStackWidget targetTabSheet = this; if (targetTabSheet == sourceWidget && targetTabSheet.getTabCount() <= 1) { //VConsole.log("updateDropDetails: return, because target is match to source and has only one (current draggable) tab"); return false; } VExtendedVerticalLayout outerArea = findOuterArea(targetTabSheet); Widget boundingWidget = null; if (outerArea != null) { //VConsole.log("updateDropDetails: outer area is finded"); if ("area".equals(outerArea.getVariableValue(E4_ELEMENT_TYPE))) boundingWidget = outerArea; } else { boundingWidget = targetTabSheet; //VConsole.log("updateDropDetails: outer area not finded, boundingWidget = targetTabSheet"); } if (boundingWidget == null) { //VConsole.log("updateDropDetails: return, because boundingWidget not founded"); return false; } event.getDropDetails().put("targetWidgetClassName", boundingWidget.getClass().getName()); event.getDropDetails().put("dropType", "DropToTabsheetBody"); event.getDropDetails().put("targetWidgetAbsoluteLeft", boundingWidget.getAbsoluteLeft()); event.getDropDetails().put("targetWidgetAbsoluteTop", boundingWidget.getAbsoluteTop()); event.getDropDetails().put("targetWidgetOffsetWidth", boundingWidget.getOffsetWidth()); event.getDropDetails().put("targetWidgetOffsetHeight", boundingWidget.getOffsetHeight()); int x0 = boundingWidget.getAbsoluteLeft(); int y0 = boundingWidget.getAbsoluteTop(); int dx = boundingWidget.getOffsetWidth(); int dy = boundingWidget.getOffsetHeight(); int docPrcnt = 30; double docX = dx * docPrcnt / 100; double docY = dy * docPrcnt / 100; double d = 1; Vector mousePos = Vector.valueOf(mouseX, mouseY); Integer side = GeomUtils.findDockSide(x0, y0, dx, dy, docX, docY, mousePos); //VConsole.log("updateDropDetails: finded dock side = " + side + ", old dock side = " + dockSide); if (side != null) { double _x = 0, _y = 0, _w = 0, _h = 0; if (side == Side.LEFT) { _x = d; _y = d; _w = docX - d; _h = dy - 2 * d; } else if (side == Side.TOP) { _x = d; _y = d; _w = dx - 2 * d; _h = docY - d; } else if (side == Side.RIGHT) { _x = dx - docX; _y = d; _w = docX - d; _h = dy - 2 * d; } else if (side == Side.BOTTOM) { _x = d; _y = dy - docY; _w = dx - 2 * d; _h = docY - d; } else if (side == Side.CENTER) { _x = d; _y = d; _w = dx - 2 * d; _h = dy - 2 * d; } else return false; _x = x0 + _x; _y = y0 + _y; if (dockZone1 == null) { dockZone1 = DOM.createDiv(); dockZone2 = DOM.createDiv(); dockZone3 = DOM.createDiv(); dockZone4 = DOM.createDiv(); } //VConsole.log("updateDropDetails: x=" + _x + "; y=" + _y + "; w=" + _w + "; h=" + _h); if (side != dockSide) { //VConsole.log("updateDropDetails: dock side will be updated"); int l = 3; String style1 = "position: absolute; left: " + _x + "px; top: " + _y + "px; width: " + _w + "px; height: " + l + "px; background-image: url(" + baseURL + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;"; dockZone1.setAttribute("style", style1); String style2 = "position: absolute; left: " + _x + "px; top: " + (_y + _h - l) + "px; width: " + _w + "px; height: " + l + "px; background-image: url(" + baseURL + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;"; dockZone2.setAttribute("style", style2); String style3 = "position: absolute; left: " + _x + "px; top: " + _y + "px; width: " + l + "px; height: " + _h + "px; background-image: url(" + baseURL + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;"; dockZone3.setAttribute("style", style3); String style4 = "position: absolute; left: " + (_x + _w - l) + "px; top: " + _y + "px; width: " + l + "px; height: " + _h + "px; background-image: url(" + baseURL + "VAADIN/themes/dragdrop/vaadock/img/dockzone.png); z-index: 20000;"; dockZone4.setAttribute("style", style4); //setStyleName(dockZone, "v-etot-sukin-syn"); //dockZoneContainer = boundingWidget.getElement(); dockZoneContainer = RootPanel.get().getElement(); DOM.appendChild(dockZoneContainer, dockZone1); DOM.appendChild(dockZoneContainer, dockZone2); DOM.appendChild(dockZoneContainer, dockZone3); DOM.appendChild(dockZoneContainer, dockZone4); dockSide = side; } } } return true; }