List of usage examples for com.google.gwt.user.client.ui UIObject getAbsoluteLeft
public int getAbsoluteLeft()
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.// w ww . 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 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();/* w w w . java 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.page.DiffPanel.java
License:Open Source License
private void fillDiffContent(DiffListModel model) { List<DiffModel> diffList = model.revs; //now render diff object diffContent.clear();//from w ww. ja va 2s . co m isConflictMerged = false; int idx = 0; for (Iterator<DiffModel> iter = diffList.iterator(); iter.hasNext();) { final DiffModel diff = iter.next(); if (model.type == DiffListModel.FLAT_TYPE) { diffContent.add(diff.content); //only one element exist, so not necessary to continue; break; } diff.index = idx++; if (diff.type == DiffModel.NOCHANGE) { diffContent.add(diff.content); } else { ClickLink link = new ClickLink(diff.content); if (diff.type == DiffModel.ADD) link.addStyleName(Css.DIFF_INSERTION); else link.addStyleName(Css.DIFF_DELETION); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { UIObject sender = (UIObject) event.getSource(); DiffActionMenu menu = new DiffActionMenu(diff); int left = sender.getAbsoluteLeft() + 10; int top = sender.getAbsoluteTop() + 10; menu.setPopupPosition(left, top); menu.show(); //TODO: need add windowResizeListener } }); link.setObject(diff); diffContent.add(link); } } diffContent.submit(); }
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// w ww. j a va 2s . com * @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 . jav a2 s . co 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 w w .ja va 2 s . 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:com.vaadin.addon.charts.client.ui.MouseEventDetailsBuilder.java
/** * Construct a {@link MouseEventDetails} object from the given * {@link ChartClickEvent}// w ww . j a v a2 s . c om * * @param event * The event to use as a source for the details * @param relativeToObject * The element used to calculate * {@link MouseEventDetails#getxValue()} and * {@link MouseEventDetails#getyValue()} * @return mouseEventDetails containing information from the event */ public static MouseEventDetails buildMouseEventDetails(ChartClickEvent event, UIObject relativeToObject) { MouseEventDetails mouseEventDetails = new MouseEventDetails(); initCommonValues(mouseEventDetails, event); ValueAxisPair xPair = event.getXPairs().get(0); ValueAxisPair yPair = event.getYPairs().get(0); double x = xPair.getValue(); double y = yPair.getValue(); int absoluteX = relativeToObject.getAbsoluteLeft() + new Double(xPair.getAxis().toPixels(x, false)).intValue(); int absoluteY = relativeToObject.getAbsoluteTop() + new Double(yPair.getAxis().toPixels(y, false)).intValue(); mouseEventDetails.setAbsoluteX(absoluteX); mouseEventDetails.setAbsoluteY(absoluteY); mouseEventDetails.setxValue(x); mouseEventDetails.setyValue(y); return mouseEventDetails; }
From source file:com.vaadin.addon.charts.client.ui.MouseEventDetailsBuilder.java
/** * Construct a {@link MouseEventDetails} object from the given * {@link PointClickEvent}/* ww w .j ava2 s . c o m*/ * * @param event * The event to use as a source for the details * @param relativeToObject * The element used to calculate * {@link MouseEventDetails#getxValue()} and * {@link MouseEventDetails#getyValue()} * @return mouseEventDetails containing information from the event */ public static MouseEventDetails buildMouseEventDetails(PointClickEvent event, UIObject relativeToObject) { MouseEventDetails mouseEventDetails = new MouseEventDetails(); initCommonValues(mouseEventDetails, event); int absoluteX = relativeToObject.getAbsoluteLeft() + new Double(event.getXAxis().toPixels(event.getX(), false)).intValue(); int absoluteY = relativeToObject.getAbsoluteTop() + new Double(event.getYAxis().toPixels(event.getY(), false)).intValue(); mouseEventDetails.setAbsoluteX(absoluteX); mouseEventDetails.setAbsoluteY(absoluteY); mouseEventDetails.setxValue(event.getX()); mouseEventDetails.setyValue(event.getY()); return mouseEventDetails; }
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./*www.j av a 2 s .com*/ */ 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 ava2 s .c o m */ 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"); } }