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

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

Introduction

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

Prototype

public static int getClientWidth() 

Source Link

Usage

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

License:Open Source License

/**
 * Shows the dialog and centers it horizontally, but positions it at a fixed vertical position.<p>
 * //  w w w  .jav a 2 s  .  com
 * @param top the top position
 */
public void centerHorizontally(int top) {

    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;
        setPopupPosition(Math.max(left, 0), Math.max(top, 0));
    } else {
        show();
        int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
        setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0));
    }
}

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

License:Open Source License

/**
 * Called on mouse down in the caption area, begins the dragging loop by
 * turning on event capture.//from ww w .  j  av  a  2s  .  c o  m
 * 
 * @see DOM#setCapture
 * @see #continueDragging
 * @param event the mouse down event that triggered dragging
 */
protected void beginDragging(MouseDownEvent event) {

    m_dragging = true;
    m_windowWidth = Window.getClientWidth();
    m_clientLeft = Document.get().getBodyOffsetLeft();
    m_clientTop = Document.get().getBodyOffsetTop();
    DOM.setCapture(getElement());
    m_dragStartX = event.getX();
    m_dragStartY = event.getY();
    addStyleName(I_LayoutBundle.INSTANCE.dialogCss().dragging());
}

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

License:Open Source License

/**
 * Positions the menu popup the button.<p>
 * /*from  www .  j a  v a2 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   w ww  . j av  a 2s.co  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) {
            /*//from w ww  .  ja  va2  s  .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);
    }
}

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

License:Apache License

private void ensureInitialized() {
    scrollPanel.checkMinSize();
    logDockPanel.resize(Window.getClientWidth(), Window.getClientHeight());
}

From source file:com.appspot.codsallarts.client.Application.java

License:Apache License

@Override
protected void onLoad() {
    super.onLoad();
    onWindowResized(Window.getClientWidth(), Window.getClientHeight());
}

From source file:com.apress.progwt.client.widget.datepicker.HDatePicker.java

License:Apache License

protected void showCalendar() {
    calendarPopup.show();// www . ja  v a  2 s.  c o  m
    if (align == HorizontalPanel.ALIGN_RIGHT) {

        // getAbsoluteLeft() is broken in FF for things in our
        // gadgetDisplayer
        // seems to be a known problem, but no good fix. Even FireBug
        // says that the
        // left position is 450px, which is totally wrong.
        //
        // found native method below on forum, but it returns the same
        // thing
        //
        // int left = this.getAbsoluteLeft() - WIDTH;
        int left = Window.getClientWidth() - WIDTH;

        // make sure it doesn't go too low
        int top = this.getAbsoluteTop() + this.getOffsetHeight() + 4;
        top = (Window.getClientHeight() - top > 400) ? top : Window.getClientHeight() - 400;

        calendarPopup.setPopupPosition(left, top);
        Log.debug("SHOW RIGHT " + (this.getAbsoluteLeft() - WIDTH) + " "
                + (this.getAbsoluteTop() + this.getOffsetHeight() + 4));

        // Logger.log("SHOW RIGHT "+getAbsoluteLeft(getElement())+"
        // FIX "+getAbsoluteLeftFix(getElement()));

        calendarPopup.setHeight(120 + "px");
        calendarPopup.setWidth(165 + "px");
        calendarPopup.setStyleName("date_popupPanel");
    } else {
        calendarPopup.setPopupPosition(this.getAbsoluteLeft(),
                this.getAbsoluteTop() + this.getOffsetHeight() + 4);
        calendarPopup.setHeight(120 + "px");
        calendarPopup.setWidth(165 + "px");
        calendarPopup.setStyleName("date_popupPanel");
    }
}

From source file:com.arcbees.gquery.appear.client.Appear.java

License:Apache License

private static boolean isScrolledIntoView(Element e, AppearImpl impl) {
    int docViewTop = Window.getScrollTop();
    int docViewBottom = docViewTop + Window.getClientHeight();
    int docViewLeft = Window.getScrollLeft();
    int docViewRight = docViewLeft + Window.getClientWidth();

    AppearOffset offset = impl.getOptions().getOffset();
    int elemTop = e.getAbsoluteTop() + offset.getTop();
    int elemLeft = e.getAbsoluteLeft() + offset.getLeft();
    int elemBottom = elemTop + e.getOffsetHeight() - offset.getBottom();
    int elemRight = elemLeft + e.getOffsetWidth() - offset.getRight();

    boolean isVerticalVisible = elemTop >= docViewTop && elemBottom <= docViewBottom
            || elemTop <= docViewBottom && elemBottom > docViewBottom
            || elemBottom >= docViewTop && elemTop < docViewTop;

    boolean isHorizontalVisible = elemLeft >= docViewLeft && elemRight <= docViewRight
            || elemLeft <= docViewRight && elemRight > docViewRight
            || elemRight >= docViewLeft && elemLeft < docViewLeft;

    return isVerticalVisible && isHorizontalVisible;
}

From source file:com.arcbees.gquery.tooltip.client.TooltipImpl.java

License:Apache License

private TooltipPlacement ensureTooltipIsVisible(TooltipPlacement originalTooltipPlacement, OffsetInfo oi,
        long actualHeight, long actualWidth) {
    long bound;//from   www . j  a  v  a2s  .c om

    switch (originalTooltipPlacement) {
    case TOP:
        bound = oi.top - actualHeight;

        if (bound < 0) {
            return TooltipPlacement.BOTTOM;
        }

        break;
    case BOTTOM:
        bound = oi.top + oi.height + actualHeight;

        if (bound > Window.getClientHeight()) {
            return TooltipPlacement.TOP;
        }

        break;
    case LEFT:
        bound = oi.left - actualWidth;

        if (bound < 0) {
            return TooltipPlacement.RIGHT;
        }

        break;
    case RIGHT:
        bound = oi.left + oi.width;

        if (bound > Window.getClientWidth()) {
            return TooltipPlacement.LEFT;
        }

        break;
    default:
        throw new RuntimeException("unknown or null TooltipPlacement");
    }

    return originalTooltipPlacement;
}