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:geogebra.web.gui.util.PopupPanel.java

License:Apache License

/**
 * Centers the popup in the browser window and shows it. If the popup was
 * already showing, then the popup is centered.
 *//*  w  w w.j ava 2  s .  c om*/
public void center() {
    boolean initiallyShowing = showing;
    boolean initiallyAnimated = isAnimationEnabled;

    if (!initiallyShowing) {
        setVisible(false);
        setAnimationEnabled(false);
        show();
    }

    // If left/top are set from a previous center() call, and our content
    // has changed, we may get a bogus getOffsetWidth because our new content
    // is wrapping (giving a lower offset width) then it would without the
    // previous left. Setting left/top back to 0 avoids this.
    Element elem = getElement();
    elem.getStyle().setPropertyPx("left", 0);
    elem.getStyle().setPropertyPx("top", 0);

    int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
    int top = (Window.getClientHeight() - getOffsetHeight()) >> 1;
    setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0));

    if (!initiallyShowing) {
        setAnimationEnabled(initiallyAnimated);
        // Run the animation. The popup is already visible, so we can skip the
        // call to setState.
        if (initiallyAnimated) {
            impl.setClip(getElement(), "rect(0px, 0px, 0px, 0px)");
            setVisible(true);
            resizeAnimation.run(ANIMATION_DURATION);
        } else {
            setVisible(true);
        }
    }
}

From source file:gov.nist.appvet.gwt.client.gui.AppVetPanel.java

License:Open Source License

public static int[] getCenterPosition(com.google.gwt.user.client.ui.UIObject object) {
    final int windowWidth = Window.getClientWidth();
    final int windowHeight = Window.getClientHeight();
    final int xposition = (windowWidth / 2) - (object.getOffsetHeight() / 2);
    final int yposition = (windowHeight / 2) - (object.getOffsetWidth() / 2);
    final int[] position = { xposition, yposition };
    return position;
}

From source file:gov.nist.spectrumbrowser.client.LoginScreen.java

License:Open Source License

public LoginScreen(SpectrumBrowser spectrumBrowser) {
    verticalPanel = new VerticalPanel();
    RootPanel rootPanel = RootPanel.get();
    VerticalPanel rootVerticalPanel = new VerticalPanel();
    rootPanel.add(rootVerticalPanel);/*from w ww.j  a  v  a  2 s.c o m*/
    rootVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    rootVerticalPanel.setWidth(Window.getClientWidth() + "px");

    HorizontalPanel hpanel = new HorizontalPanel();
    int height = 50;
    hpanel.setWidth(SpectrumBrowser.MAP_WIDTH + "px");
    Image nistLogo = new Image(SpectrumBrowser.getIconsPath() + "nist-logo.png");
    nistLogo.setPixelSize((int) (215.0 / 95.0 * height), height);
    Image ntiaLogo = new Image(SpectrumBrowser.getIconsPath() + "ntia-logo.png");
    ntiaLogo.setPixelSize(height, height);
    hpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    hpanel.add(nistLogo);
    HTML html = new HTML("<h2>CAC Measured Spectrum Occupancy Database (BETA)</h2>");
    hpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    hpanel.add(html);
    hpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    hpanel.add(ntiaLogo);
    rootVerticalPanel.add(hpanel);

    rootVerticalPanel.add(verticalPanel);
    this.spectrumBrowser = spectrumBrowser;
}

From source file:gov.wa.wsdot.mobile.client.activities.ferries.vesselwatch.VesselWatchMapViewGwtImpl.java

License:Open Source License

public VesselWatchMapViewGwtImpl() {

    initWidget(uiBinder.createAndBindUi(this));

    accessibilityPrepare();/*w  w w . j a v a2  s  .  c o m*/

    if (MGWT.getOsDetection().isAndroid()) {
        leftFlexSpacer.setVisible(false);
    }

    if (localStorage != null) {
        storageMap = new StorageMap(localStorage);
        if (!storageMap.containsKey("KEY_SHOW_CAMERAS")) {
            localStorage.setItem("KEY_SHOW_CAMERAS", "true"); // Set initial default value
        }

        // Set initial default location and zoom to Seattle area.
        localStorage.setItem("KEY_MAP_LAT", "47.565125");
        localStorage.setItem("KEY_MAP_LON", "-122.480508");
        localStorage.setItem("KEY_MAP_ZOOM", "11");
    }

    final TrafficLayer trafficLayer = TrafficLayer.newInstance();

    LatLng center = LatLng.newInstance(Double.valueOf(localStorage.getItem("KEY_MAP_LAT")),
            Double.valueOf(localStorage.getItem("KEY_MAP_LON")));

    MapOptions opts = MapOptions.newInstance();
    opts.setMapTypeId(MapTypeId.ROADMAP);
    opts.setCenter(center);
    opts.setZoom(Integer.valueOf(localStorage.getItem("KEY_MAP_ZOOM"), 10));
    opts.setPanControl(false);
    opts.setZoomControl(false);
    opts.setMapTypeControl(false);
    opts.setScaleControl(false);
    opts.setStreetViewControl(false);
    opts.setOverviewMapControl(false);

    // Custom map style to remove all "Points of Interest" labels from map
    MapTypeStyle style1 = MapTypeStyle.newInstance();
    style1.setFeatureType(MapTypeStyleFeatureType.POI);
    style1.setElementType(MapTypeStyleElementType.LABELS);
    style1.setStylers(new MapTypeStyler[] { MapTypeStyler.newVisibilityStyler("off") });
    MapTypeStyle[] styles = { style1 };

    opts.setMapTypeStyles(styles);

    mapWidget = new MyMapWidget(opts);
    trafficLayer.setMap(mapWidget);
    flowPanel.add(mapWidget);

    mapWidget.setSize(Window.getClientWidth() + "px",
            (Window.getClientHeight() - ParserUtils.windowUI()) + "px");

    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            MapHandlerRegistration.trigger(mapWidget, MapEventType.RESIZE);

        }
    });

    mapWidget.addResizeHandler(new ResizeMapHandler() {
        @Override
        public void onEvent(ResizeMapEvent event) {
            mapWidget.setSize(Window.getClientWidth() + "px",
                    (Window.getClientHeight() - ParserUtils.windowUI()) + "px");
        }
    });

    mapWidget.addIdleHandler(new IdleMapHandler() {

        @Override
        public void onEvent(IdleMapEvent event) {
            localStorage.setItem("KEY_MAP_LAT", String.valueOf(mapWidget.getCenter().getLatitude()));
            localStorage.setItem("KEY_MAP_LON", String.valueOf(mapWidget.getCenter().getLongitude()));
            localStorage.setItem("KEY_MAP_ZOOM", String.valueOf(mapWidget.getZoom()));

            if (presenter != null) {
                presenter.onMapIsIdle();
            }
        }
    });

}

From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.TrafficMapViewGwtImpl.java

License:Open Source License

public TrafficMapViewGwtImpl() {

    initWidget(uiBinder.createAndBindUi(this));

    accessibilityPrepare();//  w w w.java  2s  .  c om

    if (MGWT.getOsDetection().isAndroid()) {
        leftFlexSpacer.setVisible(false);
    }

    if (localStorage != null) {
        storageMap = new StorageMap(localStorage);
        if (!storageMap.containsKey("KEY_SHOW_CAMERAS")) {
            localStorage.setItem("KEY_SHOW_CAMERAS", "true"); // Set initial default value
        }
        if (!storageMap.containsKey("KEY_SHOW_RESTAREAS")) {
            localStorage.setItem("KEY_SHOW_RESTAREAS", "false"); // Set initial default value
        }

        // Set initial default location and zoom to Seattle area.
        if (!storageMap.containsKey("KEY_MAP_LAT")) {
            localStorage.setItem("KEY_MAP_LAT", "47.5990");
        }
        if (!storageMap.containsKey("KEY_MAP_LON")) {
            localStorage.setItem("KEY_MAP_LON", "-122.3350");
        }
        if (!storageMap.containsKey("KEY_MAP_ZOOM")) {
            localStorage.setItem("KEY_MAP_ZOOM", "12");
        }
    }

    final TrafficLayer trafficLayer = TrafficLayer.newInstance();

    LatLng center = LatLng.newInstance(Double.valueOf(localStorage.getItem("KEY_MAP_LAT")),
            Double.valueOf(localStorage.getItem("KEY_MAP_LON")));

    MapOptions opts = MapOptions.newInstance();
    opts.setMapTypeId(MapTypeId.ROADMAP);
    opts.setCenter(center);
    opts.setZoom(Integer.valueOf(localStorage.getItem("KEY_MAP_ZOOM"), 10));
    opts.setPanControl(false);
    opts.setZoomControl(false);
    opts.setMapTypeControl(false);
    opts.setScaleControl(false);
    opts.setStreetViewControl(false);
    opts.setOverviewMapControl(false);

    // Custom map style to remove all "Points of Interest" labels from map
    MapTypeStyle style1 = MapTypeStyle.newInstance();
    style1.setFeatureType(MapTypeStyleFeatureType.POI);
    style1.setElementType(MapTypeStyleElementType.LABELS);
    style1.setStylers(new MapTypeStyler[] { MapTypeStyler.newVisibilityStyler("off") });
    MapTypeStyle[] styles = { style1 };

    opts.setMapTypeStyles(styles);

    mapWidget = new MyMapWidget(opts);
    trafficLayer.setMap(mapWidget);
    flowPanel.add(mapWidget);

    mapWidget.setSize(Window.getClientWidth() + "px",
            (Window.getClientHeight() - ParserUtils.windowUI()) + "px");

    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            MapHandlerRegistration.trigger(mapWidget, MapEventType.RESIZE);

        }
    });

    mapWidget.addResizeHandler(new ResizeMapHandler() {
        @Override
        public void onEvent(ResizeMapEvent event) {
            mapWidget.setSize(Window.getClientWidth() + "px",
                    (Window.getClientHeight() - ParserUtils.windowUI()) + "px");
        }
    });

    mapWidget.addIdleHandler(new IdleMapHandler() {

        @Override
        public void onEvent(IdleMapEvent event) {
            localStorage.setItem("KEY_MAP_LAT", String.valueOf(mapWidget.getCenter().getLatitude()));
            localStorage.setItem("KEY_MAP_LON", String.valueOf(mapWidget.getCenter().getLongitude()));
            localStorage.setItem("KEY_MAP_ZOOM", String.valueOf(mapWidget.getZoom()));

            if (presenter != null) {
                presenter.onMapIsIdle();
            }
        }
    });
}

From source file:gwt.material.design.client.base.AbstractSideNav.java

License:Apache License

protected void setupShowOnAttach() {
    if (showOnAttach != null) {
        // Ensure the side nav starts closed
        $(activator).trigger("menu-in", null);

        if (showOnAttach) {
            Scheduler.get().scheduleDeferred(() -> {
                // We are ignoring cases with mobile
                if (Window.getClientWidth() > 960) {
                    show();//from  ww w .  j av  a  2 s.  co  m
                }
            });
        }
    } else {
        if (Window.getClientWidth() > 960) {
            $(activator).trigger("menu-out", null);
        }
    }
}

From source file:gwt.material.design.components.client.ui.MaterialSnackbar.java

License:Apache License

protected void adjustPosition() {

    final Element fab = DOMHelper.getElementByClass(CssName.MDC_FAB__FIXED);
    final int thisPosition = getElement().getAbsoluteRight();
    final int fabPosition = fab == null ? Integer.MAX_VALUE : fab.getAbsoluteLeft();
    final boolean isLargeScreen = Window.getClientWidth() >= 1024;
    final String adjustPosition = thisPosition >= fabPosition
            ? "calc(56px + " + (isLargeScreen ? "1.5rem" : "1rem") + ")"
            : "0px";
    setCssProperty(CssMixin.MDC_SNACKBAR__POSITION_ADJUST, adjustPosition);

}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

private void calculateContainment() {
    String containmentAsString = options.getContainment();
    int[] containmentAsArray = options.getContainmentAsArray();
    GQuery $containement = options.getContainmentAsGQuery();

    if (containmentAsArray == null && containmentAsString == null && $containement == null) {
        containment = null;/*from w  w  w .  jav a 2  s  .co  m*/
        return;
    }

    if (containmentAsArray != null) {
        containment = containmentAsArray;
        return;
    }

    if (containmentAsString != null) {
        if ("window".equals(containmentAsString)) {
            containment = new int[] { 0 /*- relativeOffset.left - parentOffset.left*/,
                    0 /*- relativeOffset.top - parentOffset.top*/,
                    Window.getClientWidth() - helperDimension.getWidth() - margin.left,
                    Window.getClientHeight() - helperDimension.getHeight() - margin.top };

            return;
        }

        if ("parent".equals(containmentAsString)) {
            $containement = $(helper.get(0).getParentElement());
        } else if ("document".equals(containmentAsString)) {
            $containement = $("body");
        } else {
            $containement = $(containmentAsString);
        }
    }

    Element ce = $containement.get(0);
    if (ce == null) {
        return;
    }

    containment = impl.calculateContainment(this, $containement.offset(), ce,
            (!"hidden".equals($containement.css("overflow"))));

}

From source file:gwtquery.plugins.draggable.client.plugins.ScrollPlugin.java

License:Apache License

public void onDrag(DraggableHandler handler, DragContext ctx, GqEvent e) {
    DraggableOptions options = handler.getOptions();
    Element draggableElement = ctx.getDraggable();
    GQuery scrollParent = handler.getHelperScrollParent();
    Element scrollParentElement = scrollParent.get(0);
    if (scrollParentElement == null) {
        return;//  www .ja  va  2s  .com
    }

    AxisOption axis = options.getAxis();
    Offset overflowOffset = $(draggableElement).data(OVERFLOW_OFFSET_KEY, Offset.class);
    int scrollSensitivity = options.getScrollSensitivity();
    int scrollSpeed = options.getScrollSpeed();

    boolean scrolled = false;

    if (scrollParentElement != null && scrollParentElement != $(GQuery.document).get(0)
            && !"html".equalsIgnoreCase(scrollParentElement.getTagName())) {
        if (AxisOption.NONE == axis || AxisOption.Y_AXIS == axis) {
            // test if we have to scroll down...
            if ((overflowOffset.top + scrollParentElement.getOffsetHeight()) - e.pageY() < scrollSensitivity) {
                scrollParentElement.setScrollTop(scrollParentElement.getScrollTop() + scrollSpeed);
                scrolled = true;
                // test if we have to scroll up...
            } else if (e.pageY() - overflowOffset.top < scrollSensitivity) {
                scrollParentElement.setScrollTop(scrollParentElement.getScrollTop() - scrollSpeed);
                scrolled = true;
            }
        }

        if (AxisOption.NONE == axis || AxisOption.X_AXIS == axis) {
            // test if we have to scroll left...
            if ((overflowOffset.left + scrollParentElement.getOffsetWidth()) - e.pageX() < scrollSensitivity) {
                scrollParentElement.setScrollLeft(scrollParentElement.getScrollLeft() + scrollSpeed);
                scrolled = true;
                // test if we have to scroll right...
            } else if (e.pageX() - overflowOffset.left < scrollSensitivity) {
                scrollParentElement.setScrollLeft(scrollParentElement.getScrollLeft() - scrollSpeed);
                scrolled = true;
            }
        }

    } else {
        if (AxisOption.NONE == axis || AxisOption.Y_AXIS == axis) {
            if (e.pageY() - document.getScrollTop() < scrollSensitivity) {
                document.setScrollTop(document.getScrollTop() - scrollSpeed);
                scrolled = true;
            } else if (Window.getClientHeight() - (e.pageY() - document.getScrollTop()) < scrollSensitivity) {
                document.setScrollTop(document.getScrollTop() + scrollSpeed);
                scrolled = true;
            }
        }

        if (AxisOption.NONE == axis || AxisOption.X_AXIS == axis) {
            if (e.pageX() - document.getScrollLeft() < scrollSensitivity) {
                document.setScrollLeft(document.getScrollLeft() - scrollSpeed);
                scrolled = true;
            } else if (Window.getClientWidth() - (e.pageX() - document.getScrollLeft()) < scrollSensitivity) {
                document.setScrollLeft(document.getScrollLeft() + scrollSpeed);
                scrolled = true;
            }
        }

    }

    if (scrolled && DragAndDropManager.getInstance().isHandleDroppable(ctx)) {
        DragAndDropManager.getInstance().initialize(ctx, e);
    }

}

From source file:harvesterUI.client.mvc.views.FormView.java

License:Open Source License

private void showDataSetComparison() {
    dataSourceTabPanel.setPosition(0, 0);
    dataSourceTabPanel.setHeight(Window.getClientHeight());
    dataSourceTabPanel.setWidth((int) (Window.getClientWidth() * 0.5) - 110);
    //        dataSourceTabPanel.layout(true);
    dataSourceTabPanel.setModal(false);//from w w w.j a va  2 s. com
    ((DataSourceForm) ((TabPanel) dataSourceTabPanel.getItem(0)).getSelectedItem().getItem(0)).resetLayout();

    if (chooseDataSetDialog == null)
        chooseDataSetDialog = new ChooseDataSetDialog();
    chooseDataSetDialog.showAndCenter();
}