List of usage examples for com.google.gwt.i18n.client NumberFormat format
public String format(Number number)
From source file:com.extjs.gxt.ui.client.widget.grid.ColumnFooter.java
License:sencha.com license
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void refresh() { ListStore<ModelData> store = grid.getStore(); int cols = cm.getColumnCount(); int models = grid.getStore().getCount(); int rowcount = rows.size(); for (int i = 0; i < rowcount; i++) { AggregationRowConfig<?> config = cm.getAggregationRow(i); FooterRow footer = rows.get(i);//from w w w. ja v a 2 s . com for (int j = 0; j < cols; j++) { String name = cm.getDataIndex(j); updateColumnWidth(j, cm.getColumnWidth(j)); if (config.getHtml(name) != null) { footer.setHtml(j, config.getHtml(name)); continue; } else if (config.getWidget(name) != null) { footer.setWidget(j, config.getWidget(name)); continue; } Number value = null; SummaryType<?> type = config.getSummaryType(name); if (type != null) { Map<String, Object> data = new FastMap<Object>(); for (int k = 0; k < models; k++) { value = type.render(value, store.getAt(k), name, data); } } if (config.getModel() != null) { Object obj = config.getModel().get(name); if (obj != null) { if (obj instanceof Number) { value = (Number) obj; } else if (obj instanceof Widget) { footer.setWidget(j, (Widget) obj); continue; } else { footer.setHtml(j, obj.toString()); continue; } } } NumberFormat format = config.getSummaryFormat(name); if (format != null && value != null) { String svalue = format.format(value.doubleValue()); footer.setHtml(j, svalue); continue; } AggregationRenderer<?> renderer = config.getRenderer(name); if (renderer != null) { Object obj = renderer.render(value, j, (Grid) grid, (ListStore) store); if (obj instanceof Widget) { footer.setWidget(j, (Widget) obj); } else if (obj != null) { footer.setHtml(j, obj.toString()); } } } } }
From source file:com.extjs.gxt.ui.client.widget.treegrid.TreeGridView.java
License:sencha.com license
@Override protected SafeHtml getRenderedValue(ColumnData data, int rowIndex, int colIndex, ModelData m, String property) { GridCellRenderer<ModelData> r = cm.getRenderer(colIndex); List<Widget> rowMap = widgetList.get(rowIndex); rowMap.add(colIndex, null);/*w ww . j av a 2 s.c om*/ if (r != null) { return r.render(ds.getAt(rowIndex), property, data, rowIndex, colIndex, ds, grid); } Object val = m.get(property); ColumnConfig c = cm.getColumn(colIndex); if (val != null && c.getNumberFormat() != null) { Number n = (Number) val; NumberFormat nf = cm.getColumn(colIndex).getNumberFormat(); return SafeHtmlUtils.fromString(nf.format(n.doubleValue())); } else if (val != null && c.getDateTimeFormat() != null) { DateTimeFormat dtf = c.getDateTimeFormat(); return SafeHtmlUtils.fromString(dtf.format((Date) val)); } String text = null; if (val != null) { text = val.toString(); } return SafeGxt.emptyToNbSpace(text); }
From source file:com.google.gwt.example.stockwatcher.client.StockWatcher.java
/** * Update a single row in the stock table. * * @param price Stock data for a single row. *///www.ja v a2 s . c om private void updateTable(StockPrice price) { // Make sure the stock is still in the stock table. if (!stocks.contains(price.getSymbol())) { return; } int row = stocks.indexOf(price.getSymbol()) + 1; // Format the data in the Price and Change fields. String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice()); NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); String changeText = changeFormat.format(price.getChange()); String changePercentText = changeFormat.format(price.getChangePercent()); // Populate the Price and Change fields with new data. stocksFlexTable.setText(row, 1, priceText); Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2); changeWidget.setText(changeText + " (" + changePercentText + "%)"); // Change the color of text in the change field based on its value. String changeStyleName = "noChange"; if (price.getChangePercent() < -0.1f) { changeStyleName = "negativeChange"; } else if (price.getChangePercent() > 0.1f) { changeStyleName = "positiveChange"; } changeWidget.setStyleName(changeStyleName); }
From source file:com.google.gwt.examples.NumberFormatExample.java
public void onModuleLoad() { NumberFormat fmt = NumberFormat.getDecimalFormat(); double value = 12345.6789; String formatted = fmt.format(value); // Prints 1,2345.6789 in the default locale GWT.log("Formatted string is" + formatted); // Turn a string back into a double value = NumberFormat.getDecimalFormat().parse("12345.6789"); GWT.log("Parsed value is" + value); // Scientific notation value = 12345.6789;//from www . ja v a 2 s .c o m formatted = NumberFormat.getScientificFormat().format(value); // prints 1.2345E4 in the default locale GWT.log("Formatted string is" + formatted); // Currency fmt = NumberFormat.getCurrencyFormat(); formatted = fmt.format(123456.7899); // prints US$123,456.79 in the default locale or $123,456.79 in the en_US // locale GWT.log("Formatted currency is" + formatted); // Custom format value = 12345.6789; formatted = NumberFormat.getFormat("000000.000000").format(value); // prints 012345.678900 in the default locale GWT.log("Formatted string is" + formatted); }
From source file:com.google.gwt.maps.sample.hellomaps.client.GeocoderDemo.java
License:Apache License
private void displayLatLng(LatLng point) { NumberFormat fmt = NumberFormat.getFormat("#.0000000#"); latLabel.setText(fmt.format(point.getLatitude())); lngLabel.setText(fmt.format(point.getLongitude())); }
From source file:com.google.gwt.maps.testing.client.maps.ElevationMapWidget.java
License:Apache License
protected void drawInfoWindow(LatLng position, double elevation) { NumberFormat format = NumberFormat.getFormat("###"); String elevationStr = format.format(elevation); String latlngStr = "[ " + format.format(position.getLatitude()) + ", " + format.format(position.getLongitude()) + " ]"; String message = "Elevation " + elevationStr + "m @ " + latlngStr; HTML html = new HTML(message); InfoWindowOptions options = InfoWindowOptions.newInstance(); options.setContent(html);/* w w w. j av a 2 s.co m*/ InfoWindow iw = InfoWindow.newInstance(options); iw.setPosition(position); iw.open(mapWidget); }
From source file:com.google.gwt.sample.client.mystockwatcherEntryPoint.java
/** * Update a single row in the stock table. * * @param price Stock data for a single row. *///from ww w.jav a2 s . c o m private void updateTable(StockData price) { // Make sure the stock is still in the stock table. if (!stocks.contains(price.getSymbol())) { return; } int row = stocks.indexOf(price.getSymbol()) + 1; // Format the data in the Price and Change fields. String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice()); NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); String changeText = changeFormat.format(price.getChange()); String changePercentText = changeFormat.format(price.getChangePercent()); // Populate the Price and Change fields with new data. stocksFlexTable.setText(row, 1, priceText); Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2); changeWidget.setText(changeText + " (" + changePercentText + "%)"); // Change the color of text in the Change field based on its value. String changeStyleName = "noChange"; if (price.getChangePercent() < -0.1f) { changeStyleName = "negativeChange"; } else if (price.getChangePercent() > 0.1f) { changeStyleName = "positiveChange"; } changeWidget.setStyleName(changeStyleName); }
From source file:com.google.gwt.sample.client.stockwatcher.java
private void updateTable(StockPrice price) { int row;//www . j av a 2 s . c om String priceText, diffText, diffPercentText; NumberFormat diffFormat; Label changeWidget; String changeStyleName = "noChange"; if (stocks.contains(price.getName()) == false) { return; } //Format text row = stocks.indexOf(price.getName()) + 1; priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice()); diffFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); diffText = diffFormat.format(price.getDiff()); diffPercentText = diffFormat.format(price.getDiffPercent()); //Populate price stocksTable.setText(row, 1, priceText); changeWidget = (Label) stocksTable.getWidget(row, 2); changeWidget.setText(diffText + " (" + diffPercentText + "%)"); // Change the color of text in the Change field based on its value. if (price.getDiffPercent() < -0.1f) { changeStyleName = "negativeChange"; } else if (price.getDiffPercent() > 0.1f) { changeStyleName = "positiveChange"; } changeWidget.setStyleName(changeStyleName); }
From source file:com.google.gwt.sample.Marketing.client.Marketing.java
private void updateListTable(Product product) { Button addProductButton = new Button("Add to Shopping cart"); Image image = new Image(); image.setPixelSize(50, 60);//from w ww .j a v a2 s . c o m int row = productFlexTable.getRowCount(); final String PIDText = Integer.toString(product.getPID()); String modelText = product.getModel(); String priceText = NumberFormat.getFormat("#,##0.00").format(product.getPrice()); NumberFormat discountFormat = NumberFormat.getFormat("#,##0.00"); String discountText = discountFormat.format(product.getDiscount()); String discountPriceText = discountFormat.format(product.getDiscountPrice()); image.setUrl("images/" + product.getImg()); addProductButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { int index = Product.indexOf(PIDText); Product p = Product.productList[index]; if (account.getUsername() == "Guest") { Window.alert("Please login before any purchase"); usernameTextBox.setFocus(true); } else { ShoppingCart.add(new ShoppingCart(p, account.getUsername())); ViewCart.setText("View Cart : " + ShoppingCart.getTotalCount() + " $" + NumberFormat.getFormat("#,##0.00").format(ShoppingCart.getTotalPrice())); } } }); productFlexTable.setText(row, 0, PIDText); productFlexTable.setText(row, 1, modelText); productFlexTable.setText(row, 2, "$" + priceText); productFlexTable.setText(row, 3, "$" + discountPriceText + " (" + discountText + "%)"); productFlexTable.setWidget(row, 4, image); productFlexTable.setWidget(row, 5, addProductButton); }
From source file:com.google.gwt.sample.stockwatch.client.StockWatcher.java
private void updateTable(StockPrice price) { //Make sure the stock is still in the stock table. if (!stocks.contains(price.getSymbol())) { return;/* w w w.j a v a 2s . co m*/ } int row = stocks.indexOf(price.getSymbol()) + 1; //Format the data in the Price and Change fields String priceText = NumberFormat.getFormat("#,##0.00").format(price.getPrice()); NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); String changeText = changeFormat.format(price.getChange()); String changePercentText = changeFormat.format(price.getChangePercent()); //Populate the Price and the Change fields with new data. stocksFlexTable.setText(row, 1, priceText); Label changeWidget = (Label) stocksFlexTable.getWidget(row, 2); changeWidget.setText(changeText + "(" + changePercentText + "%)"); // Change the color of text in the Change field based on its value String changeStyleName = "noChange"; if (price.getChangePercent() < -0.1f) { changeStyleName = "negativeChange"; } else if (price.getChangePercent() > 0.1f) { changeStyleName = "positiveChange"; } changeWidget.setStyleName(changeStyleName); }