Example usage for com.google.gwt.i18n.client NumberFormat getDecimalFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getDecimalFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client NumberFormat getDecimalFormat.

Prototype

public static NumberFormat getDecimalFormat() 

Source Link

Document

Provides the standard decimal format for the default locale.

Usage

From source file:info.geekinaction.autoalert.view.FormatUtil.java

License:Open Source License

/**
 * @see FormatUtil#formatNumber(Float, NumberFormat)
 *//*from   w w  w  .j  a v a 2 s  . c  o m*/
public static String formatNumber(Float number) {
    return formatNumber(number, NumberFormat.getDecimalFormat());
}

From source file:net.officefloor.demo.stocks.client.StockWatchWidget.java

License:Open Source License

/**
 * Initiate./*from   w  w w.j  a  v  a 2 s . com*/
 * 
 * @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.s17fabu.vip.gwt.showcase.client.content.i18n.CwNumberFormat.java

License:Apache License

/**
 * Update the selected pattern based on the pattern in the list.
 *//*w w w  .j a  va  2s. co  m*/
private void updatePattern() {
    switch (patternList.getSelectedIndex()) {
    case 0:
        activeFormat = NumberFormat.getDecimalFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 1:
        activeFormat = NumberFormat.getCurrencyFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 2:
        activeFormat = NumberFormat.getScientificFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 3:
        activeFormat = NumberFormat.getPercentFormat();
        patternBox.setText(activeFormat.getPattern());
        patternBox.setEnabled(false);
        break;
    case 4:
        patternBox.setEnabled(true);
        String pattern = patternBox.getText();
        try {
            activeFormat = NumberFormat.getFormat(pattern);
        } catch (IllegalArgumentException e) {
            showErrorMessage(constants.cwNumberFormatInvalidPattern());
            return;
        }
        break;
    }

    // Update the formatted value
    updateFormattedValue();
}

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 ww  w . jav  a  2s. c o  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.BreadLinkedFoodAmountPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> updateIntermediateState) {
    FlowPanel content = new FlowPanel();

    final EncodedFood food = meal.foods.get(foodIndex).asEncoded();
    final EncodedFood mainFood = meal.foods.get(mainFoodIndex).asEncoded();

    final String foodDescription = SafeHtmlUtils.htmlEscape(food.description().toLowerCase());
    final String mainFoodDescription = SafeHtmlUtils.htmlEscape(mainFood.description().toLowerCase());

    final String quantityStr = NumberFormat.getDecimalFormat().format(quantity);

    final FlowPanel quantityPanel = new FlowPanel();

    FlowPanel promptPanel = WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant(
                    messages.breadLinkedFood_promptText(foodDescription, mainFoodDescription, quantityStr)),
            ShepherdTour.createTourButton(shepherdTour, BreadLinkedFoodAmountPrompt.class.getSimpleName()));

    PromptUtil.addBackLink(content);/*from   w ww  . j a  va  2 s  .c o m*/
    content.add(promptPanel);
    ShepherdTour.makeShepherdTarget(promptPanel);

    Button allButton = WidgetFactory.createButton(messages.breadLinkedFood_allButtonLabel(),
            new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    onComplete.call(MealOperation.updateFood(foodIndex, new Function1<FoodEntry, FoodEntry>() {
                        @Override
                        public FoodEntry apply(FoodEntry argument) {
                            EncodedFood f = argument.asEncoded();
                            return f.withPortionSize(
                                    PortionSize.complete(f.completedPortionSize().multiply(quantity))).withFlag(
                                            ShowBreadLinkedFoodAmountPrompt.FLAG_BREAD_LINKED_FOOD_AMOUNT_SHOWN);
                        }
                    }));
                }
            });

    allButton.getElement().setId("intake24-all-button");
    ShepherdTour.makeShepherdTarget(allButton);

    content.add(WidgetFactory.createButtonsPanel(allButton));

    final QuantityCounter counter = new QuantityCounter(0.25, quantity, Math.max(1.0, quantity));

    ShepherdTour.makeShepherdTarget(counter.fractionalCounter);
    ShepherdTour.makeShepherdTarget(counter.wholeLabel);
    ShepherdTour.makeShepherdTarget(counter.wholeCounter);

    Button confirmQuantityButton = WidgetFactory.createGreenButton(messages.quantity_continueButtonLabel(),
            new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    onComplete.call(MealOperation.updateFood(foodIndex, new Function1<FoodEntry, FoodEntry>() {
                        @Override
                        public FoodEntry apply(FoodEntry argument) {
                            EncodedFood f = argument.asEncoded();
                            return f.withPortionSize(
                                    PortionSize.complete(f.completedPortionSize().multiply(counter.getValue())))
                                    .withFlag(
                                            ShowBreadLinkedFoodAmountPrompt.FLAG_BREAD_LINKED_FOOD_AMOUNT_SHOWN);
                        }
                    }));
                }
            });

    confirmQuantityButton.getElement().setId("intake24-quantity-prompt-continue-button");

    quantityPanel.add(counter);
    quantityPanel.add(confirmQuantityButton);

    ShepherdTour.makeShepherdTarget(confirmQuantityButton);

    content.add(quantityPanel);

    return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS);
}

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  ww  . ja v  a2 s  . co 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.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();//from  w  w  w. j  av a 2 s .c o  m
    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));
}

From source file:nl.ru.languageininteraction.language.client.view.ScorePageView.java

License:Open Source License

public void setUserScore(int userScore) {
    NumberFormat decimalFormat = NumberFormat.getDecimalFormat();
    String formattedScore = decimalFormat.format(userScore);
    scorePageBuilder.setLabel(SvgTextElements.tspan3303, formattedScore);
}

From source file:nl.ru.languageininteraction.language.client.view.ScorePageView.java

License:Open Source License

public void setUserLevel(int choicePerRound) {
    NumberFormat decimalFormat = NumberFormat.getDecimalFormat();
    String formattedChoiceCount = decimalFormat.format(choicePerRound);
    scorePageBuilder.setLabel(SvgTextElements.tspan4237, formattedChoiceCount);
}

From source file:nl.ru.languageininteraction.language.client.view.ScorePageView.java

License:Open Source License

public void setEndangeredCount(int endangeredCount) {
    NumberFormat decimalFormat = NumberFormat.getDecimalFormat();
    String formattedChoiceCount = decimalFormat.format(endangeredCount);
    scorePageBuilder.setLabel(SvgTextElements.tspan4192, formattedChoiceCount);
}