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.lorepo.icplayer.client.module.choice.MyPopupPanel.java

License:Apache License

/**
 * Positions the popup, called after the offset width and height of the popup
 * are known.// w w w  .j  ava 2 s . c om
 *
 * @param relativeObject the ui object to position relative to
 * @param offsetWidth the drop down's offset width
 * @param offsetHeight the drop down's offset height
 */
private void position(final UIObject relativeObject, int offsetWidth, int offsetHeight) {
    // Calculate left position for the popup. The computation for
    // the left position is bidi-sensitive.

    int textBoxOffsetWidth = relativeObject.getOffsetWidth();

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

    int left;

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

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

From source file:com.LSH.client.LSH.java

License:Apache License

/**
 * ?   UI/*from  w  ww .java2  s . c om*/
 */
public void onModuleLoad() {

    /*  ? ? */

    String linkWidth = String.valueOf(Window.getClientWidth() / 4);

    // HP = HorizontalPanel; VP = VerticalPanel
    final HorizontalPanel simpleDataHP = new HorizontalPanel(); //  ?  ??
    final HorizontalPanel simpleAnswerHP = new HorizontalPanel(); //  ?  
    final VerticalPanel simpleVP = new VerticalPanel(); //  ? ? ,  

    simpleShortButton.addClickHandler(new SimpleClickHandler()); // ??    
    simpleOriginalLink.addKeyDownHandler(new EnterKeyListener(simpleShortButton)); // ??    ? Enter
    simpleCopyButton.addClickHandler(new CopyClickHandler("simpleAnswer")); // ??       ?

    simpleOriginalLink.setWidth(linkWidth); // ?  ?
    simpleDataHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); // 
    simpleDataHP.setSpacing(5); // ?

    //  
    simpleDataHP.add(simpleOriginalLink);
    simpleDataHP.add(simpleShortButton);

    // ?, ?
    simpleAnswerHP.setSpacing(5);
    simpleAnswerHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    //  
    simpleAnswerHP.add(simpleShortText);
    simpleAnswerHP.add(simpleShortLink);
    simpleAnswerHP.add(simpleCopyButton);

    //  
    simpleVP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    simpleVP.setSpacing(10);
    simpleVP.add(simpleDataHP);
    simpleVP.add(simpleAnswerHP);

    // ?   ?
    simpleShortText.setVisible(false);
    simpleCopyButton.setVisible(false);

    /*  ? ? */
    //  ? ?
    final HorizontalPanel complexLinkHP = new HorizontalPanel(); //  ?  ??
    final HorizontalPanel complexDataHP = new HorizontalPanel(); // 
    final HorizontalPanel complexOptionalData = new HorizontalPanel(); //  
    final HorizontalPanel complexAnswerHP = new HorizontalPanel(); // 

    final VerticalPanel complexVP = new VerticalPanel(); //  ,  
    final VerticalPanel complexOptionalVP = new VerticalPanel(); //  ,  

    EnterKeyListener complexKey = new EnterKeyListener(complexShortButton); //  ?   Enter
    complexCopyButton.addClickHandler(new CopyClickHandler("complexAnswer"));

    // ?     ??
    complexTime.addItem("1 hour");
    complexTime.addItem("12 hours");
    complexTime.addItem("1 day");
    complexTime.addItem("1 week");
    complexTime.addItem("1 month");
    complexTime.addItem("Unlimited");
    complexTime.setSelectedIndex(3);

    // ??  ?
    complexOriginalLink.setWidth(linkWidth);
    complexCount.setWidth("40px");
    complexCount.setValue(10);

    complexShortButton.addClickHandler(new ComplexClickHandler()); //   ?  
    // ?  ?  Enter  ? ?
    complexOriginalLink.addKeyDownHandler(complexKey);
    complexName.addKeyDownHandler(complexKey);
    complexCount.addKeyDownHandler(complexKey);
    complexTime.addKeyDownHandler(complexKey);
    complexPassword.addKeyDownHandler(complexKey);

    // ??     ?
    complexLinkHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    complexLinkHP.setSpacing(5);
    complexLinkHP.add(complexText);
    complexLinkHP.add(complexOriginalLink);

    complexDataHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    complexDataHP.setSpacing(5);
    complexDataHP.add(complexTimeText);
    complexDataHP.add(complexTime);
    complexDataHP.add(complexCountText);
    complexDataHP.add(complexCount);

    complexCount.setAlignment(ValueBoxBase.TextAlignment.CENTER); // ? ? 
    complexCount.setMaxLength(5); // ?? - ?

    complexOptionalData.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    complexOptionalData.setSpacing(5);
    complexOptionalData.add(complexNameText);
    complexOptionalData.add(complexName);
    complexOptionalData.add(complexPasswordText);
    complexOptionalData.add(complexPassword);

    complexAnswerHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    complexAnswerHP.setSpacing(5);
    complexAnswerHP.add(complexShortText);
    complexAnswerHP.add(complexShortLink);
    complexAnswerHP.add(complexCopyButton);

    complexVP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    complexVP.setSpacing(5);
    complexVP.add(complexLinkHP);
    complexVP.add(complexDataHP);

    complexOptionalVP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    complexOptionalVP.setSpacing(5);
    complexOptionalVP.add(complexOptionalData);
    complexOptionalVP.add(complexShortButton);
    complexOptionalVP.add(complexAnswerHP);

    //   
    complexShortText.setVisible(false);
    complexCopyButton.setVisible(false);

    /* ?? ? ?  */

    loginButton.addClickHandler(new ClickHandler() { //        
        @Override
        public void onClick(ClickEvent event) {
            dialog.Login();
        }
    });

    logoutButton.addClickHandler(new ClickHandler() { //  
        @Override
        public void onClick(ClickEvent event) { //  
            Cookies.removeCookie(cookieName); // ?   

            //   ?  ? ???
            loginButton.setVisible(true);
            loginLabel.setHTML("");
            loginLabel.setVisible(false);
            logoutButton.setVisible(false);
        }
    });

    // ??     
    final HorizontalPanel loginHP = new HorizontalPanel();
    loginHP.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    loginHP.setSpacing(5);
    loginHP.add(loginLabel);
    loginHP.add(logoutButton);
    loginHP.add(loginButton);

    logoutButton.setVisible(false);
    dialog.hide(); //     ?

    // ?    ?
    RootPanel.get("Login").add(loginHP);
    RootPanel.get("SimpleShort").add(simpleVP);
    RootPanel.get("ComplexShort").add(complexVP);
    RootPanel.get("ComplexShortOptional").add(complexOptionalVP);
}

From source file:com.milmaps.client.MobileEntryPoint.java

License:Open Source License

private void setView() {
    int w = Window.getClientWidth();
    int h = Window.getClientHeight();

    m_controlsAndMap.setPixelSize(w, h);
    m_touchPanel.setPixelSize(w, h);//from  w ww .  java  2s.co m
    m_mapView.resizeMap(w, h);
    m_mapView.updateView();
}

From source file:com.minesweeper.client.MinesweeperWidget.java

License:Apache License

/**
 * Timer to clear the UI./* ww  w  . j a va2 s. co m*/
 */
//   Timer timer = new Timer() {
//      @Override
//      public void run() {
//         status.setInnerText("");
//         status.setClassName(STATUS_NONE);
//      }
//   };
//
//   private void setStatus(String message, boolean error) {
//      status.setInnerText(message);
//      if (error) {
//         status.setClassName(STATUS_ERROR);
//      } else {
//         if (message.length() == 0) {
//            status.setClassName(STATUS_NONE);
//         } else {
//            status.setClassName(STATUS_SUCCESS);
//         }
//      }
//
//      timer.schedule(STATUS_DELAY);
//   }

public MinesweeperWidget() {
    initWidget(uiBinder.createAndBindUi(this));
    final EventBus eventBus = new SimpleEventBus();

    requestFactory.initialize(eventBus);

    // Fill the list
    fillList();

    for (int i = 0; i < buttonPanel.length; i++) {
        previous[i] = new Button("Previous");
        buttonPanel[i] = new HorizontalPanel();
        buttonPanel[i].add(previous[i]);
        next[i] = new Button("Next");
        buttonPanel[i].add(next[i]);
        buttonPanel[i].addStyleName("buttonPanel");

        next[i].setEnabled(false);
        next[i].addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                showNext(((Button) event.getSource()).getTitle());
            }
        });
        previous[i].setEnabled(false);
        previous[i].addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                showPrevious(((Button) event.getSource()).getTitle());
            }
        });
    }

    next[0].setTitle("Logs");
    next[1].setTitle("Forms");

    previous[0].setTitle("Logs");
    previous[1].setTitle("Forms");

    FlowPanel p = new FlowPanel();
    p.add(listBox);
    p.setStyleName("buttonPanel");

    logsPanel.add(logsTable);
    logsPanel.add(buttonPanel[0]);
    tabPanel.add(logsPanel, "Logs");

    formsPanel.add(formsTable);
    formsPanel.add(buttonPanel[1]);
    tabPanel.add(formsPanel, "Forms");

    tabPanel.selectTab(0);
    tabPanel.setPixelSize(Window.getClientWidth(), Window.getClientHeight());

    VerticalPanel mainPanel = new VerticalPanel();
    mainPanel.add(p);
    mainPanel.add(tabPanel);

    ScrollPanel scroll = new ScrollPanel(mainPanel);
    scroll.setPixelSize(Window.getClientWidth(), Window.getClientHeight());

    // Associate the main panel with the HTML host page
    RootPanel.get("accGames").add(scroll);

    // List box with accessible games
    listBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            updateTable(listBox.getValue(listBox.getSelectedIndex()));
            if (indexOfLogs * MAX_LOG + MAX_LOG > logs.size())
                next[0].setEnabled(false);
            else
                next[0].setEnabled(true);
            if (indexOfForms * MAX_LOG + MAX_LOG > forms.size())
                next[1].setEnabled(false);
            else
                next[1].setEnabled(true);
        }
    });

    // Setup timer to refresh list automatically.
    Timer refreshTimer = new Timer() {

        @Override
        public void run() {
            fillList();
        }
    };
    refreshTimer.scheduleRepeating(REFRESH_INTERVAL);
}

From source file:com.moesol.gwt.maps.client.controls.BubbleControl.java

License:Open Source License

/**
 * Show the bubble control over the map using an animation. If you call this
 * method from HoverHandler you can pass clientX and clientY from the event
 * to have the bubble show up near the mouse.
 * /*from ww w  .  j a v a2  s.c  o m*/
 * @param x
 *            - clientX
 * @param y
 *            - clientY
 */
public void animateShow(int x, int y) {
    m_initialX = x;
    m_initialY = y;

    Animation a = new Animation() {

        @Override
        protected void onStart() {
            //getWidget().getElement().getStyle().setProperty("fontSize", 0.0 * 100.0 + "%");
            setPopupPosition(m_initialX, m_initialY);
            show();
        }

        @Override
        protected void onUpdate(double progress) {
            //getWidget().getElement().getStyle().setProperty("fontSize", progress * 100.0 + "%");
            int targetX = Math.min(m_initialX + (int) (LEFT_OFFSET * progress),
                    Window.getClientWidth() - getOffsetWidth());
            int targetY = m_initialY + (int) (TOP_OFFSET * progress) - getOffsetHeight();
            targetY = Math.max(targetY, Document.get().getScrollTop());
            setPopupPosition(targetX, targetY);
        }
    };

    a.run(m_duration);
}

From source file:com.moesol.gwt.maps.client.controls.BubbleControl.java

License:Open Source License

/**
 * Show the bubble control over the map without any animation. 
 * //  w  ww  . j  a  v  a2  s  .c om
 * @param x clientX
 * @param y clientY
 */
public void show(int x, int y) {
    int targetX = Math.min(x + (int) (LEFT_OFFSET), Window.getClientWidth() - getOffsetWidth());
    int targetY = y + (int) (TOP_OFFSET) - getOffsetHeight();
    targetY = Math.max(targetY, Document.get().getScrollTop());
    setPopupPosition(targetX, targetY);
    show();
}

From source file:com.moesol.gwt.maps.client.Driver.java

License:Open Source License

protected void resizeMap() {
    int h = Window.getClientHeight();
    int w = Window.getClientWidth();
    m_map.resizeMap(w - 50, h - 50);//  ww w .  j a va2s .c  om

    updateTileInfo();
}

From source file:com.moesol.gwt.maps.client.MCOP.java

License:Open Source License

private void doMapPanel(RootPanel mapPanel) {
    DOM.setInnerHTML(mapPanel.getElement(), "");
    TouchPanel touchPanel = makeTouchPanel();
    AbsolutePanel controlsAndMap = new AbsolutePanel();

    m_msg = new Label("msg...");
    m_map = new MapView();
    loadLayerConfigsFromClient();/* w  w w .  j  a v a  2s  .c  o  m*/

    int w = Window.getClientWidth() - 20;
    int h = Window.getClientHeight() - 20;

    controlsAndMap.setPixelSize(w, h);
    m_map.setPixelSize(w, h);
    m_map.updateView();
    bindListeners(touchPanel, m_map);

    Button in = new Button(" + ", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            goIn();
        }
    });
    Button out = new Button(" - ", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            goOut();
        }
    });

    HorizontalPanel bar = new HorizontalPanel();
    bar.add(in);
    bar.add(out);
    bar.add(m_msg);

    touchPanel.setWidget(m_map);
    controlsAndMap.add(touchPanel);
    controlsAndMap.add(bar);
    controlsAndMap.setWidgetPosition(bar, 10, 10);
    mapPanel.add(controlsAndMap);

    // Layer a tranparent dialog...
    //      DialogBox db = new DialogBox();
    //      VerticalPanel dbPanel = new VerticalPanel();
    //      db.setHTML("<a href='' onclick='false'>x</a>");
    //      db.setPopupPosition(100, 10);
    //      db.setPixelSize(100, 100);
    //      db.show();
}

From source file:com.moesol.mapsample.client.MapSample.java

License:Open Source License

protected void resizeMap() {
    int h = Window.getClientHeight();
    int w = Window.getClientWidth();
    m_map.resizeMap(w - 50, h - 50);//from   w w w. j  av  a  2 s  .c o  m
    updateTileInfo();
}

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.ExplorerShell.java

License:sencha.com license

public ExplorerShell() {
    monitorWindowResize = true;//www  .j  ava2s . c  o m
    Window.enableScrolling(false);
    setPixelSize(Window.getClientWidth(), Window.getClientHeight());

    setStateful(true);
    setStateId("explorerLayout");

    BorderLayoutStateHandler state = new BorderLayoutStateHandler(this);
    state.loadState();
}