List of usage examples for com.google.gwt.i18n.client NumberFormat format
public String format(Number number)
From source file:fr.insalyon.creatis.vip.application.client.view.monitor.chart.JobStatsChart.java
License:Open Source License
public void build() { chartLayout.removeMembers(chartLayout.getMembers()); int completedJobs = 0; int cancelledJobs = 0; int failedJobs = 0; int stalledJobs = 0; int totalJobs = 0; long completedJobsExec = 0, cancelledJobsExec = 0, failedJobsExec = 0, stalledJobsExec = 0, totalJobsExec = 0;// w w w . ja v a2 s . co m // add data /* grid.setData(new PropertyRecord[]{ new PropertyRecord("Completed Jobs", data.get(0) + ""), new PropertyRecord("completed WaitingTime", data.get(1) + ""), new PropertyRecord("completed ExecutionTime", data.get(2) + ""), new PropertyRecord("completed InputTime", data.get(3) + ""), new PropertyRecord("completed OutputTime", data.get(4) + ""), new PropertyRecord("Cancelled Jobs", data.get(5) + ""), new PropertyRecord("Cancelled WaitingTime", data.get(6) + ""), new PropertyRecord("Cancelled ExecutionTime", data.get(7) + ""), new PropertyRecord("Cancelled InputTime", data.get(8) + ""), new PropertyRecord("Cancelled OutputTime", data.get(9) + ""), new PropertyRecord("failedApplication Jobs", data.get(10) + ""), new PropertyRecord("failedApplication WaitingTime", data.get(11) + ""), new PropertyRecord("failedApplication ExecutionTime", data.get(12) + ""), new PropertyRecord("failedApplication InputTime", data.get(13) + ""), new PropertyRecord("failedApplication OutputTime", data.get(14) + ""), new PropertyRecord("failedInput Jobs", data.get(15) + ""), new PropertyRecord("failedInput WaitingTime", data.get(16) + ""), new PropertyRecord("failedInput ExecutionTime", data.get(17) + ""), new PropertyRecord("failedInput InputTime", data.get(18) + ""), new PropertyRecord("failedInput OutputTime", data.get(19) + ""), new PropertyRecord("failedInput Jobs", data.get(15) + ""), new PropertyRecord("failedInput WaitingTime", data.get(16) + ""), new PropertyRecord("failedInput ExecutionTime", data.get(17) + ""), new PropertyRecord("failedInput InputTime", data.get(18) + ""), new PropertyRecord("failedInput OutputTime", data.get(19) + ""), new PropertyRecord("failedOutput Jobs", data.get(20) + ""), new PropertyRecord("failedOutput WaitingTime", data.get(21) + ""), new PropertyRecord("failedOutput ExecutionTime", data.get(22) + ""), new PropertyRecord("failedOutput InputTime", data.get(23) + ""), new PropertyRecord("failedOutput OutputTime", data.get(24) + ""), new PropertyRecord("failedStalled Jobs", data.get(25) + ""), new PropertyRecord("failedStalled WaitingTime", data.get(26) + ""), new PropertyRecord("failedStalled ExecutionTime", data.get(27) + ""), new PropertyRecord("failedStalled InputTime", data.get(28) + ""), new PropertyRecord("failedStalled OutputTime", data.get(29) + "") }); * */ //PropertyRecord[] p = new PropertyRecord[data.size()]; for (int i = 0; i < data.size(); i++) { if (data.get(i) != null) { addRowData(data.get(i)); String[] v = data.get(i).split("##"); //p[i] = new PropertyRecord(v[0], v[1]); switch (i) { case 0: completedJobs = completedJobs + Integer.parseInt(v[1]); break; case 2: completedJobsExec = completedJobsExec + Integer.parseInt(v[1]); break; case 5: cancelledJobs = cancelledJobs + Integer.parseInt(v[1]); break; case 7: cancelledJobsExec = cancelledJobsExec + Integer.parseInt(v[1]); break; case 10: failedJobs = failedJobs + Integer.parseInt(v[1]); break; case 12: failedJobsExec = failedJobsExec + Integer.parseInt(v[1]); break; case 15: failedJobs = failedJobs + Integer.parseInt(v[1]); break; case 17: failedJobsExec = failedJobsExec + Integer.parseInt(v[1]); break; case 20: failedJobs = failedJobs + Integer.parseInt(v[1]); break; case 22: failedJobsExec = failedJobsExec + Integer.parseInt(v[1]); break; case 25: stalledJobs = stalledJobs + Integer.parseInt(v[1]); case 27: stalledJobsExec = stalledJobsExec + Integer.parseInt(v[1]); } } } totalJobs = completedJobs + cancelledJobs + failedJobs + stalledJobs; grid.setData(new PropertyRecord[] { new PropertyRecord("Completed Jobs", completedJobs + ""), new PropertyRecord("Cancelled Jobs", cancelledJobs + ""), new PropertyRecord("Failed Jobs", failedJobs + ""), new PropertyRecord("Stalled Jobs", stalledJobs + ""), new PropertyRecord("Total Jobs", totalJobs + "") }); //grid.setCursor(Cursor.TEXT); ListGrid gridExecution = new ListGrid(); gridExecution.setWidth(280); gridExecution.setHeight(145); gridExecution.setShowAllRecords(true); ListGridField propertyField = new ListGridField("property", "Job Types"); ListGridField valueField = new ListGridField("value", "Execution Times (sec)"); valueField.setAlign(Alignment.RIGHT); valueField.setCellFormatter(new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) { return null; } try { NumberFormat nf = NumberFormat.getDecimalFormat(); return nf.format(Double.parseDouble((String) value)); } catch (Exception e) { return value.toString(); } } }); gridExecution.setFields(propertyField, valueField); totalJobsExec = completedJobsExec + cancelledJobsExec + failedJobsExec + stalledJobsExec; gridExecution.setData( new PropertyRecord[] { new PropertyRecord("Completed-jobs execution time", completedJobsExec + ""), new PropertyRecord("Cancelled-jobs execution time", cancelledJobsExec + ""), new PropertyRecord("Failed-jobs execution time", failedJobsExec + ""), new PropertyRecord("Stalled-jobs execution time", stalledJobsExec + ""), new PropertyRecord("Total execution time", totalJobsExec + "") }); chartLayout.addMember(gridExecution); gridExecution.setCanSelectCells(true); gridExecution.setCanSelectText(true); gridExecution.setCanEdit(true); chartLayout.addMember(getRowDataImg()); }
From source file:fr.insalyon.creatis.vip.application.client.view.monitor.ChartsTab.java
License:Open Source License
private void configureGrid() { grid = new ListGrid(); grid.setWidth(280);//from www. jav a 2s .co m grid.setHeight(145); grid.setShowAllRecords(true); grid.setShowEmptyMessage(true); grid.setEmptyMessage("<br>No data available."); ListGridField propertyField = new ListGridField("property", "Properties"); ListGridField valueField = new ListGridField("value", "Value"); valueField.setAlign(Alignment.RIGHT); valueField.setCellFormatter(new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) { return null; } try { NumberFormat nf = NumberFormat.getDecimalFormat(); return nf.format(Double.parseDouble((String) value)); } catch (Exception e) { return value.toString(); } } }); grid.setFields(propertyField, valueField); leftVLayout.addMember(grid); }
From source file:fr.insalyon.creatis.vip.application.client.view.monitor.StatsTab.java
License:Open Source License
private void configureGrid() { grid = new ListGrid(); grid.setWidth(280);/*from w ww . j a v a 2 s . com*/ grid.setHeight(145); grid.setShowAllRecords(true); grid.setShowEmptyMessage(true); grid.setEmptyMessage("<br>No data available."); ListGridField propertyField = new ListGridField("property", "Properties"); ListGridField valueField = new ListGridField("value", "Value"); valueField.setAlign(Alignment.RIGHT); valueField.setCellFormatter(new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) { return null; } try { NumberFormat nf = NumberFormat.getDecimalFormat(); return nf.format(Double.parseDouble((String) value)); } catch (Exception e) { return value.toString(); } } }); grid.setFields(propertyField, valueField); grid.setCanSelectCells(true); grid.setCanEdit(true); //grid.setAutoFetchData(true); //grid.setCanDragSelect(true); grid.setCanSelectText(true); grid.setCursor(Cursor.TEXT); leftVLayout.addMember(grid); }
From source file:fr.insalyon.creatis.vip.core.client.view.util.FieldUtil.java
License:Open Source License
/** * Gets a CellFormatter to parse file sizes. * * @return//from ww w. j a va 2 s .c o m */ public static CellFormatter getSizeCellFormatter() { return new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) { return null; } long length = ((Number) value).longValue(); if (length > 0) { String size = length + " B"; NumberFormat nf = NumberFormat.getFormat("#.##"); if (length / 1024 > 0) { if (length / (1024 * 1024) > 0) { if (length / (1024 * 1024 * 1024) > 0) { size = nf.format(length / (double) (1024 * 1024 * 1024)) + " GB"; } else { size = nf.format(length / (double) (1024 * 1024)) + " MB"; } } else { size = nf.format(length / (double) 1024) + " KB"; } } return size; } else { return ""; } } }; }
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 . j a v a 2 s.c om*/ 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.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 av a 2 s .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.OutputProgressBar.java
License:Open Source License
public void setValue(T value) { this.value = value; double val = 0; if (value == null) { val = this.min; } else {//from w w w . j a v a 2s.co 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.nist.spectrumbrowser.client.FftPowerOneAcquisitionSpectrogramChart.java
License:Open Source License
public void draw() { try {/*from w ww . jav a 2 s . com*/ 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 ww . j a va 2 s . c o m*/ 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.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
private static void updateResults(Search searchData, String query, String page) { StringBuilder sb = new StringBuilder(); JsArray<Results> searchResults = searchData.getResults(); JsArrayString searchRelated = searchData.getRelated(); JsArray<BoostedResults> boostedResults = searchData.getBoostedResults(); NumberFormat fmt = NumberFormat.getDecimalFormat(); // See if there are any related topics results. if (searchRelated != null) { for (int j = 0; j < searchRelated.length(); j++) { ListItem item = new ListItem(); Anchor a = new Anchor(); item.add(addSearchRelated(a, searchRelated.get(j))); list.add(item);//www. j a va 2s. c om } relatedTopicsHTMLPanel.add(list); leftNavBoxHTMLPanel.setVisible(true); } // See if there are any boosted results. if (boostedResults != null) { boostedResultsHTMLPanel.setVisible(true); for (int i = 0; i < boostedResults.length(); i++) { boostedResultsHTMLPanel.add( new HTML("<p><span style=\"font-size:1.2em;\"><a href=\"" + boostedResults.get(i).getUrl() + "\" style=\"color:#036;\">" + boostedResults.get(i).getTitle() + "</a></span><br />" + boostedResults.get(i).getDescription() + "<br />" + "<a href=\"" + boostedResults.get(i).getUrl() + "\" style=\"color:#488048\">" + boostedResults.get(i).getUrl() + "</a></p>")); } } // See if there are any returned results. if (searchResults.length() > 0) { bingLogoHTMLPanel.setVisible(true); searchResultsForHTML.setHTML("<h4 style=\"line-height:2em;\">Results " + searchData.getStartRecord() + "-" + searchData.getEndRecord() + " of about " + fmt.format(searchData.getTotal()) + " for \"" + query + "\"</h4>"); for (int i = 0; i < searchResults.length(); i++) { sb.append(buildResult(searchResults.get(i))); } searchResultsHTML.setHTML(sb.toString()); int totalPages = (searchData.getTotal() + 10 - 1) / 10; // (results + resultsPerPage - 1) / resultsPerPage PageLinks pageLinks = new PageLinks(totalPages, Integer.parseInt(page), query); paginationHTMLPanel.add(pageLinks); } else { searchResultsForHTML.setHTML("<h4>Sorry. No results found for \"" + query + "\".</h4>"); } loadingImage.setVisible(false); }