Example usage for com.google.gwt.user.client.ui CheckBox getValue

List of usage examples for com.google.gwt.user.client.ui CheckBox getValue

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui CheckBox getValue.

Prototype

@Override
public Boolean getValue() 

Source Link

Document

Determines whether this check box is currently checked.

Usage

From source file:org.zanata.webtrans.client.view.TransFilterView.java

License:Open Source License

private static boolean allHaveValue(boolean checkValue, CheckBox... checkboxes) {
    for (CheckBox checkbox : checkboxes) {
        if (checkbox.getValue() != checkValue) {
            return false;
        }//from  www .  jav a2  s  .co m
    }
    return true;
}

From source file:thothbot.parallax.demo.client.content.geometries.GeometryExtrudeSplines.java

License:Open Source License

@Override
public void onAnimationReady(AnimationReadyEvent event) {
    super.onAnimationReady(event);

    final DemoScene rs = (DemoScene) this.renderingPanel.getAnimatedScene();

    this.renderingPanel.getCanvas().addMouseMoveHandler(new MouseMoveHandler() {
        @Override/*  ww w . ja  v a2  s .  co m*/
        public void onMouseMove(MouseMoveEvent event) {
            rs.mouseX = (event.getX() - renderingPanel.getRenderer().getAbsoluteWidth() / 2);
            rs.targetRotation = rs.targetRotationOnMouseDown + (rs.mouseX - rs.mouseXOnMouseDown) * 0.02;
        }
    });

    this.renderingPanel.getCanvas().addMouseDownHandler(new MouseDownHandler() {

        @Override
        public void onMouseDown(MouseDownEvent event) {
            rs.mouseXOnMouseDown = event.getX() - renderingPanel.getRenderer().getAbsoluteWidth() / 2;
            rs.targetRotationOnMouseDown = rs.targetRotation;

        }
    });

    FlowPanel panel = new FlowPanel();
    panel.setStyleName("common-panel", true);
    panel.setStyleName("corner-panel", true);
    this.renderingPanel.add(panel);
    this.renderingPanel.setWidgetLeftWidth(panel, 1, Unit.PX, 40, Unit.EM);
    this.renderingPanel.setWidgetTopHeight(panel, 1, Unit.PX, 19, Unit.EM);

    // Splines
    panel.add(new InlineLabel("Spline:"));

    final ListBox splines = new ListBox();
    splines.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            rs.extrudePath = rs.splines().get(splines.getValue(splines.getSelectedIndex()));
            rs.addTube();
        }
    });

    for (String key : rs.splines().keySet())
        splines.addItem(key);

    panel.add(splines);

    panel.add(new InlineHTML("<br/>"));

    // Scale
    panel.add(new InlineLabel("Scale:"));

    final ListBox scale = new ListBox();
    scale.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            rs.scale = Integer.parseInt(scale.getValue(scale.getSelectedIndex()));
            rs.setScale();
        }
    });

    for (String key : Arrays.asList("1", "2", "4", "6", "10"))
        scale.addItem(key, key);
    scale.setItemSelected(2, true);

    panel.add(scale);

    panel.add(new InlineHTML("<br/>"));

    // Extrusion Segments
    panel.add(new InlineLabel("Extrusion Segments:"));

    final ListBox extrusionSegments = new ListBox();
    extrusionSegments.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            rs.extrusionSegments = Integer
                    .parseInt(extrusionSegments.getValue(extrusionSegments.getSelectedIndex()));
            rs.addTube();
        }
    });

    for (String key : Arrays.asList("50", "100", "200", "400"))
        extrusionSegments.addItem(key);
    extrusionSegments.setItemSelected(1, true);

    panel.add(extrusionSegments);

    panel.add(new InlineHTML("<br/>"));

    // Radius Segments
    panel.add(new InlineLabel("Radius Segments:"));

    final ListBox radiusSegments = new ListBox();
    radiusSegments.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            rs.radiusSegments = Integer.parseInt(radiusSegments.getValue(radiusSegments.getSelectedIndex()));
            rs.addTube();
        }
    });

    for (String key : Arrays.asList("1", "2", "3", "4", "5", "6", "8", "12"))
        radiusSegments.addItem(key, key);
    radiusSegments.setItemSelected(2, true);

    panel.add(radiusSegments);

    panel.add(new InlineHTML("<br/>"));

    // Debug normals
    panel.add(new InlineLabel("Debug normals:"));
    final CheckBox isDebugNormals = new CheckBox();
    isDebugNormals.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            rs.isDebug = isDebugNormals.getValue();
            rs.addTube();
        }
    });

    panel.add(isDebugNormals);

    // Closed
    panel.add(new InlineLabel("Closed:"));
    final CheckBox isClosed = new CheckBox();
    isClosed.setValue(true);
    isClosed.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            rs.isClosed = isClosed.getValue();
            rs.addTube();
        }
    });

    panel.add(isClosed);

    panel.add(new InlineHTML("<br/>"));

    final Button animation = new Button("Camera Spline Animation View: OFF");
    animation.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            rs.isAnimation = !rs.isAnimation;
            animation.setText("Camera Spline Animation View: " + ((rs.isAnimation) ? "ON" : "OFF"));
        }
    });

    // Camera Spline Animation View
    panel.add(animation);

    panel.add(new InlineHTML("<br/>"));

    // Look Ahead
    panel.add(new InlineLabel("Look Ahead:"));
    final CheckBox isLookAhead = new CheckBox();
    isLookAhead.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            rs.isLookAhead = isLookAhead.getValue();
        }
    });

    panel.add(isLookAhead);

    // Camera Helper
    panel.add(new InlineLabel("Camera Helper:"));
    final CheckBox isCameraHelper = new CheckBox();
    isCameraHelper.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            rs.isShowCameraHelper = isCameraHelper.getValue();
            rs.animateCamera();
        }
    });
    panel.add(isCameraHelper);
}

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.AutomaticAssociatedFoodsPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        Callback1<Function1<Meal, Meal>> updateIntermediateState) {
    final FlowPanel content = new FlowPanel();
    PromptUtil.addBackLink(content);/* ww  w . ja  v  a 2s . c o m*/

    final FlowPanel promptPanel = WidgetFactory.createPromptPanel(SafeHtmlUtils.fromSafeConstant(
            messages.assocFoods_automaticPrompt(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))));

    content.add(promptPanel);

    final LoadingPanel loading = new LoadingPanel(messages.foodBrowser_loadingMessage());

    content.add(loading);

    final ArrayList<FoodHeader> encodedFoods = new ArrayList<>();
    final ArrayList<String> foodCodes = new ArrayList<>();

    for (FoodEntry e : meal.foods) {
        if (e.isEncoded()) {

            EncodedFood ef = e.asEncoded();

            encodedFoods.add(new FoodHeader(ef.data.code, ef.data.localDescription));
            foodCodes.add(ef.data.code);
        }
    }

    FoodDataService.INSTANCE.getAutomaticAssociatedFoods(locale, foodCodes,
            new MethodCallback<AutomaticAssociatedFoods>() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    content.remove(loading);
                    content.add(WidgetFactory.createDefaultErrorMessage());
                }

                @Override
                public void onSuccess(Method method, AutomaticAssociatedFoods response) {
                    content.remove(loading);

                    final List<CheckBox> checkBoxes = new ArrayList<>();
                    final Map<CheckBox, CategoryHeader> foodMap = new LinkedHashMap<>();

                    List<CategoryHeader> categories = response.categories.stream()
                            .filter(c -> milkIsRerevant(c)).collect(Collectors.toList());

                    List<String> codes = categories.stream().map(c -> c.code).collect(Collectors.toList());

                    if (!cachedAssociatedFoodsChanged(codes) || codes.size() == 0) {
                        cacheAssociatedFoods(listToJsArray(new ArrayList<>()));
                        onComplete.call(MealOperation.update(m -> m.markAssociatedFoodsComplete()));
                    } else {
                        cacheAssociatedFoods(listToJsArray(codes));
                        UxEventsHelper.postAutomaticAssociatedFoodsReceived(new AutomaticData(
                                Viewport.getCurrent(), encodedFoods, response.categories, new ArrayList<>()));
                    }

                    for (CategoryHeader category : categories) {
                        CheckBox cb = new CheckBox(SafeHtmlUtils.fromString(category.description()));

                        FlowPanel div = new FlowPanel();
                        div.getElement().getStyle().setPaddingBottom(4, Style.Unit.PX);
                        div.add(cb);
                        cb.getElement().getFirstChildElement().getStyle().setMargin(0, Style.Unit.PX);
                        content.add(div);

                        checkBoxes.add(cb);
                        foodMap.put(cb, category);
                    }

                    Button continueButton = WidgetFactory.createGreenButton("Continue", "continue-button",
                            new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent clickEvent) {

                                    ArrayList<String> selectedCategories = new ArrayList<>();

                                    for (CheckBox cb : checkBoxes) {
                                        if (cb.getValue()) {
                                            selectedCategories.add(foodMap.get(cb).code);
                                        }
                                    }

                                    UxEventsHelper.postAutomaticAssociatedFoodsResponse(
                                            new AutomaticData(Viewport.getCurrent(), encodedFoods,
                                                    response.categories, selectedCategories));

                                    onComplete.call(MealOperation.update(m -> {
                                        List<FoodEntry> newFoodEntries = new ArrayList<>();

                                        for (CheckBox cb : checkBoxes) {
                                            if (cb.getValue()) {
                                                Optional<FoodEntry> assocFood;
                                                CategoryHeader ch = foodMap.get(cb);
                                                switch (ch.code) {
                                                case SpecialData.FOOD_CODE_MILK_ON_CEREAL:
                                                    assocFood = meal.foods.stream()
                                                            .filter(f -> isCerealWithMilk(f)).findFirst();
                                                    if (assocFood.isPresent()) {
                                                        addFood(newFoodEntries, ch, assocFood);
                                                    }
                                                    break;
                                                case SpecialData.FOOD_CODE_MILK_IN_HOT_DRINK:
                                                    assocFood = meal.foods.stream()
                                                            .filter(f -> isHotDrinkWithMilk(f)).findFirst();
                                                    if (assocFood.isPresent()) {
                                                        addFood(newFoodEntries, ch, assocFood);
                                                    }
                                                    break;
                                                default:
                                                    addFood(newFoodEntries, ch, Optional.empty());
                                                    break;

                                                }
                                            }
                                        }

                                        if (newFoodEntries.size() > 0) {
                                            return m.withFoods(m.foods.plusAll(newFoodEntries));
                                        } else {
                                            cacheAssociatedFoods(listToJsArray(new ArrayList<>()));
                                            return m.withFoods(m.foods.plusAll(newFoodEntries))
                                                    .markAssociatedFoodsComplete();
                                        }

                                    }));
                                }
                            });

                    content.add(WidgetFactory.createButtonsPanel(continueButton));
                }
            });

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.ReadyMealsPrompt.java

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) {

    FlowPanel content = new FlowPanel();

    FlowPanel promptPanel = WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant(
                    messages.readyMeals_promptText(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))),
            ShepherdTour.createTourButton(tour, ReadyMealsPrompt.class.getSimpleName()));
    ShepherdTour.makeShepherdTarget(promptPanel);

    content.add(promptPanel);/* w w w  .  j a  va 2s.  co  m*/

    PVector<WithIndex<FoodEntry>> potentialReadyMeals = filter(zipWithIndex(meal.foods),
            new Function1<WithIndex<FoodEntry>, Boolean>() {
                @Override
                public Boolean apply(WithIndex<FoodEntry> argument) {
                    return argument.value.accept(new FoodEntry.Visitor<Boolean>() {

                        @Override
                        public Boolean visitRaw(RawFood food) {
                            return false;
                        }

                        @Override
                        public Boolean visitEncoded(EncodedFood food) {
                            return !food.isDrink() && !food.link.isLinked() && food.data.readyMealOption;
                        }

                        @Override
                        public Boolean visitTemplate(TemplateFood food) {
                            return false;
                        }

                        @Override
                        public Boolean visitMissing(MissingFood food) {
                            return false;
                        }

                        @Override
                        public Boolean visitCompound(CompoundFood food) {
                            return false;
                        }
                    });
                }
            });

    final Map<CheckBox, Integer> checkBoxToIndex = new HashMap<CheckBox, Integer>();

    FlowPanel checkboxesDiv = new FlowPanel();
    checkboxesDiv.addStyleName("scran24-ready-meals-checkboxes-block");
    checkboxesDiv.getElement().setId("intake24-ready-meals-list");

    for (WithIndex<FoodEntry> f : potentialReadyMeals) {
        FlowPanel rowDiv = new FlowPanel();

        CheckBox readyMealCheck = new CheckBox(SafeHtmlUtils.htmlEscape(f.value.description()));
        readyMealCheck.addStyleName("scran24-ready-meals-checkbox");

        checkBoxToIndex.put(readyMealCheck, f.index);

        rowDiv.add(readyMealCheck);

        checkboxesDiv.add(rowDiv);
    }

    content.add(checkboxesDiv);

    Button finishedButton = WidgetFactory.createButton(messages.editMeal_finishButtonLabel(),
            new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    onComplete.call(MealOperation.update(new Function1<Meal, Meal>() {
                        @Override
                        public Meal apply(Meal argument) {
                            Meal result = argument;

                            for (CheckBox check : checkBoxToIndex.keySet()) {
                                int index = checkBoxToIndex.get(check);
                                result = (check.getValue())
                                        ? result.updateFood(index, result.foods.get(index).markReadyMeal())
                                        : result;
                            }

                            return result.markReadyMealsComplete();
                        }
                    }));
                }
            });

    finishedButton.getElement().setId("intake24-ready-meals-finished-button");

    ShepherdTour.makeShepherdTarget(checkboxesDiv, finishedButton);

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

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.scheme.MultipleChoiceCheckboxQuestion.java

@Override
public SimpleSurveyStageInterface getInterface(final Callback1<Survey> onComplete,
        Callback2<Survey, Boolean> onIntermediateStateChange) {
    final FlowPanel content = new FlowPanel();
    content.addStyleName("intake24-multiple-choice-question");
    content.addStyleName("intake24-survey-content-container");

    content.add(WidgetFactory.createPromptPanel(questionText));

    FlowPanel checkboxesDiv = new FlowPanel();
    checkboxesDiv.addStyleName("scran24-ready-meals-checkboxes-block");

    final ArrayList<CheckBox> checkBoxes = new ArrayList<CheckBox>();

    for (String option : options) {
        FlowPanel rowDiv = new FlowPanel();
        CheckBox checkBox = new CheckBox(SafeHtmlUtils.htmlEscape(option));
        checkBox.setFormValue(option);//from  w  ww  .j a v  a  2  s. c  o  m
        checkBox.addStyleName("scran24-ready-meals-checkbox");
        checkBoxes.add(checkBox);
        rowDiv.add(checkBox);
        checkboxesDiv.add(rowDiv);
    }

    if (!otherOptionName.isEmpty()) {
        FlowPanel otherPanel = new FlowPanel();
        otherOption = new CheckBox(otherOptionName.getOrDie() + ": ");
        otherPanel.add(otherOption);
        otherBox = new TextBox();
        otherPanel.add(otherBox);
        checkboxesDiv.add(otherPanel);

        otherBox.addFocusHandler(new FocusHandler() {
            @Override
            public void onFocus(FocusEvent event) {
                otherOption.setValue(true);
            }
        });
    }

    content.add(checkboxesDiv);

    Button accept = WidgetFactory.createGreenButton(acceptText, "multipleChoiceCheckboxContinueButton",
            new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {

                    StringBuilder value = new StringBuilder();
                    boolean first = true;

                    for (CheckBox checkBox : checkBoxes)
                        if (checkBox.getValue()) {
                            if (first)
                                first = false;
                            else
                                value.append(", ");

                            value.append(checkBox.getFormValue());
                        }

                    if (!otherOptionName.isEmpty()) {
                        if (otherOption.getValue()) {
                            if (!first)
                                value.append(", ");
                            value.append(otherBox.getText());
                        }
                    }

                    onComplete.call(state.withData(dataField, value.toString()));
                }
            });

    content.add(checkboxesDiv);
    content.add(accept);

    return new SimpleSurveyStageInterface(content, MultipleChoiceCheckboxQuestion.class.getSimpleName());
}