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.sitecake.contentmanager.client.toolbar.ContentManagerToolbar.java

private void setPosition(int x, int y, boolean constraint, boolean save) {
    int windowWidth = Window.getClientWidth();
    int windowHeight = Window.getClientHeight();
    int elementWidth = getElement().getOffsetWidth();
    int elementHeight = getElement().getOffsetHeight();
    int maxWidth = windowWidth - elementWidth;
    int maxHeight = windowHeight - elementHeight;

    if (constraint) {
        x = (x < 0) ? 0 : ((x > maxWidth) ? maxWidth : x);
        y = (y < 0) ? 0 : ((y > maxHeight) ? maxHeight : y);
    }/* w  ww  .  j  av  a  2 s  .c  o  m*/

    Style style = getElement().getStyle();
    style.setLeft(x, Unit.PX);
    style.setTop(y, Unit.PX);

    if (y > windowHeight / 2) {
        addStyleName(EditorClientBundle.INSTANCE.css().toolbarBottomPosition());
        newItems.addStyleName(EditorClientBundle.INSTANCE.css().toolbarIconsUp());
        newItems.removeStyleName(EditorClientBundle.INSTANCE.css().toolbarIconsDown());
    } else {
        removeStyleName(EditorClientBundle.INSTANCE.css().toolbarBottomPosition());
        newItems.addStyleName(EditorClientBundle.INSTANCE.css().toolbarIconsDown());
        newItems.removeStyleName(EditorClientBundle.INSTANCE.css().toolbarIconsUp());
    }

    if (save) {
        propertyManager.setProperty(POSITION_X, x, PropertyScope.APPLICATION);
        propertyManager.setProperty(POSITION_Y, y, PropertyScope.APPLICATION);
    }
}

From source file:com.smartgwt.mobile.client.widgets.layout.NavigationBar.java

License:Open Source License

@SGWTInternal
public void _layOutMembers() {
    if (!isAttached())
        return;/*from   w w  w  . java  2s .  c  o  m*/
    if (!isVisible() || !navStack.isVisible())
        return;
    if (layoutTimer == null) {
        layoutTimer = new Timer() {

            @Override
            public void run() {
                final float _1vw = Window.getClientWidth(); // 1 viewport width
                final NavigationItem item = ensureItem();
                final Header1 titleView = item.getTitleView();
                final float minTitleViewWidth, titleViewContentWidth;
                if (titleView == null) {
                    minTitleViewWidth = 0.0f;
                    titleViewContentWidth = 0.0f;
                } else {
                    final SpanElement span = titleView._getSpan();
                    span.getStyle().clearPadding();
                    final float titleViewWidth = ElementUtil.getOuterWidth(titleView.getElement(), true);
                    minTitleViewWidth = titleViewWidth - titleView.getElement().getClientWidth();
                    titleViewContentWidth = span.getOffsetWidth();
                }
                final float titleViewAutoWidth = minTitleViewWidth + titleViewContentWidth;
                final NavigationButton leftButton = item.getLeftButton();
                final Canvas rightBarItem = item.getRightBarItem();
                final float leftButtonHMargin, absoluteMinLeftButtonWidth, leftButtonContentWidth;
                if (leftButton == null) {
                    leftButtonHMargin = 0.0f;
                    absoluteMinLeftButtonWidth = 0.0f;
                    leftButtonContentWidth = 0.0f;
                } else {
                    final Element element = leftButton.getElement();
                    leftButtonHMargin = ElementUtil.getHMarginWidth(element);
                    absoluteMinLeftButtonWidth = ElementUtil.getMinMarginBoxWidth(element);
                    leftButtonContentWidth = leftButton._getContentWidth();
                }
                final float rightBarItemHMargin, absoluteMinRightBarItemWidth, rightBarItemContentWidth;
                if (rightBarItem == null) {
                    rightBarItemHMargin = 0.0f;
                    absoluteMinRightBarItemWidth = 0.0f;
                    rightBarItemContentWidth = 0.0f;
                } else {
                    final Element element = rightBarItem.getElement();
                    rightBarItemHMargin = ElementUtil.getHMarginWidth(element);
                    absoluteMinRightBarItemWidth = ElementUtil.getMinMarginBoxWidth(element);
                    rightBarItemContentWidth = ((NavigationBarItem) rightBarItem)._getContentWidth();
                }
                final float leftButtonAutoWidth = absoluteMinLeftButtonWidth + leftButtonContentWidth,
                        rightBarItemAutoWidth = absoluteMinRightBarItemWidth + rightBarItemContentWidth;

                final float totalWidth = titleViewAutoWidth + leftButtonAutoWidth + rightBarItemAutoWidth;

                float newLeftButtonMarginBoxWidth = 0.0f, newRightButtonMarginBoxWidth = 0.0f;
                if (totalWidth + 0.000001f >= _1vw) {
                    final float minLeftButtonWidth = leftButton == null ? 0.0f
                            : absoluteMinLeftButtonWidth + Math.min(53.0f, leftButtonContentWidth),
                            minRightBarItemWidth = rightBarItem == null ? 0.0f
                                    : absoluteMinRightBarItemWidth + (rightBarItem instanceof NavigationButtons
                                            ? rightBarItemContentWidth
                                            : Math.min(53.0f, rightBarItemContentWidth));
                    assert minLeftButtonWidth <= leftButtonAutoWidth + 0.000001f;
                    assert minRightBarItemWidth <= rightBarItemAutoWidth + 0.000001f;

                    final float r = _1vw - titleViewAutoWidth - minLeftButtonWidth - minRightBarItemWidth;
                    if (r < 0.000001f) {
                        newLeftButtonMarginBoxWidth = minLeftButtonWidth;
                        newRightButtonMarginBoxWidth = minRightBarItemWidth;
                    } else { // The title gets as much width as it needs while still giving the left and/or right
                             // buttons a minimum client width (at most 53px).  The remaining width is distributed to
                             // the left and right buttons.
                        if (leftButton != null || rightBarItem != null) {
                            final float denominator = leftButtonAutoWidth - minLeftButtonWidth
                                    + rightBarItemAutoWidth - minRightBarItemWidth;
                            if (denominator < 2.0f + 0.000001f) {
                                newLeftButtonMarginBoxWidth = minLeftButtonWidth;
                                newRightButtonMarginBoxWidth = minRightBarItemWidth;
                            } else {
                                newLeftButtonMarginBoxWidth = minLeftButtonWidth
                                        + (leftButtonAutoWidth - minLeftButtonWidth) / denominator * r;
                                newRightButtonMarginBoxWidth = minRightBarItemWidth
                                        + (rightBarItemAutoWidth - minRightBarItemWidth) / denominator * r;
                            }
                        }
                    }
                } else {
                    newLeftButtonMarginBoxWidth = leftButtonAutoWidth;
                    newRightButtonMarginBoxWidth = rightBarItemAutoWidth;

                    final float leftButtonExtra = Math.max(0.0f, leftButtonAutoWidth - rightBarItemAutoWidth),
                            rightButtonExtra = Math.max(0.0f, rightBarItemAutoWidth - leftButtonAutoWidth);
                    float r = _1vw - totalWidth;
                    assert r + 0.000001f >= 0.0f;
                    if (titleView != null) {
                        if (r + 0.000001f >= leftButtonExtra + rightButtonExtra) {
                            final float rightPadding = leftButtonExtra, leftPadding = rightButtonExtra;
                            final SpanElement span = titleView._getSpan();
                            final Style spanStyle = span.getStyle();
                            spanStyle.setPaddingRight(rightPadding, Unit.PX);
                            spanStyle.setPaddingLeft(leftPadding, Unit.PX);
                        } else {
                            if (leftButtonExtra + 0.000001f >= rightButtonExtra) {
                                final float rightPadding = r;
                                final SpanElement span = titleView._getSpan();
                                span.getStyle().setPaddingRight(rightPadding, Unit.PX);
                            } else {
                                final float leftPadding = r;
                                final SpanElement span = titleView._getSpan();
                                span.getStyle().setPaddingLeft(leftPadding, Unit.PX);
                            }
                        }
                    }
                }
                if (leftButton != null) {
                    ElementUtil.setBorderBoxWidth(leftButton.getElement(),
                            newLeftButtonMarginBoxWidth - leftButtonHMargin);
                }
                if (rightBarItem != null) {
                    ElementUtil.setBorderBoxWidth(rightBarItem.getElement(),
                            newRightButtonMarginBoxWidth - rightBarItemHMargin);
                }
                if (titleView != null) {
                    // Instead of setting the left and right padding, set the `left' and `right'
                    // CSS properties.
                    // There is a WebKit bug that affects iOS 6 where left and right padding
                    // is incorrectly factored into the calculation of how wide the <h1>
                    // element is for the purpose of centering the text.
                    // https://bugs.webkit.org/show_bug.cgi?id=75277
                    titleView.getElement().getStyle().setLeft(newLeftButtonMarginBoxWidth, Unit.PX);
                    titleView.getElement().getStyle().setRight(newRightButtonMarginBoxWidth, Unit.PX);
                    titleView.getElement().getStyle().clearVisibility();
                }

                layoutTimer = null;
            } // run()
        };
        layoutTimer.schedule(1);
    }
}

From source file:com.square.composant.aide.gwt.client.AideComposant.java

License:Open Source License

/**
 * constructeur./*from  ww w. j  a v a 2s  .  co m*/
 * @param id id de composant.
 * @param isAdmin Admin/user
 */
public AideComposant(final Long id, final boolean isAdmin) {

    // CONSTANTE COMPOSANT
    this.isAdmin = isAdmin;
    this.id = id;
    this.aideConstants = GWT.create(AideComposantMessages.class);
    this.clientWidth = Window.getClientWidth();

    // GESTION POPUP MESSAGE
    aideIcone = new AideImage(AideComposantRessources.INSTANCE.iconeAide());
    final LoadingPopup loading = LoadingPopup.getInstance();
    loading.setWidth("500");
    loading.setHTML(aideConstants.chargementEnCours());
    this.panelAide = new Popup(aideConstants.popupTitle(), true, false, false);
    this.aideText = new HTML();
    this.aideText.setWidth("500px");
    panelAide.setWidget(aideText);

    aideIcone.addContextMenuHandler(new ContextMenuHandler() {

        @Override
        public void onContextMenu(ContextMenuEvent event) {

            if (isAdmin) {
                // MASQUER POPUP AFFICHAGE
                event.stopPropagation();
                panelAide.hide();
                // CHARGEMENT ET AFFICHAGE POPUP EDITION
                fireAideEventEdition(aideIcone.getAbsoluteLeft(), aideIcone.getAbsoluteTop(), loading);
                controleAffichagePopup(aideIcone.getAbsoluteLeft(), aideIcone.getAbsoluteTop(), loading);
            }

        }
    });

    // GESTION POPUP MODE LECTURE
    updatePopup = createUpdatePanel();
    aideIcone.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            // MASQUER POPUP AFFICHAGE
            controleAffichagePopup(aideIcone.getAbsoluteLeft(), aideIcone.getAbsoluteTop(), loading);
            fireAideEvent(aideIcone.getAbsoluteLeft(), aideIcone.getAbsoluteTop(), loading);
        }
    });

    // PANEL PRINCIPAL INITIALISATION
    aideIconeAdmin = new AideImage(AideComposantRessources.INSTANCE.iconeSansAide());

    aideIconeAdmin.addContextMenuHandler(new ContextMenuHandler() {

        @Override
        public void onContextMenu(ContextMenuEvent event) {
            event.stopPropagation();
            event.getNativeEvent().stopPropagation();
            if (isAdmin) {
                // MASQUER POPUP AFFICHAGE
                panelAide.hide();
                // CHARGEMENT ET AFFICHAGE POPUP EDITION
                fireAideEventEdition(aideIconeAdmin.getAbsoluteLeft(), aideIconeAdmin.getAbsoluteTop(),
                        loading);
                controleAffichagePopup(aideIconeAdmin.getAbsoluteLeft(), aideIconeAdmin.getAbsoluteTop(),
                        loading);
            }
        }
    });

    panelIcone = new SimplePanel();
    panelIcone.add(aideIconeAdmin);
    this.setVisible(false);
    initWidget(panelIcone);

}

From source file:com.sun.labs.aura.music.wsitm.client.ui.widget.steerable.ResizableTagWidget.java

License:Open Source License

public ResizableTagWidget(MainPanel mainPanel, ClientDataManager cdm, SharedSteeringCIMenu sharedArtistMenu,
        SharedSteeringCIMenu sharedTagMenu) {

    super(mainPanel);

    this.cdm = cdm;
    this.sharedArtistMenu = sharedArtistMenu;
    this.sharedTagMenu = sharedTagMenu;

    int panelWidth = 480;
    if (Window.getClientWidth() > 1024) {
        panelWidth = (int) (Window.getClientWidth() * 480.0 / 1024.0);
    }//from   w  w w  .j av a  2  s .c o m

    fP = new FocusPanel();
    fP.setWidth(panelWidth + "px");
    fP.setHeight("450px");
    flowP = new FlowPanel();
    flowP.setWidth("500px");
    flowP.getElement().setAttribute("style", "margin-top: 15px");
    fP.add(flowP);
    initWidget(fP);

    tagCloud = new HashMap<String, SpannedNEffectPanel>();
    fP.addMouseListener(new MouseListener() {

        @Override
        public void onMouseDown(Widget arg0, int newX, int newY) {
            lastY = newY;
            lastX = newX;

            ((FocusPanel) arg0).setFocus(false);
        }

        @Override
        public void onMouseEnter(Widget arg0) {
        }

        @Override
        public void onMouseLeave(Widget arg0) {
            boolean wasTrue = false;
            for (SpannedNEffectPanel sep : tagCloud.values()) {
                ResizableTag dW = sep.getTag();
                if (dW.hasClicked()) {
                    wasTrue = true;
                }
                dW.setClickFalse();
            }
            if (wasTrue) {
                updateRecommendations();
            }

            ((FocusPanel) arg0).setFocus(false);
        }

        @Override
        public void onMouseMove(Widget arg0, int newX, int newY) {

            // Take either increment from Y or X movement. Taking both
            // modifies the size too quickly.
            // -- Going up or right grows the tags.
            int diffY = lastY - newY;
            int diffX = newX - lastX;
            int increment = 0;
            if (Math.abs(diffY) > Math.abs(diffX)) {
                increment = diffY;
            } else {
                increment = diffX;
            }

            // Don't refresh everytime to let the browser take its breath
            if (Math.abs(increment) > 3) {

                double diff = 0;
                maxSize = 0; // reset maxsize to deal with when the top tag is scaled down
                for (SpannedNEffectPanel sep : tagCloud.values()) {
                    ResizableTag dW = sep.getTag();
                    double oldSize = dW.getCurrentSize();
                    double tempDiff = dW.updateSize(increment, true);

                    if (oldSize != dW.getCurrentSize()) {
                        hasChanged = true;
                    }

                    if (tempDiff != 0) {
                        diff = tempDiff;
                    }

                    if (Math.abs(dW.getCurrentSize()) > maxSize) {
                        maxSize = Math.abs(dW.getCurrentSize());
                    }
                }

                //
                // Do a second pass to modify the tags that aren't being resized
                // if the one that is resized has reached its max/min size
                if (diff != 0) {
                    diff = diff / (tagCloud.size() - 1);
                    for (SpannedNEffectPanel sep : tagCloud.values()) {
                        ResizableTag dW = sep.getTag();
                        double oldSize = dW.getCurrentSize();
                        dW.updateSize(diff, false);

                        if (oldSize != dW.getCurrentSize()) {
                            hasChanged = true;
                        }

                        if (Math.abs(dW.getCurrentSize()) > maxSize) {
                            maxSize = Math.abs(dW.getCurrentSize());
                        }
                    }
                }

                lastY = newY;
                lastX = newX;
            }

            ((FocusPanel) arg0).setFocus(false);
        }

        @Override
        public void onMouseUp(Widget arg0, int arg1, int arg2) {
            for (SpannedNEffectPanel sep : tagCloud.values()) {
                ResizableTag dW = sep.getTag();
                dW.setClickFalse();
            }
            ((FocusPanel) arg0).setFocus(false);
            updateRecommendations();
        }
    });
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.widget.steerable.TagMeterWidget.java

License:Open Source License

public TagMeterWidget(MainPanel mainPanel, ClientDataManager cdm) {
    super(mainPanel);

    this.cdm = cdm;
    int panelWidth = 480;
    if (Window.getClientWidth() > 1024) {
        panelWidth = (int) (Window.getClientWidth() * 480.0 / 1024.0);
    }/*w ww  .  j  ava2  s.  c o m*/

    mainTagPanel = new VerticalPanel();
    mainTagPanel.setWidth(panelWidth + "px");
    tagCloud = new HashMap<String, CloudItemMeter>();
    initWidget(mainTagPanel);
}

From source file:com.tasktop.c2c.server.tasks.client.widgets.TaskDetailsPopupPanel.java

License:Open Source License

public void showAt(final int targetAbsoluteLeft, final int targetAbsoluteTop, final int targetOffsetWidth,
        final int targetOffsetHeight) {
    setPopupPositionAndShow(new PopupPanel.PositionCallback() {
        @Override//  www  . j  a v a 2 s  .  co  m
        public void setPosition(int offsetWidth, int offsetHeight) {
            // There doesn't appear to be a reliable way to get the width and height of this popup from the element
            // itself, so I have to resort to hardcoded values (spent a couple of hours trying to get the right
            // values here - popup.getWidget().getElement().getClientHeight() returned the correct height, but the
            // width was way off
            int popupWidth = 297;
            int popupHeight = 350;
            int anchorRight = targetAbsoluteLeft + targetOffsetWidth;
            int anchorBottom = targetAbsoluteTop + targetOffsetHeight;
            int windowRight = Window.getClientWidth() + Window.getScrollLeft();
            int windowBottom = Window.getScrollTop() + Window.getClientHeight();

            // By default, set our left and top to be just below the Anchor's bottom right corner.
            int popupLeft = anchorRight;
            int popupTop = anchorBottom;

            if ((popupLeft + popupWidth) > windowRight) {
                // If there's not enough space to the right, then make sure our popup is touching the
                // right edge of the screen
                popupLeft = windowRight - popupWidth;
            }

            if ((popupTop + popupHeight) > windowBottom) {
                // If there's not enough space at the bottom, then make sure our popup is touching the
                // bottom edge of the screen
                popupTop = windowBottom - popupHeight;
            }
            setPopupPosition(popupLeft, popupTop);
        }
    });
}

From source file:com.test.morphia.client.loginview.LoginView.java

License:Open Source License

public LoginView() {

    int windowHeight = Window.getClientHeight();
    int windowWidth = Window.getClientWidth();

    loginLayout.setCellSpacing(6);//from w w w . j  a v a2 s .  c  o m
    FlexCellFormatter cellFormatter = loginLayout.getFlexCellFormatter();

    // Add a title to the form
    loginLayout.setHTML(0, 0, this.headline);

    // Add username and password fields
    username.setWidth("150px");
    password.setWidth("150px");
    loginLayout.setHTML(1, 0, this.usernameLabel);
    loginLayout.setWidget(1, 1, username);
    loginLayout.setHTML(2, 0, passwordLabel);
    loginLayout.setWidget(2, 1, password);

    //Add the loginbutton to the form
    loginLayout.setWidget(3, 0, loginbutton);
    cellFormatter.setColSpan(3, 0, 2);
    cellFormatter.setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_CENTER);

    // Wrap the content in a DecoratorPanel
    decPanel.setWidget(loginLayout);

    mainpanel.setWidth(windowWidth / 2 + "px");
    mainpanel.setHeight(windowHeight * 0.6 + "px");
    mainpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    mainpanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    mainpanel.add(logo);
    mainpanel.add(secondoHeadline);
    mainpanel.add(decPanel);
}

From source file:com.threerings.gwt.ui.Popups.java

License:Open Source License

/**
 * Shows the supplied popup in the specified position relative to the specified target widget.
 *///  www  .  j av a2 s. c o m
public static <T extends PopupPanel> T show(T popup, Position pos, Widget target) {
    popup.setVisible(false);
    popup.show();

    int left, top;
    switch (pos) {
    case RIGHT:
        left = target.getAbsoluteLeft() + target.getOffsetWidth() + NEAR_GAP;
        break;
    default:
        left = target.getAbsoluteLeft();
        break;
    }
    if (left + popup.getOffsetWidth() > Window.getClientWidth()) {
        left = Math.max(0, Window.getClientWidth() - popup.getOffsetWidth());
    }

    switch (pos) {
    case ABOVE:
        top = target.getAbsoluteTop() - popup.getOffsetHeight() - NEAR_GAP;
        break;
    case OVER:
        top = target.getAbsoluteTop();
        break;
    case RIGHT:
        top = target.getAbsoluteTop() + (target.getOffsetHeight() - popup.getOffsetHeight()) / 2;
        break;
    default:
    case BELOW:
        top = target.getAbsoluteTop() + target.getOffsetHeight() + NEAR_GAP;
        break;
    }

    popup.setPopupPosition(left, top);
    popup.setVisible(true);
    return popup;
}

From source file:com.threerings.gwt.ui.Popups.java

License:Open Source License

/**
 * Centers the supplied vertically on the supplied trigger widget. The popup's showing state
 * will be preserved.//from   ww w  .  j av a 2 s .  c o m
 *
 * @return the supplied popup.
 */
public static <T extends PopupPanel> T centerOn(T popup, int ypos) {
    boolean wasHidden = !popup.isShowing();
    boolean wasVisible = popup.isVisible();
    if (wasVisible) {
        popup.setVisible(false);
    }
    if (wasHidden) {
        popup.show();
    }
    int left = (Window.getClientWidth() - popup.getOffsetWidth()) >> 1;
    int top = ypos - popup.getOffsetHeight() / 2;
    // bound the popup into the visible browser area if possible
    if (popup.getOffsetHeight() < Window.getClientHeight()) {
        top = Math.min(Math.max(0, top), Window.getClientHeight() - popup.getOffsetHeight());
    }
    popup.setPopupPosition(left, top);
    if (wasHidden) {
        popup.hide();
    }
    if (wasVisible) {
        popup.setVisible(true);
    }
    return popup;
}

From source file:com.threerings.gwt.ui.Widgets.java

License:Open Source License

/**
 * Wraps the supplied contents in a scroll panel that will set the max-width to
 * Window.getClientWidth()-xpad and the max-height to Window.getClientHeight()-ypad. If either
 * xpad or ypad are less than zero, the max-size attribute on that axis will not be set.
 *///from  w  w  w.ja  v  a2  s.  c o  m
public static ScrollPanel newScrollPanel(Widget contents, int xpad, int ypad) {
    ScrollPanel panel = new ScrollPanel(contents);
    if (xpad >= 0) {
        String maxWidth = (Window.getClientWidth() - xpad) + "px";
        DOM.setStyleAttribute(panel.getElement(), "maxWidth", maxWidth);
    }
    if (ypad >= 0) {
        String maxHeight = (Window.getClientHeight() - ypad) + "px";
        DOM.setStyleAttribute(panel.getElement(), "maxHeight", maxHeight);
    }
    return panel;
}