List of usage examples for com.google.gwt.i18n.client NumberFormat format
public String format(Number number)
From source file:com.google.gwt.sample.stockwatcher.StockWatcher.client.StockWatcher.java
License:Open Source License
private void updateTable(StockPrice stockPrice) { // make sure the stock is still in our watch list if (!stocks.contains(stockPrice.getSymbol())) { return;/*from w ww. ja v a2s .c o m*/ } int row = stocks.indexOf(stockPrice.getSymbol()) + 1; // Format the data in the Price and Change fields. String priceText = NumberFormat.getFormat("#,##0.00").format(stockPrice.getPrice()); NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); String changeText = changeFormat.format(stockPrice.getChange()); String changePercentText = changeFormat.format(stockPrice.getChangePercent()); // Populate the Price and Change fields with new data. stocksFlexTable.setText(row, 1, priceText); //Use the line of code without styling stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)"); /* Esto lo dejo pendiente, poner estilo a las filas. //Use this with styling 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 (stockPrice.getChangePercent() < -0.1f) { changeStyleName = "negativeChange"; } else if (stockPrice.getChangePercent() > 0.1f) { changeStyleName = "positiveChange"; } changeWidget.setStyleName(changeStyleName); */ }
From source file:com.google.gwt.sample.stockwatcher.uibinder.client.StockWatcherWidget.java
private void updateTable(final StockPrice price) { if (!stocks.contains(price.getSymbol())) { return;//from www.j ava 2 s . co m } int row = stocks.indexOf(price.getSymbol()) + 1; 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()); stockFlexTable.setText(row, 1, priceText); // stockFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)"); Label changeWidget = (Label) stockFlexTable.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.stockwatcher2.StockWatcher2.client.StockWatcher2.java
private void updateTable(StockPrice stockPrice) { // TODO Auto-generated method stub if (!stocks.contains(stockPrice.getSymbol())) { return;/* ww w.j a v a2 s . c o m*/ } int row = stocks.indexOf(stockPrice.getSymbol()) + 1; // Format the data in the Price and Change fields. String priceText = NumberFormat.getFormat("#,##0.0").format(stockPrice.getPrice()); NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.0;-#,##0.0"); String changeText = changeFormat.format(stockPrice.getChange()); String changePercentText = changeFormat.format(stockPrice.getChangePercent()); // Populate the Price and Change fields with new data. stocksflexTable.setText(row, 1, priceText); stocksflexTable.setText(row, 2, changeText + "(" + changePercentText + "%)"); }
From source file:com.google.gwt.sample.stockwatcher_json.client.StockWatcherJSON.java
private void updateTable(StockData price) { // Make sure the stock is still in the stock table. if (!stocks.contains(price.getSymbol())) { return;/*from w ww . j ava2s . c o 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 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.stockwatcher_rpc.client.StockWatcherRPC.java
/** * Update a single row in the stock table. * //from w ww . ja va 2s . co m * @param price * Stock data for a single row. */ 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.sample.userwatcher.client.PageWithoutPhoto.java
/** * Update a single row in the stock table. */*from ww w . j a va2 s. c om*/ * @param price Stock data for a single row. */ 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); stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)"); }
From source file:com.google.gwt.sample.userwatcher.client.PageWithPhoto.java
/** * Update a single row in the stock table. *//from w ww .j av a2 s .co m * @param price Stock data for a single row. */ 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); stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)"); }
From source file:com.gwtext.sample.charts.client.yui.IncomeChartSample.java
License:Open Source License
public Panel getViewPanel() { if (panel == null) { panel = new Panel(); panel.setLayout(new VerticalLayout(15)); MemoryProxy proxy = new MemoryProxy(getData()); RecordDef recordDef = new RecordDef( new FieldDef[] { new IntegerFieldDef("year"), new IntegerFieldDef("revenue"), new IntegerFieldDef("expense"), new IntegerFieldDef("income") }); ArrayReader reader = new ArrayReader(recordDef); final Store store = new Store(proxy, reader); store.load();//from w w w . ja v a2 s . c om SeriesDefX incomeSeries = new SeriesDefX("Income", "income"); incomeSeries.setType(ChartType.LINE); SeriesDef[] seriesDef = new SeriesDef[] { new SeriesDefX("Revenue", "revenue"), new SeriesDefX("Expense", "expense"), incomeSeries }; NumericAxis currencyAxis = new NumericAxis(); //currencyAxis.setLabelFunction("formatCurrencyAxisLabel"); final BarChart chart = new BarChart(); chart.setTitle("Income Chart"); chart.setWMode("transparent"); chart.setStore(store); chart.setSeries(seriesDef); chart.setYField("year"); chart.setXAxis(currencyAxis); chart.setExpressInstall("js/yui/assets/expressinstall.swf"); chart.setWidth(500); chart.setHeight(400); panel.add(chart); Renderer renderer = new Renderer() { public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { NumberFormat nf = NumberFormat.getCurrencyFormat(); return nf.format(((Number) value).doubleValue()); } }; ColumnConfig yearConfig = new ColumnConfig("Year", "year", 100, true); NumberField yearField = new NumberField(); yearField.setAllowDecimals(false); yearField.setSelectOnFocus(true); yearConfig.setEditor(new GridEditor(yearField)); NumberField revenueField = new NumberField(); revenueField.setSelectOnFocus(true); ColumnConfig revenueConfig = new ColumnConfig("Revenue", "revenue", 130, true); revenueConfig.setEditor(new GridEditor(revenueField)); revenueConfig.setRenderer(renderer); NumberField expenseField = new NumberField(); expenseField.setSelectOnFocus(true); ColumnConfig expenseConfig = new ColumnConfig("Expense", "expense", 130, true); expenseConfig.setEditor(new GridEditor(expenseField)); expenseConfig.setRenderer(renderer); NumberField incomeField = new NumberField(); incomeField.setSelectOnFocus(true); ColumnConfig incomeConfig = new ColumnConfig("Income", "income", 130, true); incomeConfig.setEditor(new GridEditor(incomeField)); incomeConfig.setRenderer(renderer); ColumnModel columnModel = new ColumnModel( new ColumnConfig[] { yearConfig, revenueConfig, expenseConfig, incomeConfig }); EditorGridPanel grid = new EditorGridPanel(); grid.setStore(store); grid.setClicksToEdit(1); grid.setColumnModel(columnModel); grid.setWidth(500); grid.addEditorGridListener(new EditorGridListenerAdapter() { public void onAfterEdit(GridPanel grid, Record record, String field, Object newValue, Object oldValue, int rowIndex, int colIndex) { store.commitChanges(); chart.refresh(); } }); panel.add(grid); } return panel; }
From source file:com.gwtext.sample.charts.client.yui.LineChartSample.java
License:Open Source License
public Panel getViewPanel() { if (panel == null) { panel = new Panel(); panel.setLayout(new VerticalLayout(15)); MemoryProxy proxy = new MemoryProxy(getData()); RecordDef recordDef = new RecordDef(new FieldDef[] { new StringFieldDef("month"), new FloatFieldDef("rent"), new FloatFieldDef("utilities") }); ArrayReader reader = new ArrayReader(recordDef); final Store store = new Store(proxy, reader); store.load();//from w w w .j ava 2 s . com SeriesDefY[] seriesDef = new SeriesDefY[] { new SeriesDefY("Rent", "rent"), new SeriesDefY("Utilities", "utilities") }; NumericAxis currencyAxis = new NumericAxis(); currencyAxis.setMinimum(800); currencyAxis.setLabelFunction("formatCurrencyAxisLabel"); final LineChart chart = new LineChart(); chart.setTitle("Monthly Expenses"); chart.setWMode("transparent"); chart.setStore(store); chart.setSeries(seriesDef); chart.setXField("month"); chart.setYAxis(currencyAxis); chart.setDataTipFunction("getDataTipText"); chart.setExpressInstall("js/yui/assets/expressinstall.swf"); chart.setWidth(500); chart.setHeight(400); panel.add(chart); Renderer renderer = new Renderer() { public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { NumberFormat nf = NumberFormat.getCurrencyFormat(); return nf.format(((Number) value).doubleValue()); } }; ColumnConfig monthConfig = new ColumnConfig("Month", "month", 150, true); TextField monthField = new TextField(); monthField.setSelectOnFocus(true); monthConfig.setEditor(new GridEditor(monthField)); NumberField rentField = new NumberField(); rentField.setSelectOnFocus(true); ColumnConfig rentConfig = new ColumnConfig("Rent", "rent", 100, true); rentConfig.setEditor(new GridEditor(rentField)); rentConfig.setRenderer(renderer); NumberField utilitiesField = new NumberField(); utilitiesField.setSelectOnFocus(true); ColumnConfig utilitiesConfig = new ColumnConfig("Utilities", "utilities", 100, true); utilitiesConfig.setEditor(new GridEditor(utilitiesField)); utilitiesConfig.setRenderer(renderer); ColumnModel columnModel = new ColumnModel( new ColumnConfig[] { monthConfig, rentConfig, utilitiesConfig }); EditorGridPanel grid = new EditorGridPanel(); grid.setStore(store); grid.setClicksToEdit(1); grid.setColumnModel(columnModel); grid.setWidth(360); grid.addEditorGridListener(new EditorGridListenerAdapter() { public void onAfterEdit(GridPanel grid, Record record, String field, Object newValue, Object oldValue, int rowIndex, int colIndex) { store.commitChanges(); chart.refresh(); } }); panel.add(grid); } return panel; }
From source file:com.howard.lsp.lab8.lab9.stockwatcher.StockWatcher.client.StockWatcher.java
License:Open Source License
private void updateTable(StockPrice stockPrice) { // make sure the stock is still in our watch list if (!stocks.contains(stockPrice.getSymbol())) { return;/*ww w .j a v a 2 s.com*/ } int row = stocks.indexOf(stockPrice.getSymbol()) + 1; // Format the data in the Price and Change fields. String priceText = NumberFormat.getFormat("#,##0.00").format(stockPrice.getPrice()); NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); String changeText = changeFormat.format(stockPrice.getChange()); String changePercentText = changeFormat.format(stockPrice.getChangePercent()); // Populate the Price and Change fields with new data. stocksFlexTable.setText(row, 1, priceText); stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)"); }