Example usage for com.vaadin.client Util getElementFromPoint

List of usage examples for com.vaadin.client Util getElementFromPoint

Introduction

In this page you can find the example usage for com.vaadin.client Util getElementFromPoint.

Prototype

@Deprecated
public static com.google.gwt.user.client.Element getElementFromPoint(int clientX, int clientY) 

Source Link

Document

Returns the topmost element of from given coordinates.

Usage

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 ww w.  j a  v a 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:info.magnolia.ui.vaadin.gwt.client.layout.thumbnaillayout.widget.EscalatorThumbnailsPanel.java

License:Open Source License

public EscalatorThumbnailsPanel(final Listener listener) {
    this.listener = listener;

    final TouchDelegate touchDelegate = new TouchDelegate(this);
    touchDelegate.addTouchHandler(/*from   w  w  w. j  a va2s . c om*/
            new MagnoliaPinchRecognizer(touchDelegate, new UIObjectToOffsetProvider(scroller)));
    MultiTapRecognizer multitapRecognizer = new MultiTapRecognizer(touchDelegate, 1, 2);
    touchDelegate.addTouchHandler(multitapRecognizer);

    addHandler(new MagnoliaPinchStartEvent.Handler() {
        @Override
        public void onPinchStart(MagnoliaPinchStartEvent event) {
            /**
             * TODO: Pinch does not work reliably yet, to be sorted out...
             */
            //scale((float) event.getScaleFactor());
        }
    }, MagnoliaPinchStartEvent.TYPE);

    addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            final NativeEvent nativeEvent = event.getNativeEvent();
            final Element element = findThumbnail(Element.as(nativeEvent.getEventTarget()));
            if (element != null) {
                boolean isMetaKeyPressed = nativeEvent.getMetaKey();
                boolean isShiftPressed = nativeEvent.getShiftKey();
                EscalatorThumbnailsPanel.this.listener.onThumbnailClicked(getThumbnailIndex(element),
                        isMetaKeyPressed, isShiftPressed);
            }

        }
    }, ClickEvent.getType());

    addDomHandler(new ContextMenuHandler() {

        @Override
        public void onContextMenu(ContextMenuEvent event) {
            Element thumbnail = findThumbnail(Element.as(event.getNativeEvent().getEventTarget()));
            if (thumbnail != null) {
                EscalatorThumbnailsPanel.this.listener.onThumbnailRightClicked(getThumbnailIndex(thumbnail),
                        event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
            }

        }
    }, ContextMenuEvent.getType());

    addHandler(new MultiTapHandler() {
        @Override
        public void onMultiTap(MultiTapEvent event) {
            int x = event.getTouchStarts().get(0).get(0).getPageX();
            int y = event.getTouchStarts().get(0).get(0).getPageY();
            final Element thumbnail = findThumbnail(Util.getElementFromPoint(x, y));
            if (thumbnail != null) {
                EscalatorThumbnailsPanel.this.listener.onThumbnailDoubleClicked(getThumbnailIndex(thumbnail));
            }
        }
    }, MultiTapEvent.getType());

    thumbnailSizeSlider.addValueChangeHandler(new ValueChangeHandler<Integer>() {
        @Override
        public void onValueChange(ValueChangeEvent<Integer> event) {
            scale(event.getValue() / 100f);
        }
    });

    add(thumbnailSizeSlider);

    this.size = new ThumbnailsSizeKeeper(imageContainer);

    addStyleName(THUMBNAIL_LAYOUT_STYLE_NAME);

    scroller.getElement().appendChild(imageContainer);
    scroller.addStyleName(THUMBNAIL_SCROLLER_STYLE_NAME);
    scroller.addScrollHandler(scrollHandler);

    scroller.getElement().insertFirst(upperSpacer);
    scroller.getElement().insertAfter(lowerSpacer, imageContainer);

    add(scroller);

    thumbnailFlyweight = new Thumbnail();
}