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

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

Introduction

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

Prototype

public static int getScrollLeft() 

Source Link

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  ww w  .  j  a  va  2s  .  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:ch.unifr.pai.twice.multipointer.client.MouseCursor.java

License:Apache License

/**
 * Reposition the mouse pointer to x and y coordinates
 * //from www .j av a2  s  .c o  m
 * @param x
 * @param y
 */
private void move(int x, int y) {
    this.x = x;
    this.y = y;
    Element e = getElementFromPoint(x, y);
    int shrinkX = x + image.getOffsetWidth() - Window.getClientWidth() - Window.getScrollLeft();
    int shrinkY = y + image.getOffsetHeight() - Window.getClientHeight() - Window.getScrollTop();
    setWidth(Math.max(0, (image.getOffsetWidth() - (shrinkX > 0 ? shrinkX : 0))) + "px");
    setHeight(Math.max(0, (image.getOffsetHeight() - (shrinkY > 0 ? shrinkY : 0))) + "px");
    int clientX = x + Window.getScrollLeft();
    int clientY = y + Window.getScrollTop();
    if (!e.equals(oldElement)) {
        if (oldElement != null)
            fireMouseEvent("mouseout", uuid, color, oldElement, clientX, clientY);
        fireMouseEvent("mouseover", uuid, color, e, clientX, clientY);
    }
    fireMouseEvent("mousemove", uuid, color, e, clientX, clientY);
    oldElement = e;
    getElement().getStyle().setLeft(x, Unit.PX);
    getElement().getStyle().setTop(y, Unit.PX);
    if (storage != null) {
        storage.setItem("ch.unifr.pai.mice.multicursor.position." + fileName + ".x", String.valueOf(x));
        storage.setItem("ch.unifr.pai.mice.multicursor.position." + fileName + ".y", String.valueOf(y));
    }
}

From source file:ch.unifr.pai.twice.multipointer.provider.client.MouseCursor.java

License:Apache License

/**
 * Reposition the mouse pointer to x and y coordinates
 * /*  w  w w .  j av a2 s  .  c o m*/
 * @param event
 */
void move(RemoteMouseMoveEvent event) {
    genericEventHandling(event);
    this.x = event.x;
    this.y = event.y;
    Element e = getElementFromPoint(x, y);
    int shrinkX = x + image.getOffsetWidth() - Window.getClientWidth() - Window.getScrollLeft();
    int shrinkY = y + image.getOffsetHeight() - Window.getClientHeight() - Window.getScrollTop();
    setWidth(Math.max(0, (image.getOffsetWidth() - (shrinkX > 0 ? shrinkX : 0))) + "px");
    setHeight(Math.max(0, (image.getOffsetHeight() - (shrinkY > 0 ? shrinkY : 0))) + "px");
    int clientX = x + Window.getScrollLeft();
    int clientY = y + Window.getScrollTop();
    if (!e.equals(oldElement)) {
        if (oldElement != null)
            fireMouseEvent("mouseout", uuid, color, oldElement, clientX, clientY);
        fireMouseEvent("mouseover", uuid, color, e, clientX, clientY);
    }
    fireMouseEvent("mousemove", uuid, color, e, clientX, clientY);
    oldElement = e;
    getElement().getStyle().setLeft(x, Unit.PX);
    getElement().getStyle().setTop(y, Unit.PX);
    if (storage != null) {
        storage.setItem("ch.unifr.pai.mice.multicursor.position." + fileName + ".x", String.valueOf(x)); //old version mice
        storage.setItem("ch.unifr.pai.mice.multicursor.position." + fileName + ".y", String.valueOf(y)); //old version mice
    }

    show();
}

From source file:ch.unifr.pai.twice.widgets.mpproxy.client.ScreenShotDistributor.java

License:Apache License

/**
 * Send the screenshot to the server/*from   w w  w  . j a v a2  s  .co  m*/
 */
public void sendScreenShot() {
    String screen = Document.get().getDocumentElement().getInnerHTML();
    if (!screen.equals(lastSent) || lastLeft != Window.getScrollLeft() || lastTop != Window.getScrollTop()) {
        String url = Window.Location.getHref();
        URLParser p = new URLParser(url, Rewriter.getServletPath(Window.Location.getHref()));
        RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
                GWT.getModuleBaseURL() + "manager?url=" + p.getProxyBasePath() + "&width="
                        + Window.getClientWidth() + "&height=" + Window.getClientHeight() + "&top="
                        + Window.getScrollTop() + "&left=" + Window.getScrollLeft());
        lastSent = screen;
        lastLeft = Window.getScrollLeft();
        lastTop = Window.getScrollTop();
        screen = screen.replace('\n', ' ');
        screen = screen.replaceAll("<body", "<body><div class=\"readOnlyView\" style=\"width:"
                + Window.getClientWidth() + "; height:" + Window.getClientHeight() + ";\"");
        screen = screen.replaceAll("<\\/body>", "</div></body>");
        screen = screen.replaceAll("(<script).*?(\\/script>)", "");
        try {
            rb.sendRequest(screen, new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onError(Request request, Throwable exception) {
                    Window.alert("Screenshot sent");
                }
            });
        } catch (RequestException e) {
            e.printStackTrace();
        }
    }
}

From source file:co.fxl.gui.gwt.GWTDisplay.java

License:Open Source License

void resetScrollPanelTop() {
    if (isChrome && !scrolling && Window.getScrollTop() != 0) {
        Window.scrollTo(Window.getScrollLeft(), 0);
    }
}

From source file:com.alkacon.acacia.client.ui.InlineEntityWidget.java

License:Open Source License

/**
 * Positions the given pop-up relative to the reference element.<p>
 *///w  ww. j av a2  s  . c om
void positionPopup() {

    if (m_referenceElement != null) {
        PositionBean referencePosition = PositionBean.getInnerDimensions(m_referenceElement);
        int currentTop = m_popup.getAbsoluteTop();
        int windowHeight = Window.getClientHeight();
        int scrollTop = Window.getScrollTop();
        int contentHeight = m_popup.getOffsetHeight();
        int top = referencePosition.getTop();
        if (((windowHeight + scrollTop) < (top + referencePosition.getHeight() + contentHeight + 20))
                && ((contentHeight + 40) < top)) {
            top = top - contentHeight - 5;
            if ((currentTop < top) && ((top - currentTop) < 200)) {
                // keep the current position
                top = currentTop;
            }
        } else {
            top = top + referencePosition.getHeight() + 5;
            if ((currentTop > top) && ((currentTop - top) < 200)) {
                // keep the current position
                top = currentTop;
            }
        }
        m_popup.center();
        m_popup.setPopupPosition(m_popup.getPopupLeft(), top);
        if (((contentHeight + top) - scrollTop) > windowHeight) {
            Window.scrollTo(Window.getScrollLeft(), ((contentHeight + top) - windowHeight) + 20);
        }
    } else {
        m_popup.center();
    }
}

From source file:com.alkacon.geranium.client.dnd.DNDHandler.java

License:Open Source License

/**
 * Execute on mouse wheel event.<p>
 * //from w w  w .  j a v  a  2s .co  m
 * @param event the native event
 */
protected void onMouseWheelScroll(Event event) {

    int scrollStep = event.getMouseWheelVelocityY() * 5;
    Element scrollTarget;
    if (getCurrentTarget() != null) {
        scrollTarget = getCurrentTarget().getElement();
    } else {
        scrollTarget = RootPanel.getBodyElement();
    }
    while ((scrollTarget.getScrollHeight() == scrollTarget.getClientHeight())
            && (scrollTarget != RootPanel.getBodyElement())) {
        scrollTarget = scrollTarget.getParentElement();
    }
    if (scrollTarget == RootPanel.getBodyElement()) {
        int top = Window.getScrollTop() + scrollStep;
        int left = Window.getScrollLeft();
        if (top < 0) {
            top = 0;
        }
        Window.scrollTo(left, top);
    } else {
        int top = scrollTarget.getScrollTop() + scrollStep;
        if (top < 0) {
            top = 0;
        }
        scrollTarget.setScrollTop(top);
    }
    onMove(event);
}

From source file:com.alkacon.geranium.client.dnd.DNDHandler.java

License:Open Source License

/**
 * Convenience method to get the appropriate scroll direction.<p>
 * //from   ww w  . ja va  2s.  c om
 * @param offset the scroll parent border offset, if the cursor is within the border offset, scrolling should be triggered
 * 
 * @return the scroll direction
 */
private Direction getScrollDirection(int offset) {

    if (m_scrollElement == null) {
        Element body = RootPanel.getBodyElement();
        int windowHeight = Window.getClientHeight();
        int bodyHeight = body.getClientHeight();
        if (windowHeight < bodyHeight) {
            if (((windowHeight - m_clientY) < offset)
                    && (Window.getScrollTop() < (bodyHeight - windowHeight))) {
                return Direction.down;
            }
            if ((m_clientY < offset) && (Window.getScrollTop() > 0)) {
                return Direction.up;
            }
        }

        int windowWidth = Window.getClientWidth();
        int bodyWidth = body.getClientWidth();
        if (windowWidth < bodyWidth) {
            if (((windowWidth - m_clientX) < offset) && (Window.getScrollLeft() < (bodyWidth - windowWidth))) {
                return Direction.right;
            }
            if ((m_clientX < offset) && (Window.getScrollLeft() > 0)) {
                return Direction.left;
            }
        }

        return null;
    } else {
        int outerHeight = m_scrollElement.getClientHeight();
        int innerHeight = m_scrollElement.getScrollHeight();
        if (outerHeight < innerHeight) {
            if ((((outerHeight + m_scrollElement.getAbsoluteTop()) - m_clientY) < offset)
                    && (m_scrollElement.getScrollTop() < (innerHeight - outerHeight))) {
                return Direction.down;
            }
            if (((m_clientY - m_scrollElement.getAbsoluteTop()) < offset)
                    && (m_scrollElement.getScrollTop() > 0)) {
                return Direction.up;
            }
        }
        int outerWidth = m_scrollElement.getClientWidth();
        int innerWidth = m_scrollElement.getScrollWidth();
        if (outerWidth < innerWidth) {
            if ((((outerWidth + m_scrollElement.getAbsoluteLeft()) - m_clientX) < offset)
                    && (m_scrollElement.getScrollLeft() < (innerWidth - outerWidth))) {
                return Direction.right;
            }
            if (((m_clientX - m_scrollElement.getAbsoluteLeft()) < offset)
                    && (m_scrollElement.getScrollLeft() > 0)) {
                return Direction.left;
            }
        }
        return null;
    }
}

From source file:com.alkacon.geranium.client.ui.HighlightingBorder.java

License:Open Source License

/**
 * Sets the border position.<p>/* ww w.  j av  a2 s.c  o  m*/
 * 
 * @param height the height
 * @param width the width
 * @param positionLeft the absolute left position
 * @param positionTop the absolute top position
 */
public void setPosition(int height, int width, int positionLeft, int positionTop) {

    positionLeft -= BORDER_OFFSET;

    // make sure highlighting does not introduce additional horizontal scroll-bars
    if ((m_positioningParent == null) && (positionLeft < 0)) {
        // position left should not be negative
        width += positionLeft;
        positionLeft = 0;
    }
    width += (2 * BORDER_OFFSET) - BORDER_WIDTH;
    if ((m_positioningParent == null) && (Window.getClientWidth() < (width + positionLeft))
            && (Window.getScrollLeft() == 0)) {
        // highlighting should not extend over the right hand 
        width = Window.getClientWidth() - (positionLeft + BORDER_WIDTH);
    }
    Style style = getElement().getStyle();
    style.setLeft(positionLeft, Unit.PX);
    style.setTop(positionTop - BORDER_OFFSET, Unit.PX);
    setHeight((height + (2 * BORDER_OFFSET)) - BORDER_WIDTH);
    setWidth(width);
}

From source file:com.alkacon.geranium.client.ui.input.A_SelectBox.java

License:Open Source License

/**
 * Internal method which is called when the selector is opened.<p>
 *//*from  w  ww . j  av  a2s  . com*/
protected void open() {

    if (!m_enabled) {
        return;
    }

    m_openClose.setDown(true);
    if (m_maxCellWidth == 0) {
        initMaxCellWidth();
    }
    int selectorWidth = m_maxCellWidth;
    // should not be any wider than the actual window
    int windowWidth = Window.getClientWidth();
    if (m_maxCellWidth > windowWidth) {
        selectorWidth = windowWidth - 10;
    }
    m_popup.setWidth(selectorWidth + "px");
    m_popup.show();
    int panelTop = m_panel.getElement().getAbsoluteTop();
    int openerHeight = DomUtil.getCurrentStyleInt(m_opener.getElement(), DomUtil.Style.height);
    int popupHeight = m_popup.getOffsetHeight();
    int dx = 0;
    if (selectorWidth > (m_opener.getOffsetWidth() - 2)) {
        int spaceOnTheRight = (Window.getClientWidth() + Window.getScrollLeft()) - m_opener.getAbsoluteLeft()
                - selectorWidth - 2;
        dx = spaceOnTheRight < 0 ? spaceOnTheRight : 0;
    }
    if (((Window.getClientHeight() - (panelTop + openerHeight)) < popupHeight) && (panelTop > popupHeight)) {
        DomUtil.positionElement(m_popup.getElement(), m_panel.getElement(), dx, -(popupHeight - 2));
        m_selectBoxState.setValue(I_LayoutBundle.INSTANCE.generalCss().cornerBottom());
        m_selectorState.setValue(I_LayoutBundle.INSTANCE.generalCss().cornerTop());
    } else {
        DomUtil.positionElement(m_popup.getElement(), m_panel.getElement(), dx, openerHeight);
        m_selectBoxState.setValue(I_LayoutBundle.INSTANCE.generalCss().cornerTop());
        m_selectorState.setValue(I_LayoutBundle.INSTANCE.generalCss().cornerBottom());
    }
    // m_selectBoxState.setValue(CSS.selectBoxOpen());
}