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:uk.ac.ncl.openlab.intake24.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  ww  w.j a  v  a  2 s .  c  om
    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(),
            "quantityPromptContinueButton", 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);
                        }
                    }));
                }
            });

    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,
            BreadLinkedFoodAmountPrompt.class.getSimpleName());
}

From source file:uk.ac.ncl.openlab.intake24.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  . j  a v  a2  s.  c om

    SlidingScaleDef ssd = new SlidingScaleDef(def.scaleDef.baseImageUrl, def.scaleDef.overlayImageUrl,
            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, "drinkScaleAcceptButton",
            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;
}