Example usage for com.google.gwt.query.client.plugins.events GqEvent pageY

List of usage examples for com.google.gwt.query.client.plugins.events GqEvent pageY

Introduction

In this page you can find the example usage for com.google.gwt.query.client.plugins.events GqEvent pageY.

Prototype

public final int pageY() 

Source Link

Document

The mouse position relative to the top edge of the document.

Usage

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

public void initialize(Element element, GqEvent e) {

    helperCssPosition = helper.css("position");
    helperScrollParent = helper.as(UiPlugin.GQueryUi).scrollParent();
    helperOffsetParent = helper.offsetParent();

    if ("html".equalsIgnoreCase(helperOffsetParent.get(0).getTagName())) {
        helperOffsetParent = $(body);/*  ww w.  j ava  2 s .  co m*/
    }

    setMarginCache(element);

    absPosition = new Offset(element.getAbsoluteLeft(), element.getAbsoluteTop());

    offset = new Offset(absPosition.left - margin.left, absPosition.top - margin.top);

    offsetClick = new Offset(e.pageX() - offset.left, e.pageY() - offset.top);

    parentOffset = calculateParentOffset(element);
    relativeOffset = calculateRelativeHelperOffset(element);

    originalEventPageX = e.pageX();
    originalEventPageY = e.pageY();

    position = calculateOriginalPosition(element, e);
    originalPosition = new Offset(position.left, position.top);

    if (options.getCursorAt() != null) {
        adjustOffsetFromHelper(options.getCursorAt());
    }
    calculateContainment();

}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

private Offset generatePosition(GqEvent e, boolean initPosition) {

    GQuery scroll = getScrollParent();// w  ww .  ja  va 2  s  .  com
    boolean scrollIsRootNode = isRootNode(scroll.get(0));

    int pageX = e.pageX();
    int pageY = e.pageY();

    if (!initPosition) {
        if (containment != null && containment.length == 4) {
            if (e.pageX() - offsetClick.left < containment[0]) {
                pageX = containment[0] + offsetClick.left;
            }
            if (e.pageY() - offsetClick.top < containment[1]) {
                pageY = containment[1] + offsetClick.top;
            }
            if (e.pageX() - offsetClick.left > containment[2]) {
                pageX = containment[2] + offsetClick.left;
            }
            if (e.pageY() - offsetClick.top > containment[3]) {
                pageY = containment[3] + offsetClick.top;
            }
        }

        if (options.getGrid() != null) {
            int[] grid = options.getGrid();
            int roundedTop = originalEventPageY + Math.round((pageY - originalEventPageY) / grid[1]) * grid[1];
            int roundedLeft = originalEventPageX + Math.round((pageX - originalEventPageX) / grid[0]) * grid[0];

            if (containment != null && containment.length == 4) {
                boolean isOutOfContainment0 = roundedLeft - offsetClick.left < containment[0];
                boolean isOutOfContainment1 = roundedTop - offsetClick.top < containment[1];
                boolean isOutOfContainment2 = roundedLeft - offsetClick.left > containment[2];
                boolean isOutOfContainment3 = roundedTop - offsetClick.top > containment[3];

                pageY = !(isOutOfContainment1 || isOutOfContainment3) ? roundedTop
                        : (!isOutOfContainment1) ? roundedTop - grid[1] : roundedTop + grid[1];
                pageX = !(isOutOfContainment0 || isOutOfContainment2) ? roundedLeft
                        : (!isOutOfContainment0) ? roundedLeft - grid[0] : roundedLeft + grid[0];

            } else {
                pageY = roundedTop;
                pageX = roundedLeft;
            }

        }
    }

    int top = pageY - offsetClick.top - relativeOffset.top - parentOffset.top
            + ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
                    : scrollIsRootNode ? 0 : scroll.scrollTop());

    int left = pageX - offsetClick.left - relativeOffset.left - parentOffset.left
            + ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
                    : scrollIsRootNode ? 0 : scroll.scrollLeft());
    return new Offset(left, top);
}

From source file:gwtquery.plugins.draggable.client.plugins.ScrollPlugin.java

License:Apache License

public void onDrag(DraggableHandler handler, DragContext ctx, GqEvent e) {
    DraggableOptions options = handler.getOptions();
    Element draggableElement = ctx.getDraggable();
    GQuery scrollParent = handler.getHelperScrollParent();
    Element scrollParentElement = scrollParent.get(0);
    if (scrollParentElement == null) {
        return;/*ww  w. ja va  2 s. com*/
    }

    AxisOption axis = options.getAxis();
    Offset overflowOffset = $(draggableElement).data(OVERFLOW_OFFSET_KEY, Offset.class);
    int scrollSensitivity = options.getScrollSensitivity();
    int scrollSpeed = options.getScrollSpeed();

    boolean scrolled = false;

    if (scrollParentElement != null && scrollParentElement != $(GQuery.document).get(0)
            && !"html".equalsIgnoreCase(scrollParentElement.getTagName())) {
        if (AxisOption.NONE == axis || AxisOption.Y_AXIS == axis) {
            // test if we have to scroll down...
            if ((overflowOffset.top + scrollParentElement.getOffsetHeight()) - e.pageY() < scrollSensitivity) {
                scrollParentElement.setScrollTop(scrollParentElement.getScrollTop() + scrollSpeed);
                scrolled = true;
                // test if we have to scroll up...
            } else if (e.pageY() - overflowOffset.top < scrollSensitivity) {
                scrollParentElement.setScrollTop(scrollParentElement.getScrollTop() - scrollSpeed);
                scrolled = true;
            }
        }

        if (AxisOption.NONE == axis || AxisOption.X_AXIS == axis) {
            // test if we have to scroll left...
            if ((overflowOffset.left + scrollParentElement.getOffsetWidth()) - e.pageX() < scrollSensitivity) {
                scrollParentElement.setScrollLeft(scrollParentElement.getScrollLeft() + scrollSpeed);
                scrolled = true;
                // test if we have to scroll right...
            } else if (e.pageX() - overflowOffset.left < scrollSensitivity) {
                scrollParentElement.setScrollLeft(scrollParentElement.getScrollLeft() - scrollSpeed);
                scrolled = true;
            }
        }

    } else {
        if (AxisOption.NONE == axis || AxisOption.Y_AXIS == axis) {
            if (e.pageY() - document.getScrollTop() < scrollSensitivity) {
                document.setScrollTop(document.getScrollTop() - scrollSpeed);
                scrolled = true;
            } else if (Window.getClientHeight() - (e.pageY() - document.getScrollTop()) < scrollSensitivity) {
                document.setScrollTop(document.getScrollTop() + scrollSpeed);
                scrolled = true;
            }
        }

        if (AxisOption.NONE == axis || AxisOption.X_AXIS == axis) {
            if (e.pageX() - document.getScrollLeft() < scrollSensitivity) {
                document.setScrollLeft(document.getScrollLeft() - scrollSpeed);
                scrolled = true;
            } else if (Window.getClientWidth() - (e.pageX() - document.getScrollLeft()) < scrollSensitivity) {
                document.setScrollLeft(document.getScrollLeft() + scrollSpeed);
                scrolled = true;
            }
        }

    }

    if (scrolled && DragAndDropManager.getInstance().isHandleDroppable(ctx)) {
        DragAndDropManager.getInstance().initialize(ctx, e);
    }

}

From source file:gwtquery.plugins.selectable.client.Selectable.java

License:Apache License

protected void onSelection(Element selectable, GqEvent event) {

    if (!isLassoSelectionEnable(event)) {
        return;/*from   w  w  w . j av  a  2 s  .c  om*/
    }

    lasso.draw(event.pageX(), event.pageY());

    int x1 = lasso.element.getAbsoluteLeft(), y1 = lasso.element.getAbsoluteTop();
    int x2 = lasso.element.getAbsoluteRight(), y2 = lasso.element.getAbsoluteBottom();

    GQuery selectees = $(selectable).data(SELECTEES_KEY, GQuery.class);

    for (Element e : selectees.elements()) {
        SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
        if (si == null || si.getElement() == selectable) {
            continue;
        }

        boolean hit = false;
        if (Tolerance.TOUCH == options.getTolerance()) {
            hit = !(si.getLeft() > x2 || si.getRight() < x1 || si.getTop() > y2 || si.getBottom() < y1);
        } else if (Tolerance.FIT == options.getTolerance()) {
            hit = si.getLeft() > x1 && si.getRight() < x2 && si.getTop() > y1 && si.getBottom() < y2;
        }

        if (hit) {
            if (si.isSelected()) {
                si.$element().removeClass(CssClassNames.UI_SELECTED);
                si.setSelected(false);
            }
            if (si.isUnselecting()) {
                si.$element().removeClass(CssClassNames.UI_UNSELECTING);
                si.setUnselecting(false);
            }
            if (!si.isSelecting()) {
                si.selecting();
                trigger(new SelectingEvent(e), options.getOnSelecting(), e);
            }
        } else {
            if (si.isSelecting()) {
                if (isMetaKeyEnabled(event) && si.isStartSelected()) {
                    // keep previously selected element
                    si.select();
                } else {
                    si.$element().removeClass(CssClassNames.UI_SELECTING);
                    si.setSelecting(false);
                    if (si.isStartSelected()) { // previously selected ->
                        // flag it as unselecting
                        si.$element().addClass(CssClassNames.UI_UNSELECTING);
                        si.setUnselecting(true);
                        trigger(new UnselectingEvent(e), options.getOnUnselecting(), e);
                    }

                }
            }

            if (si.isSelected() && !isMetaKeyEnabled(event) && !si.isStartSelected()) {
                si.unselecting();
                trigger(new UnselectingEvent(e), options.getOnUnselecting(), e);

            }
        }

    }

}

From source file:gwtquery.plugins.selectable.client.Selectable.java

License:Apache License

protected void onSelectionStart(Element selectable, GqEvent event) {

    trigger(new SelectionStartEvent(selectable), options.getOnStartSelection(), selectable);

    if (isLassoSelectionEnable(event)) {
        opos = new int[] { event.pageX(), event.pageY() };
        lasso.show(opos[0], opos[1], options.getAppendTo());
    }//w w  w  .  j  av  a 2  s . c  o m

    if (options.isAutoRefresh()) {
        refreshSelectees(selectable);
    }

    GQuery selectedSelectees = $(selectable).data(SELECTEES_KEY, GQuery.class)
            .filter("." + CssClassNames.UI_SELECTED);

    for (Element e : selectedSelectees.elements()) {
        SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
        si.setStartSelected(true);
        // if not meta-key or ctrl-keypressed, unselect elements
        if (!isMetaKeyEnabled(event)) {
            si.unselecting();
            trigger(new UnselectingEvent(e), options.getOnUnselecting(), e);
        }
    }

    // remove old selected (case where filter was change before this
    // selection) if no meta-key was pressed
    if (!isMetaKeyEnabled(event)) {
        GQuery oldSelected = $('.' + CssClassNames.UI_SELECTED, selectable);
        for (Element e : oldSelected.elements()) {
            SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
            if (si == null) { // old selectee
                e.removeClassName(CssClassNames.UI_SELECTED);
                trigger(new UnselectedEvent(e), options.getOnUnselected(), e);
            }
        }
    }

    // retrieve the element that was the target of the event and its parents
    // (maybe one of the parent is the selectee)
    GQuery eventTarget = $((Element) event.getEventTarget().cast());
    GQuery parentsAndSelf = eventTarget.parents().add(eventTarget);
    for (Element e : parentsAndSelf.elements()) {
        SelectableItem si = $(e).data(SELECTABLE_ITEM_KEY, SelectableItem.class);
        if (si != null) {
            // ok a selectable-item exists on the element...
            // it is a selectable element
            boolean doSelection = !isMetaKeyEnabled(event) || !si.isSelected();
            if (doSelection) {
                si.selecting();
                trigger(new SelectingEvent(e), options.getOnSelecting(), e);
            } else {
                si.unselecting();
                trigger(new UnselectingEvent(e), options.getOnUnselecting(), e);
            }

        }
    }
}