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:lh.api.showcase.client.BasicAbstractFormResultView.java

License:Apache License

protected Widget getResultWidgets() {
    VerticalPanel panel = new VerticalPanel();
    panel.setWidth("100%");
    ((HasHorizontalAlignment) panel).setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    panel.setSpacing(10);//from  www.j  a  va  2  s.  c  o  m
    panel.add(new HTML("<br>"));

    if (grid != null) {
        panel.add(new Label(Messages.Util.INSTANCE.get().results()));
        panel.add(grid);
    }

    DisclosurePanel advancedDisclosure = new DisclosurePanel(Messages.Util.INSTANCE.get().rawResults());

    StringBuilder textAreaWidth = new StringBuilder();
    textAreaWidth.append(Math.min(500, Window.getClientWidth()));
    textAreaWidth.append("px");
    textArea.setSize(textAreaWidth.toString(), "300px");
    //textArea.getElement().getStyle().setProperty("maxWidth", "500px");
    //textArea.setHeight("300px");
    advancedDisclosure.add(textArea);

    panel.add(advancedDisclosure);

    return panel;
}

From source file:liber.browse.client.WysiwymMenuBar.java

License:Apache License

/**
 * Performs the action associated with the given menu item. If the item has a
 * popup associated with it, the popup will be shown. If it has a command
 * associated with it, and 'fireCommand' is true, then the command will be
 * fired. Popups associated with other items will be hidden.
 *
 * @param item the item whose popup is to be shown. @param fireCommand <code>true</code>
 * if the item's command should be fired, <code>false</code> otherwise.
 *//*from w w  w  . j av a2s.c  o m*/
void doItemAction(final WysiwymMenuItem item, boolean fireCommand) {
    // If the given item is already showing its menu, we're done.
    if ((shownChildMenu != null) && (item.getSubMenu() == shownChildMenu)) {
        return;
    }

    // If another item is showing its menu, then hide it.
    if (shownChildMenu != null) {
        shownChildMenu.onHide();
        popup.hide();
    }

    // If the item has no popup, optionally fire its command.
    if (item.getSubMenu() == null) {
        if (fireCommand) {
            // Close this menu and all of its parents.
            closeAllParents();

            // Fire the item's command.
            Command cmd = item.getCommand();
            if (cmd != null) {
                DeferredCommand.add(cmd);
            }
        }
        return;
    }

    // Ensure that the item is selected.
    selectItem(item);

    // Create a new popup for this item, and position it next to
    // the item (below if this is a horizontal menu bar, to the
    // right if it's a vertical bar).
    popup = new PopupPanel(true) {
        {
            setWidget(item.getSubMenu());
            item.getSubMenu().onShow();
        }

        public boolean onEventPreview(Event event) {
            // Hook the popup panel's event preview. We use this to keep it from
            // auto-hiding when the parent menu is clicked.
            switch (DOM.eventGetType(event)) {
            case Event.ONCLICK:
                // If the event target is part of the parent menu, suppress the
                // event altogether.
                Element target = DOM.eventGetTarget(event);
                Element parentMenuElement = item.getParentMenu().getElement();
                if (DOM.isOrHasChild(parentMenuElement, target)) {
                    return false;
                }
                break;
            }

            return super.onEventPreview(event);
        }
    };
    popup.addPopupListener(this);

    /** ADDED TO ENSURE THAT POPUP-MENUS DO NOT RUN OFF SCREEN */
    if ((item.getAbsoluteLeft() + item.getOffsetWidth() + 150) > Window.getClientWidth()) //don't let the menu run off the page
        popup.setPopupPosition(item.getAbsoluteLeft() - 120, item.getAbsoluteTop());
    else
        popup.setPopupPosition(item.getAbsoluteLeft() + item.getOffsetWidth(), item.getAbsoluteTop());

    shownChildMenu = item.getSubMenu();
    item.getSubMenu().parentMenu = this;

    // Show the popup, ensuring that the WysiwymMenuBar's event preview remains on top
    // of the popup's.
    popup.show();
}

From source file:mobi.openddr.example.gwtcanvasdemo.client.DmapGwtCanvas.java

License:Open Source License

public void onModuleLoad() {
    UserAgent impl = GWT.create(UserAgent.class);
    Window win = GWT.create(Window.class);

    String compileTimeValue = impl.getCompileTimeValue();
    String runtimeValue = impl.getRuntimeValue();
    System.out.println(compileTimeValue + "->" + runtimeValue);
    height = win.getClientHeight() - 100;
    width = win.getClientWidth() - 80;

    canvas = Canvas.createIfSupported();
    backBuffer = Canvas.createIfSupported();
    if (canvas == null) {
        RootPanel.get(HOLDER_ID).add(new Label(UPGRADE_MESSAGE));
        return;//from   w  ww  .  j  a va  2  s  .c o m
    }

    // init the canvases
    canvas.setWidth(width + "px");
    canvas.setHeight(height + "px");
    canvas.setCoordinateSpaceWidth(width);
    canvas.setCoordinateSpaceHeight(height);
    backBuffer.setCoordinateSpaceWidth(width);
    backBuffer.setCoordinateSpaceHeight(height);
    RootPanel.get(HOLDER_ID).add(canvas);
    context = canvas.getContext2d();
    backBufferContext = backBuffer.getContext2d();

    // init the objects
    logoGroup = new LogoGroup(width, height, 18, 165);
    ballGroup = new BallGroup(width, height);
    lens = new Lens(35, 15, width, height, new Vector(320, 150), new Vector(1, 1));

    // init handlers
    initHandlers();

    // setup timer
    final Timer timer = new Timer() {
        @Override
        public void run() {
            doUpdate();
        }
    };
    timer.scheduleRepeating(REFRESH_RATE);
}

From source file:n3phele.client.N3phele.java

License:Open Source License

/**
 * @wbp.parser.entryPoint/*from  w ww  .  ja v  a  2 s. c o  m*/
 */
public void onModuleLoad() {

    StyleInjector.inject(n3pheleResource.css().getText());
    n3pheleResource.css().ensureInjected();
    if (clientFactory == null)
        clientFactory = GWT.create(ClientFactory.class);
    if (basePanel == null) {
        basePanel = new BasePanel(clientFactory);
        base = new FlexTable();
        RootPanel.get().add(base);
        base.addStyleName(N3phele.n3pheleResource.css().baseBackground());
        base.getRowFormatter().addStyleName(0, n3pheleResource.css().baseBackgroundRow());

        Window.addResizeHandler(new ResizeHandler() {
            public void onResize(ResizeEvent event) {
                int height = event.getHeight();
                int width = event.getWidth();
                base.setHeight(height + "px");
                base.setWidth(width + "px");
            }
        });
        //
        base.setWidget(0, 0, basePanel);
        base.setSize(Window.getClientWidth() + "px", Window.getClientHeight() + "px");
        base.setBorderWidth(0);

        base.getCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER,
                HasVerticalAlignment.ALIGN_TOP);
    }

    if (activityMapper == null)
        activityMapper = new AppActivityMapper(clientFactory);
    if (activityManager == null) {
        activityManager = new ActivityManager(activityMapper, clientFactory.getEventBus());
        activityManager.setDisplay(basePanel);
    }

    if (!AuthenticatedRequestFactory.isAuthenticated()) {
        clientFactory.getPlaceController().goTo(new LoginPlace("authenticate"));
    } else {
        initHistory();
        basePanel.enableDecorations(initMainMenu());
        initLHS();
        historyHandler.handleCurrentHistory();

    }
}

From source file:n3phele.client.N3phele.java

License:Open Source License

public static void checkSize() {
    base.setSize(Window.getClientWidth() + "px", Window.getClientHeight() - 1 + "px");
    base.setSize(Window.getClientWidth() + "px", Window.getClientHeight() + "px");
}

From source file:net.autosauler.ballance.client.gui.CommInfoPanel.java

License:Apache License

/**
 * Instantiates a new comm info panel.//from  w w  w .  j  a v  a2  s.  co  m
 */
public CommInfoPanel() {
    super(false);
    Image i = new Image(Images.menu.icoRefresh());
    Label msg = new Label(M.comm.commInProgress());

    HorizontalPanel panel = new HorizontalPanel();
    panel.setWidth("200px");
    panel.setHeight("32px");
    panel.add(i);
    panel.setCellWidth(i, "32px");
    panel.setSpacing(2);
    panel.add(msg);

    setWidget(panel);

    // int width = RootPanel.get().getOffsetWidth();
    // int height = RootPanel.get().getOffsetHeight();

    int width = Window.getClientWidth() - 20;
    int height = Window.getClientHeight() * 3 / 4;

    int x = 250;
    int y = 100;
    if (width > 0) {
        x = width - 320;
    }
    if (height > 0) {
        y = height;
    }
    setPopupPosition(x, y);
}

From source file:net.dancioi.jcsphotogallery.client.view.desktop.ViewHandlers.java

License:Open Source License

private void addResizeBrowserListener() {
    keepBottomPanelVisible(Window.getClientWidth(), Window.getClientHeight(), currentScrollPosition);

    Window.addResizeHandler(new ResizeHandler() {

        @Override/*ww  w.  j a  va2 s .c  o  m*/
        public void onResize(ResizeEvent event) {
            keepBottomPanelVisible(event.getWidth(), event.getHeight(), currentScrollPosition);
        }

    });

    Window.addWindowScrollHandler(new ScrollHandler() {

        @Override
        public void onWindowScroll(ScrollEvent event) {
            currentScrollPosition = event.getScrollTop();
            keepBottomPanelVisible(Window.getClientWidth(), Window.getClientHeight() + event.getScrollTop(), 0);
        }
    });
}

From source file:net.dancioi.jcsphotogallery.client.view.PopupGeneric.java

License:Open Source License

private void initialize() {
    browserWindowWidth = Window.getClientWidth();
    browserWindowHeight = Window.getClientHeight();
    browserScrollLeft = Window.getScrollLeft();
    browserScrollTop = Window.getScrollTop();
}

From source file:net.opentsdb.tsd.client.QueryUi.java

License:Open Source License

/**
 * This is the entry point method.// w  ww .  j  ava  2s  .  c o  m
 */
public void onModuleLoad() {
    asyncGetJson(AGGREGATORS_URL, new GotJsonCallback() {
        public void got(final JSONValue json) {
            // Do we need more manual type checking?  Not sure what will happen
            // in the browser if something other than an array is returned.
            final JSONArray aggs = json.isArray();
            for (int i = 0; i < aggs.size(); i++) {
                aggregators.add(aggs.get(i).isString().stringValue());
            }
            ((MetricForm) metrics.getWidget(0)).setAggregators(aggregators);
        }
    });

    // All UI elements need to regenerate the graph when changed.
    {
        final ValueChangeHandler<Date> vch = new ValueChangeHandler<Date>() {
            public void onValueChange(final ValueChangeEvent<Date> event) {
                refreshGraph();
            }
        };
        TextBox tb = start_datebox.getTextBox();
        tb.addBlurHandler(refreshgraph);
        tb.addKeyPressHandler(refreshgraph);
        start_datebox.addValueChangeHandler(vch);
        tb = end_datebox.getTextBox();
        tb.addBlurHandler(refreshgraph);
        tb.addKeyPressHandler(refreshgraph);
        end_datebox.addValueChangeHandler(vch);
    }
    autoreoload_interval.addBlurHandler(refreshgraph);
    autoreoload_interval.addKeyPressHandler(refreshgraph);
    yrange.addBlurHandler(refreshgraph);
    yrange.addKeyPressHandler(refreshgraph);
    y2range.addBlurHandler(refreshgraph);
    y2range.addKeyPressHandler(refreshgraph);
    ylog.addClickHandler(new AdjustYRangeCheckOnClick(ylog, yrange));
    y2log.addClickHandler(new AdjustYRangeCheckOnClick(y2log, y2range));
    ylog.addClickHandler(refreshgraph);
    y2log.addClickHandler(refreshgraph);
    ylabel.addBlurHandler(refreshgraph);
    ylabel.addKeyPressHandler(refreshgraph);
    y2label.addBlurHandler(refreshgraph);
    y2label.addKeyPressHandler(refreshgraph);
    yformat.addBlurHandler(refreshgraph);
    yformat.addKeyPressHandler(refreshgraph);
    y2format.addBlurHandler(refreshgraph);
    y2format.addKeyPressHandler(refreshgraph);
    wxh.addBlurHandler(refreshgraph);
    wxh.addKeyPressHandler(refreshgraph);
    horizontalkey.addClickHandler(refreshgraph);
    keybox.addClickHandler(refreshgraph);
    nokey.addClickHandler(refreshgraph);

    yrange.setValidationRegexp("^(" // Nothing or
            + "|\\[([-+.0-9eE]+|\\*)?" // "[start
            + ":([-+.0-9eE]+|\\*)?\\])$"); //   :end]"
    yrange.setVisibleLength(5);
    yrange.setMaxLength(44); // MAX=2^26=20 chars: "[-$MAX:$MAX]"
    yrange.setText("[0:]");

    y2range.setValidationRegexp("^(" // Nothing or
            + "|\\[([-+.0-9eE]+|\\*)?" // "[start
            + ":([-+.0-9eE]+|\\*)?\\])$"); //   :end]"
    y2range.setVisibleLength(5);
    y2range.setMaxLength(44); // MAX=2^26=20 chars: "[-$MAX:$MAX]"
    y2range.setText("[0:]");
    y2range.setEnabled(false);
    y2log.setEnabled(false);

    ylabel.setVisibleLength(10);
    ylabel.setMaxLength(50); // Arbitrary limit.
    y2label.setVisibleLength(10);
    y2label.setMaxLength(50); // Arbitrary limit.
    y2label.setEnabled(false);

    yformat.setValidationRegexp("^(|.*%..*)$"); // Nothing or at least one %?
    yformat.setVisibleLength(10);
    yformat.setMaxLength(16); // Arbitrary limit.
    y2format.setValidationRegexp("^(|.*%..*)$"); // Nothing or at least one %?
    y2format.setVisibleLength(10);
    y2format.setMaxLength(16); // Arbitrary limit.
    y2format.setEnabled(false);

    wxh.setValidationRegexp("^[1-9][0-9]{2,}x[1-9][0-9]{2,}$"); // 100x100
    wxh.setVisibleLength(9);
    wxh.setMaxLength(11); // 99999x99999
    wxh.setText((Window.getClientWidth() - 20) + "x" + (Window.getClientHeight() * 4 / 5));

    final FlexTable table = new FlexTable();
    table.setText(0, 0, "From");
    {
        final HorizontalPanel hbox = new HorizontalPanel();
        hbox.add(new InlineLabel("To"));
        final Anchor now = new Anchor("(now)");
        now.addClickHandler(new ClickHandler() {
            public void onClick(final ClickEvent event) {
                end_datebox.setValue(new Date());
                refreshGraph();
            }
        });
        hbox.add(now);
        hbox.add(autoreoload);
        hbox.setWidth("100%");
        table.setWidget(0, 1, hbox);
    }
    autoreoload.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            if (autoreoload.isChecked()) {
                final HorizontalPanel hbox = new HorizontalPanel();
                hbox.setWidth("100%");
                hbox.add(new InlineLabel("Every:"));
                hbox.add(autoreoload_interval);
                hbox.add(new InlineLabel("seconds"));
                table.setWidget(1, 1, hbox);
                if (autoreoload_interval.getValue().isEmpty()) {
                    autoreoload_interval.setValue("15");
                }
                autoreoload_interval.setFocus(true);
                lastgraphuri = ""; // Force refreshGraph.
                refreshGraph(); // Trigger the 1st auto-reload
            } else {
                table.setWidget(1, 1, end_datebox);
            }
        }
    });
    autoreoload_interval.setValidationRegexp("^([5-9]|[1-9][0-9]+)$"); // >=5s
    autoreoload_interval.setMaxLength(4);
    autoreoload_interval.setVisibleLength(8);

    table.setWidget(1, 0, start_datebox);
    table.setWidget(1, 1, end_datebox);
    {
        final HorizontalPanel hbox = new HorizontalPanel();
        hbox.add(new InlineLabel("WxH:"));
        hbox.add(wxh);
        table.setWidget(0, 3, hbox);
    }
    {
        final MetricForm.MetricChangeHandler metric_change_handler = new MetricForm.MetricChangeHandler() {
            public void onMetricChange(final MetricForm metric) {
                final int index = metrics.getWidgetIndex(metric);
                metrics.getTabBar().setTabText(index, getTabTitle(metric));
            }

            private String getTabTitle(final MetricForm metric) {
                final String metrictext = metric.getMetric();
                final int last_period = metrictext.lastIndexOf('.');
                if (last_period < 0) {
                    return metrictext;
                }
                return metrictext.substring(last_period + 1);
            }
        };
        final EventsHandler updatey2range = new EventsHandler() {
            protected <H extends EventHandler> void onEvent(final DomEvent<H> event) {
                for (final Widget metric : metrics) {
                    if (!(metric instanceof MetricForm)) {
                        continue;
                    }
                    if (((MetricForm) metric).x1y2().getValue()) {
                        y2range.setEnabled(true);
                        y2log.setEnabled(true);
                        y2label.setEnabled(true);
                        y2format.setEnabled(true);
                        return;
                    }
                }
                y2range.setEnabled(false);
                y2log.setEnabled(false);
                y2label.setEnabled(false);
                y2format.setEnabled(false);
            }
        };
        final MetricForm metric = new MetricForm(refreshgraph);
        metric.x1y2().addClickHandler(updatey2range);
        metric.setMetricChangeHandler(metric_change_handler);
        metrics.add(metric, "metric 1");
        metrics.selectTab(0);
        metrics.add(new InlineLabel("Loading..."), "+");
        metrics.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
            public void onBeforeSelection(final BeforeSelectionEvent<Integer> event) {
                final int item = event.getItem();
                final int nitems = metrics.getWidgetCount();
                if (item == nitems - 1) { // Last item: the "+" was clicked.
                    event.cancel();
                    final MetricForm metric = new MetricForm(refreshgraph);
                    metric.x1y2().addClickHandler(updatey2range);
                    metric.setMetricChangeHandler(metric_change_handler);
                    metric.setAggregators(aggregators);
                    metrics.insert(metric, "metric " + nitems, item);
                    metrics.selectTab(item);
                    metric.setFocus(true);
                }
            }
        });
        table.setWidget(2, 0, metrics);
    }
    table.getFlexCellFormatter().setColSpan(2, 0, 2);
    table.getFlexCellFormatter().setRowSpan(1, 3, 2);
    final DecoratedTabPanel optpanel = new DecoratedTabPanel();
    optpanel.add(makeAxesPanel(), "Axes");
    optpanel.add(makeKeyPanel(), "Key");
    optpanel.selectTab(0);
    table.setWidget(1, 3, optpanel);

    final DecoratorPanel decorator = new DecoratorPanel();
    decorator.setWidget(table);
    final VerticalPanel graphpanel = new VerticalPanel();
    graphpanel.add(decorator);
    {
        final VerticalPanel graphvbox = new VerticalPanel();
        graphvbox.add(graphstatus);
        graph.setVisible(false);
        graphvbox.add(graph);
        graph.addErrorHandler(new ErrorHandler() {
            public void onError(final ErrorEvent event) {
                graphstatus.setText("Oops, failed to load the graph.");
            }
        });
        graphpanel.add(graphvbox);
    }
    final DecoratedTabPanel mainpanel = new DecoratedTabPanel();
    mainpanel.setWidth("100%");
    mainpanel.add(graphpanel, "Graph");
    mainpanel.add(stats_table, "Stats");
    mainpanel.add(logs, "Logs");
    mainpanel.add(build_data, "Version");
    mainpanel.selectTab(0);
    mainpanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
        public void onBeforeSelection(final BeforeSelectionEvent<Integer> event) {
            clearError();
            final int item = event.getItem();
            switch (item) {
            case 1:
                refreshStats();
                return;
            case 2:
                refreshLogs();
                return;
            case 3:
                refreshVersion();
                return;
            }
        }
    });
    final VerticalPanel root = new VerticalPanel();
    root.setWidth("100%");
    root.add(current_error);
    current_error.setVisible(false);
    current_error.addStyleName("dateBoxFormatError");
    root.add(mainpanel);
    RootPanel.get("queryuimain").add(root);
    // Must be done at the end, once all the widgets are attached.
    ensureSameWidgetSize(optpanel);
}

From source file:net.sf.mmm.client.ui.gwt.widgets.PopupMouseHandler.java

License:Apache License

/**
 * {@inheritDoc}/*from w  w w  .j  a  v a  2s  . c  o  m*/
 */
@Override
protected void initializeOnMouseDown(MouseDownEvent event) {

    super.initializeOnMouseDown(event);
    this.popupRectangle = new Rectangle(this.popupWindow.getAbsoluteLeft(), this.popupWindow.getAbsoluteTop(),
            this.popupWindow.getOffsetWidth(), this.popupWindow.getOffsetHeight());

    int clientWidth = Window.getClientWidth();
    int clientHeight = Window.getClientHeight();
    this.minWidth = (int) LengthProperty.MIN_WIDTH.getLengthInPixel(this.popupWindow, clientWidth);
    this.minHeight = (int) LengthProperty.MIN_HEIGHT.getLengthInPixel(this.popupWindow, clientHeight);
    if (this.minWidth == 0) {
        this.minWidth = clientWidth / 10;
    }
    if (this.minHeight == 0) {
        this.minHeight = clientHeight / 10;
    }
}