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.threerings.perf.html.PerfTestHtml.java

public void onModuleLoad() {
    HtmlPlatform.Config config = new HtmlPlatform.Config();
    config.antiAliasing = false;// w  ww  . ja va2s .  co m
    config.backgroundFrameMillis = 100; // 10 fps background rendering
    final HtmlPlatform plat = new HtmlPlatform(config);
    //plat.assets().setPathPrefix("playn-perf/");

    plat.graphics().setSize(Window.getClientWidth(), Window.getClientHeight());
    Window.scrollTo(0, 0);

    plat.log().setCollector(new Collector() {
        public void logged(Level level, String msg, Throwable e) {
            log(level.toString() + ": " + msg);
            if (e != null) {
                log(e.getMessage());
            }
        }

        native void log(String msg) /*-{ console.log(msg); }-*/;
    });

    new PerfTest(plat);
    plat.start();
}

From source file:com.tractionsoftware.gwt.user.client.util.Geometry.java

License:Apache License

/**
 * This takes into account scrolling and will be in absolute
 * coordinates where the top left corner of the page is 0,0 but
 * the viewport may be scrolled to something else.
 *//*from w  w  w .j  av  a  2 s.c  om*/
public static final Rect getViewportBounds() {
    return new Rect(Window.getScrollLeft(), Window.getScrollTop(), Window.getClientWidth(),
            Window.getClientHeight());
}

From source file:com.ui.gwt.mobile.client.components.mobile.TouchHandler.java

License:Apache License

/**
 * Touch move handler./* w  w  w .  j a va  2  s  . c o  m*/
 *
 * @param e The touchmove event.
 */
private void onMove(final TouchEvent e) {
    if (!tracking || dragDelegate == null) {
        return;
    }

    // Prevent native scrolling.
    e.preventDefault();

    Touch touch = getTouchFromEvent(e);
    Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY());

    double moveX = lastTouchPosition.x - touchCoordinate.x;
    double moveY = lastTouchPosition.y - touchCoordinate.y;
    totalMoveX += Math.abs(moveX);
    totalMoveY += Math.abs(moveY);
    lastTouchPosition.x = touchCoordinate.x;
    lastTouchPosition.y = touchCoordinate.y;

    // Handle case where they are getting close to leaving the window.
    // End events are unreliable when the touch is leaving the viewport area.
    // If they are close to the bottom or the right, and we don't get any other
    // touch events for another 100ms, assume they have left the screen. This
    // does not seem to be a problem for scrolling off the top or left of the
    // viewport area.
    if (scrollOffTimer != null) {
        scrollOffTimer.cancel();
    }
    if ((Window.getClientHeight() - touchCoordinate.y) < TOUCH_END_WORKAROUND_THRESHOLD
            || (Window.getClientWidth() - touchCoordinate.x) < TOUCH_END_WORKAROUND_THRESHOLD) {

        scrollOffTimer = new Timer() {
            @Override
            public void run() {
                e.setTimeStamp(Duration.currentTimeMillis());
                onEnd(e);
            }
        };
        scrollOffTimer.schedule(100);
    }

    // boolean firstDrag = false;
    if (!dragging) {
        if (totalMoveY > MIN_TRACKING_FOR_DRAG || totalMoveX > MIN_TRACKING_FOR_DRAG) {
            dragging = true;
            // firstDrag = true;
            dragDelegate.onDragStart(e);
        }
    }

    if (dragging) {
        dragDelegate.onDragMove(e);

        lastEvent = e;

        // This happens when they are dragging slowly. If they are dragging slowly
        // then we should reset the start time and position to where they are now.
        // This will be important during the drag end when we report to the
        // draggable delegate what kind of drag just happened.
        if (e.getTimeStamp() - recentTime > MAX_TRACKING_TIME) {
            recentTime = e.getTimeStamp();
            recentTouchPosition = touchCoordinate;
        }
    }
}

From source file:com.urlisit.siteswrapper.cloud.client.RenderedPage.java

License:Apache License

private static void sizeLayoutElements() {
    RenderedPage.windowHeight = Window.getClientHeight();
    RenderedPage.windowWidth = Window.getClientWidth();
    RenderedPage.mainPanel.setHeight(RenderedPage.windowHeight + "px");
    RenderedPage.mainPanel.setWidth(RenderedPage.windowWidth + "px");
    RenderedPage.locLangSelectorWidth = (int) Math
            .round(RenderedPage.locLangSelectorWidthPercent * RenderedPage.windowWidth);
    RenderedPage.locLangSelectorHeight = (int) Math
            .round(RenderedPage.locLangSelectorHeightPercent * RenderedPage.windowHeight);
    RenderedPage.locLangSelectorTop = (int) Math
            .round(RenderedPage.locLangSelectorTopPercent * RenderedPage.windowHeight);
    RenderedPage.locLangSelectorLeft = (int) Math
            .round(RenderedPage.locLangSelectorLeftPercent * RenderedPage.windowWidth);
    RenderedPage.locLangSelector.setSize(RenderedPage.locLangSelectorWidth + "px",
            RenderedPage.locLangSelectorHeight + "px");
    RenderedPage.searchFieldWidth = (int) Math
            .round(RenderedPage.searchFieldWidthPercent * RenderedPage.windowWidth);
    ;//  ww  w  . j av a  2 s  . c  om
    RenderedPage.searchFieldHeight = (int) Math
            .round(RenderedPage.searchFieldHeightPercent * RenderedPage.windowHeight);
    RenderedPage.searchFieldLeft = (int) Math
            .round(RenderedPage.searchFieldLeftPercent * RenderedPage.windowWidth);
    RenderedPage.searchFieldTop = (int) Math
            .round(RenderedPage.searchFieldTopPercent * RenderedPage.windowHeight);
    RenderedPage.searchField.setPixelSize(RenderedPage.searchFieldWidth, RenderedPage.searchFieldHeight);
    RenderedPage.searchButtonHeight = (int) Math
            .round(RenderedPage.searchButtonHeightPercent * RenderedPage.windowHeight);
    RenderedPage.searchButtonWidth = (int) Math
            .round(RenderedPage.searchButtonHeight * RenderedPage.searchButtonWidthPercent);
    RenderedPage.searchButtonLeft = (int) Math
            .round(RenderedPage.searchButtonLeftPercent * RenderedPage.windowWidth);
    RenderedPage.searchButtonTop = (int) Math
            .round(RenderedPage.searchButtonTopPercent * RenderedPage.windowHeight);
    RenderedPage.searchButton.setPixelSize(RenderedPage.searchButtonWidth, RenderedPage.searchButtonHeight);
    RenderedPage.mainMenuTop = (int) Math.round(RenderedPage.mainMenuTopPercent * RenderedPage.windowHeight);
    RenderedPage.mainMenu.getElement().getStyle().setWidth(RenderedPage.windowWidth, Style.Unit.PX);
}

From source file:com.urlisit.siteswrapper.cloud.view.Koninklijke.java

License:Apache License

@Override
protected void initWidget(Widget widget) {
    presenter.bindView(this);
    viewPanel = (AbsolutePanel) widget;//from w ww  .j  a va2s .c  om
    viewPanel.setPixelSize(Window.getClientWidth(), Window.getClientHeight());
    viewPanel.getElement().getStyle().setPosition(Position.RELATIVE);
    super.initWidget(viewPanel);
}

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

License:Apache License

@Override
public void onResize() {
    if (isLoaded) {
        windowWidth = BigDecimal.valueOf(Window.getClientWidth());
        windowHeight = BigDecimal.valueOf(Window.getClientHeight());
        imageWidth = BigDecimal.valueOf(image.getWidth());
        imageHeight = BigDecimal.valueOf(image.getHeight());
        widthRatio = windowWidth.divide(imageWidth, 4, BigDecimal.ROUND_HALF_EVEN);
        heightRatio = windowHeight.divide(imageHeight, 4, BigDecimal.ROUND_HALF_EVEN);
        int left = 0;
        int top = 0;
        if (widthRatio.compareTo(heightRatio) >= 0) {
            scaledWidth = widthRatio.multiply(imageWidth);
            scaledHeight = widthRatio.multiply(imageHeight);
            top = scaledHeight.subtract(windowHeight).divide(new BigDecimal(2)).intValue();
            image.setWidth(scaledWidth.intValue() + "px");
            image.setHeight(scaledHeight.intValue() + "px");
            view.getPanel().setWidgetPosition(this, left, -top);
        } else {//from   w  ww  .j a v a  2  s  .c  o m
            scaledWidth = heightRatio.multiply(imageWidth);
            scaledHeight = heightRatio.multiply(imageHeight);
            left = scaledWidth.subtract(windowWidth).divide(new BigDecimal(2)).intValue();
            image.setWidth(scaledWidth.intValue() + "px");
            image.setHeight(scaledHeight.intValue() + "px");
            view.getPanel().setWidgetPosition(this, -left, top);
        }
    }
}

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

License:Apache License

public void resize() {
    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(logo, left, top);
    } else {/*from  w  w w. ja va2 s .c o  m*/
        logo.addLoadHandler(new LoadHandler() {
            @Override
            public void onLoad(LoadEvent event) {
                //logo.setVisible(true);
                loaded = true;
                resize();
            }
        });
    }
}

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

License:Apache License

/**
 * // w  w w  . j av a 2  s. c  om
 */
public InformationItemPopup(Item item, Literals literals) {
    this.item = item;
    this.literals = literals;
    popup.setText(item.getName());
    popup.setGlassEnabled(true);
    popup.setAnimationEnabled(true);
    VerticalPanel contents = new VerticalPanel();
    contents.setSpacing(5);
    contents.setWidth(Double.valueOf(Window.getClientWidth() * .75).intValue() + "px");
    popup.setWidget(contents);
    HTML description = new HTML(item.getDescription());
    contents.add(description);
    //contents.setCellHorizontalAlignment(description, HasHorizontalAlignment.ALIGN_CENTER);
    contents.setCellHorizontalAlignment(description, HasHorizontalAlignment.ALIGN_JUSTIFY);
    HorizontalPanel hContents = new HorizontalPanel();
    String videoEmbedHtml = literals.youTubeOldEmbed420x315().replace("VIDEO_URL", item.getVideoUrl());
    final HTML video = new HTML(videoEmbedHtml);
    final Image image = new Image(item.getImageUrl());
    image.setVisible(false);
    image.addLoadHandler(new LoadHandler() {
        @Override
        public void onLoad(LoadEvent event) {
            BigDecimal newHeight = BigDecimal.valueOf(315.00);
            BigDecimal width = BigDecimal.valueOf(Integer.valueOf(image.getWidth()).doubleValue());
            BigDecimal height = BigDecimal.valueOf(Integer.valueOf(image.getHeight()).doubleValue());
            BigDecimal newWidth = newHeight.multiply(width.divide(height, 4, BigDecimal.ROUND_HALF_EVEN));
            image.setPixelSize(newWidth.intValue(), newHeight.intValue());
            image.setVisible(true);
        }
    });
    hContents.add(video);
    hContents.add(image);
    contents.add(hContents);
    contents.setCellHorizontalAlignment(hContents, HasHorizontalAlignment.ALIGN_CENTER);
    Button closeButton = new Button("Close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            popup.hide();
        }
    });
    contents.add(closeButton);
    contents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT);
}

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

License:Apache License

public void show() {
    //Window.alert(Double.valueOf(Window.getClientWidth() * .75).intValue() + "");
    popup.setHeight(Double.valueOf(Window.getClientHeight() * .75).intValue() + "px");
    popup.setWidth(Double.valueOf(Window.getClientWidth() * .75).intValue() + "px");
    popup.center();//from  www  . j  a v a  2  s  .c o m
    popup.show();
}

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

License:Apache License

@Override
public void onResize() {
    int left = leftPercent.multiply(BigDecimal.valueOf(Double.valueOf(Window.getClientWidth()))).intValue();
    int top = topPercent.multiply(BigDecimal.valueOf(Double.valueOf(Window.getClientHeight()))).intValue();
    view.getPanel().setWidgetPosition(logo, left, top);
}