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.urlisit.siteswrapper.cloud.widgets.OldMenu.java

License:Apache License

public void resize(int viewNumber) {
    Literals literals = entries.get(viewNumber).getView().getLiterals();
    LookAndFeel lookAndFeel = entries.get(viewNumber).getView().getLookAndFeel();
    int numCells = menu.getCellCount(literals.rowZero());
    double menuWidth = Window.getClientWidth()
            - (Window.getClientWidth() * Double.valueOf(lookAndFeel.getMainMenuLeft()));
    int cellWidth = (int) Math.round(menuWidth / numCells);
    for (int x = 0; x < numCells; x++) {
        menu.getCellFormatter().setWidth(literals.rowZero(), x, cellWidth + literals.px());
        menu.getCellFormatter().setHorizontalAlignment(literals.zero(), x, HasHorizontalAlignment.ALIGN_LEFT);
    }/*from   w  w  w.  ja  v a  2s.  com*/
    int left = (int) Math.round(Window.getClientWidth() * Double.valueOf(lookAndFeel.getMainMenuLeft()));
    int top = (int) Math.round(Double.valueOf(lookAndFeel.getMainMenuTopPercent()) * Window.getClientHeight());
    entries.get(viewNumber).getView().getPanel().add(menu, left, top);
}

From source file:com.urlisit.siteswrapper.cloud.widgets.PogoImage.java

License:Apache License

/** 
 * This method must be called whenever the logo's size has been modified. This is typically the result of the browser
 * window being resized and is typically handled by the owning ViewPanel, View or some other implementor of the
 * ProvidesResize interface. Because a resize involves getting and setting the size of the Image widget, the image
 * must already be loaded. Consequently, if isLoaded() returns false, a LoadHandler is created and onResize()
 * rescheduled to occur when Image.getWidth/getHeight will succeed.
 * //from ww w . j  ava 2  s  .  c  o m
 * @see com.google.gwt.user.client.ui.RequiresResize#onResize()
 */
@Override
public void onResize() {
    if (isLoaded()) {
        int left = leftPercent.multiply(BigDecimal.valueOf(Double.valueOf(Window.getClientWidth()))).intValue();
        int top = topPercent.multiply(BigDecimal.valueOf(Double.valueOf(Window.getClientHeight()))).intValue();
        newWidth = widthPercent.multiply(BigDecimal.valueOf(Double.valueOf(Window.getClientWidth())));
        oldWidth = BigDecimal.valueOf(Integer.valueOf(logo.getWidth()).doubleValue());
        oldHeight = BigDecimal.valueOf(Integer.valueOf(logo.getHeight()).doubleValue());
        newHeight = newWidth.multiply(oldWidth.divide(oldHeight, 4, BigDecimal.ROUND_HALF_EVEN));
        logo.setPixelSize(newWidth.intValue(), newHeight.intValue());
        view.getPanel().setWidgetPosition(this, left, top);
    } else {
        logo.addLoadHandler(new LoadHandler() {
            @Override
            public void onLoad(LoadEvent event) {
                isLoaded = true;
                onResize();
            }
        });
    }
}

From source file:com.urlisit.siteswrapper.cloud.widgets.Selector.java

License:Apache License

@Override
public void onResize() {
    Literals literals = presenter.getView(Window.getTitle()).getLiterals();
    LookAndFeel lookAndFeel = presenter.getView(Window.getTitle()).getLookAndFeel();
    ViewPanel panel = presenter.getView(Window.getTitle()).getPanel();
    int numCells = mainMenu.getCellCount(literals.rowZero());
    double width = Window.getClientWidth()
            - (Window.getClientWidth() * Double.valueOf(lookAndFeel.getMainMenuLeft()));
    int cellWidth = (int) Math.round(width / numCells);
    for (int x = 0; x < numCells; x++) {
        mainMenu.getCellFormatter().setWidth(literals.rowZero(), x, cellWidth + literals.px());
        mainMenu.getCellFormatter().setHorizontalAlignment(literals.zero(), x,
                HasHorizontalAlignment.ALIGN_LEFT);
    }//from  w  w w .j  a v a2 s .  c  om
    int left = (int) Math.round(Window.getClientWidth() * Double.valueOf(lookAndFeel.getMainMenuLeft()));
    int top = (int) Math.round(Double.valueOf(lookAndFeel.getMainMenuTopPercent()) * Window.getClientHeight());
    panel.add(this, left, top);
}

From source file:com.urlisit.siteswrapper.cloud.widgets.ViewPanel.java

License:Apache License

@Override
public void onResize() {
    getElement().getStyle().setPosition(Position.RELATIVE);
    setPixelSize(Window.getClientWidth(), Window.getClientHeight());
    for (Widget child : getChildren()) {
        if (child instanceof RequiresResize) {
            ((RequiresResize) child).onResize();
        }//w  w w  .  j a  va 2  s.c  o m
    }
}

From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java

private void setHyperlinkTooltipPosition(int offsetWidth, int offsetHeight, DivElement element) {
    // Calculate left position for the popup. The computation for
    // the left position is bidi-sensitive.

    int textBoxOffsetWidth = element.getOffsetWidth();

    // Compute the difference between the popup's width and the
    // textbox's width
    int offsetWidthDiff = offsetWidth - textBoxOffsetWidth;

    int left;/*from w w w.  jav a2 s .  co m*/

    if (LocaleInfo.getCurrentLocale().isRTL()) { // RTL case

        int textBoxAbsoluteLeft = element.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 = element.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 = element.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 + element.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 += element.getOffsetHeight();
    }
    hyperlinkTooltip.setPopupPosition(left, top);
}

From source file:com.vaadin.client.debug.internal.VDebugWindow.java

License:Apache License

/**
 * Applies the appropriate instance variables for width, height, x, y
 * depending on if the window is minimized or not.
 * /*  w w w  . j av a 2  s . com*/
 * If the value is negative, the window is positioned that amount of pixels
 * from the right/bottom instead of left/top.
 * 
 * Finally, the position is bounds-checked so that the window is not moved
 * off-screen (the adjusted values are not saved).
 */
private void applyPositionAndSize() {
    int x = 0;
    int y = 0;
    if (minimized) {
        x = minX;
        if (minX < 0) {
            x = Window.getClientWidth() + minX;
        }
        y = minY;
        if (minY < 0) {
            y = Window.getClientHeight() + minY;
        }

    } else {
        x = fullX;
        if (fullX < 0) {
            x = Window.getClientWidth() + fullX;
        }
        y = fullY;
        if (y < 0) {
            y = Window.getClientHeight() + fullY;
        }
        content.setWidth(fullW + "px");
        content.setHeight(fullH + "px");
    }

    applyBounds(x, y);
}

From source file:com.vaadin.client.debug.internal.VDebugWindow.java

License:Apache License

private void applyBounds(int x, int y) {
    // bounds check
    if (x < 0) {
        x = 0;//ww  w.  java 2  s .com
    }
    if (x > Window.getClientWidth() - getOffsetWidth()) {
        // not allowed off-screen to the right
        x = Window.getClientWidth() - getOffsetWidth();
    }
    if (y > Window.getClientHeight() - getOffsetHeight()) {
        y = Window.getClientHeight() - getOffsetHeight();
    }
    if (y < 0) {
        y = 0;
    }

    setPopupPosition(x, y);

}

From source file:com.vaadin.client.debug.internal.VDebugWindow.java

License:Apache License

/**
 * Reads position and size from the DOM to local variables (which in turn
 * can be stored to localStorage)/*from   w w  w .  jav a  2s  .  c  o  m*/
 */
private void readPositionAndSize() {
    int x = getPopupLeft();
    int fromRight = Window.getClientWidth() - x - getOffsetWidth();
    if (fromRight < x) {
        x -= Window.getClientWidth();
    }

    int y = getPopupTop();
    int fromBottom = Window.getClientHeight() - y - getOffsetHeight();
    if (fromBottom < y) {
        y -= Window.getClientHeight();
    }

    if (minimized) {
        minY = y;
        minX = x;
    } else {
        fullY = y;
        fullX = x;
        fullW = content.getOffsetWidth();
        fullH = content.getOffsetHeight();
    }

}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

@Override
protected void init() {
    super.init();
    registerRpc(PageClientRpc.class, new PageClientRpc() {

        @Override/*from  w w w.  j  a v  a2 s .  c o m*/
        public void reload() {
            Window.Location.reload();

        }
    });
    registerRpc(ScrollClientRpc.class, new ScrollClientRpc() {
        @Override
        public void setScrollTop(int scrollTop) {
            getWidget().getElement().setScrollTop(scrollTop);
        }

        @Override
        public void setScrollLeft(int scrollLeft) {
            getWidget().getElement().setScrollLeft(scrollLeft);
        }
    });
    registerRpc(UIClientRpc.class, new UIClientRpc() {
        @Override
        public void uiClosed(final boolean sessionExpired) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    // Only notify user if we're still running and not eg.
                    // navigating away (#12298)
                    if (getConnection().isApplicationRunning()) {
                        if (sessionExpired) {
                            getConnection().showSessionExpiredError(null);
                        } else {
                            getState().enabled = false;
                            updateEnabledState(getState().enabled);
                        }
                        getConnection().setApplicationRunning(false);
                    }
                }
            });
        }
    });
    registerRpc(DebugWindowClientRpc.class, new DebugWindowClientRpc() {

        @Override
        public void reportLayoutProblems(String json) {
            VConsole.printLayoutProblems(getValueMap(json), getConnection());
        }

        private native ValueMap getValueMap(String json)
        /*-{
        return JSON.parse(json);
        }-*/;
    });

    getWidget().addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            getRpcProxy(UIServerRpc.class).resize(event.getHeight(), event.getWidth(), Window.getClientWidth(),
                    Window.getClientHeight());
            if (getState().immediate || getPageState().hasResizeListeners) {
                getConnection().getServerRpcQueue().flush();
            }
        }
    });
    getWidget().addScrollHandler(new ScrollHandler() {
        private int lastSentScrollTop = Integer.MAX_VALUE;
        private int lastSentScrollLeft = Integer.MAX_VALUE;

        @Override
        public void onScroll(ScrollEvent event) {
            Element element = getWidget().getElement();
            int newScrollTop = element.getScrollTop();
            int newScrollLeft = element.getScrollLeft();
            if (newScrollTop != lastSentScrollTop || newScrollLeft != lastSentScrollLeft) {
                lastSentScrollTop = newScrollTop;
                lastSentScrollLeft = newScrollLeft;
                getRpcProxy(UIServerRpc.class).scroll(newScrollTop, newScrollLeft);
            }
        }
    });
}

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

License:Apache License

/**
 * Shows context menu at given location IF it contain at least one item.
 * /*from  www.j av a 2  s.  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
    WidgetUtil.sinkOnloadForImages(menu.getElement());

    // Store the currently focused element, which will be re-focused when
    // context menu is closed
    focusedElement = WidgetUtil.getFocusedElement();

    // reset height (if it has been previously set explicitly)
    setHeight("");

    setPopupPositionAndShow(new PositionCallback() {
        @Override
        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 = Math.max(0, Window.getClientHeight() - offsetHeight);
            }
            if (top == 0) {
                setHeight(Window.getClientHeight() + "px");
            }
            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() {
                @Override
                public void execute() {
                    // Focus the menu.
                    menu.setFocus(true);

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

        }
    });
}