List of usage examples for com.google.gwt.user.client.ui UIObject getOffsetWidth
public int getOffsetWidth()
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 w w w . j a va 2 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:cc.kune.bootstrap.client.actions.ui.PopupBSMenuGui.java
License:GNU Affero Public License
public void showRelativeTo(final Object relative) { createPopupIfNecessary();/*from w w w . j ava 2 s . c o m*/ if (relative instanceof String) { popup.showRelativeTo(RootPanel.get((String) relative)); } else if (relative instanceof UIObject) { final Boolean atRight = ((Boolean) descriptor.getValue(MenuDescriptor.MENU_ATRIGHT)); if (atRight) { popup.setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(final int offsetWidth, final int offsetHeight) { final UIObject obj = (UIObject) relative; popup.setPopupPosition(obj.getAbsoluteLeft() + obj.getOffsetWidth(), obj.getAbsoluteTop() + 30); } }); } else { popup.showRelativeTo((UIObject) relative); } } else if (relative instanceof Position) { popup.setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(final int offsetWidth, final int offsetHeight) { final Position position = (Position) relative; popup.setPopupPosition(position.getX(), position.getY()); } }); } descriptor.putValue(MenuDescriptor.MENU_ONSHOW, popup); Tooltip.getTip().hide(); }
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 www . j a v a 2 s . c o 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.//from www. j a v a2s . 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:com.seanchenxi.gwt.serenity.client.view.impl.SidebarImpl.java
License:Apache License
public SidebarImpl() { menu = new NavigationBar(); menu.addStyleName(getResources().style().sideBar()); NavigationItem item = new NavigationItem(getResources().icon_Home_black()); item.setId(ids.home());// w ww . java2s . co m menu.addItem(item); searchBox = new SearchBox(); searchBox.setFieldWidth("250px"); searchBox.addSearchHandler(new SearchEvent.Handler() { @Override public void onSearch(SearchEvent event) { presenter.search(event.getSearchValue()); } }); item = new NavigationItem(getResources().icon_Search_black()); item.setId(ids.search()); item.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Object obj = event.getSource(); searchBox.show(); if (obj instanceof UIObject) { UIObject uio = (UIObject) obj; searchBox.setPopupPosition(uio.getAbsoluteLeft() + uio.getOffsetWidth(), uio.getAbsoluteTop()); } else { searchBox.center(); } } }); menu.addItem(item); item = new NavigationItem(getResources().icon_Grid_black()); item.setLabelBox(catPopup = new PopupLabelBox(1)); item.setId(ids.category()); menu.addItem(item); item = new NavigationItem(getResources().icon_Info_black()); item.setId(ids.about()); menu.addItem(item); menu.addSelectionHandler(new SelectionHandler<NavigationItem>() { @Override public void onSelection(SelectionEvent<NavigationItem> event) { NavigationItem item = event.getSelectedItem(); if (ids.home().equalsIgnoreCase(item.getId())) { presenter.goToHome(); } else if (ids.about().equalsIgnoreCase(item.getId())) { presenter.goToAbout(); } else if (ids.category().equalsIgnoreCase(item.getId())) { String slug = item.getLabelBox().getSelectedLabel(); if (slug != null) { presenter.goToCategory(slug); } } } }); }
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. *///from w ww . jav a 2 s. c o m 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:de.eckhartarnold.client.Toolbox.java
License:Apache License
/** * Returns the offset width of an UI object. Usually, the same as * <code>uiobject.getOffsetWidth()</code> * @param uiobject the UIObject for which the width shall be determined * @return the offset width of uiobject. *//*from w w w . j a v a 2 s.c o m*/ public static int getOffsetWidth(UIObject uiobject) { return uiobject.getOffsetWidth(); }
From source file:edu.caltech.ipac.firefly.ui.GwtUtil.java
public static int getElementWidth(UIObject uiObject) { return uiObject.getOffsetWidth() - getHorizPadding(uiObject) - getHorizBorder(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 getLeftRelativeObject(final UIObject relativeObject) { int offsetWidth = getOffsetWidth(); int relativeElemOffsetWidth = relativeObject.getOffsetWidth(); int offsetWidthDiff = offsetWidth - relativeElemOffsetWidth; int left;// w w w .ja v a 2s. c o m 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; }