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.vaadin.client.VDebugConsole.java

License:Apache License

private void setToDefaultSizeAndPos() {
    String cookie = Cookies.getCookie(POS_COOKIE_NAME);
    int width, height, top, left;
    boolean autoScrollValue = false;
    if (cookie != null) {
        String[] split = cookie.split(",");
        left = Integer.parseInt(split[0]);
        top = Integer.parseInt(split[1]);
        width = Integer.parseInt(split[2]);
        height = Integer.parseInt(split[3]);
        autoScrollValue = Boolean.valueOf(split[4]);
    } else {// w  ww. j a v  a  2 s.com
        int windowHeight = Window.getClientHeight();
        int windowWidth = Window.getClientWidth();
        width = DEFAULT_WIDTH;
        height = DEFAULT_HEIGHT;

        if (height > windowHeight / 2) {
            height = windowHeight / 2;
        }
        if (width > windowWidth / 2) {
            width = windowWidth / 2;
        }

        top = windowHeight - (height + 10);
        left = windowWidth - (width + 10);
    }
    setPixelSize(width, height);
    setPopupPosition(left, top);
    autoScroll.setValue(autoScrollValue);
}

From source file:com.vaadin.client.VTooltip.java

License:Apache License

/**
 * Show a popup containing the currentTooltipInfo
 * //from  w  w w. j a v a  2s  .  com
 */
private void showTooltip() {
    if (currentTooltipInfo.hasMessage()) {
        // Issue #8454: With IE7 the tooltips size is calculated based on
        // the last tooltip's position, causing problems if the last one was
        // in the right or bottom edge. For this reason the tooltip is moved
        // first to 0,0 position so that the calculation goes correctly.
        setPopupPosition(0, 0);

        setPopupPositionAndShow(new PositionCallback() {
            @Override
            public void setPosition(int offsetWidth, int offsetHeight) {

                if (offsetWidth > getMaxWidth()) {
                    setWidth(getMaxWidth() + "px");

                    // Check new height and width with reflowed content
                    offsetWidth = getOffsetWidth();
                    offsetHeight = getOffsetHeight();
                }

                int x = 0;
                int y = 0;
                if (BrowserInfo.get().isTouchDevice()) {
                    setMaxWidth(Window.getClientWidth());
                    offsetWidth = getOffsetWidth();
                    offsetHeight = getOffsetHeight();

                    x = getFinalTouchX(offsetWidth);
                    y = getFinalTouchY(offsetHeight);
                } else {
                    x = getFinalX(offsetWidth);
                    y = getFinalY(offsetHeight);
                }

                setPopupPosition(x, y);
                sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT);
            }

            /**
             * Return the final X-coordinate of the tooltip based on cursor
             * position, size of the tooltip, size of the page and necessary
             * margins.
             * 
             * @param offsetWidth
             * @return The final X-coordinate
             */
            private int getFinalX(int offsetWidth) {
                int x = 0;
                int widthNeeded = 10 + MARGIN + offsetWidth;
                int roomLeft = tooltipEventMouseX;
                int roomRight = Window.getClientWidth() - roomLeft;
                if (roomRight > widthNeeded) {
                    x = tooltipEventMouseX + 10 + Window.getScrollLeft();
                } else {
                    x = tooltipEventMouseX + Window.getScrollLeft() - 10 - offsetWidth;
                }
                if (x + offsetWidth + MARGIN - Window.getScrollLeft() > Window.getClientWidth()) {
                    x = Window.getClientWidth() - offsetWidth - MARGIN + Window.getScrollLeft();
                }

                if (tooltipEventMouseX != EVENT_XY_POSITION_OUTSIDE) {
                    // Do not allow x to be zero, for otherwise the tooltip
                    // does not close when the mouse is moved (see
                    // isTooltipOpen()). #15129
                    int minX = Window.getScrollLeft() + MARGIN;
                    x = Math.max(x, minX);
                }
                return x;
            }

            /**
             * Return the final X-coordinate of the tooltip based on cursor
             * position, size of the tooltip, size of the page and necessary
             * margins.
             *
             * @param offsetWidth
             * @return The final X-coordinate
             */
            private int getFinalTouchX(int offsetWidth) {
                int x = 0;
                int widthNeeded = 10 + offsetWidth;
                int roomLeft = currentElement != null ? currentElement.getAbsoluteLeft()
                        : EVENT_XY_POSITION_OUTSIDE;
                int viewPortWidth = Window.getClientWidth();
                int roomRight = viewPortWidth - roomLeft;
                if (roomRight > widthNeeded) {
                    x = roomLeft;
                } else {
                    x = roomLeft - offsetWidth;
                }
                if (x + offsetWidth - Window.getScrollLeft() > viewPortWidth) {
                    x = viewPortWidth - offsetWidth + Window.getScrollLeft();
                }

                if (roomLeft != EVENT_XY_POSITION_OUTSIDE) {
                    // Do not allow x to be zero, for otherwise the tooltip
                    // does not close when the mouse is moved (see
                    // isTooltipOpen()). #15129
                    int minX = Window.getScrollLeft();
                    x = Math.max(x, minX);
                }
                return x;
            }

            /**
             * Return the final Y-coordinate of the tooltip based on cursor
             * position, size of the tooltip, size of the page and necessary
             * margins.
             * 
             * @param offsetHeight
             * @return The final y-coordinate
             * 
             */
            private int getFinalY(int offsetHeight) {
                int y = 0;
                int heightNeeded = 10 + offsetHeight;
                int roomAbove = tooltipEventMouseY;
                int roomBelow = Window.getClientHeight() - roomAbove;

                if (roomBelow > heightNeeded) {
                    y = tooltipEventMouseY + 10 + Window.getScrollTop();
                } else {
                    y = tooltipEventMouseY + Window.getScrollTop() - 10 - offsetHeight;
                }

                if (y + offsetHeight + MARGIN - Window.getScrollTop() > Window.getClientHeight()) {
                    y = tooltipEventMouseY - 5 - offsetHeight + Window.getScrollTop();
                    if (y - Window.getScrollTop() < 0) {
                        // tooltip does not fit on top of the mouse either,
                        // put it at the top of the screen
                        y = Window.getScrollTop();
                    }
                }

                if (tooltipEventMouseY != EVENT_XY_POSITION_OUTSIDE) {
                    // Do not allow y to be zero, for otherwise the tooltip
                    // does not close when the mouse is moved (see
                    // isTooltipOpen()). #15129
                    int minY = Window.getScrollTop() + MARGIN;
                    y = Math.max(y, minY);
                }
                return y;
            }

            /**
             * Return the final Y-coordinate of the tooltip based on cursor
             * position, size of the tooltip, size of the page and necessary
             * margins.
             *
             * @param offsetHeight
             * @return The final y-coordinate
             *
             */
            private int getFinalTouchY(int offsetHeight) {
                int y = 0;
                int heightNeeded = 10 + offsetHeight;
                int roomAbove = currentElement != null
                        ? currentElement.getAbsoluteTop() + currentElement.getOffsetHeight()
                        : EVENT_XY_POSITION_OUTSIDE;
                int roomBelow = Window.getClientHeight() - roomAbove;

                if (roomBelow > heightNeeded) {
                    y = roomAbove;
                } else {
                    y = roomAbove - offsetHeight
                            - (currentElement != null ? currentElement.getOffsetHeight() : 0);
                }

                if (y + offsetHeight - Window.getScrollTop() > Window.getClientHeight()) {
                    y = roomAbove - 5 - offsetHeight + Window.getScrollTop();
                    if (y - Window.getScrollTop() < 0) {
                        // tooltip does not fit on top of the mouse either,
                        // put it at the top of the screen
                        y = Window.getScrollTop();
                    }
                }

                if (roomAbove != EVENT_XY_POSITION_OUTSIDE) {
                    // Do not allow y to be zero, for otherwise the tooltip
                    // does not close when the mouse is moved (see
                    // isTooltipOpen()). #15129
                    int minY = Window.getScrollTop();
                    y = Math.max(y, minY);
                }
                return y;
            }
        });
    } else {
        hide();
    }
}

From source file:com.vaadin.client.widgets.Overlay.java

License:Apache License

/**
 * Gets the visual viewport width, which is useful for e.g iOS where the
 * view can be zoomed in while keeping the layout viewport intact.
 * /*from   w  w  w  .  jav a 2 s .  c  o m*/
 * Falls back to layout viewport; for those browsers/devices the difference
 * is that the scrollbar with is included (if there is a scrollbar).
 * 
 * @since 7.0.7
 * @return
 */
private int getVisualViewportWidth() {
    int w = (int) getSubpixelInnerWidth();
    if (w < 0) {
        return Window.getClientWidth();
    } else {
        return w;
    }
}

From source file:com.vaadin.terminal.gwt.client.ApplicationConnection.java

License:Open Source License

/**
 * Converts relative sizes into pixel sizes.
 * //from  w  ww.  j a va2 s  .  c  o  m
 * @param child
 * @return true if the child has a relative size
 */
private boolean handleComponentRelativeSize(ComponentDetail cd) {
    if (cd == null) {
        return false;
    }
    boolean debugSizes = false;

    FloatSize relativeSize = cd.getRelativeSize();
    if (relativeSize == null) {
        return false;
    }
    Widget widget = (Widget) cd.getComponent();

    boolean horizontalScrollBar = false;
    boolean verticalScrollBar = false;

    Container parent = Util.getLayout(widget);
    RenderSpace renderSpace;

    // Parent-less components (like sub-windows) are relative to browser
    // window.
    if (parent == null) {
        renderSpace = new RenderSpace(Window.getClientWidth(), Window.getClientHeight());
    } else {
        renderSpace = parent.getAllocatedSpace(widget);
    }

    if (relativeSize.getHeight() >= 0) {
        if (renderSpace != null) {

            if (renderSpace.getScrollbarSize() > 0) {
                if (relativeSize.getWidth() > 100) {
                    horizontalScrollBar = true;
                } else if (relativeSize.getWidth() < 0 && renderSpace.getWidth() > 0) {
                    int offsetWidth = widget.getOffsetWidth();
                    int width = renderSpace.getWidth();
                    if (offsetWidth > width) {
                        horizontalScrollBar = true;
                    }
                }
            }

            int height = renderSpace.getHeight();
            if (horizontalScrollBar) {
                height -= renderSpace.getScrollbarSize();
            }
            if (validatingLayouts && height <= 0) {
                zeroHeightComponents.add(cd.getComponent());
            }

            height = (int) (height * relativeSize.getHeight() / 100.0);

            if (height < 0) {
                height = 0;
            }

            if (debugSizes) {
                VConsole.log("Widget " + Util.getSimpleName(widget) + "/" + getPid(widget.getElement())
                        + " relative height " + relativeSize.getHeight() + "% of " + renderSpace.getHeight()
                        + "px (reported by "

                        + Util.getSimpleName(parent) + "/" + (parent == null ? "?" : parent.hashCode()) + ") : "
                        + height + "px");
            }
            widget.setHeight(height + "px");
        } else {
            widget.setHeight(relativeSize.getHeight() + "%");
            VConsole.error(Util.getLayout(widget).getClass().getName() + " did not produce allocatedSpace for "
                    + widget.getClass().getName());
        }
    }

    if (relativeSize.getWidth() >= 0) {

        if (renderSpace != null) {

            int width = renderSpace.getWidth();

            if (renderSpace.getScrollbarSize() > 0) {
                if (relativeSize.getHeight() > 100) {
                    verticalScrollBar = true;
                } else if (relativeSize.getHeight() < 0 && renderSpace.getHeight() > 0
                        && widget.getOffsetHeight() > renderSpace.getHeight()) {
                    verticalScrollBar = true;
                }
            }

            if (verticalScrollBar) {
                width -= renderSpace.getScrollbarSize();
            }
            if (validatingLayouts && width <= 0) {
                zeroWidthComponents.add(cd.getComponent());
            }

            width = (int) (width * relativeSize.getWidth() / 100.0);

            if (width < 0) {
                width = 0;
            }

            if (debugSizes) {
                VConsole.log("Widget " + Util.getSimpleName(widget) + "/" + getPid(widget.getElement())
                        + " relative width " + relativeSize.getWidth() + "% of " + renderSpace.getWidth()
                        + "px (reported by " + Util.getSimpleName(parent) + "/"
                        + (parent == null ? "?" : getPid(parent)) + ") : " + width + "px");
            }
            widget.setWidth(width + "px");
        } else {
            widget.setWidth(relativeSize.getWidth() + "%");
            VConsole.error(Util.getLayout(widget).getClass().getName() + " did not produce allocatedSpace for "
                    + widget.getClass().getName());
        }
    }

    return true;
}

From source file:com.vaadin.terminal.gwt.client.ui.VContextMenu.java

License:Open Source License

/**
 * Shows context menu at given location IF it contain at least one item.
 * //  www .  ja v a2s .c  o m
 * @param left
 * @param top
 */
public void showAt(int left, int top) {
    final Action[] actions = actionOwner.getActions();
    if (actions == null || actions.length == 0) {
        // Only show if there really are actions
        return;
    }
    this.left = left;
    this.top = top;
    menu.clearItems();
    for (int i = 0; i < actions.length; i++) {
        final Action a = actions[i];
        menu.addItem(new MenuItem(a.getHTML(), true, a));
    }

    // Attach onload listeners to all images
    Util.sinkOnloadForImages(menu.getElement());

    setPopupPositionAndShow(new PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            // mac FF gets bad width due GWT popups overflow hacks,
            // re-determine width
            offsetWidth = menu.getOffsetWidth();
            int left = VContextMenu.this.left;
            int top = VContextMenu.this.top;
            if (offsetWidth + left > Window.getClientWidth()) {
                left = left - offsetWidth;
                if (left < 0) {
                    left = 0;
                }
            }
            if (offsetHeight + top > Window.getClientHeight()) {
                top = top - offsetHeight;
                if (top < 0) {
                    top = 0;
                }
            }
            setPopupPosition(left, top);

            /*
             * Move keyboard focus to menu, deferring the focus setting so
             * the focus is certainly moved to the menu in all browser after
             * the positioning has been done.
             */
            Scheduler.get().scheduleDeferred(new Command() {
                public void execute() {
                    // Focus the menu.
                    menu.setFocus(true);

                    // Unselect previously selected items
                    menu.selectItem(null);
                }
            });

        }
    });
}

From source file:com.vaadin.terminal.gwt.client.ui.VPopupCalendar.java

License:Open Source License

/**
 * Opens the calendar panel popup/* w w  w  .  j  a  va 2 s.  co m*/
 */
public void openCalendarPanel() {

    if (!open && !readonly) {
        open = true;

        if (getCurrentDate() != null) {
            calendar.setDate((Date) getCurrentDate().clone());
        } else {
            calendar.setDate(new Date());
        }

        // clear previous values
        popup.setWidth("");
        popup.setHeight("");
        popup.setPopupPositionAndShow(new PositionCallback() {
            public void setPosition(int offsetWidth, int offsetHeight) {
                final int w = offsetWidth;
                final int h = offsetHeight;
                final int browserWindowWidth = Window.getClientWidth() + Window.getScrollLeft();
                final int browserWindowHeight = Window.getClientHeight() + Window.getScrollTop();
                int t = calendarToggle.getAbsoluteTop();
                int l = calendarToggle.getAbsoluteLeft();

                // Add a little extra space to the right to avoid
                // problems with IE7 scrollbars and to make it look
                // nicer.
                int extraSpace = 30;

                boolean overflowRight = false;
                if (l + +w + extraSpace > browserWindowWidth) {
                    overflowRight = true;
                    // Part of the popup is outside the browser window
                    // (to the right)
                    l = browserWindowWidth - w - extraSpace;
                }

                if (t + h + calendarToggle.getOffsetHeight() + 30 > browserWindowHeight) {
                    // Part of the popup is outside the browser window
                    // (below)
                    t = browserWindowHeight - h - calendarToggle.getOffsetHeight() - 30;
                    if (!overflowRight) {
                        // Show to the right of the popup button unless we
                        // are in the lower right corner of the screen
                        l += calendarToggle.getOffsetWidth();
                    }
                }

                // fix size
                popup.setWidth(w + "px");
                popup.setHeight(h + "px");

                popup.setPopupPosition(l, t + calendarToggle.getOffsetHeight() + 2);

                /*
                 * We have to wait a while before focusing since the popup
                 * needs to be opened before we can focus
                 */
                Timer focusTimer = new Timer() {
                    @Override
                    public void run() {
                        setFocus(true);
                    }
                };

                focusTimer.schedule(100);
            }
        });
    } else {
        VConsole.error("Cannot reopen popup, it is already open!");
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VView.java

License:Open Source License

/**
 * Called when a resize event is received.
 *///from   www . j  a  va  2 s .c o  m
private void onResize() {
    /*
     * IE (pre IE9 at least) will give us some false resize events due to
     * problems with scrollbars. Firefox 3 might also produce some extra
     * events. We postpone both the re-layouting and the server side event
     * for a while to deal with these issues.
     * 
     * We may also postpone these events to avoid slowness when resizing the
     * browser window. Constantly recalculating the layout causes the resize
     * operation to be really slow with complex layouts.
     */
    boolean lazy = resizeLazy || BrowserInfo.get().isIE8();

    if (lazy) {
        delayedResizeExecutor.trigger();
    } else {
        windowSizeMaybeChanged(Window.getClientWidth(), Window.getClientHeight());
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VWindow.java

License:Open Source License

public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    id = uidl.getId();/*from  w ww  .  j a  v  a  2  s.  c  o m*/
    this.client = client;

    // Workaround needed for Testing Tools (GWT generates window DOM
    // slightly different in different browsers).
    DOM.setElementProperty(closeBox, "id", id + "_window_close");

    if (uidl.hasAttribute("invisible")) {
        hide();
        return;
    }

    if (!uidl.hasAttribute("cached")) {
        if (uidl.getBooleanAttribute("modal") != vaadinModality) {
            setVaadinModality(!vaadinModality);
        }
        if (!isAttached()) {
            setVisible(false); // hide until possible centering
            show();
        }
        if (uidl.getBooleanAttribute("resizable") != resizable) {
            setResizable(!resizable);
        }
        resizeLazy = uidl.hasAttribute(VView.RESIZE_LAZY);

        setDraggable(!uidl.hasAttribute("fixedposition"));

        // Caption must be set before required header size is measured. If
        // the caption attribute is missing the caption should be cleared.
        setCaption(uidl.getStringAttribute("caption"), uidl.getStringAttribute("icon"));
    }

    visibilityChangesDisabled = true;
    if (client.updateComponent(this, uidl, false)) {
        return;
    }
    visibilityChangesDisabled = false;

    clickEventHandler.handleEventHandlerRegistration(client);

    immediate = uidl.hasAttribute("immediate");

    setClosable(!uidl.getBooleanAttribute("readonly"));

    // Initialize the position form UIDL
    int positionx = uidl.getIntVariable("positionx");
    int positiony = uidl.getIntVariable("positiony");
    if (positionx >= 0 || positiony >= 0) {
        if (positionx < 0) {
            positionx = 0;
        }
        if (positiony < 0) {
            positiony = 0;
        }
        setPopupPosition(positionx, positiony);
    }

    boolean showingUrl = false;
    int childIndex = 0;
    UIDL childUidl = uidl.getChildUIDL(childIndex++);
    while ("open".equals(childUidl.getTag())) {
        // TODO multiple opens with the same target will in practice just
        // open the last one - should we fix that somehow?
        final String parsedUri = client.translateVaadinUri(childUidl.getStringAttribute("src"));
        if (!childUidl.hasAttribute("name")) {
            final Frame frame = new Frame();
            DOM.setStyleAttribute(frame.getElement(), "width", "100%");
            DOM.setStyleAttribute(frame.getElement(), "height", "100%");
            DOM.setStyleAttribute(frame.getElement(), "border", "0px");
            frame.setUrl(parsedUri);
            contentPanel.setWidget(frame);
            showingUrl = true;
        } else {
            final String target = childUidl.getStringAttribute("name");
            Window.open(parsedUri, target, "");
        }
        childUidl = uidl.getChildUIDL(childIndex++);
    }

    final Paintable lo = client.getPaintable(childUidl);
    if (layout != null) {
        if (layout != lo) {
            // remove old
            client.unregisterPaintable(layout);
            contentPanel.remove((Widget) layout);
            // add new
            if (!showingUrl) {
                contentPanel.setWidget((Widget) lo);
            }
            layout = lo;
        }
    } else if (!showingUrl) {
        contentPanel.setWidget((Widget) lo);
        layout = lo;
    }

    dynamicWidth = !uidl.hasAttribute("width");
    dynamicHeight = !uidl.hasAttribute("height");

    layoutRelativeWidth = uidl.hasAttribute("layoutRelativeWidth");
    layoutRelativeHeight = uidl.hasAttribute("layoutRelativeHeight");

    if (dynamicWidth && layoutRelativeWidth) {
        /*
         * Relative layout width, fix window width before rendering (width
         * according to caption)
         */
        setNaturalWidth();
    }

    layout.updateFromUIDL(childUidl, client);
    if (!dynamicHeight && layoutRelativeWidth) {
        /*
         * Relative layout width, and fixed height. Must update the size to
         * be able to take scrollbars into account (layout gets narrower
         * space if it is higher than the window) -> only vertical scrollbar
         */
        client.runDescendentsLayout(this);
    }

    /*
     * No explicit width is set and the layout does not have relative width
     * so fix the size according to the layout.
     */
    if (dynamicWidth && !layoutRelativeWidth) {
        setNaturalWidth();
    }

    if (dynamicHeight && layoutRelativeHeight) {
        // Prevent resizing until height has been fixed
        resizable = false;
    }

    // we may have actions and notifications
    if (uidl.getChildCount() > 1) {
        final int cnt = uidl.getChildCount();
        for (int i = 1; i < cnt; i++) {
            childUidl = uidl.getChildUIDL(i);
            if (childUidl.getTag().equals("actions")) {
                if (shortcutHandler == null) {
                    shortcutHandler = new ShortcutActionHandler(id, client);
                }
                shortcutHandler.updateActionMap(childUidl);
            }
        }

    }

    // setting scrollposition must happen after children is rendered
    contentPanel.setScrollPosition(uidl.getIntVariable("scrollTop"));
    contentPanel.setHorizontalScrollPosition(uidl.getIntVariable("scrollLeft"));

    // Center this window on screen if requested
    // This has to be here because we might not know the content size before
    // everything is painted into the window
    if (uidl.getBooleanAttribute("center")) {
        // mark as centered - this is unset on move/resize
        centered = true;
        center();
    } else {
        // don't try to center the window anymore
        centered = false;
    }
    updateShadowSizeAndPosition();
    setVisible(true);

    boolean sizeReduced = false;
    // ensure window is not larger than browser window
    if (getOffsetWidth() > Window.getClientWidth()) {
        setWidth(Window.getClientWidth() + "px");
        sizeReduced = true;
    }
    if (getOffsetHeight() > Window.getClientHeight()) {
        setHeight(Window.getClientHeight() + "px");
        sizeReduced = true;
    }

    if (dynamicHeight && layoutRelativeHeight) {
        /*
         * Window height is undefined, layout is 100% high so the layout
         * should define the initial window height but on resize the layout
         * should be as high as the window. We fix the height to deal with
         * this.
         */

        int h = contents.getOffsetHeight() + getExtraHeight();
        int w = getElement().getOffsetWidth();

        client.updateVariable(id, "height", h, false);
        client.updateVariable(id, "width", w, true);
    }

    if (sizeReduced) {
        // If we changed the size we need to update the size of the child
        // component if it is relative (#3407)
        client.runDescendentsLayout(this);
    }

    Util.runWebkitOverflowAutoFix(contentPanel.getElement());

    client.getView().scrollIntoView(uidl);

    if (uidl.hasAttribute("bringToFront")) {
        /*
         * Focus as a side-efect. Will be overridden by
         * ApplicationConnection if another component was focused by the
         * server side.
         */
        contentPanel.focus();
        bringToFrontSequence = uidl.getIntAttribute("bringToFront");
        deferOrdering();
    }
}

From source file:com.vaadin.terminal.gwt.client.VDebugConsole.java

License:Open Source License

private void setToDefaultSizeAndPos() {
    String cookie = Cookies.getCookie(POS_COOKIE_NAME);
    int width, height, top, left;
    boolean autoScrollValue = false;
    if (cookie != null) {
        String[] split = cookie.split(",");
        left = Integer.parseInt(split[0]);
        top = Integer.parseInt(split[1]);
        width = Integer.parseInt(split[2]);
        height = Integer.parseInt(split[3]);
        autoScrollValue = Boolean.valueOf(split[4]);
    } else {//from   w  ww. j a  va 2  s. com
        width = 400;
        height = 150;
        top = Window.getClientHeight() - 160;
        left = Window.getClientWidth() - 410;
    }
    setPixelSize(width, height);
    setPopupPosition(left, top);
    autoScroll.setValue(autoScrollValue);
}

From source file:com.vaadin.terminal.gwt.client.VTooltip.java

License:Open Source License

/**
 * Show a popup containing the information in the "info" tooltip
 * /*  ww  w. ja  v a 2  s  .  co m*/
 * @param info
 */
private void show(TooltipInfo info) {
    boolean hasContent = false;
    if (info.getErrorUidl() != null) {
        em.setVisible(true);
        em.updateFromUIDL(info.getErrorUidl());
        hasContent = true;
    } else {
        em.setVisible(false);
    }
    if (info.getTitle() != null && !"".equals(info.getTitle())) {
        DOM.setInnerHTML(description, info.getTitle());
        DOM.setStyleAttribute(description, "display", "");
        hasContent = true;
    } else {
        DOM.setInnerHTML(description, "");
        DOM.setStyleAttribute(description, "display", "none");
    }
    if (hasContent) {
        setPopupPositionAndShow(new PositionCallback() {
            public void setPosition(int offsetWidth, int offsetHeight) {

                if (offsetWidth > MAX_WIDTH) {
                    setWidth(MAX_WIDTH + "px");

                    // Check new height and width with reflowed content
                    offsetWidth = getOffsetWidth();
                    offsetHeight = getOffsetHeight();
                }

                int x = tooltipEventMouseX + 10 + Window.getScrollLeft();
                int y = tooltipEventMouseY + 10 + Window.getScrollTop();

                if (x + offsetWidth + MARGIN - Window.getScrollLeft() > Window.getClientWidth()) {
                    x = Window.getClientWidth() - offsetWidth - MARGIN;
                }

                if (y + offsetHeight + MARGIN - Window.getScrollTop() > Window.getClientHeight()) {
                    y = tooltipEventMouseY - 5 - offsetHeight;
                    if (y - Window.getScrollTop() < 0) {
                        // tooltip does not fit on top of the mouse either,
                        // put it at the top of the screen
                        y = Window.getScrollTop();
                    }
                }

                setPopupPosition(x, y);
                sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT);
            }
        });
    } else {
        hide();
    }
}