List of usage examples for com.vaadin.client Util getTouchOrMouseClientX
@Deprecated public static int getTouchOrMouseClientX(NativeEvent event)
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 .ja va2 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.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. co m*/ * * @param container * The widget container * @param event * The drag event * @return The horizontal drop location */ protected HorizontalDropLocation getHorizontalDropLocation(Widget container, VDragEvent event) { return VDragDropUtil.getHorizontalDropLocation(container.getElement(), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), horizontalDropRatio); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.gridlayout.VDDGridLayout.java
License:Apache License
/** * Returns the horizontal drop location//from w w w . j a v a 2s .c o m * * @param cell * The cell details * @param event * The drag event * @return */ protected HorizontalDropLocation getHorizontalDropLocation(CellDetails cell, VDragEvent event) { // Get the horizontal location HorizontalDropLocation hdetail; int x = Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()) - getAbsoluteLeft() - cell.x; assert (x >= 0 && x <= cell.width); if (x < cell.width * cellLeftRightDropRatio) { hdetail = HorizontalDropLocation.LEFT; } else if (x < cell.width * (1.0 - cellLeftRightDropRatio)) { hdetail = HorizontalDropLocation.CENTER; } else { hdetail = HorizontalDropLocation.RIGHT; } return hdetail; }
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.horizontallayout.VDDHorizontalLayout.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%;/* w ww .j a v a2s. com*/ * * @param container * The widget container * @param event * The drag event * @return The horizontal drop location */ protected HorizontalDropLocation getHorizontalDropLocation(Widget container, VDragEvent event) { return VDragDropUtil.getHorizontalDropLocation(container.getElement(), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), cellLeftRightDropRatio); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java
License:Apache License
/** * Updates the drop details while dragging. This is needed to ensure client * side criterias can validate the drop location. * // w w w.java2 s . c o m * @param event * The drag event */ protected void updateDragDetails(VDragEvent event) { Element element = event.getElementOver(); if (element == null) return; if (tabBar.getElement().isOrHasChild(element)) { Widget w = Util.findWidget(element, null); if (w == tabBar) { // Ove3r the spacer // Add index event.getDropDetails().put(Constants.DROP_DETAIL_TO, tabBar.getWidgetCount() - 1); // Add drop location event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, HorizontalDropLocation.RIGHT); } else { // Add index event.getDropDetails().put(Constants.DROP_DETAIL_TO, getTabPosition(w)); // Add drop location HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio); event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location); } // Add mouse event details MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement()); event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize()); } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.tabsheet.VDDTabSheet.java
License:Apache License
/** * Emphasisizes a container element//w ww .j ava 2s . com * * @param element */ protected void emphasis(Element element, VDragEvent event) { boolean internalDrag = event.getTransferable().getDragSource() == this; if (tabBar.getElement().isOrHasChild(element)) { Widget w = Util.findWidget(element, null); if (w == tabBar && !internalDrag) { // Over spacer Element spacerContent = spacer.getChild(0).cast(); spacerContent.appendChild(newTab); currentlyEmphasised = element; } else if (w instanceof VCaption) { // Over a tab HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio); if (location == HorizontalDropLocation.LEFT) { int index = getTabPosition(w); if (index == 0) { currentlyEmphasised = tabBar.getWidget(0).getElement().getFirstChildElement().cast(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_LEFT); } else { Widget prevTab = tabBar.getWidget(index - 1); currentlyEmphasised = prevTab.getElement(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT); } } else if (location == HorizontalDropLocation.RIGHT) { int index = getTabPosition(w); currentlyEmphasised = tabBar.getWidget(index).getElement(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT); } else { int index = getTabPosition(w); currentlyEmphasised = tabBar.getWidget(index).getElement(); currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_CENTER); } } } }
From source file:fi.jasoft.draganddrop.client.configurations.HorizontalLayoutDragAndDropConfiguration.java
License:Apache License
private Alignment getHorizontalAlign(DragAndDropEvent event) { Slot slot = getSlot(event);//from w w w. ja va 2s . c o m if (slot == null) { // Over layout return Alignment.LEFT; } int absoluteLeft = slot.getAbsoluteLeft(); int fromTop = Util.getTouchOrMouseClientX(event.getEvent()) - absoluteLeft; float percentageFromTop = (fromTop / (float) slot.getOffsetHeight()); if (percentageFromTop < 0.25) { return Alignment.LEFT; } else if (percentageFromTop > 1 - 0.25) { return Alignment.RIGHT; } else { return Alignment.CENTER; } }
From source file:fi.jasoft.draganddrop.client.configurations.OrderedLayoutDragAndDropConfiguration.java
License:Apache License
protected Slot getSlot(DragAndDropEvent event) { Element e = Util.getElementUnderMouse(event.getEvent()); /*/*from w w w .j a va 2 s. 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.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 {// w w w .ja va2 s . c o m setDragImage(cloneNode); } }