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

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

Introduction

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

Prototype

public int getOffsetHeight() 

Source Link

Document

Gets the object's offset height in pixels.

Usage

From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java

License:Apache License

/**
 * Positions the popup, called after the offset width and height of the
 * popup are known./*from www .ja v a2  s  .  com*/
 * 
 * @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 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:com.edgenius.wiki.gwt.client.widgets.Lightbox.java

License:Open Source License

/**
 * Only show background mask on owner scope. if owner is null, then it is entire page scope. 
 * @param owner/*from w  ww  .j a  va2s  . co  m*/
 * @param popup
 */
public Lightbox(UIObject owner, final PopupPanel popup) {
    this.popup = popup;
    this.owner = owner;
    background = new PopupPanel();
    background.setStyleName(Css.LIGHT_BOX_BK);

    if (owner == null) {
        DOM.setStyleAttribute(background.getElement(), "width", "100%");
        DOM.setStyleAttribute(background.getElement(), "height", "5000px"); //Window.getClientHeight()

        evtReg = Window.addResizeHandler(new ResizeHandler() {
            public void onResize(ResizeEvent event) {
                //background need be adjust size, but popup won't display if it is not showing. 
                if (popup.isShowing()) {
                    popup.center();
                    if (popup instanceof DialogBox) {
                        List<DialogListener> listeners = ((DialogBox) popup).getDialogListeners();
                        if (listeners != null) {
                            for (DialogListener listener : listeners) {
                                listener.dialogRelocated((DialogBox) popup);
                            }
                        }
                    }
                }
            }
        });
    } else {
        background.setPopupPosition(owner.getAbsoluteLeft(), owner.getAbsoluteTop());
        DOM.setStyleAttribute(background.getElement(), "width", owner.getOffsetWidth() + "px");
        DOM.setStyleAttribute(background.getElement(), "height", owner.getOffsetHeight() + "px");
    }

}

From source file:com.lorepo.icplayer.client.module.choice.MyPopupPanel.java

License:Apache License

/**
 * Positions the popup, called after the offset width and height of the popup
 * are known.// w  w  w . j a  v  a2  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 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:cz.filmtit.client.subgestbox.PosteditBox.java

License:Open Source License

/**
 * Display the postedit suggestion widget with the suggestions from the
 * underlying TranslationResult./*from  w ww . j av  a 2s.  c o m*/
 */
public void showSuggestions() {

    if (this.getSuggestions().size() > 0) {

        // showing the suggestions always below this SubgestBox:
        final UIObject relativeObject = this;
        posteditPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
            @Override
            public void setPosition(int offsetWidth, int offsetHeight) {
                // Calculate left position for the popup
                int left = relativeObject.getAbsoluteLeft();
                // Calculate top position for the popup
                int top = relativeObject.getAbsoluteTop();
                // Position below the textbox:
                top += relativeObject.getOffsetHeight();
                posteditPanel.setPopupPosition(left, top);
            }
        });
        posteditWidget.setWidth(this.getOffsetWidth() + "px");
    }
}

From source file:cz.filmtit.client.subgestbox.SubgestBox.java

License:Open Source License

/**
 * Display the suggestion widget with the suggestions from the underlying
 * TranslationResult.//from ww w .  j  ava  2 s.  com
 */
public void showSuggestions() {

    if (this.getSuggestions().size() > 0) {

        // showing the suggestions always below this SubgestBox:
        final UIObject relativeObject = this;
        suggestPanel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
            @Override
            public void setPosition(int offsetWidth, int offsetHeight) {
                // Calculate left position for the popup
                int left = relativeObject.getAbsoluteLeft();
                // Calculate top position for the popup
                int top = relativeObject.getAbsoluteTop();
                // Position below the textbox:
                top += relativeObject.getOffsetHeight();
                suggestPanel.setPopupPosition(left, top);
            }
        });
        suggestionWidget.setWidth(this.getOffsetWidth() + "px");
    }
}

From source file:de.eckhartarnold.client.Toolbox.java

License:Apache License

/**
 * Returns the offset height of an UI object. For some reason, this is often
 * zero in non-quirks mode. In this case the offset height will be guessed
 * with a very crude algorithm based on the client window's size.
 * @param uiobject the UIObject, the height of which shall be determined
 * @return the (assumed) offset height of an UI object.
 *//* www.  j a  va  2s.c  om*/
public static int getOffsetHeight(UIObject uiobject) {
    int height = uiobject.getOffsetHeight();
    if (height == 0) {
        int clientW = Window.getClientWidth();
        int clientH = Window.getClientHeight();
        int width = uiobject.getOffsetWidth();
        height = clientH * width / clientW;
    }
    return height;
}

From source file:edu.caltech.ipac.firefly.ui.GwtUtil.java

public static int getElementHeight(UIObject uiObject) {
    return uiObject.getOffsetHeight() - getVertPadding(uiObject) - getVertBorder(uiObject);
}

From source file:gov.nist.appvet.gwt.client.gui.AppVetPanel.java

License:Open Source License

public static int[] getCenterPosition(com.google.gwt.user.client.ui.UIObject object) {
    final int windowWidth = Window.getClientWidth();
    final int windowHeight = Window.getClientHeight();
    final int xposition = (windowWidth / 2) - (object.getOffsetHeight() / 2);
    final int yposition = (windowHeight / 2) - (object.getOffsetWidth() / 2);
    final int[] position = { xposition, yposition };
    return position;
}

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

License:Apache License

private int getTopRelativeObject(final UIObject relativeObject) {
    int offsetHeight = getOffsetHeight();
    int top = relativeObject.getAbsoluteTop();

    int windowTop = Window.getScrollTop();
    int windowBottom = Window.getScrollTop() + Window.getClientHeight();

    int distanceFromWindowTop = top - windowTop;
    int distanceToWindowBottom = windowBottom - (top + relativeObject.getOffsetHeight());

    if (distanceToWindowBottom < offsetHeight && distanceFromWindowTop >= offsetHeight) {
        top -= offsetHeight;//from  w w w  .  jav a 2  s .c  o m
    } else {
        top += relativeObject.getOffsetHeight();
    }
    return top;
}

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   ww w . java2s.  co  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);

}