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

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

Introduction

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

Prototype

public static int getClientHeight() 

Source Link

Usage

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

License:Open Source License

/**
 * Checks whether the submenu should be opened above instead of below.<p>
 * /*from  ww w .  ja va2  s.c om*/
 * @param referenceElement the reference element 
 * @return true if the new submenu should be opened above 
 */
public boolean openAbove(Element referenceElement) {

    int windowTop = Window.getScrollTop();
    int windowBottom = Window.getScrollTop() + Window.getClientHeight();
    int spaceAbove = referenceElement.getAbsoluteTop() - windowTop;
    int spaceBelow = windowBottom - referenceElement.getAbsoluteBottom();
    return spaceAbove > spaceBelow;
}

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

License:Open Source License

/**
 * Sets position and size of the overlay area.<p>
 * //  ww w  .  ja v a2  s.c om
 * @param posX the new X position
 * @param posY the new Y position
 * @param height the new height
 * @param width the new width
 */
private void setSelectPosition(int posX, int posY, int height, int width) {

    int useWidth = Window.getClientWidth();
    int bodyWidth = RootPanel.getBodyElement().getClientWidth() + RootPanel.getBodyElement().getOffsetLeft();
    if (bodyWidth > useWidth) {
        useWidth = bodyWidth;
    }
    int useHeight = Window.getClientHeight();
    int bodyHeight = RootPanel.getBodyElement().getClientHeight() + RootPanel.getBodyElement().getOffsetTop();
    if (bodyHeight > useHeight) {
        useHeight = bodyHeight;
    }

    m_overlayLeftStyle.setWidth(posX - m_offset, Unit.PX);
    m_overlayLeftStyle.setHeight(useHeight, Unit.PX);

    m_borderLeftStyle.setHeight(height + (2 * m_offset), Unit.PX);
    m_borderLeftStyle.setTop(posY - (2 * m_offset), Unit.PX);
    m_borderLeftStyle.setLeft(posX - (2 * m_offset), Unit.PX);

    m_overlayTopStyle.setLeft(posX - m_offset, Unit.PX);
    m_overlayTopStyle.setWidth(width + (2 * m_offset), Unit.PX);
    m_overlayTopStyle.setHeight(posY - m_offset, Unit.PX);

    m_borderTopStyle.setLeft(posX - m_offset, Unit.PX);
    m_borderTopStyle.setTop(posY - (2 * m_offset), Unit.PX);
    if (m_hasButtonBar) {
        m_borderTopStyle.setWidth(width + (2 * m_offset) + BUTTON_BAR_WIDTH, Unit.PX);
    } else {
        m_borderTopStyle.setWidth(width + (2 * m_offset), Unit.PX);
    }

    m_overlayBottomStyle.setLeft(posX - m_offset, Unit.PX);
    m_overlayBottomStyle.setWidth(width + m_offset + m_offset, Unit.PX);
    m_overlayBottomStyle.setHeight(useHeight - posY - height - m_offset, Unit.PX);
    m_overlayBottomStyle.setTop(posY + height + m_offset, Unit.PX);

    m_borderBottomStyle.setLeft(posX - m_offset, Unit.PX);
    m_borderBottomStyle.setTop((posY + height) + m_offset, Unit.PX);
    if (m_hasButtonBar) {
        m_borderBottomStyle.setWidth(width + (2 * m_offset) + BUTTON_BAR_WIDTH, Unit.PX);
    } else {
        m_borderBottomStyle.setWidth(width + (2 * m_offset), Unit.PX);
    }

    m_overlayRightStyle.setLeft(posX + width + m_offset, Unit.PX);
    m_overlayRightStyle.setWidth(useWidth - posX - width - m_offset, Unit.PX);
    m_overlayRightStyle.setHeight(useHeight, Unit.PX);

    m_borderRightStyle.setHeight(height + (2 * m_offset), Unit.PX);
    m_borderRightStyle.setTop(posY - (2 * m_offset), Unit.PX);
    if (m_hasButtonBar) {
        m_borderRightStyle.setLeft(posX + width + m_offset + BUTTON_BAR_WIDTH, Unit.PX);
    } else {
        m_borderRightStyle.setLeft(posX + width + m_offset, Unit.PX);
    }

    m_buttonBar.getStyle().setTop(posY - m_offset, Unit.PX);
    m_buttonBar.getStyle().setHeight(height + (2 * m_offset), Unit.PX);
    m_buttonBar.getStyle().setLeft(posX + width + m_offset + 1, Unit.PX);
}

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 .ja  va 2s.  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

/**
 * Convenience method to get the appropriate scroll direction.<p>
 * /*from w  w  w.  j  a v  a 2  s  . 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.input.A_SelectBox.java

License:Open Source License

/**
 * Internal method which is called when the selector is opened.<p>
 *///from  w  w w .j a v a2 s  .  c o m
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());
}

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

License:Open Source License

/**
 * @see com.google.gwt.user.client.ui.PopupPanel#center()
 *///from   w w w  .ja  va 2 s .c  o  m
@Override
public void center() {

    if (Position.FIXED.getCssName().equals(getElement().getStyle().getPosition())) {
        show();
        // keep position fixed, as may have been set to absolute
        setPositionFixed();
        int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
        int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
        setPopupPosition(Math.max(left, 0), Math.max(top, 0));
    } else {
        super.center();
        if (m_resizeHandlerRegistration == null) {
            m_resizeHandlerRegistration = Window.addResizeHandler(new ResizeHandler() {

                public void onResize(ResizeEvent event) {

                    m_windowWidth = event.getWidth();
                }
            });
        }
    }
}

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

License:Open Source License

/**
 * Returns the maximum available height inside the popup.<p>
 * //  ww w.  j a v  a2 s  .  c om
 * @param fixedContentHeight fixed content height to deduct from the available height
 * 
 * @return the maximum available height
 */
public int getAvailableHeight(int fixedContentHeight) {

    if (m_buttonPanel.isVisible()) {
        fixedContentHeight += m_buttonPanel.getOffsetHeight();
    }
    return Window.getClientHeight() - 150 - fixedContentHeight;
}

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

License:Open Source License

/**
 * Positions the menu popup the button.<p>
 * //from  w  ww .  j a  v a 2 s  .c o  m
 * @param popup the popup to position 
 * @param button the toolbar button
 * @param toolbarWidth the width of the toolbar
 * @param isToolbarMode a flag indicating whether the button is in toolbar mode
 * @param arrow the arrow shaped connector element  
 */
protected static void positionPopup(Popup popup, Widget button, int toolbarWidth, boolean isToolbarMode,
        Element arrow) {

    int spaceAssurance = 20;
    int space = toolbarWidth + (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
    PositionBean buttonPosition = PositionBean.generatePositionInfo(button.getElement());
    int buttonMiddle = (buttonPosition.getLeft() - Window.getScrollLeft()) + (buttonPosition.getWidth() / 2);
    // get the content width
    int contentWidth = 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_LayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getWidth();
    int arrowHeight = I_LayoutBundle.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_LayoutBundle.INSTANCE.dialogCss().menuArrowTop();

    int contentTop = (((buttonPosition.getTop() + buttonPosition.getHeight()) - Window.getScrollTop())
            + arrowHeight) - 2;
    if (!isToolbarMode) {
        contentTop = (buttonPosition.getTop() + buttonPosition.getHeight() + arrowHeight) - 2;
        int contentHeight = 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_LayoutBundle.INSTANCE.dialogCss().menuArrowBottom();
        }
    } else {
        contentLeft = contentLeft - Window.getScrollLeft();
        popup.setPositionFixed();
    }

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

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

From source file:com.alkacon.geranium.client.util.ToolTipHandler.java

License:Open Source License

/** 
 * Sets the tool-tip position.<p>/*from www  .  ja v a 2  s .c  o  m*/
 * 
 * @param absLeft the mouse pointer absolute left
 * @param absTop the mouse pointer absolute top
 */
private void setToolTipPosition(int absLeft, int absTop) {

    if (m_toolTip != null) {
        int height = m_toolTip.getOffsetHeight();
        int width = m_toolTip.getOffsetWidth();
        int windowHeight = Window.getClientHeight();
        int windowWidth = Window.getClientWidth();
        int left = absLeft + m_offsetLeft;
        if ((left + width) > windowWidth) {
            left = windowWidth - m_offsetLeft - width;
        }
        m_toolTip.getStyle().setLeft(left, Unit.PX);
        int top = absTop + m_offsetTop;
        if (((top + height) > windowHeight) && ((height + m_offsetTop) < absTop)) {
            top = absTop - m_offsetTop - height;
        }
        m_toolTip.getStyle().setTop(top, Unit.PX);
    }
}

From source file:com.allen_sauer.gwt.log.client.DivLogger.java

License:Apache License

@Override
public void log(LogRecord record) {
    String text = record.getFormattedMessage().replaceAll("<", "&lt;").replaceAll(">", "&gt;");
    String title = makeTitle(record);
    Throwable throwable = record.getThrowable();
    if (throwable != null) {
        while (throwable != null) {
            /*//w w  w  . ja v a2s  .c o  m
             * Use throwable.toString() and not throwable.getClass().getName() and
             * throwable.getMessage(), so that instances of UnwrappedClientThrowable, when stack trace
             * deobfuscation is enabled) display properly
             */
            text += "<b>" + throwable.toString() + "</b>";
            StackTraceElement[] stackTraceElements = throwable.getStackTrace();
            if (stackTraceElements.length > 0) {
                text += "<div class='log-stacktrace'>";
                for (StackTraceElement element : stackTraceElements) {
                    text += STACKTRACE_ELEMENT_PREFIX + element + "<br>";
                }
                text += "</div>";
            }
            throwable = throwable.getCause();
            if (throwable != null) {
                text += "Caused by: ";
            }
        }
    }
    text = text.replaceAll("\r\n|\r|\n", "<BR>");
    addLogText("<div class='" + LogClientBundle.INSTANCE.css().logMessage()
            + "' onmouseover='className+=\" log-message-hover\"' "
            + "onmouseout='className=className.replace(/ log-message-hover/g,\"\")' style='color: "
            + getColor(record.getLevel()) + "' title='" + title + "'>" + text + "</div>");

    // Intended to run the first time a message is logged
    if (!logDockPanel.isAttached()) {
        ensureInitialized();

        // Attach dock panel to the bottom of the window
        logDockPanel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
        moveTo(0, 0);
        int x = Math.max(0, (Window.getClientWidth() - logDockPanel.getOffsetWidth()) / 2);
        int y = Math.max(0, Window.getClientHeight() - logDockPanel.getOffsetHeight());
        moveTo(x, y);
        logDockPanel.getElement().getStyle().setVisibility(Visibility.VISIBLE);
    }
}