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.extjs.gxt.samples.client.examples.organizer.ImageOrganizerExample.java
License:Open Source License
@Override protected void onRender(Element parent, int index) { super.onRender(parent, index); LayoutContainer container = new LayoutContainer(); container.setStyleAttribute("margin", "20px"); container.setSize(650, 300);/*from w w w . ja va 2 s. co m*/ container.setBorders(true); container.setLayout(new BorderLayout()); ContentPanel west = new ContentPanel(); west.setHeading("My Albums"); ToolBar toolBar = new ToolBar(); Button newAlbum = new Button("New Album"); newAlbum.setIcon(Resources.ICONS.album()); newAlbum.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { MessageBox.prompt("New Album", "Enter the new album name:", new Listener<MessageBoxEvent>() { public void handleEvent(MessageBoxEvent be) { if (be.getButtonClicked().getItemId().equals(Dialog.OK) && be.getValue() != null) { tree.getStore().add(createAlbum(be.getValue()), false); tree.setLeaf( tree.getStore().getRootItems().get(tree.getStore().getRootItems().size() - 1), false); } } }); } }); toolBar.add(newAlbum); west.setTopComponent(toolBar); TreeStore<ModelData> treeStore = new TreeStore<ModelData>(); tree = new TreePanel<ModelData>(treeStore); tree.setDisplayProperty("name"); tree.getStyle().setLeafIcon(IconHelper.create("user")); tree.getStyle().setNodeCloseIcon(IconHelper.create("icon-album")); tree.getStyle().setNodeOpenIcon(IconHelper.create("icon-album")); west.add(tree); treeStore.add(createAlbum("Album 1"), false); tree.setLeaf(treeStore.getRootItems().get(0), false); BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 200, 100, 300); westData.setMargins(new Margins(5, 0, 5, 5)); westData.setSplit(true); container.add(west, westData); ContentPanel center = new ContentPanel(); center.setHeading("My Images"); // center.setScrollMode(Scroll.AUTO); center.setLayout(new FitLayout()); BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER); centerData.setMargins(new Margins(5)); container.add(center, centerData); final ExampleServiceAsync service = (ExampleServiceAsync) Registry.get(Examples.SERVICE); RpcProxy<List<Photo>> proxy = new RpcProxy<List<Photo>>() { @Override protected void load(Object loadConfig, AsyncCallback<List<Photo>> callback) { service.getPhotos(callback); } }; ListLoader<ListLoadResult<BeanModel>> loader = new BaseListLoader<ListLoadResult<BeanModel>>(proxy, new BeanModelReader()); ListStore<BeanModel> store = new ListStore<BeanModel>(loader); loader.load(); ListView<BeanModel> view = new ListView<BeanModel>() { @Override protected BeanModel prepareData(BeanModel model) { Photo photo = model.getBean(); long size = photo.getSize() / 1000; model.set("shortName", Format.ellipse(photo.getName(), 15)); model.set("sizeString", NumberFormat.getFormat("#0").format(size) + "k"); model.set("dateString", DateTimeFormat.getMediumDateTimeFormat().format(photo.getDate())); model.set("path", GWT.getHostPageBaseURL() + photo.getPath()); return model; } }; view.setId("img-chooser-view"); view.setTemplate(getTemplate()); view.setBorders(false); view.setStore(store); view.setItemSelector("div.thumb-wrap"); center.add(view); new ListViewDragSource(view); TreePanelDropTarget target = new TreePanelDropTarget(tree) { @SuppressWarnings("rawtypes") @Override protected void handleAppendDrop(DNDEvent event, TreeNode item) { List<BeanModel> sel = event.getData(); for (BeanModel bean : sel) { ModelData m = new BaseModelData(); for (String s : bean.getPropertyNames()) { m.set(s, bean.get(s)); } tree.getStore().add(item.getModel(), m, false); } } }; target.setOperation(Operation.COPY); target.setFeedback(Feedback.APPEND); add(container); }
From source file:com.extjs.gxt.samples.client.examples.view.ImageChooserExample.java
License:Open Source License
@Override protected void onRender(Element parent, int index) { super.onRender(parent, index); detailTp = XTemplate.create(getDetailTemplate()); final ExampleServiceAsync service = (ExampleServiceAsync) Registry.get(Examples.SERVICE); RpcProxy<List<Photo>> proxy = new RpcProxy<List<Photo>>() { @Override/* w ww. j a va2s.c om*/ protected void load(Object loadConfig, AsyncCallback<List<Photo>> callback) { service.getPhotos(callback); } }; ListLoader<ListLoadResult<BeanModel>> loader = new BaseListLoader<ListLoadResult<BeanModel>>(proxy, new BeanModelReader()); store = new ListStore<BeanModel>(loader); loader.load(); chooser = new Dialog(); chooser.setId("img-chooser-dlg"); chooser.setHeading("Choose an Image"); chooser.setMinWidth(500); chooser.setMinHeight(300); chooser.setModal(true); chooser.setLayout(new BorderLayout()); chooser.setBodyStyle("border: none;background: none"); chooser.setBodyBorder(false); chooser.setButtons(Dialog.OKCANCEL); chooser.setHideOnButtonClick(true); chooser.addListener(Events.Hide, new Listener<WindowEvent>() { public void handleEvent(WindowEvent be) { BeanModel model = view.getSelectionModel().getSelectedItem(); if (model != null) { Photo photo = model.getBean(); if (be.getButtonClicked() == chooser.getButtonById("ok")) { image.setUrl(photo.getPath()); image.setVisible(true); } } } }); ContentPanel main = new ContentPanel(); main.setBorders(true); main.setBodyBorder(false); main.setLayout(new FitLayout()); main.setHeaderVisible(false); ToolBar bar = new ToolBar(); bar.add(new LabelToolItem("Filter:")); StoreFilterField<BeanModel> field = new StoreFilterField<BeanModel>() { @Override protected boolean doSelect(Store<BeanModel> store, BeanModel parent, BeanModel record, String property, String filter) { Photo photo = record.getBean(); String name = photo.getName().toLowerCase(); if (name.indexOf(filter.toLowerCase()) != -1) { return true; } return false; } @Override protected void onFilter() { super.onFilter(); view.getSelectionModel().select(0, false); } }; field.setWidth(100); field.bind(store); bar.add(field); bar.add(new SeparatorToolItem()); bar.add(new LabelToolItem("Sort By:")); sort = new SimpleComboBox<String>(); sort.setTriggerAction(TriggerAction.ALL); sort.setEditable(false); sort.setForceSelection(true); sort.setWidth(90); sort.add("Name"); sort.add("File Size"); sort.add("Last Modified"); sort.setSimpleValue("Name"); sort.addListener(Events.Select, new Listener<FieldEvent>() { public void handleEvent(FieldEvent be) { sort(); } }); bar.add(sort); main.setTopComponent(bar); view = new ListView<BeanModel>() { @Override protected BeanModel prepareData(BeanModel model) { Photo photo = model.getBean(); long size = photo.getSize() / 1000; model.set("shortName", Format.ellipse(photo.getName(), 15)); model.set("sizeString", NumberFormat.getFormat("#0").format(size) + "k"); model.set("dateString", DateTimeFormat.getMediumDateTimeFormat().format(photo.getDate())); model.set("modPath", GWT.getHostPageBaseURL() + photo.getPath()); return model; } }; view.setId("img-chooser-view"); view.setTemplate(getTemplate()); view.setBorders(false); view.setStore(store); view.setItemSelector("div.thumb-wrap"); view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); view.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BeanModel>>() { public void handleEvent(SelectionChangedEvent<BeanModel> be) { onSelectionChange(be); } }); main.add(view); details = new LayoutContainer(); details.setBorders(true); details.setStyleAttribute("backgroundColor", "white"); BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST, 150, 150, 250); eastData.setSplit(true); BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER); centerData.setMargins(new Margins(0, 5, 0, 0)); chooser.add(main, centerData); chooser.add(details, eastData); setLayout(new FlowLayout(10)); add(new Button("Choose", new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { chooser.show(); view.getSelectionModel().select(0, false); } })); image = new Image(); image.getElement().getStyle().setProperty("marginTop", "10px"); image.setVisible(false); add(image); }
From source file:com.extjs.gxt.ui.client.util.Format.java
License:sencha.com license
/** * Formats the number.//from w w w . ja va 2 s . c om * * @param value the number * @param format the format using the {@link DateTimeFormat} syntax. * @return the formatted string */ public static String number(double value, String format) { return NumberFormat.getFormat(format).format(value); }
From source file:com.extjs.gxt.ui.client.widget.form.NumberPropertyEditor.java
License:sencha.com license
/** * Creates a new number property editor. * /* ww w .j a va 2 s. c o m*/ * @param pattern the number format pattern */ public NumberPropertyEditor(String pattern) { this(NumberFormat.getFormat(pattern)); }
From source file:com.extjs.gxt.ui.client.widget.table.NumberCellRenderer.java
License:Open Source License
/** * Creates a new number cell renderer.//from w ww. jav a2 s . com * * @param pattern the pattern used by {@link NumberFormat} */ public NumberCellRenderer(String pattern) { this.format = NumberFormat.getFormat(pattern); }
From source file:com.github.gwt.user.client.ui.grids.minutes.MinutesGrid.java
License:Apache License
@Override protected String getText(final int index) { return getStateValue().getHours() + ":" + NumberFormat.getFormat("00").format(INTERVAL * index); }
From source file:com.google.caliper.cloud.client.BenchmarkDataViewer.java
License:Apache License
/** * Rebuilds the index from the combinations of variables to the * corresponding datapoint./*from w ww .java2s . c o m*/ */ private void rebuildIndex() { this.unitMap = new HashMap<MeasurementType, String>(); this.divideByMap = new HashMap<MeasurementType, Integer>(); this.numberFormatMap = new HashMap<MeasurementType, NumberFormat>(); this.maxMap = new HashMap<MeasurementType, Double>(); this.minMap = new HashMap<MeasurementType, Double>(); this.referencePointMap = new HashMap<MeasurementType, Double>(); this.useRawMap = new HashMap<MeasurementType, Boolean>(); for (MeasurementType measurementType : orderedMeasurementTypes) { if (measurementType == MeasurementType.DEBUG) { continue; } double min = Double.POSITIVE_INFINITY; double max = 0; // select the units to use - default to ns/us/ms/s if there are any differences in the // user-defined units between runs. Map<String, Integer> units = null; boolean useRaw = false; UNIT_SELECTION_LOOP: for (RunMeta runMeta : runMetas) { for (ScenarioResult scenarioResults : runMeta.getRun().getMeasurements().values()) { MeasurementSet measurementSet = scenarioResults.getMeasurementSet(measurementType); // if we have no measurement for this run, just skip this run. if (measurementSet == null) { continue UNIT_SELECTION_LOOP; } if (units == null) { units = measurementSet.getUnitNames(); } else if (!units.equals(measurementSet.getUnitNames())) { useRaw = true; units = DEFAULT_UNITS.get(measurementType); break UNIT_SELECTION_LOOP; } } } useRawMap.put(measurementType, useRaw); if (units == null) { units = DEFAULT_UNITS.get(measurementType); } keysToDatapoints.clear(); for (RunMeta runMeta : runMetas) { for (Map.Entry<Scenario, ScenarioResult> entry : runMeta.getRun().getMeasurements().entrySet()) { ScenarioResult scenarioResult = normalize(entry.getValue()); Scenario scenario = entry.getKey(); Key key = new Key(variables.size()); boolean isShown = true; for (Variable variable : variables) { Value value = variable.get(runMeta, scenario); if (value != null) { isShown = isShown && value.isShown(); } key.set(variable, value); } if (isShown) { MeasurementSet measurementSet = scenarioResult.getMeasurementSet(measurementType); if (measurementSet != null) { min = Math.min(min, getMin(measurementType, measurementSet)); max = Math.max(max, getMax(measurementType, measurementSet)); } } keysToDatapoints.put(key, new Datapoint(scenarioResult, runMeta.getStyle())); } } this.maxMap.put(measurementType, max); this.minMap.put(measurementType, min); this.referencePointMap.put(measurementType, min); List<Map.Entry<String, Integer>> entries = new ArrayList<Map.Entry<String, Integer>>(units.entrySet()); // sort entries in reverse order Collections.sort(entries, new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Map.Entry<String, Integer> a, Map.Entry<String, Integer> b) { return b.getValue().compareTo(a.getValue()); } }); int numDigitsInMin = ceil(Math.log10(min)); String unitCandidate = null; for (Map.Entry<String, Integer> entry : entries) { if (min / entry.getValue() >= 1) { unitCandidate = entry.getKey(); break; } } if (unitCandidate == null) { // if no unit works, just use the smallest available unit. unitCandidate = entries.get(entries.size() - 1).getKey(); } unitMap.put(measurementType, unitCandidate); divideByMap.put(measurementType, units.get(unitCandidate)); int decimalDigits = ceil(Math.max(0, Math.log10(divideByMap.get(measurementType)) + DIGITS_OF_PRECISION - numDigitsInMin)); String format = "#,###,##0"; if (decimalDigits > 0) { format += "."; for (int i = 0; i < decimalDigits; i++) { format += "0"; } } numberFormatMap.put(measurementType, NumberFormat.getFormat(format)); } }
From source file:com.google.gdata.data.media.mediarss.NormalPlayTime.java
License:Apache License
/** * Gets the standard {@code seconds.fraction } representation for this object. * /*from w w w . j a v a 2s . c o m*/ * @return {@code seconds.fraction} or {@code "now"} */ public String getNptSecondsRepresentation() { if (isNow) { return "now"; } long seconds = ms / 1000l; long fraction = ms % 1000l; if (fraction == 0) { return Long.toString(seconds); } return NumberFormat.getFormat("00").format(seconds) + "." + NumberFormat.getFormat("000").format(fraction); }
From source file:com.google.gdata.data.media.mediarss.NormalPlayTime.java
License:Apache License
/** * Gets the standard {@code hh:mm:ss.fraction } representation for this object. * //w w w . java2s. c o m * @return {@code hh:mm:ss.fraction} or {@code "now"} */ public String getNptHhmmssRepresentation() { if (isNow) { return "now"; } long fraction = ms % 1000l; long totalseconds = ms / 1000l; long seconds = totalseconds % 60l; long totalminutes = totalseconds / 60l; long minutes = totalminutes % 60l; long hours = totalminutes / 60l; if (fraction > 0) { return NumberFormat.getFormat("00").format(hours) + ":" + NumberFormat.getFormat("00").format(minutes) + ":" + NumberFormat.getFormat("00").format(seconds) + "." + NumberFormat.getFormat("000").format(fraction); } else { return NumberFormat.getFormat("00").format(hours) + ":" + NumberFormat.getFormat("000").format(minutes) + ":" + NumberFormat.getFormat("000").format(seconds); } }
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. *//*from w w w . j a v a 2 s .c o m*/ 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); }