Example usage for com.google.gwt.user.client.ui UIObject getAbsoluteLeft

List of usage examples for com.google.gwt.user.client.ui UIObject getAbsoluteLeft

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui UIObject getAbsoluteLeft.

Prototype

public int getAbsoluteLeft() 

Source Link

Document

Gets the object's absolute left position in pixels, as measured from the browser window's client area.

Usage

From source file:org.cruxframework.crux.smartfaces.client.dialog.PopupPanel.java

License:Apache License

private int getLeftRelativeObject(final UIObject relativeObject) {
    int offsetWidth = getOffsetWidth();
    int relativeElemOffsetWidth = relativeObject.getOffsetWidth();
    int offsetWidthDiff = offsetWidth - relativeElemOffsetWidth;
    int left;/*www. ja  v  a  2 s. c om*/

    if (LocaleInfo.getCurrentLocale().isRTL()) { // RTL case

        int relativeElemAbsoluteLeft = relativeObject.getAbsoluteLeft();
        left = relativeElemAbsoluteLeft - offsetWidthDiff;
        if (offsetWidthDiff > 0) {
            int windowRight = Window.getClientWidth() + Window.getScrollLeft();
            int windowLeft = Window.getScrollLeft();

            int relativeElemLeftValForRightEdge = relativeElemAbsoluteLeft + relativeElemOffsetWidth;
            int distanceToWindowRight = windowRight - relativeElemLeftValForRightEdge;
            int distanceFromWindowLeft = relativeElemLeftValForRightEdge - windowLeft;
            if (distanceFromWindowLeft < offsetWidth && distanceToWindowRight >= offsetWidthDiff) {
                left = relativeElemAbsoluteLeft;
            }
        }
    } else { // LTR case

        left = relativeObject.getAbsoluteLeft();
        if (offsetWidthDiff > 0) {
            int windowRight = Window.getClientWidth() + Window.getScrollLeft();
            int windowLeft = Window.getScrollLeft();
            int distanceToWindowRight = windowRight - left;
            int distanceFromWindowLeft = left - windowLeft;
            if (distanceToWindowRight < offsetWidth && distanceFromWindowLeft >= offsetWidthDiff) {
                left -= offsetWidthDiff;
            }
        }
    }
    return left;
}

From source file:org.openremote.app.client.widget.PopupPanel.java

License:Apache License

/**
 * Positions the popup, called after the offset width and height of the popup
 * are known./* w ww  .jav  a  2s. c om*/
 *
 * @param relativeObject the ui object to position relative to
 * @param offsetWidth the drop down's offset width
 * @param offsetHeight the drop down's offset height
 */
private void position(final UIObject relativeObject, int offsetWidth, int offsetHeight) {
    // Calculate left position for the popup. The computation for
    // the left position is bidi-sensitive.

    int textBoxOffsetWidth = relativeObject.getOffsetWidth();

    // Compute the difference between the popup's width and the
    // textbox's width
    int offsetWidthDiff = offsetWidth - textBoxOffsetWidth;

    int left;

    if (LocaleInfo.getCurrentLocale().isRTL()) { // RTL case

        int textBoxAbsoluteLeft = relativeObject.getAbsoluteLeft();

        // Right-align the popup. Note that this computation is
        // valid in the case where offsetWidthDiff is negative.
        left = textBoxAbsoluteLeft - offsetWidthDiff;

        // If the suggestion popup is not as wide as the text box, always
        // align to the right edge of the text box. Otherwise, figure out whether
        // to right-align or left-align the popup.
        if (offsetWidthDiff > 0) {

            // Make sure scrolling is taken into account, since
            // box.getAbsoluteLeft() takes scrolling into account.
            int windowRight = Window.getClientWidth() + Window.getScrollLeft();
            int windowLeft = Window.getScrollLeft();

            // Compute the left value for the right edge of the textbox
            int textBoxLeftValForRightEdge = textBoxAbsoluteLeft + textBoxOffsetWidth;

            // Distance from the right edge of the text box to the right edge
            // of the window
            int distanceToWindowRight = windowRight - textBoxLeftValForRightEdge;

            // Distance from the right edge of the text box to the left edge of the
            // window
            int distanceFromWindowLeft = textBoxLeftValForRightEdge - windowLeft;

            // If there is not enough space for the overflow of the popup's
            // width to the right of the text box and there IS enough space for the
            // overflow to the right of the text box, then left-align the popup.
            // However, if there is not enough space on either side, stick with
            // right-alignment.
            if (distanceFromWindowLeft < offsetWidth && distanceToWindowRight >= offsetWidthDiff) {
                // Align with the left edge of the text box.
                left = textBoxAbsoluteLeft;
            }
        }
    } else { // LTR case

        // Left-align the popup.
        left = relativeObject.getAbsoluteLeft();

        // If the suggestion popup is not as wide as the text box, always align to
        // the left edge of the text box. Otherwise, figure out whether to
        // left-align or right-align the popup.
        if (offsetWidthDiff > 0) {
            // Make sure scrolling is taken into account, since
            // box.getAbsoluteLeft() takes scrolling into account.
            int windowRight = Window.getClientWidth() + Window.getScrollLeft();
            int windowLeft = Window.getScrollLeft();

            // Distance from the left edge of the text box to the right edge
            // of the window
            int distanceToWindowRight = windowRight - left;

            // Distance from the left edge of the text box to the left edge of the
            // window
            int distanceFromWindowLeft = left - windowLeft;

            // If there is not enough space for the overflow of the popup's
            // width to the right of hte text box, and there IS enough space for the
            // overflow to the left of the text box, then right-align the popup.
            // However, if there is not enough space on either side, then stick with
            // left-alignment.
            if (distanceToWindowRight < offsetWidth && distanceFromWindowLeft >= offsetWidthDiff) {
                // Align with the right edge of the text box.
                left -= offsetWidthDiff;
            }
        }
    }

    // Calculate top position for the popup

    int top = relativeObject.getAbsoluteTop();

    // Make sure scrolling is taken into account, since
    // box.getAbsoluteTop() takes scrolling into account.
    int windowTop = Window.getScrollTop();
    int windowBottom = Window.getScrollTop() + Window.getClientHeight();

    // Distance from the top edge of the window to the top edge of the
    // text box
    int distanceFromWindowTop = top - windowTop;

    // Distance from the bottom edge of the window to the bottom edge of
    // the text box
    int distanceToWindowBottom = windowBottom - (top + relativeObject.getOffsetHeight());

    // If there is not enough space for the popup's height below the text
    // box and there IS enough space for the popup's height above the text
    // box, then position the popup above the text box. However, if there
    // is not enough space on either side, then stick with displaying the
    // popup below the text box.
    if (distanceToWindowBottom < offsetHeight && distanceFromWindowTop >= offsetHeight) {
        top -= offsetHeight;
    } else {
        // Position above the text box
        top += relativeObject.getOffsetHeight();
    }
    setPopupPosition(left, top);
}

From source file:org.openremote.manager.client.widget.AbstractAppPanel.java

License:Open Source License

public void showBottomRightOf(UIObject bottomRightTarget, int marginRight, int marginBottom) {
    this.bottomRightTarget = bottomRightTarget;
    this.marginRight = marginRight;
    this.marginBottom = marginBottom;
    getPopupPanel().setPopupPositionAndShow((offsetWidth, offsetHeight) -> {
        int bottom = bottomRightTarget.getAbsoluteTop() + bottomRightTarget.getOffsetHeight();
        int right = bottomRightTarget.getAbsoluteLeft() + bottomRightTarget.getOffsetWidth();
        int top = bottom - offsetHeight - marginBottom;
        int left = right - offsetWidth - marginRight;
        getPopupPanel().setPopupPosition(left, top);
    });//w  ww  . j a v a  2s.c  o m
}

From source file:org.openremote.manager.client.widget.AbstractAppPanel.java

License:Open Source License

public void showTopLeftOf(UIObject topLeftTarget, int marginTop, int marginLeft) {
    this.topLeftTarget = topLeftTarget;
    this.marginTop = marginTop;
    this.marginLeft = marginLeft;
    getPopupPanel().setPopupPositionAndShow((offsetWidth, offsetHeight) -> {
        int top = topLeftTarget.getAbsoluteTop() + marginTop;
        int left = topLeftTarget.getAbsoluteLeft() + marginLeft;
        getPopupPanel().setPopupPosition(left, top);
    });// ww  w . j  a  va  2 s .  c o m
}

From source file:org.roda.wui.client.common.popup.CalloutPopup.java

private Pair<Integer, Integer> getBottomRight(UIObject target, int offsetWidth, int offsetHeight) {
    int left = target.getAbsoluteLeft() + target.getOffsetWidth() / 2 - offsetWidth + ARROW_OFFSET_PX;
    int top = target.getAbsoluteTop() - offsetHeight - MARGIN_FROM_TARGET_PX;

    // change top value if popup top disappears of the page (goes to bottom)
    if (top < 0) {
        top = target.getAbsoluteTop() + target.getOffsetHeight() + MARGIN_FROM_TARGET_PX;
        addStyleDependentName(CalloutPosition.TOP_RIGHT.name().toLowerCase());
    } else {/*from w ww.  j a v  a 2s  . com*/
        addStyleDependentName(CalloutPosition.BOTTOM_RIGHT.name().toLowerCase());
    }

    return Pair.of(left, top);
}

From source file:org.roda.wui.client.common.popup.CalloutPopup.java

private Pair<Integer, Integer> getTopRight(UIObject target, int offsetWidth, int offsetHeight) {
    int left = target.getAbsoluteLeft() + target.getOffsetWidth() / 2 - offsetWidth + ARROW_OFFSET_PX;
    int top = target.getAbsoluteTop() + target.getOffsetHeight() + MARGIN_FROM_TARGET_PX;
    addStyleDependentName(CalloutPosition.TOP_RIGHT.name().toLowerCase());
    return Pair.of(left, top);
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu.java

License:Open Source License

public void showRelativeToUpward(final UIObject target) {
    setPopupPositionAndShow(new PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            setPopupPosition(target.getAbsoluteLeft(), target.getAbsoluteTop() - offsetHeight);
        }//from w  ww .jav a  2  s .c om
    });
}