Example usage for com.google.gwt.i18n.client NumberFormat getFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client NumberFormat getFormat.

Prototype

public static NumberFormat getFormat(String pattern) 

Source Link

Document

Gets a NumberFormat instance for the default locale using the specified pattern and the default currencyCode.

Usage

From source file:fr.mncc.gwttoolbox.datagrid.client.Grid.java

License:Open Source License

public SimplePager createPager() {
    if (pager_ != null)
        return pager_;

    pager_ = new SimplePager(SimplePager.TextLocation.CENTER) {

        @Override/*from   w  w  w. jav a 2  s  .co  m*/
        public void setPageStart(int index) {
            if (getDisplay() != null)
                getDisplay().setVisibleRange(index, getDisplay().getVisibleRange().getLength());
        }

        @Override
        protected String createText() {

            // Default text is 1 based.
            NumberFormat formatter = NumberFormat.getFormat("#,###");
            HasRows display = getDisplay();
            Range range = display.getVisibleRange();
            int pageStart = range.getStart() + 1;
            int pageSize = range.getLength();
            int dataSize = display.getRowCount();
            int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
            endIndex = Math.max(pageStart, endIndex);
            boolean exact = display.isRowCountExact();
            return formatter.format(pageStart) + "-" + formatter.format(endIndex)
                    + (exact ? " " + DataGridConstants.INSTANCE.of() + " "
                            : " " + DataGridConstants.INSTANCE.ofOver() + " ")
                    + formatter.format(dataSize);
        }
    };
    pager_.setDisplay(this);
    return pager_;
}

From source file:fr.putnami.pwt.core.widget.client.helper.NumberRenderer.java

License:Open Source License

public NumberRenderer(String format) {
    if (format == null) {
        this.formater = NumberFormat.getDecimalFormat();
    } else {//from   w w  w . j a  va  2 s.  co m
        this.formater = NumberFormat.getFormat(format);
    }
}

From source file:fr.putnami.pwt.core.widget.client.InputFile.java

License:Open Source License

@Override
public void redraw() {
    this.cancelBtn.removeFromParent();
    this.uploadBtn.removeFromParent();
    this.fileNameAnchor.removeFromParent();
    this.placeholderText.removeFromParent();
    this.progressBarWrapper.removeFromParent();
    if (this.fileId != null) {
        this.append(this.progressBarWrapper);
        this.addAddon(this.cancelBtn);
    } else {/*  w  w  w  . j  a  va  2s .c o  m*/
        FileDto value = this.getValue();
        if (value != null) {
            NumberFormat nf = NumberFormat.getFormat("#.##");

            long size = value.getContentLength();
            String displaySize = "";
            if (size > 1024 * 1024) {
                displaySize = nf.format(size / (1024 * 1024D)) + " MB";
            } else if (size > 1024) {
                displaySize = nf.format(size / 1024D) + " KB";
            } else {
                displaySize = nf.format(size) + " B";
            }

            this.fileNameAnchor.setLink(urlDownload + value.getToken());
            this.fileNameAnchor.setText(value.getName() + " - (" + displaySize + ")");
            this.placeholderText.setText(null);
            this.append(this.fileNameAnchor);
            this.addAddon(this.cancelBtn);
        } else {
            this.fileNameAnchor.setLink(null);
            this.fileNameAnchor.setText(null);
            this.placeholderText.setText(this.placeholder);
            this.append(this.placeholderText);
        }
        this.addAddon(this.uploadBtn);
    }
}

From source file:fr.putnami.pwt.core.widget.client.mask.IntegerTokenHelper.java

License:Open Source License

public void setFormater(String format) {
    this.formater = NumberFormat.getFormat(format);
}

From source file:fr.putnami.pwt.core.widget.client.OutputProgressBar.java

License:Open Source License

public void setValue(T value) {
    this.value = value;
    double val = 0;
    if (value == null) {
        val = this.min;
    } else {//w w w .j a  v  a  2  s. c o m
        val = value.doubleValue();
    }
    if (val > this.max) {
        val = this.max;
    } else if (val < this.min) {
        val = this.min;
    }

    this.progressBarElement.setAttribute(OutputProgressBar.ATT_ARIA_VALUE, value + "");
    double percent = 100 * (val - this.min) / (this.max - this.min);
    this.progressBarElement.getStyle().setProperty("width", percent, Unit.PCT);

    NumberFormat formatter = NumberFormat.getFormat("#.##");

    String stringToDisplay = this.format;
    stringToDisplay = RegExp.compile("\\{0\\}").replace(stringToDisplay, formatter.format(val));
    stringToDisplay = RegExp.compile("\\{1\\}").replace(stringToDisplay, formatter.format(percent));
    stringToDisplay = RegExp.compile("\\{2\\}").replace(stringToDisplay, formatter.format(this.min));
    stringToDisplay = RegExp.compile("\\{3\\}").replace(stringToDisplay, formatter.format(this.max));

    this.progressBarElement.removeAllChildren();
    if (this.displayValue) {
        this.progressBarElement.setInnerText(stringToDisplay);
    } else {
        SpanElement reader = Document.get().createSpanElement();
        reader.setInnerText(stringToDisplay);
        reader.addClassName("sr-only");
        this.progressBarElement.appendChild(reader);
    }
}

From source file:gov.nih.nci.ncicb.tcgaportal.level4.gwt.anomalysearch.client.util.GWTNumberFormatter.java

public GWTNumberFormatter(String pattern) {
    numberFormat = NumberFormat.getFormat(pattern);
}

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

License:Open Source License

private String formatToPrecision(int precision, double value) {
    String format = "00.";
    for (int i = 0; i < precision; i++) {
        format += "0";
    }//from  w  w w  .j  av a 2 s  .com
    return NumberFormat.getFormat(format).format(value);
}

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

License:Open Source License

public void draw() {
    try {/*from  w ww . j  av a2s .co  m*/
        vpanel.clear();

        super.drawNavigation();
        HTML pageTitle = new HTML("<h2>" + getEndLabel() + "</h2>");
        vpanel.add(pageTitle);

        title = new HTML("<H3>Acquisition Start Time : " + localDateOfAcquisition + "; Occupancy Threshold : "
                + cutoff + " dBm; Measurements Per Acquisition = " + measurementsPerAcquisition + "</H3>");

        vpanel.add(title);

        double timeResolution = (double) (timeDelta + 1) / (double) measurementCount;

        int freqResolution = (int) round((this.mMaxFreq - this.mMinFreq) / this.binsPerMesurement);

        HTML subTitle = new HTML("<h3>Time Resolution= " + round3(timeResolution) + " s; Resolution BW = "
                + freqResolution + " Hz; Measurements = " + measurementCount + "; Max Occupancy = "
                + maxOccupancy + "%; Median Occupancy = " + medianOccupancy + "%; Mean Occupancy = "
                + meanOccupancy + "%; Min Occupancy = " + minOccupancy + "%</h3>");
        vpanel.add(subTitle);

        help = new Label("Single click for detail. Double click to zoom");
        vpanel.add(help);

        spectrogramVerticalPanel = new VerticalPanel();

        hpanel = new HorizontalPanel();

        commands = new Grid(1, 7);
        commands.setStyleName("selectionGrid");

        for (int i = 0; i < commands.getRowCount(); i++) {
            for (int j = 0; j < commands.getColumnCount(); j++) {
                commands.getCellFormatter().setHorizontalAlignment(i, j, HasHorizontalAlignment.ALIGN_CENTER);
                commands.getCellFormatter().setVerticalAlignment(i, j, HasVerticalAlignment.ALIGN_MIDDLE);
            }
        }

        hpanel.setSpacing(10);
        hpanel.setStyleName("spectrogram");
        xaxisPanel = new HorizontalPanel();
        xaxisPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        HorizontalPanel xaxis = new HorizontalPanel();
        xaxis.setWidth(canvasPixelWidth + 30 + "px");
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        NumberFormat numberFormat = NumberFormat.getFormat("00.00");
        xaxis.add(new Label(numberFormat.format(minTime)));
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        xaxis.add(new Label("Time (sec)"));
        xaxis.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        xaxis.add(new Label(numberFormat.format(minTime + timeDelta)));
        xaxisPanel.add(xaxis);

        // Attach the previous reading button.

        if (prevAcquisitionTime != mSelectionTime) {

            final Button prevDayButton = new Button();
            prevDayButton.setEnabled(true);
            prevDayButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    mSelectionTime = prevAcquisitionTime;
                    prevDayButton.setEnabled(false);
                    acquisitionDuration = 0;
                    leftBound = 0;
                    rightBound = 0;
                    window = measurementsPerAcquisition;
                    help.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.showWaitImage();
                    mSpectrumBrowser.getSpectrumBrowserService()
                            .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId, prevAcquisitionTime,
                                    mSys2detect, mMinFreq, mMaxFreq, cutoff,
                                    FftPowerOneAcquisitionSpectrogramChart.this);

                }
            });

            prevDayButton.setText("<< Prev. Acquisition");
            commands.setWidget(0, 0, prevDayButton);

        }

        // Attach button for panning within the acquisition

        if (leftBound > 0) {
            Button panLeftButton = new Button();
            panLeftButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    if (leftBound - window >= 0) {
                        leftBound = (int) (leftBound - window);
                        rightBound = rightBound + window;
                    } else {
                        rightBound = rightBound + leftBound;
                        leftBound = 0;
                    }
                    help.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.getSpectrumBrowserService()
                            .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId, mSelectionTime,
                                    mSys2detect, mMinFreq, mMaxFreq, (int) leftBound, (int) rightBound, cutoff,
                                    FftPowerOneAcquisitionSpectrogramChart.this);
                }
            });
            panLeftButton.setText("< Pan Left");
            panLeftButton.setTitle("Click to pan left");
            commands.setWidget(0, 1, panLeftButton);
        }

        // Attach the labels for the spectrogram power
        VerticalPanel powerLevelPanel = new VerticalPanel();
        powerLevelPanel.setWidth(100 + "px");
        this.maxPowerLabel = new Label();
        this.minPowerLabel = new Label();
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        powerLevelPanel.add(maxPowerLabel);
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        powerLevelPanel.add(new Label("Power (dBm) "));
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
        powerLevelPanel.add(minPowerLabel);
        // Attach labels for the frequency.
        freqPanel = new VerticalPanel();
        freqPanel.setWidth(100 + "px");
        powerLevelPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
        freqPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        freqPanel.add(new Label(Double.toString(maxFreqMhz)));
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        freqPanel.add(new Label("Frequency (MHz)"));
        freqPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
        freqPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        freqPanel.add(new Label(Double.toString(minFreqMhz)));
        powerMapPanel = new HorizontalPanel();
        powerMapPanel.setWidth(30 + "px");
        hpanel.add(freqPanel);
        spectrogramPanel = new VerticalPanel();

        HorizontalPanel spectrogramAndPowerMapPanel = new HorizontalPanel();
        spectrogramAndPowerMapPanel.add(spectrogramPanel);
        spectrogramAndPowerMapPanel.add(powerMapPanel);
        hpanel.add(spectrogramAndPowerMapPanel);
        currentValue = new Label("Click for power spectrum and power at selected time. Double click to zoom.");
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.add(commands);
        if (maxTime - minTime < acquisitionDuration) {
            Button unzoom = new Button("Zoom Out");

            unzoom.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    zoomOut();
                }
            });
            commands.setWidget(0, 2, unzoom);
        }
        spectrogramVerticalPanel.add(currentValue);
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        spectrogramVerticalPanel.add(hpanel);
        String helpString = "Single click for power spectrum. Double click to zoom.";

        // Add the slider bar for min occupancy selection.
        occupancyMinPowerVpanel = new VerticalPanel();
        occupancyMinPowerVpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        occupancyMinPowerVpanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

        occupancyMinPowerSliderBar = new SliderBarSimpleVertical(100, canvasPixelHeight + "px", true);
        occupancyMinPowerVpanel.add(occupancyMinPowerSliderBar);
        occupancyMinPowerSliderBar.setMaxValue(100);

        this.occupancyMinPowerLabel = new Label();
        occupancyMinPowerVpanel.add(occupancyMinPowerLabel);

        final Button clearTabsButton = new Button("Close Tabs");
        commands.setWidget(0, 3, clearTabsButton);
        clearTabsButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                tabPanel.clear();
                tabPanel.add(spectrogramVerticalPanel, "[Spectrogram]");
                tabPanel.add(occupancyPanel, "[Occupancy]");
                tabPanel.selectTab(0);
            }
        });

        final Button cutoffAndRedrawButton = new Button("Cutoff and Redraw");
        commands.setWidget(0, 4, cutoffAndRedrawButton);
        cutoffAndRedrawButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                mSpectrumBrowser.showWaitImage();
                cutoffAndRedrawButton.setEnabled(false);
                help.setText(COMPUTING_PLEASE_WAIT);
                mSpectrumBrowser.getSpectrumBrowserService().generateSingleAcquisitionSpectrogramAndOccupancy(
                        mSensorId, mSelectionTime, mSys2detect, mMinFreq, mMaxFreq, leftBound, rightBound,
                        cutoffPower, FftPowerOneAcquisitionSpectrogramChart.this);

            }
        });
        occupancyMinPowerSliderBar
                .addBarValueChangedHandler(new OccupancyMinPowerSliderHandler(occupancyMinPowerLabel));
        int initialValue = (int) ((double) (maxPower - cutoff) / (double) (maxPower - minPower) * 100);
        occupancyMinPowerSliderBar.setValue(initialValue);

        hpanel.add(occupancyMinPowerVpanel);

        spectrogramPanel.setTitle(helpString);
        spectrumAndOccupancyPanel = new VerticalPanel();
        spectrumAndOccupancyPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        spectrogramVerticalPanel.add(spectrumAndOccupancyPanel);

        occupancyPanel = new VerticalPanel();
        occupancyPanel.setWidth(canvasPixelWidth + "px");
        occupancyPanel.setHeight(canvasPixelHeight + "px");
        occupancyPanel.setPixelSize(canvasPixelWidth, canvasPixelHeight);
        // Fine pan to the right.
        if (rightBound > 0) {
            Button rightPanButton = new Button();
            rightPanButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    logger.finest("rightBound = " + rightBound + " leftBound = " + leftBound + " window =  "
                            + window + " aquisitionDuration = " + measurementsPerAcquisition);
                    if (rightBound - window > 0) {
                        rightBound = rightBound - window;
                        leftBound = leftBound + window;
                    } else {
                        leftBound = leftBound + rightBound;
                        rightBound = 0;
                    }
                    help.setText(COMPUTING_PLEASE_WAIT);
                    mSpectrumBrowser.showWaitImage();
                    mSpectrumBrowser.getSpectrumBrowserService()
                            .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId, mSelectionTime,
                                    mSys2detect, mMinFreq, mMaxFreq, (int) leftBound, (int) rightBound, cutoff,
                                    FftPowerOneAcquisitionSpectrogramChart.this);
                }
            });
            commands.setWidget(0, 5, rightPanButton);
            rightPanButton.setTitle("Click to pan right");
            rightPanButton.setText("Pan Right >");
        }

        // Attach the next spectrogram panel.

        if (nextAcquisitionTime != mSelectionTime) {
            final Button nextAquisitionButton = new Button();
            nextAquisitionButton.setEnabled(true);
            nextAquisitionButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    logger.finer("getting next spectrogram");
                    try {
                        mSelectionTime = nextAcquisitionTime;
                        nextAquisitionButton.setEnabled(false);
                        acquisitionDuration = 0;
                        leftBound = 0;
                        rightBound = 0;
                        window = measurementsPerAcquisition;
                        mSpectrumBrowser.showWaitImage();
                        help.setText(COMPUTING_PLEASE_WAIT);

                        mSpectrumBrowser.getSpectrumBrowserService()
                                .generateSingleAcquisitionSpectrogramAndOccupancy(mSensorId,
                                        nextAcquisitionTime, mSys2detect, mMinFreq, mMaxFreq, cutoff,
                                        FftPowerOneAcquisitionSpectrogramChart.this);
                    } catch (Throwable th) {
                        logger.log(Level.SEVERE, "Error calling spectrum browser service", th);
                    }

                }
            });
            nextAquisitionButton.setText("Next Acquisition >>");
            // .setHTML("<img border='0' src='myicons/right-arrow.png' />");
            commands.setWidget(0, 6, nextAquisitionButton);
        }
        setSpectrogramImage();
        drawOccupancyChart();
        tabPanel = new TabPanel();
        tabPanel.add(spectrogramVerticalPanel, "[Spectrogram]");
        tabPanel.add(occupancyPanel, "[Occupancy]");
        tabPanel.selectTab(0);
        vpanel.add(tabPanel);
        tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

            @Override
            public void onSelection(SelectionEvent<Integer> event) {
                int item = event.getSelectedItem();
                if (item == 0) {
                    help.setText("Single click for detail. Double click to zoom");
                } else if (item == 1) {
                    help.setText("Single click for spectrum");
                } else {
                    help.setText("");
                }
            }
        });

    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Problem drawing specgtrogram", ex);
    }
}

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

License:Open Source License

public void draw() {
    ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);

    chartLoader.loadApi(new Runnable() {

        @Override/*from  w w  w .j  a  v a 2  s .c  om*/
        public void run() {
            mVerticalPanel.clear();
            horizontalPanel = new HorizontalPanel();
            horizontalPanel.setWidth(SpectrumBrowser.SPEC_WIDTH + "px");
            horizontalPanel.setHeight(SpectrumBrowser.SPEC_HEIGHT + "px");

            lineChart = new LineChart();
            horizontalPanel.add(lineChart);
            drawNavigation();
            String dateString = jsonValue.isObject().get("formattedDate").isString().stringValue();
            HTML heading = new HTML("<h2>" + END_LABEL + "</h2>");
            mVerticalPanel.add(heading);
            int minFreq = (int) ((mMinFreq + 500000) / 1E6);
            int maxFreq = (int) ((mMaxFreq + 500000) / 1E6);
            int nChannels = (int) jsonValue.isObject().get(Defines.CHANNEL_COUNT).isNumber().doubleValue();
            int acquisitionCount = (int) jsonValue.isObject().get(Defines.ACQUISITION_COUNT).isNumber()
                    .doubleValue();
            int measurementsPerAcquisition = (int) jsonValue.isObject().get("measurementsPerAcquisition")
                    .isNumber().doubleValue();
            int cutoff = (int) jsonValue.isObject().get("cutoff").isNumber().doubleValue();
            HTML infoTitle = new HTML("<h3> Start Time = " + dateString + ";Detected System = " + sys2detect
                    + "; minFreq = " + minFreq + " MHz; maxFreq = " + maxFreq + " MHz" + "; nChannels = "
                    + nChannels + "; Occupancy cutoff = " + cutoff + " dBm </h3>");
            mVerticalPanel.add(infoTitle);
            HTML infoTitle1 = new HTML("<h3>Measurements Per Acquisition = " + measurementsPerAcquisition
                    + "; Acquisition Count = " + acquisitionCount + "</h3>");
            mVerticalPanel.add(infoTitle1);
            prevNextButtons = new Grid(1, 2);

            Label helpText = new Label("Click on data point to see detail.");

            mVerticalPanel.add(helpText);

            mVerticalPanel.add(prevNextButtons);

            mVerticalPanel.add(horizontalPanel);

            final long currentStartTime = (long) jsonValue.isObject().get("currentIntervalStart").isNumber()
                    .doubleValue();
            final long prevStartTime = (long) jsonValue.isObject().get("prevIntervalStart").isNumber()
                    .doubleValue();
            final long nextStartTime = (long) jsonValue.isObject().get("nextIntervalStart").isNumber()
                    .doubleValue();
            int count = 0;
            if (prevStartTime < currentStartTime) {
                Button prevIntervalButton = new Button("<< Previous Day");
                prevIntervalButton.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        mSpectrumBrowser.showWaitImage();
                        mSpectrumBrowser.getSpectrumBrowserService().getOneDayStats(mSensorId, lat, lon, alt,
                                prevStartTime, sys2detect, mMinFreq, mMaxFreq,
                                FftPowerOneDayOccupancyChart.this);
                    }
                });
                prevNextButtons.setWidget(0, 0, prevIntervalButton);
                count++;
            }

            if (nextStartTime > currentStartTime) {
                Button nextIntervalButton = new Button("Next Day >>");
                nextIntervalButton.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        mSpectrumBrowser.showWaitImage();
                        mSpectrumBrowser.getSpectrumBrowserService().getOneDayStats(mSensorId, lat, lon, alt,
                                nextStartTime, sys2detect, mMinFreq, mMaxFreq,
                                FftPowerOneDayOccupancyChart.this);

                    }
                });
                prevNextButtons.setWidget(0, 1, nextIntervalButton);
                count++;
            }

            if (count != 0) {
                prevNextButtons.setStyleName("selectionGrid");

            }
            for (int i = 0; i < prevNextButtons.getRowCount(); i++) {
                for (int j = 0; j < prevNextButtons.getColumnCount(); j++) {
                    prevNextButtons.getCellFormatter().setHorizontalAlignment(i, j,
                            HasHorizontalAlignment.ALIGN_CENTER);
                    prevNextButtons.getCellFormatter().setVerticalAlignment(i, j,
                            HasVerticalAlignment.ALIGN_MIDDLE);
                }
            }

            DataTable dataTable = DataTable.create();
            dataTable.addColumn(ColumnType.NUMBER, " Hours since start of day.");
            dataTable.addColumn(ColumnType.NUMBER, " Max");
            dataTable.addColumn(ColumnType.NUMBER, " Min");
            dataTable.addColumn(ColumnType.NUMBER, " Median");
            dataTable.addColumn(ColumnType.NUMBER, " Mean");

            JSONObject jsonObject = jsonValue.isObject().get("values").isObject();
            int rowCount = jsonObject.size();
            logger.finer("rowCount " + rowCount);
            dataTable.addRows(rowCount);
            try {
                int rowIndex = 0;
                for (String secondString : jsonObject.keySet()) {
                    JSONObject statsObject = jsonObject.get(secondString).isObject();
                    int second = Integer.parseInt(secondString);
                    long time = (long) statsObject.get("t").isNumber().doubleValue();
                    double mean = statsObject.get("meanOccupancy").isNumber().doubleValue() * 100;
                    double max = statsObject.get("maxOccupancy").isNumber().doubleValue() * 100;
                    double min = statsObject.get("minOccupancy").isNumber().doubleValue() * 100;
                    double median = statsObject.get("medianOccupancy").isNumber().doubleValue() * 100;
                    float hours = round3((double) second / (double) 3600);
                    int hourDelta = (int) hours;
                    int minutes = (int) ((((hours - hourDelta) * 60.0) / 60.0) * 60);
                    int seconds = (int) (((float) (second - hourDelta * 60 * 60 - minutes * 60) / 60.0) * 60);
                    NumberFormat nf = NumberFormat.getFormat("00");
                    dataTable.setCell(rowIndex, 0, hours,
                            nf.format(hourDelta) + ":" + nf.format(minutes) + ":" + nf.format(seconds));
                    dataTable.setCell(rowIndex, 1, round2(max), round2(max) + "%");
                    dataTable.setCell(rowIndex, 2, round2(min), round2(min) + "%");
                    dataTable.setCell(rowIndex, 3, round2(median), round2(median) + "%");
                    dataTable.setCell(rowIndex, 4, round2(mean), round2(mean) + "%");
                    selectionProperties.put(rowIndex, new SelectionProperty(time));
                    rowIndex++;
                }

                lineChart.addSelectHandler(new SelectHandler() {

                    @Override
                    public void onSelect(SelectEvent event) {
                        JsArray<Selection> selections = lineChart.getSelection();
                        int length = selections.length();
                        for (int i = 0; i < length; i++) {
                            int row = selections.get(i).getRow();
                            SelectionProperty property = selectionProperties.get(row);

                            new FftPowerOneAcquisitionSpectrogramChart(mSensorId, property.selectionTime,
                                    sys2detect, mMinFreq, mMaxFreq, mVerticalPanel, mSpectrumBrowser,
                                    navigation);
                        }
                    }
                });
                LineChartOptions options = LineChartOptions.create();
                options.setBackgroundColor("#f0f0f0");
                options.setPointSize(5);
                lineChart.setHeight(SpectrumBrowser.SPEC_HEIGHT + "px");
                lineChart.setWidth(SpectrumBrowser.SPEC_WIDTH + "px");
                HAxis haxis = HAxis.create("Hours since start of day.");
                haxis.setMinValue(0);
                haxis.setMaxValue(24);
                options.setHAxis(haxis);
                options.setVAxis(VAxis.create("Occupancy %"));
                lineChart.setStyleName("lineChart");
                lineChart.draw(dataTable, options);
                lineChart.setVisible(true);

                horizontalPanel.add(lineChart);
                mSpectrumBrowser.hideWaitImage();
            } catch (Throwable throwable) {
                logger.log(Level.SEVERE, "Problem parsing json ", throwable);
            }
        }
    });

}

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

License:Open Source License

public String formatToPrecision(int precision, double value) {
    String format = "00.";
    for (int i = 0; i < precision; i++) {
        format += "0";
    }/*ww  w. j a v  a  2 s .c  o m*/
    return NumberFormat.getFormat(format).format(value);
}