Example usage for com.google.gwt.user.client Window getClientHeight

List of usage examples for com.google.gwt.user.client Window getClientHeight

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window getClientHeight.

Prototype

public static int getClientHeight() 

Source Link

Usage

From source file:com.google.gerrit.client.editor.EditScreen.java

License:Apache License

void adjustHeight() {
    int height = header.getOffsetHeight();
    int rest = Gerrit.getHeaderFooterHeight() + height + 5; // Estimate
    mv.getGapElement().getStyle().setHeight(Window.getClientHeight() - rest, Unit.PX);
    cmBase.adjustHeight(height);/*from   www  .ja  v a 2  s  . c  om*/
    cmEdit.adjustHeight(height);
}

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();//from   w  w w. ja v a  2s. c  o m
    }
    setPopupPosition(sLeft + dLeft, (sTop + cHeight) - (myHeight + 10));
}

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();
        }//ww w.j  a va2s . c om
    });

    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.gears.sample.gwtnote.client.ui.RichTextWidget.java

License:Apache License

/**
 * Creates a new widget. This class needs access to certain fields and methods
 * on the application enclosing it./*from www  . ja v a  2s. c o m*/
 * 
 * @param parent the host application
 */
public RichTextWidget(final GWTNote parent) {
    super();

    VerticalPanel top = new VerticalPanel();
    top.setWidth("100%");
    HorizontalPanel header = new HorizontalPanel();
    top.add(header);
    header.setWidth("100%");

    header.add(new Label("GWT GearsNote"));

    header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    status = new Label("Ready");
    header.add(status);

    this.bodyWidget = new RichTextArea();
    bodyWidget.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            String newText = bodyWidget.getText();
            if (((newText == null) && (curText != null)) || ((newText != null) && !newText.equals(curText))) {
                curText = newText;
            }
        }
    });

    HorizontalPanel controls = new HorizontalPanel();
    RichTextToolbar tb = new RichTextToolbar(this.bodyWidget);
    name = new TextBox();
    name.setText("default");
    name.setEnabled(false);
    nameEdit = new PushButton("Edit");
    nameEdit.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            String curName = name.getText();
            boolean doNotify = !oldName.equals(curName);
            if (!nameEditable) { // if becoming editable, store off current value
                oldName = curName;
            }
            if (nameEditable && (curName == null || "".equals(curName))) {
                // if becoming un-editable, check to make sure it's valid
                Window.alert("The note name cannot be blank. Please try again.");
                nameEdit.setText(oldName);
                return;
            }
            // if all else is good, just flip the state
            nameEditable = !nameEditable;
            name.setEnabled(nameEditable);
            nameEdit.getUpFace().setText((nameEditable ? "Confirm" : "Edit"));
            if (doNotify) {
                notifyNameListeners();
            }
        }
    });
    nameEdit.addStyleName("edit-button");

    options = new ListBox();
    controls.add(tb);
    options.addItem("default");
    options.setSelectedIndex(0);
    options.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            String newName = options.getItemText(options.getSelectedIndex());
            name.setText(newName);
            notifyNameListeners();
        }
    });
    HorizontalPanel tmp = new HorizontalPanel();
    tmp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    tmp.add(new Label("Note name:"));
    tmp.add(name);
    tmp.add(nameEdit);
    tmp.add(options);
    controls.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    controls.setWidth("100%");
    controls.add(tmp);
    top.add(controls);

    top.add(bodyWidget);
    this.bodyWidget.setWidth("100%");
    top.setCellHeight(bodyWidget, ((int) (Window.getClientHeight() * .75)) + "px");
    this.bodyWidget.setHeight("100%");

    initWidget(top);
}

From source file:com.google.gwt.gen2.demo.collapsiblepanel.client.CollapsiblePanelDemo.java

License:Apache License

/**
 * This is the entry point method.//from   w w  w  .jav  a 2 s  . co  m
 */
public void onModuleLoad() {
    try {

        // Some random contents to make the tree interesting.
        Panel contents = createSchoolNavBar();
        FastTree.injectDefaultCss();
        CollapsiblePanel.injectDefaultCss();

        // The panel.
        final CollapsiblePanel panel = new CollapsiblePanel();
        panel.addCollapsedStateHandler(new CollapsedStateHandler() {
            public void onCollapsedState(CollapsedStateEvent e) {
                Window.alert("panel collapsed");
            }
        });

        panel.addExpandedStateHandler(new ExpandedStateHandler() {
            public void onExpandedState(ExpandedStateEvent e) {
                Window.alert("panel expanded");
            }
        });

        String value = Location.getParameter("collapsed");
        if (value != null) {
            value = value.trim();
            if (value.equals("true")) {
                panel.setCollapsedState(true);
            } else if (value.equals("false")) {
                // do nothing, default.
            } else {
                Window.alert("collapsed should not be given " + value + " use true or false instead");
            }
        }
        RootPanel.get("collapsible-panel").add(panel);
        panel.add(contents);
        panel.setHeight(Window.getClientHeight() - 1 + "px");
        panel.hookupControlToggle(controlButton);
    } catch (RuntimeException e) {
        if (GWT.isScript()) {
            Log.severe(e.getMessage());
        }
        throw e;
    }
}

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();//w  w w .j  av  a2  s .  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();//from   ww w .  j a v  a2 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);/*from   w  w w .  j  a  v a2  s.c  o 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;
}

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

public static String getImage(String _path) {
    String path1 = _path.replaceAll("<.*?\"", "");
    String path2 = path1.replaceAll("\".*?>", "");
    return "<img src='" + path2 + "' height='" + Window.getClientHeight() * 0.8
            + "' style='vertical-align:middle;' />";
}