List of usage examples for com.google.gwt.i18n.client NumberFormat getFormat
public static NumberFormat getFormat(String pattern)
NumberFormat
instance for the default locale using the specified pattern and the default currencyCode. From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.grid.RowNumbererGridExample.java
License:sencha.com license
@Override public Widget asWidget() { final NumberFormat number = NumberFormat.getFormat("0.00"); IdentityValueProvider<Stock> identity = new IdentityValueProvider<Stock>(); RowNumberer<Stock> numberer = new RowNumberer<Stock>(identity); ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 200, "Company"); ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol"); ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last"); ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change"); changeCol.setCell(new AbstractCell<Double>() { @Override//from www . j av a 2 s. com public void render(Context context, Double value, SafeHtmlBuilder sb) { String style = "style='color: " + (value < 0 ? "red" : "green") + "'"; String v = number.format(value); sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>"); } }); ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated"); lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy"))); List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>(); l.add(numberer); l.add(nameCol); l.add(symbolCol); l.add(lastCol); l.add(changeCol); l.add(lastTransCol); ColumnModel<Stock> cm = new ColumnModel<Stock>(l); ListStore<Stock> store = new ListStore<Stock>(props.key()); store.addAll(TestData.getStocks()); final Grid<Stock> grid = new Grid<Stock>(store, cm); grid.getView().setAutoExpandColumn(nameCol); grid.setBorders(false); grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); numberer.initPlugin(grid); ContentPanel cp = new ContentPanel(); cp.setHeadingText("RowNumberer Grid"); cp.getHeader().setIcon(ExampleImages.INSTANCE.table()); cp.setPixelSize(600, 320); cp.addStyleName("margin-10"); cp.setButtonAlign(BoxLayoutPack.END); cp.addButton(new TextButton("Remove a Row", new SelectHandler() { @Override public void onSelect(SelectEvent event) { grid.getStore().remove(grid.getStore().get(0)); if (grid.getStore().size() == 0) { TextButton b = (TextButton) event.getSource(); b.disable(); } } })); cp.setWidget(grid); return cp; }
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.layout.PortalLayoutContainerExample.java
License:sencha.com license
public Widget createGrid() { final NumberFormat number = NumberFormat.getFormat("0.00"); ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 200, "Company"); ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol"); ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last"); ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change"); changeCol.setCell(new AbstractCell<Double>() { @Override/* w ww.j a v a 2s . co m*/ public void render(Context context, Double value, SafeHtmlBuilder sb) { String style = "style='color: " + (value < 0 ? "red" : "green") + "'"; String v = number.format(value); sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>"); } }); ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated"); lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy"))); List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>(); l.add(nameCol); l.add(symbolCol); l.add(lastCol); l.add(changeCol); l.add(lastTransCol); ColumnModel<Stock> cm = new ColumnModel<Stock>(l); ListStore<Stock> store = new ListStore<Stock>(props.key()); store.addAll(TestData.getStocks()); final Grid<Stock> grid = new Grid<Stock>(store, cm); grid.getView().setAutoExpandColumn(nameCol); grid.setBorders(true); grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); // needed to enable quicktips (qtitle for the heading and qtip for the // content) that are setup in the change GridCellRenderer new QuickTip(grid); return grid; }
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.layout.PortalLayoutContainerUiBinderExample.java
License:sencha.com license
@UiFactory() public Grid<Stock> createGrid() { final NumberFormat number = NumberFormat.getFormat("0.00"); ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 200, "Company"); ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol"); ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last"); ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change"); changeCol.setCell(new AbstractCell<Double>() { @Override/* www .j a v a2 s . c om*/ public void render(Context context, Double value, SafeHtmlBuilder sb) { SafeStylesBuilder stylesBuilder = new SafeStylesBuilder(); stylesBuilder.appendTrustedString("color:" + (value < 0 ? "red" : "green") + ";"); String v = number.format(value); CellTemplates cellTemplates = GWT.create(CellTemplates.class); SafeHtml template = cellTemplates.template(stylesBuilder.toSafeStyles(), v, v); sb.append(template); } }); ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated"); lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy"))); List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>(); l.add(nameCol); l.add(symbolCol); l.add(lastCol); l.add(changeCol); l.add(lastTransCol); ColumnModel<Stock> cm = new ColumnModel<Stock>(l); ListStore<Stock> store = new ListStore<Stock>(props.key()); store.addAll(TestData.getStocks()); final Grid<Stock> grid = new Grid<Stock>(store, cm); grid.getView().setAutoExpandColumn(nameCol); grid.setBorders(false); grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); // needed to enable quicktips (qtitle for the heading and qtip for the // content) that are setup in the change GridCellRenderer new QuickTip(grid); return grid; }
From source file:com.nabla.wapp.client.model.CurrencyFormatter.java
License:Apache License
public CurrencyFormatter(final String format) { if (format == null || format.isEmpty()) { this.format = null; this.zeroPattern = null; } else {// w ww .j a va 2 s .c o m final String[] tokens = format.split(";"); if (tokens.length < 2) { this.format = NumberFormat.getFormat(format); this.zeroPattern = null; } else { this.format = NumberFormat.getFormat(tokens[0] + ";" + tokens[1]); if (tokens.length < 3) this.zeroPattern = (format.charAt(format.length() - 1) == ';') ? "" : null; else this.zeroPattern = tokens[2]; } } }
From source file:com.nabla.wapp.client.model.CurrencyFormatter.java
License:Apache License
public CurrencyFormatter(final String format, final String zeroPattern) { this.format = NumberFormat.getFormat(format); this.zeroPattern = zeroPattern; }
From source file:com.nabla.wapp.client.model.PoundFormatter.java
License:Apache License
public PoundFormatter(final String format) { if (format == null || format.isEmpty()) { this.format = null; this.zeroPattern = null; } else {/* www . ja v a 2 s . c om*/ final String[] tokens = format.split(";"); if (tokens.length < 2) { this.format = NumberFormat.getFormat(format); this.zeroPattern = null; } else { this.format = NumberFormat.getFormat(tokens[0] + ";" + tokens[1]); if (tokens.length < 3) this.zeroPattern = (format.charAt(format.length() - 1) == ';') ? "" : null; else this.zeroPattern = tokens[2]; } } }
From source file:com.nabla.wapp.client.model.PoundFormatter.java
License:Apache License
public PoundFormatter(final String format, final String zeroPattern) { this.format = NumberFormat.getFormat(format); this.zeroPattern = zeroPattern; }
From source file:com.nitrous.gwt.earth.client.demo.GroundAltitudeDemo.java
License:Apache License
/** * Display content on the map//from w w w. j av a 2 s. c o m */ private void loadMapContent() { // The GEPlugin is the core class and is a great place to start browsing // the API final GEPlugin ge = earth.getGEPlugin(); ge.getWindow().setVisibility(true); // add a navigation control ge.getNavigationControl().setVisibility(GEVisibility.VISIBILITY_AUTO); // add some layers ge.enableLayer(GELayerId.LAYER_BORDERS, true); ge.enableLayer(GELayerId.LAYER_ROADS, true); ge.enableLayer(GELayerId.LAYER_TERRAIN, true); // Fly to the Grand Canyon KmlLookAt la = ge.createLookAt(""); la.set(36.20839, -112.45803, 0, KmlAltitudeMode.ALTITUDE_RELATIVE_TO_GROUND, -30, 40, 10000); ge.getView().setAbstractView(la); // listen to the click event on the globe and window GoogleEarth.addEventListener(ge.getWindow(), "mousemove", new KmlEventListener() { @Override public void onEvent(KmlEvent evt) { String statusHTML = "N/A"; KmlMouseEvent event = (KmlMouseEvent) evt; if (event.getDidHitGlobe()) { double latitude = event.getLatitude(); double longitude = event.getLongitude(); double groundAltitude = ge.getGlobe().getGroundAltitude(latitude, longitude); if (groundAltitude != 0) { statusHTML = "<span style=\"color:#000; font-weight:bold;\">" + NumberFormat.getFormat("#,##0.0#").format(groundAltitude) + " meters</span>"; } } Document.get().getElementById("ground-altitude").setInnerHTML(statusHTML); } }); }
From source file:com.npisoft.officine.client.application.GridExample.java
License:sencha.com license
@Override public Widget asWidget() { final NumberFormat number = NumberFormat.getFormat("0.00"); ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50, SafeHtmlUtils.fromTrustedString("<b>Company</b>")); ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol"); ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last"); ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change"); changeCol.setCell(new AbstractCell<Double>() { @Override/* w w w.java2s . com*/ public void render(Context context, Double value, SafeHtmlBuilder sb) { String style = "style='color: " + (value < 0 ? "red" : "green") + "'"; String v = number.format(value); sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>"); } }); ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated"); lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy"))); List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>(); l.add(nameCol); l.add(symbolCol); l.add(lastCol); l.add(changeCol); l.add(lastTransCol); ColumnModel<Stock> cm = new ColumnModel<Stock>(l); ListStore<Stock> store = new ListStore<Stock>(props.key()); store.addAll(getStocks()); root = new ContentPanel(); // panel = new (); // panel.setCollapsible(true); // panel.setPixelSize(500, 400); // panel.addStyleName("margin-10"); root.setHeadingText("Basic Grid"); root.getHeader().setIcon(ExampleImages.INSTANCE.table()); root.setPixelSize(600, 300); root.addStyleName("margin-10"); //ToolButton info = new ToolButton(ToolButton.QUESTION); //ToolTipConfig config = new ToolTipConfig("Example Info", // "This examples includes resizable panel, reorderable columns and grid state."); //config.setMaxWidth(225); //info.setToolTipConfig(config); // root.addTool(info); final Resizable resizable = new Resizable(root, Dir.E, Dir.SE, Dir.S); root.addExpandHandler(new ExpandHandler() { @Override public void onExpand(ExpandEvent event) { resizable.setEnabled(true); } }); root.addCollapseHandler(new CollapseHandler() { @Override public void onCollapse(CollapseEvent event) { resizable.setEnabled(false); } }); final Grid<Stock> grid = new Grid<Stock>(store, cm); grid.getView().setAutoExpandColumn(nameCol); grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); grid.setBorders(false); grid.setColumnReordering(true); grid.setStateful(true); grid.setStateId("gridExample"); GridStateHandler<Stock> state = new GridStateHandler<Stock>(grid); state.loadState(); ToolBar toolBar = new ToolBar(); toolBar.setEnableOverflow(false); // toolBar.add(new LabelToolItem("Selection Mode: ")); BoxLayoutData flex = new BoxLayoutData(new Margins(0, 5, 0, 5)); flex.setFlex(1); toolBar.add(new Label(), flex); TextButton btn0 = new TextButton(); btn0.setIcon(ExampleImages.INSTANCE.add()); btn0.setWidth(50); btn0.setToolTip("Ajouter"); btn0.setIconAlign(IconAlign.TOP); toolBar.add(btn0); HelloWindowExample helloWindowExample = new HelloWindowExample(); final Window window = (Window) helloWindowExample.asWidget(); btn0.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { window.show(); } }); window.setData("open", btn0); TextButton btn2 = new TextButton(); btn2.setIcon(ExampleImages.INSTANCE.delete0()); btn2.setWidth(50); btn2.setToolTip("Supprimer"); btn2.setIconAlign(IconAlign.TOP); toolBar.add(btn2); TextButton btn1 = new TextButton(); btn1.setIcon(ExampleImages.INSTANCE.edit()); btn1.setWidth(50); btn1.setToolTip("Editer"); btn1.setIconAlign(IconAlign.TOP); toolBar.add(btn1); TextButton btn3 = new TextButton(); btn3.setIcon(ExampleImages.INSTANCE.search()); btn3.setWidth(50); btn3.setToolTip("Chercher"); btn3.setIconAlign(IconAlign.TOP); toolBar.add(btn3); // toolBar.getToolTip().add SimpleComboBox<String> type = new SimpleComboBox<String>(new StringLabelProvider<String>()); type.setTriggerAction(TriggerAction.ALL); type.setEditable(false); type.setWidth(100); type.add("Row"); type.add("Cell"); type.setValue("Row"); // we want to change selection model on select, not value change which // fires on blur type.addSelectionHandler(new SelectionHandler<String>() { @Override public void onSelection(SelectionEvent<String> event) { boolean cell = event.getSelectedItem().equals("Cell"); if (cell) { CellSelectionModel<Stock> c = new CellSelectionModel<Stock>(); c.addCellSelectionChangedHandler(new CellSelectionChangedHandler<Stock>() { @Override public void onCellSelectionChanged(CellSelectionChangedEvent<Stock> event) { } }); grid.setSelectionModel(c); } else { grid.setSelectionModel(new GridSelectionModel<Stock>()); } } }); type.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { } }); // toolBar.add(type); VerticalLayoutContainer con = new VerticalLayoutContainer(); root.setWidget(con); // root.setHeaderVisible(false); con.add(toolBar, new VerticalLayoutData(1, -1)); con.add(grid, new VerticalLayoutData(1, 1)); // final PagingLoader<PagingLoadConfig, PagingLoadResult<Post>> loader = // new PagingLoader<PagingLoadConfig, PagingLoadResult<Post>>( // proxy); // loader.setRemoteSort(true); // loader.addLoadHandler(new // LoadResultListStoreBinding<PagingLoadConfig, Post, // PagingLoadResult<Post>>(store)); final PagingToolBar pagingToolBar = new PagingToolBar(50); pagingToolBar.getElement().getStyle().setProperty("borderBottom", "none"); // pagingToolBar.bind(loader); con.add(pagingToolBar, new VerticalLayoutData(1, -1)); // needed to enable quicktips (qtitle for the heading and qtip for the // content) that are setup in the change GridCellRenderer new QuickTip(grid); return root; }
From source file:com.npisoft.officine.client.application.referentiel.product.refofficine.edit.AggregationGridExample.java
License:sencha.com license
@Override public Widget asWidget() { if (panel == null) { StockProperties props = GWT.create(StockProperties.class); final NumberFormat numberFormat = NumberFormat.getFormat("0.00"); final NumberFormat currency = NumberFormat.getCurrencyFormat(); List<ColumnConfig<Stock, ?>> configs = new ArrayList<ColumnConfig<Stock, ?>>(); ColumnConfig<Stock, String> nameColumn = new ColumnConfig<Stock, String>(props.name(), 200, "Company"); configs.add(nameColumn);/* w ww . ja v a 2s .c o m*/ ColumnConfig<Stock, String> symbolColumn = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol"); configs.add(symbolColumn); ColumnConfig<Stock, Double> lastColumn = new ColumnConfig<Stock, Double>(props.last(), 100, "Last"); lastColumn.setCell(new PropertyDisplayCell<Double>(new DoublePropertyEditor(currency))); configs.add(lastColumn); ColumnConfig<Stock, Double> changeColumn = new ColumnConfig<Stock, Double>(props.change(), 100, "Change"); changeColumn.setCell(new PropertyDisplayCell<Double>(new DoublePropertyEditor(numberFormat)) { @Override public void render(com.google.gwt.cell.client.Cell.Context context, Double value, SafeHtmlBuilder sb) { String style = value < 0 ? "red" : "green"; sb.appendHtmlConstant("<span style='color:" + style + "'>"); super.render(context, value, sb); sb.appendHtmlConstant("</span>"); } }); configs.add(changeColumn); ColumnConfig<Stock, Date> dateColumn = new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Date"); dateColumn.setCell(new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT))); configs.add(dateColumn); final ListStore<Stock> store = new ListStore<Stock>(props.key()); store.addAll(TestData.getStocks()); ColumnModel<Stock> cm = new ColumnModel<Stock>(configs); cm.addHeaderGroup(0, 0, new HeaderGroupConfig("Stock Information", 1, 2)); cm.addHeaderGroup(0, 2, new HeaderGroupConfig("Stock Performance", 1, 2)); AggregationRowConfig<Stock> averages = new AggregationRowConfig<Stock>(); averages.setRenderer(nameColumn, new AggregationSafeHtmlRenderer<Stock>("Average")); averages.setRenderer(lastColumn, new AggregationNumberSummaryRenderer<Stock, Number>(currency, new AvgSummaryType<Number>())); averages.setRenderer(changeColumn, new AggregationNumberSummaryRenderer<Stock, Number>(numberFormat, new AvgSummaryType<Number>())); cm.addAggregationRow(averages); AggregationRowConfig<Stock> max = new AggregationRowConfig<Stock>(); max.setRenderer(nameColumn, new AggregationSafeHtmlRenderer<Stock>("Maximum")); max.setRenderer(lastColumn, new AggregationNumberSummaryRenderer<Stock, Number>(currency, new MaxSummaryType<Number>())); max.setRenderer(changeColumn, new AggregationNumberSummaryRenderer<Stock, Number>(numberFormat, new MaxSummaryType<Number>())); cm.addAggregationRow(max); AggregationRowConfig<Stock> min = new AggregationRowConfig<Stock>(); min.setRenderer(nameColumn, new AggregationSafeHtmlRenderer<Stock>("Minimum")); min.setRenderer(lastColumn, new AggregationNumberSummaryRenderer<Stock, Number>(currency, new MinSummaryType<Number>())); min.setRenderer(changeColumn, new AggregationNumberSummaryRenderer<Stock, Number>(numberFormat, new MinSummaryType<Number>())); cm.addAggregationRow(min); panel = new FramedPanel(); panel.setHeaderVisible(false); panel.setCollapsible(true); panel.setBorders(false); panel.setAnimCollapse(false); panel.setHeadingText("Aggregation Rows"); panel.setPixelSize(680, 300); panel.addStyleName("margin-10"); grid = new Grid<Stock>(store, cm); //grid.setBorders(true); grid.getView().setAutoExpandColumn(nameColumn); panel.add(grid); } return panel; }