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:org.opencms.ade.containerpage.client.ui.groupeditor.A_CmsGroupEditor.java

License:Open Source License

/**
 * Opens the group container edit dialog.<p>
 *
 * @param dialogTitle the dialog title/*ww w  .  j  a  v a2  s. c  o  m*/
 */
protected void openDialog(String dialogTitle) {

    m_editorDialog.setCaption(dialogTitle);
    int contentHeight = m_dialogContent.getOffsetHeight();
    m_editorDialog.setMainContent(m_dialogContent);
    // position dialog and show it
    if (m_groupContainerPosition != null) {
        int lefthandSpace = m_groupContainerPosition.getLeft() - Window.getScrollLeft();
        int righthandSpace = (Window.getClientWidth() + Window.getScrollLeft())
                - (m_groupContainerPosition.getLeft() + m_groupContainerPosition.getWidth());
        int requiredWidth = CmsPopup.DEFAULT_WIDTH + 30;
        int left = m_groupContainerPosition.getLeft();
        if (requiredWidth > (righthandSpace + m_groupContainerPosition.getWidth())) {
            left = (Window.getClientWidth() + Window.getScrollLeft()) - requiredWidth;
        }
        if (left < Window.getScrollLeft()) {
            left = 0;
        }
        if (lefthandSpace > requiredWidth) {
            // place left of the group container if there is enough space
            m_editorDialog.setPopupPosition(m_groupContainerPosition.getLeft() - requiredWidth,
                    m_groupContainerPosition.getTop() - 1);
        } else if ((m_groupContainerPosition.getTop() - Window.getScrollTop()) > (contentHeight
                + DIALOG_BASE_HEIGHT + 50)) {
            // else place above if there is enough space

            m_editorDialog.setPopupPosition(left,
                    m_groupContainerPosition.getTop() - (contentHeight + DIALOG_BASE_HEIGHT));
        } else if (righthandSpace > requiredWidth) {
            // else on the right if there is enough space
            m_editorDialog.setPopupPosition(
                    m_groupContainerPosition.getLeft() + m_groupContainerPosition.getWidth() + 20,
                    m_groupContainerPosition.getTop() - 1);
        } else {
            // last resort, place below
            m_editorDialog.setPopupPosition(left,
                    m_groupContainerPosition.getTop() + m_groupContainerPosition.getHeight() + 20);
        }
        m_editorDialog.show();
    } else {
        // should never happen
        m_editorDialog.center();
    }
    if (!m_controller.getData().isUseClassicEditor()) {
        for (Widget element : m_groupContainer) {
            if (element instanceof CmsContainerPageElementPanel) {
                ((CmsContainerPageElementPanel) element).initInlineEditor(m_controller);
            }
        }
    }
}

From source file:org.opencms.gwt.client.dnd.CmsDNDHandler.java

License:Open Source License

/**
 * Convenience method to get the appropriate scroll direction.<p>
 * //  w  w  w.j a  v  a 2 s .co  m
 * @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) {

    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;
}

From source file:org.opencms.gwt.client.ui.CmsHighlightingBorder.java

License:Open Source License

/**
 * Sets the border position.<p>//from  w  w w.j a v a2 s .  c om
 * 
 * @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 (positionLeft < 0) {
        // position left should not be negative
        width += positionLeft;
        positionLeft = 0;
    }
    width += (2 * BORDER_OFFSET) - BORDER_WIDTH;
    if ((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:org.opencms.gwt.client.ui.CmsMenuButton.java

License:Open Source License

/**
 * Positions the menu popup the button.<p>
 *//*  w  w w  .jav  a2 s .  c o  m*/
protected void positionPopup() {

    int spaceAssurance = 20;
    int space = getToolbarWidth() + (2 * spaceAssurance);

    // get the window client width
    int windowWidth = Window.getClientWidth();
    // get the min left position
    int minLeft = (windowWidth - space) / 2;
    if (minLeft < spaceAssurance) {
        minLeft = spaceAssurance;
    }
    // get the max right position
    int maxRight = minLeft + space;
    // get the middle button position
    CmsPositionBean buttonPosition = CmsPositionBean.generatePositionInfo(m_button.getElement());
    int buttonMiddle = (buttonPosition.getLeft() - Window.getScrollLeft()) + (buttonPosition.getWidth() / 2);
    // get the content width
    int contentWidth = m_popup.getOffsetWidth();

    // the optimum left position is in the middle of the button minus the half content width
    // assume that the optimum fits into the space
    int contentLeft = buttonMiddle - (contentWidth / 2);

    if (minLeft > contentLeft) {
        // if the optimum left position of the popup is outside the min left position:
        // move the popup to the right (take the min left position as left)
        contentLeft = minLeft;
    } else if ((contentLeft + contentWidth) > maxRight) {
        // if the left position plus the content width is outside the max right position:
        // move the popup to the left (take the max right position minus the content width)
        contentLeft = maxRight - contentWidth;
    }

    // limit the right position if the popup is right outside the window 
    if ((contentLeft + contentWidth + spaceAssurance) > windowWidth) {
        contentLeft = windowWidth - contentWidth - spaceAssurance;
    }

    // limit the left position if the popup is left outside the window 
    if (contentLeft < spaceAssurance) {
        contentLeft = spaceAssurance;
    }

    int arrowSpace = 10;
    int arrowWidth = I_CmsLayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getWidth();
    int arrowHeight = I_CmsLayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getHeight();

    // the optimum position for the arrow is in the middle of the button
    int arrowLeft = buttonMiddle - contentLeft - (arrowWidth / 2);
    if ((arrowLeft + arrowWidth + arrowSpace) > contentWidth) {
        // limit the arrow position if the maximum is reached (content width 'minus x')
        arrowLeft = contentWidth - arrowWidth - arrowSpace;
    } else if ((arrowLeft - arrowSpace) < 0) {
        // limit the arrow position if the minimum is reached ('plus x')
        arrowLeft = arrowWidth + arrowSpace;
    }

    int arrowTop = -(arrowHeight - 2);
    String arrowClass = I_CmsLayoutBundle.INSTANCE.dialogCss().menuArrowTop();

    int contentTop = (((buttonPosition.getTop() + buttonPosition.getHeight()) - Window.getScrollTop())
            + arrowHeight) - 2;
    if (!m_isToolbarMode) {
        contentTop = (buttonPosition.getTop() + buttonPosition.getHeight() + arrowHeight) - 2;
        int contentHeight = m_popup.getOffsetHeight();
        int windowHeight = Window.getClientHeight();

        if (((contentHeight + spaceAssurance) < windowHeight)
                && ((buttonPosition.getTop() - Window.getScrollTop()) > contentHeight)
                && (((contentHeight + spaceAssurance + contentTop) - Window.getScrollTop()) > windowHeight)) {
            // content fits into the window height, 
            // there is enough space above the button 
            // and there is to little space below the button
            // so show above
            contentTop = ((buttonPosition.getTop() - arrowHeight) + 2) - contentHeight;
            arrowTop = contentHeight - 1;
            arrowClass = I_CmsLayoutBundle.INSTANCE.dialogCss().menuArrowBottom();
        }
    } else {
        contentLeft = contentLeft - Window.getScrollLeft();
        m_popup.setPositionFixed();
    }

    m_arrow.setClassName(arrowClass);
    m_arrow.getStyle().setLeft(arrowLeft, Unit.PX);
    m_arrow.getStyle().setTop(arrowTop, Unit.PX);

    m_popup.showArrow(m_arrow);
    m_popup.setPopupPosition(contentLeft + Window.getScrollLeft(), contentTop);
}

From source file:org.opencms.gwt.client.ui.CmsPopup.java

License:Open Source License

/**
 * Shows the dialog and centers it horizontally, but positions it at a fixed vertical position.<p>
 * //from   w ww  . j a  v a  2s .c o m
 * @param top the top position
 */
public void centerHorizontally(int top) {

    show();
    int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
    setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0));
}

From source file:org.opencms.gwt.client.ui.CmsScrollBar.java

License:Open Source License

/**
 * Returns <code>true</code> if the events mouse position is above the scroll bar knob.<p>
 *
 * @param event the mouse event//  www .j  a v  a2  s.c  o m
 *
 * @return <code>true</code> if the events mouse position is above the scroll bar knob
 */
private boolean sliderClicked(Event event) {

    boolean result = CmsPositionBean.generatePositionInfo(m_knob).isOverElement(
            event.getClientX() + Window.getScrollLeft(), event.getClientY() + Window.getScrollTop());
    CmsDebugLog.getInstance().printLine("Slider was clicked: " + result);
    return result;
}

From source file:org.opencms.gwt.client.ui.CmsShowWorkplace.java

License:Open Source License

/**
 * Opens the workplace.<p>/*from   www  .j a  va2 s  . c  o  m*/
 * 
 * @param structureId the structure id of the resource for which the workplace should be opened 
 */
protected static void openWorkplace(final CmsUUID structureId) {

    CmsRpcAction<String> callback = new CmsRpcAction<String>() {

        /**
         * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute()
         */
        @Override
        public void execute() {

            CmsCoreProvider.getService().getWorkplaceLink(structureId, this);
        }

        /**
         * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object)
         */
        @Override
        protected void onResponse(String result) {

            int width = Window.getClientWidth();
            int height = Window.getClientHeight();
            int left = Window.getScrollLeft();
            int top = Window.getScrollTop();

            openWorkplace(result, width, height, left, top);
        }
    };
    callback.execute();
}

From source file:org.opencms.gwt.client.ui.CmsToolbarPopup.java

License:Open Source License

/**
 * Positions the popup below the toolbar button.<p>
 *///from   w w  w. j a  v a 2  s  .  c  o m
public void position() {

    // get the window client width
    int windowWidth = Window.getClientWidth();
    // get the min left position
    int minLeft = MIN_MARGIN;

    // get the max right position
    int maxRight = windowWidth - MIN_MARGIN;
    // get the middle button position
    CmsPositionBean buttonPosition = CmsPositionBean.generatePositionInfo(m_button.getElement());
    int buttonMiddle = (buttonPosition.getLeft() - Window.getScrollLeft()) + (buttonPosition.getWidth() / 2);
    // get the content width
    int contentWidth = getOffsetWidth();

    // the optimum left position is in the middle of the button minus the half content width
    // assume that the optimum fits into the space
    int contentLeft = buttonMiddle - (contentWidth / 2);

    if (minLeft > contentLeft) {
        // if the optimum left position of the popup is outside the min left position:
        // move the popup to the right (take the min left position as left)
        contentLeft = minLeft;
    } else if ((contentLeft + contentWidth) > maxRight) {
        // if the left position plus the content width is outside the max right position:
        // move the popup to the left (take the max right position minus the content width)
        contentLeft = maxRight - contentWidth;
    }

    // limit the right position if the popup is right outside the window
    if ((contentLeft + contentWidth + MIN_MARGIN) > windowWidth) {
        contentLeft = windowWidth - contentWidth - MIN_MARGIN;
    }

    // limit the left position if the popup is left outside the window
    if (contentLeft < MIN_MARGIN) {
        contentLeft = MIN_MARGIN;
    }

    int arrowSpace = 10;
    int arrowWidth = 40;
    int arrowHeight = 12;

    // the optimum position for the arrow is in the middle of the button
    int arrowLeft = buttonMiddle - contentLeft - (arrowWidth / 2);
    if ((arrowLeft + arrowWidth + arrowSpace) > contentWidth) {
        // limit the arrow position if the maximum is reached (content width 'minus x')
        arrowLeft = contentWidth - arrowWidth - arrowSpace;
    } else if ((arrowLeft - arrowSpace) < 0) {
        // limit the arrow position if the minimum is reached ('plus x')
        arrowLeft = arrowWidth + arrowSpace;
    }

    int arrowTop = -(arrowHeight - 2);
    String arrowClass = I_CmsLayoutBundle.INSTANCE.dialogCss().menuArrowTop();

    int contentTop = (((buttonPosition.getTop() + buttonPosition.getHeight()) - Window.getScrollTop())
            + arrowHeight) - 2;
    if (!m_isToolbarMode) {
        contentTop = (buttonPosition.getTop() + buttonPosition.getHeight() + arrowHeight) - 2;
        int contentHeight = getOffsetHeight();
        int windowHeight = Window.getClientHeight();

        if (((contentHeight + MIN_MARGIN) < windowHeight)
                && ((buttonPosition.getTop() - Window.getScrollTop()) > contentHeight)
                && (((contentHeight + MIN_MARGIN + contentTop) - Window.getScrollTop()) > windowHeight)) {
            // content fits into the window height,
            // there is enough space above the button
            // and there is to little space below the button
            // so show above
            contentTop = ((buttonPosition.getTop() - arrowHeight) + 2) - contentHeight;
            arrowTop = contentHeight - 1;
            arrowClass = I_CmsLayoutBundle.INSTANCE.dialogCss().menuArrowBottom();
        }
    } else {
        contentLeft = contentLeft - Window.getScrollLeft();
        setPositionFixed();
    }

    m_arrow.setClassName(arrowClass);
    m_arrow.getStyle().setLeft(arrowLeft, Unit.PX);
    m_arrow.getStyle().setTop(arrowTop, Unit.PX);

    showArrow(m_arrow);
    setPopupPosition(contentLeft + Window.getScrollLeft(), contentTop);
}

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 w  w w  .  j a  v  a  2s .c o m*/
 * 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.CmsSliderMap.java

License:Open Source License

/**
 * Fired whenever a browser event is received.
 * @param event Event to process//from   ww  w  .  j  a v a2 s. c  o 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:

    }
}