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

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

Introduction

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

Prototype

public int getOffsetWidth() 

Source Link

Document

Gets the object's offset width in pixels.

Usage

From source file:org.gwm.client.util.GwmUtilities.java

License:Apache License

/**
 * Displays a frame at the center of the specified widget
 * @param frame the frame to display//from w w  w.  jav a2 s . c o m
 * @param absoluteParent the widget at which center the frame will be displayed
 */
static public void diplayAtRelativeGivenWidgetCenter(GFrame frame, UIObject absoluteParent) {
    if (frame == null || absoluteParent == null)
        throw new IllegalArgumentException("The parameters can't be null");
    int frameLeft = (absoluteParent.getOffsetWidth() - frame.getWidth()) / 2;
    int frameTop = (absoluteParent.getOffsetHeight() - frame.getHeight()) / 2;
    frame.setLocation(frameTop, frameLeft);
    frame.setVisible(true);

}

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.//ww  w .java2  s  .  c  o  m
 *
 * @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);
    });/*from  w  w w. j  a  v  a2 s.  c  o m*/
}

From source file:org.pepstock.jem.gwt.client.commons.UITools.java

License:Open Source License

/**
 * Simple tool to used to know if a Widget is visible, and if it is in foreground 
 * @param object/*from w  w  w  .j av a  2  s  .c om*/
 * @return <code>true</code> if the parameter is visible and in foreground
 */
public static boolean isInForegroundVisible(UIObject object) {
    return object.isVisible() && object.getOffsetWidth() > 0 && object.getOffsetHeight() > 0;
}

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  2 s.c om*/
        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);
}