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.google.gerrit.client.patches.PatchBrowserPopup.java

License:Apache License

@Override
public void setPosition(final int myWidth, int myHeight) {
    final int dLeft = (Window.getClientWidth() - myWidth) >> 1;
    final int cHeight = Window.getClientHeight();
    final int cHeight2 = 2 * cHeight / 3;
    final int sLeft = Window.getScrollLeft();
    final int sTop = Window.getScrollTop();

    if (myHeight > cHeight2) {
        sp.setHeight((cHeight2 - 50) + "px");
        myHeight = getOffsetHeight();//w  w  w .  j  a va 2s .  com
    }
    setPopupPosition(sLeft + dLeft, (sTop + cHeight) - (myHeight + 10));
}

From source file:com.google.gerrit.client.patches.PatchBrowserPopup.java

License:Apache License

@Override
public void onResize(final ResizeEvent event) {
    sp.setWidth((Window.getClientWidth() - 60) + "px");
    setPosition(getOffsetWidth(), getOffsetHeight());
}

From source file:com.google.gerrit.client.patches.PatchBrowserPopup.java

License:Apache License

public void open() {
    if (!fileList.isLoaded()) {
        sp.setHeight("22px");
    }/*from w  w w  .j a va2 s. co m*/
    sp.setWidth((Window.getClientWidth() - 60) + "px");
    setPopupPositionAndShow(this);
    if (fileList.isLoaded()) {
        fileList.setRegisterKeys(true);
        fileList.movePointerTo(callerKey);
    }
}

From source file:com.google.gerrit.client.ui.ProjectListPopup.java

License:Apache License

protected PopupPanel.PositionCallback getPositionCallback() {
    return new PopupPanel.PositionCallback() {
        @Override/*from   w  w  w.ja v  a 2  s  .co  m*/
        public void setPosition(int offsetWidth, int offsetHeight) {
            if (preferredTop + offsetHeight > Window.getClientWidth()) {
                preferredTop = Window.getClientWidth() - offsetHeight;
            }
            if (preferredLeft + offsetWidth > Window.getClientWidth()) {
                preferredLeft = Window.getClientWidth() - offsetWidth;
            }

            if (preferredTop < 0) {
                sp.setHeight((sp.getOffsetHeight() + preferredTop) + "px");
                preferredTop = 0;
            }
            if (preferredLeft < 0) {
                sp.setWidth((sp.getOffsetWidth() + preferredLeft) + "px");
                preferredLeft = 0;
            }

            popup.setPopupPosition(preferredLeft, preferredTop);
        }
    };
}

From source file:com.google.gwt.examples.PopupPanelExample.java

License:Apache License

public void onModuleLoad() {
    Button b1 = new Button("Click me to show popup");
    b1.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            // Instantiate the popup and show it.
            new MyPopup().show();
        }//from w w  w . java 2  s  .c  o m
    });

    RootPanel.get().add(b1);

    Button b2 = new Button("Click me to show popup partway across the screen");

    b2.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            // Create the new popup.
            final MyPopup popup = new MyPopup();
            // Position the popup 1/3rd of the way down and across the screen, and
            // show the popup. Since the position calculation is based on the
            // offsetWidth and offsetHeight of the popup, you have to use the
            // setPopupPositionAndShow(callback) method. The alternative would
            // be to call show(), calculate the left and top positions, and
            // call setPopupPosition(left, top). This would have the ugly side
            // effect of the popup jumping from its original position to its
            // new position.
            popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
                public void setPosition(int offsetWidth, int offsetHeight) {
                    int left = (Window.getClientWidth() - offsetWidth) / 3;
                    int top = (Window.getClientHeight() - offsetHeight) / 3;
                    popup.setPopupPosition(left, top);
                }
            });
        }
    });

    RootPanel.get().add(b2);
}

From source file:com.google.gwt.language.sample.hellolanguage.client.HelloLanguage.java

License:Apache License

/**
 * The onModuleLoad() method is called when the body of the document is
 * finished loading. The JavaScript APIs are not loaded unless they were
 * included in the body of the .html file. Use the LanguageUtils.loadXXX()
 * methods to load them after the app starts, but before any API calls are
 * made.//  w w  w .j a  v a  2  s.c o  m
 */
public void onModuleLoad() {

    final TabPanel demoTabPanel = new TabPanel();
    demoTabPanel.getDeckPanel().setPixelSize(Window.getClientWidth() - 30, DEMO_PANEL_HEIGHT);
    RootPanel.get().add(demoTabPanel);

    Window.addResizeHandler(new ResizeHandler() {
        public void onResize(ResizeEvent event) {
            demoTabPanel.getDeckPanel().setPixelSize(Window.getClientWidth() - 30, DEMO_PANEL_HEIGHT);
        }
    });

    final VerticalPanel transDemoPanel = new VerticalPanel();
    transDemoPanel.add(loadingLabel());

    final VerticalPanel langDetectDemoPanel = new VerticalPanel();
    langDetectDemoPanel.add(loadingLabel());

    final VerticalPanel translitDemoPanel = new VerticalPanel();
    translitDemoPanel.add(loadingLabel());

    demoTabPanel.add(transDemoPanel, "Translation demo");
    demoTabPanel.add(langDetectDemoPanel, "Language detection demo");
    demoTabPanel.add(translitDemoPanel, "Transliteration demo");
    demoTabPanel.selectTab(0);

    LanguageUtils.loadTranslation(new Runnable() {
        public void run() {
            transDemoPanel.clear();
            transDemoPanel.add(new TranslationDemo());

            langDetectDemoPanel.clear();
            langDetectDemoPanel.add(new LanguageDetectionDemo());
        }
    });

    LanguageUtils.loadTransliteration(new Runnable() {
        public void run() {
            translitDemoPanel.clear();
            TransliterationDemo translitDemo = new TransliterationDemo();
            translitDemoPanel.add(translitDemo);
        }
    });
}

From source file:com.google.gwt.sample.mobilewebapp.client.ui.WindowBasedOrientationHelper.java

License:Apache License

private static boolean calculateIsPortrait() {
    return Window.getClientHeight() > Window.getClientWidth();
}

From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java

public static StockChart createLiveChart(final String sensorName, Number[][] data, String title,
        final Boolean predictionIsEnabled, final Boolean isLiveUpdate, int steps) {

    Utility.hideTimer();/*from w  w w.ja v a  2s . co  m*/
    final StockChart chart = new StockChart();
    chart.setType(Series.Type.SPLINE).setMarginRight(30)
            .setBarPlotOptions(new BarPlotOptions().setDataLabels(new DataLabels().setEnabled(true)))
            .setChartTitleText(title).setLegend(new Legend().setEnabled(false))
            .setCredits(new Credits().setEnabled(false)).setSplinePlotOptions(
                    new SplinePlotOptions().setMarker(new Marker().setEnabled(true).setRadius(3)));
    chart.setBackgroundColor(new Color().setLinearGradient(0.0, 0.0, 1.0, 1.0).addColorStop(0, 0, 0, 0, 1)
            .addColorStop(0, 0, 0, 0, 0));

    chart.getXAxis().setDateTimeLabelFormats(new DateTimeLabelFormats().setMinute("%l:%M %p"));

    ArrayList<String> attributes = Data.sensorAttributeList.get(sensorName);
    String unit = attributes.get(5);

    chart.getYAxis().setAxisTitleText(unit)
            .setPlotLines(chart.getYAxis().createPlotLine().setValue(0).setWidth(1).setColor("#808080"));

    final Series series = chart.createSeries();
    chart.addSeries(series.setName("Data"));

    final Series predictionSeries = chart.createSeries();
    int lastRow = data.length - 1;

    if (predictionIsEnabled) {
        lastRow -= steps;
        chart.addSeries(predictionSeries.setName("Prediction"));
        for (int i = lastRow; i < data.length; i++) {
            predictionSeries.addPoint(data[i][0], data[i][1]);
        }
    }

    for (int i = 0; i < lastRow; i++) {
        series.addPoint(data[i][0], data[i][1]);
    }

    if (isLiveUpdate) {
        final Timer tempTimer = new Timer() {
            java.sql.Date lastRequestTime = new java.sql.Date(System.currentTimeMillis());

            @Override
            public void run() {
                if (chart.isAttached()) {
                    if (chart.isRendered()) {
                        long currTime = System.currentTimeMillis();
                        getAppendData(series, sensorName, lastRequestTime, new java.sql.Date(currTime),
                                predictionIsEnabled, predictionSeries);
                        lastRequestTime = new java.sql.Date(currTime + 1);
                    }
                    schedule(6000);
                } else {
                    cancel();
                }
            }
        };
        tempTimer.schedule(0);
    }

    chart.setSize(Window.getClientWidth() * 2 / 3, Window.getClientHeight() * 2 / 3);

    return chart;
}

From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java

public static Chart createReportChart(final String sensorName, Number[][] data, String title,
        final Boolean predictionIsEnabled, int steps) {

    Utility.hideTimer();// www  .  j av a 2  s .  c o  m

    final Chart chart = new Chart();
    chart.setType(Series.Type.COLUMN).setChartTitleText(title)
            .setOptions3D(
                    new Options3D().setEnabled(true).setAlpha(15).setBeta(15).setViewDistance(25).setDepth(40))
            .setLegend(new Legend().setEnabled(false)).setCredits(new Credits().setEnabled(false));
    chart.setBackgroundColor(new Color().setLinearGradient(0.0, 0.0, 1.0, 1.0).addColorStop(0, 0, 0, 0, 1)
            .addColorStop(0, 0, 0, 0, 0));

    chart.setSeriesPlotOptions(new SeriesPlotOptions().setDataLabels(new DataLabels().setEnabled(true)
            .setAlign(Labels.Align.RIGHT).setColor("#FFFFFF").setRotation(-20).setX(-3).setY(-18)));

    String[] dateContents = title.split(" ");

    chart.getXAxis().setType(Axis.Type.DATE_TIME).setMaxZoom(14 * 24 * 3600000);

    for (int i = 0; i < dateContents.length; i++) {
        if (dateContents[i].equals("Daily")) {
            chart.getXAxis().setDateTimeLabelFormats(new DateTimeLabelFormats().setDay("%e %b %Y"));
            break;
        }
        if (dateContents[i].equals("Monthly")) {
            chart.getXAxis().setDateTimeLabelFormats(new DateTimeLabelFormats().setMonth("%b %Y"));
            break;
        }
        if (dateContents[i].equals("Yearly")) {
            chart.getXAxis().setDateTimeLabelFormats(new DateTimeLabelFormats().setYear("%Y"));
            break;
        }
    }

    chart.getYAxis()
            .setPlotLines(chart.getYAxis().createPlotLine().setValue(0).setWidth(2).setColor("#808080"));

    final Series series = chart.createSeries();
    chart.addSeries(series.setName("Data"));

    final Series predictionSeries = chart.createSeries();
    int lastRow = data.length;

    if (predictionIsEnabled && data.length > 1) {
        lastRow -= steps;
        chart.addSeries(predictionSeries.setName("Prediction"));
        for (int i = lastRow; i < data.length; i++) {
            predictionSeries.addPoint(data[i][0], data[i][1]);
        }
    }

    for (int i = 0; i < lastRow; i++) {
        series.addPoint(data[i][0], data[i][1]);
    }

    chart.setSize(Window.getClientWidth() * 2 / 3, Window.getClientHeight() * 2 / 3);

    return chart;
}

From source file:com.google.gwt.sample.stockwatcher.client.ChartUtilities.java

public static HorizontalPanel createGaugeChart(final String name, final int size) {
    final HorizontalPanel lol = new HorizontalPanel();
    final Chart chart = new Chart();
    chart.setType(Series.Type.SOLID_GAUGE).setLegend(new Legend().setEnabled(false))
            .setCredits(new Credits().setEnabled(false)).setAlignTicks(false).setPlotBackgroundImage(null)
            .setBorderWidth(0).setPlotShadow(false).setExporting(new Exporting().setEnabled(false))
            .setChartTitle(new ChartTitle().setText("Latest " + name + " sensor reading"))
            .setPane(new Pane().setStartAngle(-90).setEndAngle(90).setCenter("50%", "85%")
                    .setBackground(new PaneBackground().setInnerRadius("60%").setOuterRadius("100%")
                            .setShape(PaneBackground.Shape.ARC).setBackgroundColor("rgba(0,0,0,0)")))
            .setSolidGaugePlotOptions(new SolidGaugePlotOptions().setAnimation(false));

    final ArrayList<String> attributes = Data.sensorAttributeList.get(name);

    final Number maxTreshold = (Number) Double.parseDouble(attributes.get(8));
    chart.getYAxis().setMin(0);//w  w w  .j  a  v  a2  s.co m
    chart.getYAxis().setMax(maxTreshold);
    chart.getYAxis().setLineColor("gray");

    chart.setBackgroundColor(new Color().setLinearGradient(0.0, 0.0, 1.0, 1.0).addColorStop(0, 0, 0, 0, 1)
            .addColorStop(0, 0, 0, 0, 0));

    chart.getYAxis().setTickPosition(Axis.TickPosition.INSIDE).setMinorTickPosition(Axis.TickPosition.INSIDE)
            .setLineColor("white").setTickColor("white").setMinorTickColor("white").setLineWidth(2)
            .setEndOnTick(true).setLabels(new YAxisLabels()
                    // There is no documented "distance" option for gauge chart axes
                    .setOption("distance", -20));

    final Series series = chart.createSeries();
    chart.addSeries(series.setName("Reading").addPoint(0));
    final Timer tempTimer = new Timer() {
        @Override
        public void run() {
            if (MainMenuPage.mainPanel.isVisible())
                Utility.newRequestObj().getLatestReading(name, new AsyncCallback<Double>() {
                    public void onFailure(Throwable caught) {
                        //                    Window.alert("Unable to get "+Data.currentUser+"'s sensor subscription");
                    }

                    public void onSuccess(Double reply) {
                        if (lol.isVisible()) {
                            //                    double temp = Utility.round(new Random().nextDouble()*Double.parseDouble(attributes.get(8)));
                            double temp = Utility.round(reply);
                            series.getPoints()[0].update(temp);
                            chart.setColors(updateColor(temp, maxTreshold));
                            lol.add(chart);
                        } else {
                            cancel();
                        }
                    }
                });
        }
    };

    tempTimer.scheduleRepeating(2000);
    Data.gaugeTimers.add(tempTimer);

    chart.setSize(Window.getClientWidth() * 1 / size, Window.getClientHeight() * 1 / size);
    if (size > 4) {
        chart.setSize(Window.getClientWidth() * 1 / 4, Window.getClientHeight() * 1 / 4);
    }
    lol.add(chart);
    return lol;
}