List of usage examples for com.google.gwt.i18n.client NumberFormat format
public String format(Number number)
From source file:info.geekinaction.autoalert.view.FormatUtil.java
License:Open Source License
/** * Formats the given number with the given formatter. * /*from ww w. j av a 2s.c om*/ * @param number Number to format. * @param format Formatter. * @return Formatted number. */ public static String formatNumber(Float number, NumberFormat format) { if (number == null) { return null; } return format.format(number); }
From source file:lh.api.showcase.client.UiUtils.java
License:Apache License
public static ListBox newTimeListBox() { NumberFormat nf = NumberFormat.getFormat("00"); ListBox lb = new ListBox(); for (int h = 0; h < 24; ++h) { for (int m = 0; m < 60; m += 5) { lb.addItem(nf.format(h) + ":" + nf.format(m)); }/*ww w.jav a 2 s. c om*/ } return lb; }
From source file:me.smape.client.Smape.java
License:Open Source License
private Window createGridWindow() { Window w = new Window(); w.setIcon(IconHelper.createStyle("icon-grid")); w.setMinimizable(true);/*from w w w .ja v a2s. c om*/ w.setMaximizable(true); w.setHeading("Messages Window"); w.setSize(500, 400); w.setLayout(new FitLayout()); GroupingStore<Employee> employeeList = new GroupingStore<Employee>(); employeeList.add(TestData.getEmployees()); employeeList.groupBy("department"); List<ColumnConfig> configs = new ArrayList<ColumnConfig>(); ColumnConfig column = new ColumnConfig(); column.setId("name"); column.setHeader("Sender Name"); column.setWidth(200); configs.add(column); column = new ColumnConfig("department", "User group", 150); column.setAlignment(HorizontalAlignment.LEFT); configs.add(column); column = new ColumnConfig("designation", "Taggs", 150); column.setAlignment(HorizontalAlignment.LEFT); configs.add(column); column = new ColumnConfig("salary", "Length", 100); column.setAlignment(HorizontalAlignment.RIGHT); final NumberFormat number = NumberFormat.getFormat("0.00"); GridCellRenderer<Employee> checkSalary = new GridCellRenderer<Employee>() { public String render(Employee model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<Employee> employeeList, Grid<Employee> grid) { double val = (Double) model.get(property); String style = val < 70000 ? "red" : "green"; return "<span style='color:" + style + "'>" + number.format(val) + "</span>"; } }; column.setRenderer(checkSalary); configs.add(column); column = new ColumnConfig("joiningdate", "Date", 100); column.setAlignment(HorizontalAlignment.RIGHT); column.setDateTimeFormat(DateTimeFormat.getShortDateFormat()); configs.add(column); final ColumnModel cm = new ColumnModel(configs); GroupingView view = new GroupingView(); view.setForceFit(true); view.setGroupRenderer(new GridGroupRenderer() { public String render(GroupColumnData data) { String f = cm.getColumnById(data.field).getHeader(); String l = data.models.size() == 1 ? "Item" : "Items"; return f + ": " + data.group + " (" + data.models.size() + " " + l + ")"; } }); Grid<Employee> grid = new Grid<Employee>(employeeList, cm); grid.setView(view); grid.setBorders(true); ContentPanel cp = new ContentPanel(); cp.setBodyBorder(false); cp.setHeading("Friends List"); cp.setButtonAlign(HorizontalAlignment.CENTER); cp.setLayout(new FitLayout()); cp.setSize(700, 420); cp.add(grid); w.add(cp); return w; }
From source file:net.officefloor.demo.stocks.client.StockWatchWidget.java
License:Open Source License
/** * Initiate.// w w w. j a va 2s . c o m * * @param pageSize * Number of {@link Stock} instances displayed per page. */ public StockWatchWidget(int pageSize) { // Locale specific formatters final DateTimeFormat timeFormat = DateTimeFormat.getFormat(PredefinedFormat.HOUR24_MINUTE_SECOND); final NumberFormat sizeFormat = NumberFormat.getDecimalFormat(); final NumberFormat priceFormat = NumberFormat.getFormat("0.00"); final NumberFormat percentFormat = NumberFormat.getFormat("0.00"); // Configure table final CellTable<StockEntry> table = new CellTable<StockEntry>(pageSize, new StockWatchResource()); this.addColumn(table, "Name", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = entry.getStock().getName(); return StockWatchWidget.this.nameTemplate.cell(text); } }); this.addColumn(table, "Open", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = priceFormat.format(entry.getOpenPrice()); return StockWatchWidget.this.numberTemplate.cell(text, ""); } }); this.addColumn(table, "Time", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = timeFormat.format(new Date(entry.getStockPrice().getTimestamp())); return StockWatchWidget.this.numberTemplate.cell(text, entry.getHighlightCssClass()); } }); this.addColumn(table, "Change", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { double change = entry.getOpenPercentageChange() * 100; String text = percentFormat.format(change) + "%"; String cssClass; if (change < 0) { cssClass = "StockWatchChangeNegative"; } else { text = "+" + text; cssClass = "StockWatchChangePositive"; } return StockWatchWidget.this.changeTemplate.cell(cssClass, text, entry.getHighlightCssClass()); } }); this.addColumn(table, "Size", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = sizeFormat.format(Integer.valueOf(entry.getStockPrice().getBidSize())); return StockWatchWidget.this.numberTemplate.cell(text, entry.getHighlightCssClass()); } }); this.addColumn(table, "Bid", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = priceFormat.format(entry.getStockPrice().getBidPrice()); return StockWatchWidget.this.numberTemplate.cell(text, entry.getHighlightCssClass()); } }); this.addColumn(table, "Ask", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = priceFormat.format(entry.getStockPrice().getAskPrice()); return StockWatchWidget.this.numberTemplate.cell(text, entry.getHighlightCssClass()); } }); this.addColumn(table, "Size", new ColumnValue() { @Override public SafeHtml getValue(StockEntry entry) { String text = sizeFormat.format(Integer.valueOf(entry.getStockPrice().getAskSize())); return StockWatchWidget.this.numberTemplate.cell(text, entry.getHighlightCssClass()); } }); // Add list data provider to manage the data this.displayedPrices.addDataDisplay(table); // Subscribe to stock price events OfficeFloorComet.subscribe(StockPriceEvents.class, new StockPriceEvents() { @Override public void event(StockPrice price, Stock stock) { // Remove/Add stock price to add/update it List<StockEntry> stockEntries = StockWatchWidget.this.displayedPrices.getList(); // Find the stock entry StockEntry stockEntry = null; for (StockEntry entry : stockEntries) { if (entry.getStock().getMarketId().equals(stock.getMarketId())) { stockEntry = entry; break; // found entry } } if (stockEntry == null) { return; // stock not being watched } // Update the price stockEntry.setCurrentPrice(price); // Refresh the rows for the new price StockWatchWidget.this.displayedPrices.refresh(); // Sort the rows StockWatchWidget.this.sortRows(); } }, this.filter); // Add the table this.add(table); }
From source file:net.scran24.common.client.widgets.Counter.java
public void update() { NumberFormat nf = NumberFormat.getFormat(format); box.setText(nf.format(value)); }
From source file:net.scran24.datastore.shared.Time.java
License:Apache License
public String toString() { NumberFormat nf = NumberFormat.getFormat("00"); return nf.format(hours) + ":" + nf.format(minutes); }
From source file:net.scran24.user.client.survey.portionsize.experimental.PortionSizeScriptUtil.java
License:Apache License
public static SimplePrompt<UpdateFunc> asServedPrompt(final AsServedDef asServedDef, final String lessText, final String moreText, final String confirmText, final String indexField, final String imageUrlField, final String weightField, SafeHtml promptText) { final ImageDef[] defs = new ImageDef[asServedDef.images.length]; final NumberFormat nf = NumberFormat.getDecimalFormat(); for (int i = 0; i < asServedDef.images.length; i++) { defs[i] = asServedDef.images[i].def; defs[i].label = nf.format(Math.round(asServedDef.images[i].weight)) + " " + messages.asServed_weightUnitLabel(); }//from w w w . ja v a 2s . co m AsServedPromptDef def = new AsServedPromptDef(promptText, defs, moreText, lessText, confirmText); return map(new AsServedPrompt(def), new Function1<Integer, UpdateFunc>() { @Override public UpdateFunc apply(Integer choice) { return new UpdateFunc().setField(indexField, choice.toString()) .setField(weightField, Double.toString(asServedDef.images[choice].weight)) .setField(imageUrlField, defs[choice].url); } }); }
From source file:net.scran24.user.client.survey.prompts.simple.DrinkScalePrompt.java
License:Apache License
@Override public FlowPanel getInterface(final Callback1<Double> onComplete) { FlowPanel content = new FlowPanel(); FlowPanel promptPanel = WidgetFactory.createPromptPanel(def.message, ShepherdTour.createTourButton(tour, DrinkScalePrompt.class.getSimpleName())); content.add(promptPanel);//from w w w . j a v a 2 s . c o m SlidingScaleDef ssd = new SlidingScaleDef(def.scaleDef.baseImage, def.scaleDef.overlayImage, def.scaleDef.width, def.scaleDef.height, def.scaleDef.emptyLevel, def.scaleDef.fullLevel); final Function1<Double, String> label = new Function1<Double, String>() { @Override public String apply(Double argument) { double volume = def.scaleDef.calcVolume(argument); int roundedVolume = (int) volume; NumberFormat nf = NumberFormat.getDecimalFormat(); return nf.format(roundedVolume) + " " + messages.drinkScale_volumeUnit(); } }; final SlidingScale scale = new SlidingScale(ssd, def.limit, def.initialLevel, label); content.add(scale); final Button less = WidgetFactory.createButton(def.lessLabel, new ClickHandler() { @Override public void onClick(ClickEvent event) { scale.sliderBar.setValue(scale.sliderBar.getValue() + scale.sliderBar.getStep()); /*if (scale.sliderBar.getValue() > 0.99) less.setEnabled(false); else less.setEnabled(true);*/ } }); less.getElement().setId("intake24-sliding-scale-less-button"); final Button more = WidgetFactory.createButton(def.moreLabel, new ClickHandler() { @Override public void onClick(ClickEvent event) { scale.sliderBar.setValue(scale.sliderBar.getValue() - scale.sliderBar.getStep()); /*if (scale.sliderBar.getValue() < 0.01) more.setEnabled(false); else more.setEnabled(true);*/ } }); more.getElement().setId("intake24-sliding-scale-more-button"); final Button finish = WidgetFactory.createGreenButton(def.acceptLabel, new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(scale.getValue()); } }); finish.getElement().setId("intake24-sliding-scale-continue-button"); content.add(WidgetFactory.createButtonsPanel(less, more, finish)); ShepherdTour.makeShepherdTarget(promptPanel, scale.image, scale.overlayDiv, scale.sliderBar, less, more, finish); return content; }
From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractColourReportPresenter.java
License:Open Source License
public void showColourReport(final float scoreThreshold, final MetadataField emailAddressMetadataField, final TimedStimulusListener aboveThreshold, final TimedStimulusListener belowThreshold) { // todo: use scoreThreshold final NumberFormat numberFormat2 = NumberFormat.getFormat("0.00"); // final NumberFormat numberFormat3 = NumberFormat.getFormat("0.000"); final ScoreCalculator scoreCalculator = new ScoreCalculator(userResults); for (final StimulusResponseGroup stimuliGroup : userResults.getStimulusResponseGroups()) { final GroupScoreData calculatedScores = scoreCalculator.calculateScores(stimuliGroup); ((ReportView) simpleView).showResults(stimuliGroup, calculatedScores); ((ReportView) simpleView)//from w w w . j a v a 2 s . co m .addText(messages.reportScreenScore(numberFormat2.format(calculatedScores.getScore()))); ((ReportView) simpleView).addText(messages.userfeedbackscreentext()); userResults.getUserData().updateMaxScore(calculatedScores.getScore(), 0, 0, 0, 0); // ((ReportView) simpleView).addText(messages.reportScreenSCT()); // ((ReportView) simpleView).addText(messages.reportScreenSCTaccuracy(numberFormat2.format(calculatedScores.getAccuracy()))); // ((ReportView) simpleView).addText(messages.reportScreenSCTmeanreactionTime(numberFormat3.format(calculatedScores.getMeanReactionTime() / 1000), numberFormat3.format(calculatedScores.getReactionTimeDeviation() / 1000))); // stringBuilder.append(userResults.getUserData().getMetadataValue(MetadataFieldProvider.)); submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(), 0, "Score", stimuliGroup.getPostName(), Double.toString(calculatedScores.getScore()), 0); submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(), 0, "MeanReactionTime", stimuliGroup.getPostName(), Double.toString(calculatedScores.getMeanReactionTime()), 0); submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(), 0, "ReactionTimeDeviation", stimuliGroup.getPostName(), Double.toString(calculatedScores.getReactionTimeDeviation()), 0); } // ((ReportView) simpleView).addText(messages.reportScreenPostSCTtext()); if (userResults.getUserData().getMaxScore() <= scoreThreshold) { belowThreshold.postLoadTimerFired(); // ((ReportView) simpleView).addHighlightedText(messages.positiveresultscreentext1()); // ((ReportView) simpleView).addHighlightedText(messages.positiveresultscreentext2()); // ((ReportView) simpleView).addHighlightedText(messages.positiveresultscreentext3()); } else { aboveThreshold.postLoadTimerFired(); // ((ReportView) simpleView).addHighlightedText(messages.negativeresultscreentext1()); // ((ReportView) simpleView).addHighlightedText(messages.negativeresultscreentext2()); // ((ReportView) simpleView).addHighlightedText(messages.negativeresultscreentext3()); } ((ReportView) simpleView).addPadding(); }
From source file:nl.ru.languageininteraction.language.client.view.GuessRoundView.java
License:Open Source License
private void showResult() { matchLanguageBuilder.hideGroup(SvgGroupStates.TargetButtonPlay); matchLanguageBuilder.hideGroup(SvgGroupStates.SampleButtonPlay1); matchLanguageBuilder.hideGroup(SvgGroupStates.SampleButtonPlay2); matchLanguageBuilder.hideGroup(SvgGroupStates.SampleButtonPlay3); matchLanguageBuilder.hideGroup(SvgGroupStates.SampleButtonPlay4); matchLanguageBuilder.hideGroup(SvgGroupStates.SampleButtonPlay5); matchLanguageBuilder.hideGroup(SvgGroupStates.ChoiceArrow1); matchLanguageBuilder.hideGroup(SvgGroupStates.ChoiceArrow2); matchLanguageBuilder.hideGroup(SvgGroupStates.ChoiceArrow3); matchLanguageBuilder.hideGroup(SvgGroupStates.ChoiceArrow4); matchLanguageBuilder.hideGroup(SvgGroupStates.ChoiceArrow5); // matchLanguageBuilder.hideGroup(SvgGroupStates.ChoiceArrow4); matchLanguageBuilder.showGroup(SvgGroupStates.LanguageInfoBox); matchLanguageBuilder.showGroup(SvgGroupStates.g4704); // matchLanguageBuilder.showGroup(SvgGroupStates.IncorrectButton); matchLanguageBuilder.showGroup(SvgGroupStates.NextRoundButton); audioPlayer.stopAll();// ww w. jav a 2 s . c om matchLanguageBuilder.setLabel(SvgTextElements.tspan4319, roundData.getCorrectSample().getLanguageSample().getLanguageName()); NumberFormat decimalFormat = NumberFormat.getDecimalFormat(); String formattedPopulation = decimalFormat .format(roundData.getCorrectSample().getLanguageSample().getPopulation()); matchLanguageBuilder.setLabel(SvgTextElements.tspan4326, messages.languagePopulation(formattedPopulation)); }