List of usage examples for com.vaadin.client Util getTouchOrMouseClientY
@Deprecated public static int getTouchOrMouseClientY(NativeEvent currentGwtEvent)
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.absolutelayout.VDDAbsoluteLayout.java
License:Apache License
protected void updateDragDetails(VDragEvent drag) { // Get absolute coordinates int absoluteLeft = drag.getCurrentGwtEvent().getClientX(); int absoluteTop = drag.getCurrentGwtEvent().getClientY(); drag.getDropDetails().put(Constants.DROP_DETAIL_ABSOLUTE_LEFT, absoluteLeft); drag.getDropDetails().put(Constants.DROP_DETAIL_ABSOLUTE_TOP, absoluteTop); // Get relative coordinates int offsetLeft = 0; if (drag.getDragImage() != null) { String offsetLeftStr = drag.getDragImage().getStyle().getMarginLeft(); offsetLeft = Integer.parseInt(offsetLeftStr.substring(0, offsetLeftStr.length() - 2)); }/*from w w w . jav a 2 s.c o m*/ int relativeLeft = Util.getTouchOrMouseClientX(drag.getCurrentGwtEvent()) - canvas.getAbsoluteLeft() + offsetLeft; int offsetTop = 0; if (drag.getDragImage() != null) { String offsetTopStr = drag.getDragImage().getStyle().getMarginTop(); offsetTop = Integer.parseInt(offsetTopStr.substring(0, offsetTopStr.length() - 2)); } int relativeTop = Util.getTouchOrMouseClientY(drag.getCurrentGwtEvent()) - canvas.getAbsoluteTop() + offsetTop; drag.getDropDetails().put(Constants.DROP_DETAIL_RELATIVE_LEFT, relativeLeft); drag.getDropDetails().put(Constants.DROP_DETAIL_RELATIVE_TOP, relativeTop); // Get component size ComponentConnector widgetConnector = (ComponentConnector) drag.getTransferable() .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT); if (widgetConnector != null) { drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_WIDTH, widgetConnector.getWidget().getOffsetWidth()); drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_HEIGHT, widgetConnector.getWidget().getOffsetHeight()); } else { drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_WIDTH, -1); drag.getDropDetails().put(Constants.DROP_DETAIL_COMPONENT_HEIGHT, -1); } // Add mouse event details MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(drag.getCurrentGwtEvent(), getElement()); drag.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize()); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.accordion.VDDAccordion.java
License:Apache License
/** * Returns the drop location of a tab/*from ww w . j a v a 2 s . com*/ * * @param tab * The tab that was dragged * @param event * The drag event * @return */ protected VerticalDropLocation getDropLocation(StackItem tab, VDragEvent event) { VerticalDropLocation location; if (tab.isOpen()) { location = VDragDropUtil.getVerticalDropLocation(tab.getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), tabTopBottomDropRatio); } else { location = VDragDropUtil.getVerticalDropLocation(tab.getWidget(0).getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), tabTopBottomDropRatio); } return location; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.csslayout.VDDCssLayout.java
License:Apache License
/** * Returns the horizontal location within the cell when hoovering over the * cell. By default the cell is devided into three parts: left,center,right * with the ratios 10%,80%,10%;/*from w ww . j a v a 2s . c o m*/ * * @param container * The widget container * @param event * The drag event * @return The horizontal drop location */ protected VerticalDropLocation getVerticalDropLocation(Widget container, VDragEvent event) { return VDragDropUtil.getVerticalDropLocation(container.getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), verticalDropRatio); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.formlayout.VDDFormLayout.java
License:Apache License
/** * Returns the horizontal location within the cell when hoovering over the * cell. By default the cell is devided into three parts: left,center,right * with the ratios 10%,80%,10%;/*from ww w.j a v a 2s. c o m*/ * * @param rowElement * The row * @param event * The drag event * @return The horizontal drop location */ protected VerticalDropLocation getVerticalDropLocation(Element rowElement, VDragEvent event) { return VDragDropUtil.getVerticalDropLocation((com.google.gwt.user.client.Element) rowElement, Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), cellTopBottomDropRatio); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.gridlayout.VDDGridLayout.java
License:Apache License
/** * Returns the vertical drop location//from w w w . jav a 2s . c o m * * @param cell * The cell details * @param event * The drag event * @return */ protected VerticalDropLocation getVerticalDropLocation(CellDetails cell, VDragEvent event) { // Get the vertical location VerticalDropLocation vdetail; int y = Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()) - getAbsoluteTop() - cell.y; assert (y >= 0 && y <= cell.height); if (y < cell.height * cellTopBottomDropRatio) { vdetail = VerticalDropLocation.TOP; } else if (y < cell.height * (1.0 - cellTopBottomDropRatio)) { vdetail = VerticalDropLocation.MIDDLE; } else { vdetail = VerticalDropLocation.BOTTOM; } return vdetail; }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.gridlayout.VDDGridLayout.java
License:Apache License
CellDetails getCellDetails(VDragEvent event) { int x = Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()) - getAbsoluteLeft(); int y = Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()) - getAbsoluteTop(); return getCellDetailsByCoordinates(x, y); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.verticallayout.VDDVerticalLayout.java
License:Apache License
/** * Returns the horizontal location within the cell when hovering over the * cell. By default the cell is divided into three parts: left,center,right * with the ratios 10%,80%,10%;/*ww w . ja v a 2 s .c om*/ * * @param container * The widget container * @param event * The drag event * @return The horizontal drop location */ protected VerticalDropLocation getVerticalDropLocation(Widget container, VDragEvent event) { return VDragDropUtil.getVerticalDropLocation(container.getElement(), Util.getTouchOrMouseClientY(event.getCurrentGwtEvent()), cellTopBottomDropRatio); }
From source file:fi.jasoft.draganddrop.client.configurations.OrderedLayoutDragAndDropConfiguration.java
License:Apache License
protected Slot getSlot(DragAndDropEvent event) { Element e = Util.getElementUnderMouse(event.getEvent()); /*/* w ww.j a v a 2s . c o m*/ * If we are hitting between slot search around the cursor for the * closest slot */ int nextDirection = 0; int width = 1; int pageX = Util.getTouchOrMouseClientX(event.getEvent()); int pageY = Util.getTouchOrMouseClientY(event.getEvent()); while (event.getTargetConnector().getWidget().getElement() == e) { if (nextDirection == 0) { pageY -= width; nextDirection++; } else if (nextDirection == 1) { pageX += width; nextDirection++; } else if (nextDirection == 2) { pageY += width; nextDirection++; } else if (nextDirection == 3) { pageX -= width; width++; nextDirection = 0; } e = Util.getElementFromPoint(pageX, pageY); } assert e != null : "Event target was null"; Widget w = Util.findWidget(e, null); assert w != null : "Widget was not found"; if (w != null) { while (!(w instanceof Slot) && w != null) { w = w.getParent(); } } assert w instanceof Slot; return (Slot) w; }
From source file:fi.jasoft.draganddrop.client.configurations.VerticalLayoutDragAndDropConfiguration.java
License:Apache License
private Alignment getVerticalAlign(DragAndDropEvent event) { Slot slot = getSlot(event);/* w w w. j a v a2 s . c o m*/ if (slot == null) { // Over layout return Alignment.MIDDLE; } int absoluteTop = slot.getAbsoluteTop(); int fromTop = Util.getTouchOrMouseClientY(event.getEvent()) - absoluteTop; float percentageFromTop = (fromTop / (float) slot.getOffsetHeight()); if (percentageFromTop < 0.25) { return Alignment.TOP; } else if (percentageFromTop > 1 - 0.25) { return Alignment.BOTTOM; } else { return Alignment.MIDDLE; } }
From source file:fi.jasoft.draganddrop.client.DragAndDropConnector.java
License:Apache License
private void createDragImage(Element element, boolean alignImageToEvent) { Element cloneNode = (Element) element.cloneNode(true); cloneNode.getStyle().setPosition(Position.ABSOLUTE); cloneNode.addClassName("drag-image"); cloneNode.getStyle().setWidth(element.getOffsetWidth(), Unit.PX); cloneNode.getStyle().setHeight(element.getOffsetHeight(), Unit.PX); if (alignImageToEvent) { int absoluteTop = element.getAbsoluteTop(); int absoluteLeft = element.getAbsoluteLeft(); int clientX = Util.getTouchOrMouseClientX(dragStartEvent); int clientY = Util.getTouchOrMouseClientY(dragStartEvent); int offsetX = absoluteLeft - clientX; int offsetY = absoluteTop - clientY; setDragImage(cloneNode, offsetX, offsetY); } else {//from w w w. j av a2s . c o m setDragImage(cloneNode); } }