Example usage for com.google.gwt.user.client Window getScrollTop

List of usage examples for com.google.gwt.user.client Window getScrollTop

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window getScrollTop.

Prototype

public static int getScrollTop() 

Source Link

Usage

From source file:org.opencms.gwt.client.ui.contextmenu.CmsContextMenu.java

License:Open Source License

/**
 * Sets the position of the sub menu popup.<p>
 * //from   ww  w. ja  va  2 s .  c  om
 * First calculates the best space where to show the popup.<p>
 * 
 * The following list shows the possibilities, beginning
 * with the best and ending with the worst.<p>
 * 
 * <ul>
 * <li>bottom-right</li>
 * <li>bottom-left</li>
 * <li>top-right</li>
 * <li>top-left</li>
 * </ul>
 * 
 * Then the position (top and left coordinate) are calculated.<p>
 * 
 * Finally the position of the sub menu popup is set to the calculated values.<p>
 *  
 * @param item the item to show the sub menu of
 */
protected void setSubMenuPosition(final A_CmsContextMenuItem item) {

    // calculate the left space 
    // add 10 because of the shadow and for avoiding that the browser's right window border touches the sub menu
    int leftSpace = item.getAbsoluteLeft() - (Window.getScrollLeft() + 10);
    // calculate the right space
    // add 10 because of the shadow and for avoiding that the browser's left window border touches the sub menu
    int rightSpace = Window.getClientWidth() - (item.getAbsoluteLeft() + item.getOffsetWidth() + 10);
    // if the width of the sub menu is smaller than the right space, show the sub menu on the right
    boolean showRight = item.getSubMenu().getOffsetWidth() < rightSpace;
    if (!showRight) {
        // if the width of the sub menu is larger than the right space, compare the left space with the right space
        // and show the sub menu on the right if on the right is more space than on the left
        showRight = leftSpace < rightSpace;
    }

    // calculate the top space
    // add 10 because of the shadow and for avoiding that the browser's top window border touches the sub menu
    int topSpace = item.getAbsoluteTop() - Window.getScrollTop() + 10;
    // calculate the bottom space
    // add 10 because of the shadow and for avoiding that the browser's bottom window border touches the sub menu
    int bottomSpace = Window.getClientHeight() + Window.getScrollTop() - (item.getAbsoluteTop() + 10);
    // if the height of the sub menu is smaller than the bottom space, show the sub menu on the bottom
    boolean showBottom = item.getSubMenu().getOffsetHeight() < bottomSpace;
    if (!showBottom) {
        // if the height of the sub menu is larger than the bottom space, compare the top space with 
        // the bottom space and show the sub menu on the bottom if on the bottom is more space than on the top
        showBottom = topSpace < bottomSpace;
    }

    int left;
    int top;
    if (showRight && showBottom) {
        // bottom-right
        // if to show the sub menu on the right the left coordinate is on the right end of the item, so take the 
        // item's absolute left and add the width of the item / by subtracting 4 the overlay it created
        left = item.getAbsoluteLeft() + item.getOffsetWidth() - 4;
        // if to show the sub menu on the bottom the top coordinate is on the top end of the item, so take the 
        // item's absolute top and subtract the scroll top of Window / by subtracting 4 the shadow is balanced
        top = item.getAbsoluteTop() - Window.getScrollTop() - 4;
    } else if (!showRight && showBottom) {
        // bottom-left
        // if to show the sub menu on the left, the left coordinate is on the left end of the item plus the width 
        // of the sub menu, so take the item's absolute left, subtract the sub menu's width and the scroll left
        // by subtracting 4 the overlay it created
        left = item.getAbsoluteLeft() - item.getSubMenu().getOffsetWidth() - Window.getScrollLeft() - 4;
        // if to show the sub menu on the bottom the top coordinate is on the top end of the item, so take the 
        // item's absolute top and subtract the scroll top of Window / by subtracting 4 the shadow is balanced
        top = item.getAbsoluteTop() - Window.getScrollTop() - 4;
    } else if (showRight && !showBottom) {
        // top-right
        // if to show the sub menu on the right the left coordinate is on the right end of the item, so take the 
        // item's absolute left and add the width of the item / by subtracting 4 the overlay it created
        left = item.getAbsoluteLeft() + item.getOffsetWidth() - 4;
        // if to show the sub menu on the top, the bottom-left corner of the item plus the height of the sub menu
        // is the top coordinate, so take the item's absolute top subtract the scroll top and the height of the sub
        // menu and add the height of the item / by subtracting 4 the shadow is balanced
        top = item.getAbsoluteTop() - Window.getScrollTop() - item.getSubMenu().getOffsetHeight()
                + item.getOffsetHeight() - 4;
    } else {
        // top-left
        // if to show the sub menu on the left, the left coordinate is on the left end of the item plus the width 
        // of the sub menu, so take the item's absolute left, subtract the sub menu's width and the scroll left
        // by subtracting 4 the overlay it created
        left = item.getAbsoluteLeft() - Window.getScrollLeft() - item.getSubMenu().getOffsetWidth() - 4;
        // if to show the sub menu on the top, the bottom-left corner of the item plus the height of the sub menu
        // is the top coordinate, so take the item's absolute top subtract the scroll top and the height of the sub
        // menu and add the height of the item / by subtracting 4 the shadow is balanced
        top = item.getAbsoluteTop() - Window.getScrollTop() - item.getSubMenu().getOffsetHeight()
                + item.getOffsetHeight() - 4;
    }

    // finally set the position of the popup
    m_popup.setPopupPosition(left, top);
}

From source file:org.opencms.gwt.client.ui.input.colorpicker.CmsSliderBar.java

License:Open Source License

/**
 * Fired whenever a browser event is received.<p>
 * @param event Event to process/*from w  ww.  ja v a  2s . c  om*/
 */
@Override
public void onBrowserEvent(Event event) {

    switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEUP:
        Event.releaseCapture(getElement());
        m_capturedMouse = false;
        break;
    case Event.ONMOUSEDOWN:
        Event.setCapture(getElement());
        m_capturedMouse = true;
        //$FALL-THROUGH$
    case Event.ONMOUSEMOVE:
        if (m_capturedMouse) {
            event.preventDefault();
            double abolut_top = getAbsoluteTop();
            int y = ((event.getClientY() - (int) abolut_top) + Window.getScrollTop());
            setSliderPosition(y);
            if (m_parent != null) {
                m_parent.onBarSelected(y);
            }
        }
        //$FALL-THROUGH$
    default:

    }
}

From source file:org.opencms.gwt.client.ui.input.colorpicker.CmsSliderMap.java

License:Open Source License

/**
 * Fired whenever a browser event is received.
 * @param event Event to process//from   ww w .ja  va 2 s  . co m
 */
@Override
public void onBrowserEvent(Event event) {

    super.onBrowserEvent(event);

    switch (DOM.eventGetType(event)) {
    case Event.ONMOUSEUP:
        Event.releaseCapture(m_slider.getElement());
        m_capturedMouse = false;
        break;
    case Event.ONMOUSEDOWN:
        Event.setCapture(m_slider.getElement());
        m_capturedMouse = true;
        //$FALL-THROUGH$
    case Event.ONMOUSEMOVE:
        if (m_capturedMouse) {
            event.preventDefault();
            float x = ((event.getClientX() - (m_colorUnderlay.getAbsoluteLeft())) + Window.getScrollLeft());
            float y = ((event.getClientY() - (m_colorUnderlay.getAbsoluteTop())) + Window.getScrollTop());

            if (m_parent != null) {
                m_parent.onMapSelected(x, y);
            }

            setSliderPosition(x, y);
        }
        //$FALL-THROUGH$
    default:

    }
}

From source file:org.opendatakit.aggregate.client.popups.AbstractPopupBase.java

License:Apache License

public PopupPanel.PositionCallback getPositionCallBack() {
    return new PopupPanel.PositionCallback() {
        @Override//from   w  w  w .  ja  va 2 s.  c  om
        public void setPosition(int offsetWidth, int offsetHeight) {
            int left = Window.getScrollLeft() + ((Window.getClientWidth() - offsetWidth) / 2);
            int top = Window.getScrollTop() + ((Window.getClientHeight() - offsetHeight) / 2);
            setPopupPosition(left, top);
        }
    };
}

From source file:org.opennms.dashboard.client.portlet.Dashboard.java

License:Open Source License

/**
 * <p>//from  www .  ja  v  a2s  . c  o  m
 * error
 * </p>
 * 
 * @param err
 *            a {@link java.lang.String} object.
 */
public void error(String err) {
    final DialogBox dialog = new DialogBox();
    dialog.setText("Error Occurred");

    VerticalPanel panel = new VerticalPanel();
    HTMLPanel html = new HTMLPanel(err);
    html.setStyleName("Message");
    panel.add(html);

    Button ok = new Button("OK");
    SimplePanel buttonPanel = new SimplePanel();
    buttonPanel.setWidget(ok);
    buttonPanel.setStyleName("Button");
    panel.add(buttonPanel);

    dialog.setPopupPosition(Window.getScrollLeft() + 100, Window.getScrollTop() + 100);
    dialog.setWidget(panel);

    ok.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            dialog.hide();
        }

    });

    dialog.show();

}

From source file:org.opennms.features.dashboard.client.portlet.AbsPopup.java

License:Open Source License

public void center() {

    int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
    int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
    RootPanel.get().add(this, Math.max(Window.getScrollLeft() + left, 0),
            Math.max(Window.getScrollTop() + top, 0));
    if (!isVisible()) {
        setVisible(true);//w w  w. ja va  2s.c o  m
    }
}

From source file:org.openremote.app.client.toast.PopupToastDisplay.java

License:Open Source License

@Override
public void show(final Toast toast) {
    final ToastPopupPanel panel = new ToastPopupPanel(toast);

    panel.setPopupPositionAndShow((offsetWidth, offsetHeight) -> {
        int originLeft = Window.getScrollLeft() + Window.getClientWidth() - offsetWidth - MARGIN_RIGHT_PIXEL;
        int originTop = Window.getScrollTop() + Window.getClientHeight() - offsetHeight - MARGIN_BOTTOM_PIXEL;
        setRelativePosition(toastPanels.values(), panel, originLeft, originTop, originTop, offsetHeight,
                offsetWidth);/*from w w w . j a  v  a2  s . c  o m*/
    });

    toastPanels.put(toast, panel);
}

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./* w  ww  .jav a  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 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.pentaho.gwt.widgets.client.dialogs.DialogBox.java

License:Open Source License

protected void block() {
    pageBackground.setSize("100%", Window.getClientHeight() + Window.getScrollTop() + "px"); //$NON-NLS-1$ //$NON-NLS-2$
    pageBackground.setVisible(true);//from   www .  j av  a2  s. co m
    pageBackground.getElement().getStyle().setDisplay(Display.BLOCK);

}

From source file:org.pentaho.gwt.widgets.client.dialogs.ResizableDialogBox.java

License:Open Source License

public ResizableDialogBox(final String headerText, String okText, String cancelText, final Widget content,
        final boolean modal) {
    this.content = content;
    boundaryPanel = new AbsolutePanel() {
        public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            if (!modal && event.getTypeInt() == Event.ONCLICK) {
                hide();//from ww  w .j  av a 2 s .  com
            }
        }
    };
    boundaryPanel.setSize("100%", Window.getClientHeight() + Window.getScrollTop() + "px"); //$NON-NLS-1$ //$NON-NLS-2$
    boundaryPanel.setVisible(true);
    RootPanel.get().add(boundaryPanel, 0, 0);
    boundaryPanel.sinkEvents(Event.ONCLICK);
    boundaryPanel.getElement().getStyle().setProperty("cursor", "wait"); //$NON-NLS-1$ //$NON-NLS-2$

    // initialize window controller which provides drag and resize windows
    WindowController windowController = new WindowController(boundaryPanel);

    // content wrapper
    Button ok = new Button(okText);
    ok.setStylePrimaryName("pentaho-button");
    ok.getElement().setAttribute("id", "okButton"); //$NON-NLS-1$ //$NON-NLS-2$
    ok.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (validatorCallback == null || (validatorCallback != null && validatorCallback.validate())) {
                try {
                    if (callback != null) {
                        callback.okPressed();
                    }
                } catch (Throwable dontCare) {
                    //ignore
                }
                hide();
            }
        }
    });
    final HorizontalPanel dialogButtonPanel = new HorizontalPanel();
    dialogButtonPanel.setSpacing(2);
    dialogButtonPanel.add(ok);
    if (cancelText != null) {
        Button cancel = new Button(cancelText);
        cancel.setStylePrimaryName("pentaho-button");
        cancel.getElement().setAttribute("id", "cancelButton"); //$NON-NLS-1$ //$NON-NLS-2$
        cancel.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                try {
                    if (callback != null) {
                        callback.cancelPressed();
                    }
                } catch (Throwable dontCare) {
                    //ignore
                }
                hide();
            }
        });
        dialogButtonPanel.add(cancel);
    }
    HorizontalPanel dialogButtonPanelWrapper = new HorizontalPanel();
    if (okText != null && cancelText != null) {
        dialogButtonPanelWrapper.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    } else {
        dialogButtonPanelWrapper.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    }
    dialogButtonPanelWrapper.setStyleName("dialogButtonPanel"); //$NON-NLS-1$
    dialogButtonPanelWrapper.setWidth("100%"); //$NON-NLS-1$
    dialogButtonPanelWrapper.add(dialogButtonPanel);

    Grid dialogContent = new Grid(2, 1);
    dialogContent.setCellPadding(0);
    dialogContent.setCellSpacing(0);
    dialogContent.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);
    dialogContent.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_LEFT);
    // add content
    dialogContent.setWidget(0, 0, content);
    dialogContent.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
    // add button panel
    dialogContent.setWidget(1, 0, dialogButtonPanelWrapper);
    dialogContent.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
    dialogContent.setWidth("100%"); //$NON-NLS-1$
    dialogContent.setHeight("100%"); //$NON-NLS-1$

    windowPanel = new WindowPanel(windowController, headerText, dialogContent, true);
}