List of usage examples for com.google.gwt.user.client Window getScrollTop
public static int getScrollTop()
From source file:org.vaadin.addons.tuningdatefield.widgetset.client.ui.TuningDateFieldWidget.java
License:Apache License
public void updatePopupPosition() { // This has been copied from Vaadin VPopupCalendar (shame on me...) popup.setPopupPositionAndShow(new PositionCallback() { @Override//from ww w . j a v a 2s.c o m public void setPosition(int offsetWidth, int offsetHeight) { final int w = offsetWidth; final int h = offsetHeight; final int browserWindowWidth = Window.getClientWidth() + Window.getScrollLeft(); final int browserWindowHeight = Window.getClientHeight() + Window.getScrollTop(); int t = calendarToggle.getAbsoluteTop(); int l = calendarToggle.getAbsoluteLeft(); // Add a little extra space to the right to avoid // problems with IE7 scrollbars and to make it look // nicer. int extraSpace = 30; boolean overflowRight = false; if (l + +w + extraSpace > browserWindowWidth) { overflowRight = true; // Part of the popup is outside the browser window // (to the right) l = browserWindowWidth - w - extraSpace; } if (t + h + calendarToggle.getOffsetHeight() + 30 > browserWindowHeight) { // Part of the popup is outside the browser window // (below) t = browserWindowHeight - h - calendarToggle.getOffsetHeight() - 30; if (!overflowRight) { // Show to the right of the popup button unless we // are in the lower right corner of the screen l += calendarToggle.getOffsetWidth(); } } popup.setPopupPosition(l, t + calendarToggle.getOffsetHeight() + 2); } }); }
From source file:org.waveprotocol.wave.client.common.util.OffsetPosition.java
License:Apache License
/** * Create a offset position base on the event's client X, Y. The return offset * position is relative to the Document body coordinate. * * @param event//from w w w. j ava 2s . com */ public OffsetPosition(Event event) { // convert the event's client coordinate system, which is client area base, to the // body position coordinate system. this.left = event.getClientX() + Window.getScrollLeft() - Document.get().getBodyOffsetLeft(); this.top = event.getClientY() + Window.getScrollTop() - Document.get().getBodyOffsetTop(); this.offsetParent = null; }
From source file:org.zanata.webtrans.client.ui.TooltipPopupPanel.java
License:Open Source License
private void position(final Element relativeObject, int offsetWidth, int offsetHeight) { int textBoxOffsetWidth = relativeObject.getOffsetWidth(); // Compute the difference between the popup's width and the // textbox's width int offsetWidthDiff = offsetWidth - textBoxOffsetWidth; int left;// w w w .j av a2 s. c o m 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:ru.fly.client.ui.field.combobox.ComboBox.java
License:Apache License
private void updatePositionAndSize() { if (!expander.isExpanded()) return;// w w w.j a va2s.c o m int top = getElement().getAbsoluteTop() + getHeight(); int left = getElement().getAbsoluteLeft(); int wndViewHeight = Window.getClientHeight() + Window.getScrollTop() - 20; int height = getListView().getMaxHeight(); if (top < wndViewHeight / 2) { if (height > wndViewHeight - top) { height = wndViewHeight - top; } } else { if (height > getElement().getAbsoluteTop() - 20) { height = getElement().getAbsoluteTop() - 20; top = 20; } else { top = getElement().getAbsoluteTop() - height; } } if (getListView().getWidth() < getWidth()) getListView().setWidth(getWidth()); getListView().setHeight(height); getListView().setPosition(left, top); }
From source file:ru.fly.client.ui.field.datefield.DatePickerField.java
License:Apache License
protected void onExpand() { int left = getAbsoluteLeft() + getWidth() - 130; int wndViewHeight = Window.getClientHeight() + Window.getScrollTop(); getDatePicker().getElement().getStyle().setPosition(Style.Position.ABSOLUTE); getDatePicker().getElement().getStyle().setZIndex(10000); RootPanel.get().add(getDatePicker()); if (getElement().getAbsoluteTop() + getHeight() + 170 > wndViewHeight) { ((FElement) getDatePicker().getElement()).setPosition(left, getAbsoluteTop() - 170); } else {/*from w w w . j a v a 2 s . co m*/ ((FElement) getDatePicker().getElement()).setPosition(left, getAbsoluteTop() + getHeight() + 2); } getDatePicker().setValue(getValue()); }
From source file:ru.fly.client.ui.field.VariantTextField.java
License:Apache License
private void updatePositionAndSize() { if (!expander.isExpanded()) return;//from www .ja v a 2s.c o m int top = getElement().getAbsoluteTop() + getHeight(); int left = getElement().getAbsoluteLeft(); int wndViewHeight = Window.getClientHeight() + Window.getScrollTop() - 20; int height = getListView().getMaxHeight(); if (top < wndViewHeight / 2) { if (height > wndViewHeight - top) { height = wndViewHeight - top; } } else { if (height > getElement().getAbsoluteTop() - 20) { height = getElement().getAbsoluteTop() - 20; top = 20; } else { top = getElement().getAbsoluteTop() - height; } } getListView().setHeight(height); getListView().setPosition(left, top); }
From source file:se.softhouse.garden.orchid.vaadin.widgetset.client.ui.VOrchidScrollTable.java
License:Open Source License
private void handleBodyContextMenu(ContextMenuEvent event) { if (this.enabled && this.bodyActionKeys != null) { int left = Util.getTouchOrMouseClientX(event.getNativeEvent()); int top = Util.getTouchOrMouseClientY(event.getNativeEvent()); top += Window.getScrollTop(); left += Window.getScrollLeft(); this.client.getContextMenu().showAt(this, left, top); // Only prevent browser context menu if there are action handlers // registered event.stopPropagation();//from w ww .j ava 2 s . c om event.preventDefault(); } }
From source file:se.umu.cs.ldbn.client.ui.window.WindowPanel.java
License:Apache License
public void show() { //this method is implemented very badly, we should find a better solution setVisible(true);//from w w w .j a v a2s. c o m Scheduler.get().scheduleDeferred(new Command() { public void execute() { //offset size is only available after the Widget is attached to the DOM int ow = getOffsetWidth(); int oh = getOffsetHeight(); int sl = Window.getScrollLeft(); int st = Window.getScrollTop(); int wcw = Window.getClientWidth(); int wch = Window.getClientHeight(); int left = (wcw - ow) >> 1; int top = (wch - oh) >> 1; left -= Document.get().getBodyOffsetLeft(); top -= Document.get().getBodyOffsetTop(); AbsolutePanel parent = (AbsolutePanel) getParent(); parent.setWidgetPosition(WindowPanel.this, sl + left, st + top); } }); }
From source file:stroom.widget.popup.client.view.PopupSupportImpl.java
License:Apache License
/** * Positions the popup, called after the offset width and height of the * popup are known.//from w ww . ja v a 2 s .c om */ private void positionPopup(final Popup popup, final PopupType popupType, final PopupPosition popupPosition, int offsetWidth, int offsetHeight) { int shadowWidth = 0; if (popupType != PopupType.POPUP) { shadowWidth = POPUP_SHADOW_WIDTH; } offsetWidth = offsetWidth - (2 * shadowWidth); offsetHeight = offsetHeight - (2 * shadowWidth); int left = -shadowWidth; if (HorizontalLocation.LEFT.equals(popupPosition.getHorizontalLocation())) { // Positioned to the left but aligned with the right edge of the // relative box. left = popupPosition.getRight() - offsetWidth + shadowWidth; } else { // Positioned to the right but aligned with the left edge of the // relative box. left = popupPosition.getLeft() - shadowWidth; } // Make sure scrolling is taken into account, since // box.getAbsoluteLeft() takes scrolling into account. final int windowRight = Window.getClientWidth() + Window.getScrollLeft(); final int windowLeft = Window.getScrollLeft(); // Distance from the left edge of the text box to the right edge of the // window final int distanceToWindowRight = windowRight - left; // Distance from the left edge of the text box to the left edge of the // window final int distanceFromWindowLeft = left - windowLeft; // If there is not enough space for the overflow of the popup's width to // the right, and there IS enough space // for the overflow to the left, then show the popup on the left. If // there is not enough space on either side, then // position at the far left. if (distanceToWindowRight < offsetWidth) { if (distanceFromWindowLeft >= offsetWidth) { // Positioned to the left but aligned with the right edge of the // relative box. left = popupPosition.getRight() - offsetWidth + shadowWidth; } else { left = -shadowWidth; } } // Calculate top position for the popup int top = -shadowWidth; if (VerticalLocation.ABOVE.equals(popupPosition.getVerticalLocation())) { // Positioned above. top = popupPosition.getTop() - offsetHeight + shadowWidth; } else { // Default position is below. top = popupPosition.getBottom() - shadowWidth; } // Make sure scrolling is taken into account, since box.getAbsoluteTop() // takes scrolling into account. final int windowTop = Window.getScrollTop(); final int windowBottom = Window.getScrollTop() + Window.getClientHeight(); // Distance from the top edge of the window to the top edge of the text // box. final int distanceFromWindowTop = top - windowTop; // Distance from the bottom edge of the window to the relative object. final int distanceToWindowBottom = windowBottom - top; // 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. If there is not enough // space above or below, then position at the very top. if (distanceToWindowBottom < offsetHeight) { if (distanceFromWindowTop >= offsetHeight) { // Positioned above. top = popupPosition.getTop() - offsetHeight + shadowWidth; } else { top = -shadowWidth; } } // Make sure the left and top positions are on screen. if (left + offsetWidth > windowRight) { left = windowRight - offsetWidth; } if (top + offsetHeight > windowBottom) { top = windowBottom - offsetHeight; } // Make sure left and top have not ended up less than 0. if (left < 0) { left = 0; } if (top < 0) { top = 0; } popup.setPopupPosition(left, top); }
From source file:tv.dyndns.kishibe.qmaclone.client.creation.WidgetProblemForm.java
License:Open Source License
@Override public void onClick(ClickEvent event) { Widget sender = (Widget) event.getSource(); if (buttonPolygonCreation.contains(sender)) { final int answerIndex = buttonPolygonCreation.indexOf(sender); final DialogBoxPolygonCreation polygonCreation = new DialogBoxPolygonCreation( textBoxChoice[0].getText(), textBoxAnswer[answerIndex].getText()); polygonCreation.setPopupPosition(Window.getScrollLeft() + 10, Window.getScrollTop() + 10); polygonCreation.addDialogBoxPolygonCreationListener(new DialogBoxPolygonCreationListener() { public void onOk() { textBoxAnswer[answerIndex].setText(polygonCreation.getPolygonDescription()); }// ww w .j a v a 2 s . c om public void onCancel() { } }); polygonCreation.show(); } else if (sender == buttonClearProblemFeedback) { clearProblemFeedback(); } else if (sender == radioButtonNone) { updateForm(); } else if (sender == radioButtonImage) { updateForm(); } else if (sender == radioButtonYouTube) { updateForm(); } else if (sender == buttonIndicate) { onButtonIndicate(); } }