Example usage for com.google.gwt.user.client.ui HorizontalPanel setSpacing

List of usage examples for com.google.gwt.user.client.ui HorizontalPanel setSpacing

Introduction

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

Prototype

public void setSpacing(int spacing) 

Source Link

Document

Sets the amount of spacing between this panel's cells.

Usage

From source file:net.scran24.user.client.survey.prompts.AddMealPrompt.java

@Override
public SurveyStageInterface getInterface(final Callback1<SurveyOperation> onComplete,
        final Callback1<Function1<Survey, Survey>> onIntermediateStateChange) {
    SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(messages.addMeal_promptText());

    HorizontalPanel mealNamePanel = new HorizontalPanel();
    mealNamePanel.setSpacing(5);
    mealNamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

    HorizontalPanel mealListPanel = new HorizontalPanel();
    mealListPanel.setSpacing(5);//from  w w w  . j  a v a  2  s. co  m
    mealListPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

    final TextBox text = new TextBox();

    text.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            text.selectAll();
        }
    });

    text.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                if (!text.getText().isEmpty())
                    onComplete.call(SurveyOperation.update(new Function1<Survey, Survey>() {
                        @Override
                        public Survey apply(Survey argument) {
                            return argument.plusMeal(Meal.empty(text.getText()))
                                    .withSelection(new Selection.SelectedMeal(argument.meals.size(),
                                            SelectionMode.AUTO_SELECTION));
                        }
                    }));
            }
        }
    });

    final ListBox list = new ListBox();

    for (String s : PredefinedMeals.getSuggestedMealNamesForCurrentLocale())
        list.addItem(s);

    list.setSelectedIndex(selectedIndex);

    text.setText(list.getItemText(list.getSelectedIndex()));

    list.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            text.setText(list.getItemText(list.getSelectedIndex()));
        }
    });

    mealListPanel.add(new Label(messages.addMeal_predefLabel()));
    mealListPanel.add(list);
    mealListPanel.getElement().setId("intake24-predef-meal-name");
    ShepherdTour.makeShepherdTarget(mealListPanel);

    mealNamePanel.add(new Label(messages.addMeal_customLabel()));
    mealNamePanel.add(text);
    mealNamePanel.getElement().setId("intake24-custom-meal-name");
    ShepherdTour.makeShepherdTarget(mealNamePanel);

    Button acceptButton = WidgetFactory.createButton(messages.addMeal_addButtonLabel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (!text.getText().isEmpty())
                onComplete.call(SurveyOperation.update(new Function1<Survey, Survey>() {
                    @Override
                    public Survey apply(Survey argument) {
                        return argument.plusMeal(Meal.empty(text.getText()))
                                .withSelection(new Selection.SelectedMeal(argument.meals.size(),
                                        SelectionMode.AUTO_SELECTION));
                    }
                }));
        }
    });

    acceptButton.getElement().setId("intake24-accept-button");

    Button cancelButton = WidgetFactory.createButton(messages.addMeal_cancelButtonLabel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            onComplete.call(SurveyOperation.noChange);
        }
    });

    cancelButton.getElement().setId("intake24-cancel-button");

    ShepherdTour.makeShepherdTarget(acceptButton, cancelButton);

    FlowPanel contents = new FlowPanel();
    contents.add(WidgetFactory.createPromptPanel(promptText,
            ShepherdTour.createTourButton(tour, AddMealPrompt.class.getSimpleName())));
    contents.add(mealListPanel);
    contents.add(mealNamePanel);
    contents.add(WidgetFactory.createButtonsPanel(acceptButton, cancelButton));

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

From source file:net.scran24.user.client.survey.prompts.SaveHomeRecipePrompt.java

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        final Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> onIntermediateStateChange) {
    SafeHtml promptText = SafeHtmlUtils//from w  w w. j a  va  2 s  .  co m
            .fromSafeConstant(messages.homeRecipe_savePromptText(SafeHtmlUtils.htmlEscape(food.description())));

    HorizontalPanel recipeNamePanel = new HorizontalPanel();
    recipeNamePanel.setSpacing(5);
    recipeNamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

    recipeName.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            recipeName.selectAll();
        }
    });

    recipeName.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                if (!recipeName.getText().isEmpty())
                    onComplete.call(MealOperation.update(saveRecipeFunction));
            }
        }
    });

    recipeNamePanel.add(new Label(messages.homeRecipe_recipeNameLabel()));
    recipeNamePanel.add(recipeName);

    Button yesButton = WidgetFactory.createGreenButton(messages.yesNoQuestion_defaultYesLabel(),
            new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    if (!recipeName.getText().isEmpty())
                        onComplete.call(MealOperation.update(saveRecipeFunction));
                }
            });

    Button noButton = WidgetFactory.createButton(messages.yesNoQuestion_defaultNoLabel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            onComplete.call(MealOperation.update(dontSaveRecipeFunction));
        }
    });

    FlowPanel contents = new FlowPanel();
    contents.add(WidgetFactory.createPromptPanel(promptText));
    contents.add(recipeNamePanel);
    contents.add(WidgetFactory.createButtonsPanel(yesButton, noButton));

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

From source file:org.bonitasoft.console.client.view.AbstractItemList.java

License:Open Source License

protected void initView() {
    // Create the 'navigation' bar at the upper-right.
    myTopNavBar = buildTopNavBar();//from   www .ja v a  2s .  co m
    myTopNavBar.setStyleName(ITEM_LIST_NAVBAR_STYLE);
    HorizontalPanel thePageNavigator = new HorizontalPanel();
    thePageNavigator.setStyleName(ITEM_LIST_PAGE_NAVBAR_STYLE);
    // Create navigation handler.
    newestButtonTop.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            // FIXME should use the HyperLink feature and let the ViewController
            // handle the reload.
            myBonitaDataSource.getItemFilter().setStartingIndex(0);
            myItemSelection.clearSelection();
            myBonitaDataSource.reload();
        }
    });

    newerButtonTop.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            int theStartingIndex = myBonitaDataSource.getItemFilter().getStartingIndex();
            if (theStartingIndex >= myMaximalSize) {
                // FIXME should use the HyperLink feature and let the ViewController
                // handle the reload.
                myBonitaDataSource.getItemFilter().setStartingIndex(theStartingIndex - myMaximalSize);
                myItemSelection.clearSelection();
                myBonitaDataSource.reload();
            }
        }
    });

    olderButtonTop.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            int theStartingIndex = myBonitaDataSource.getItemFilter().getStartingIndex();
            myBonitaDataSource.getItemFilter().setStartingIndex(theStartingIndex + myMaximalSize);
            myItemSelection.clearSelection();
            // FIXME should use the HyperLink feature and let the ViewController
            // handle the reload.
            myBonitaDataSource.reload();
        }
    });

    oldestButtonTop.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {

            myBonitaDataSource.getItemFilter()
                    .setStartingIndex(getIndexOfLastPage(myBonitaDataSource.getSize(), myMaximalSize));
            myItemSelection.clearSelection();
            // FIXME should use the HyperLink feature and let the ViewController
            // handle the reload.
            myBonitaDataSource.reload();
        }
    });

    // Make the text looks like a link
    newestButtonTop.setStylePrimaryName(ITEMS_LINK_STYLE);
    newerButtonTop.setStylePrimaryName(ITEMS_LINK_STYLE);
    olderButtonTop.setStylePrimaryName(ITEMS_LINK_STYLE);
    oldestButtonTop.setStylePrimaryName(ITEMS_LINK_STYLE);

    newestButtonTop.setTitle(constants.firstPage());
    oldestButtonTop.setTitle(constants.lastPage());

    thePageNavigator.add(newestButtonTop);
    thePageNavigator.add(newerButtonTop);
    thePageNavigator.add(myCountLabelTop);
    thePageNavigator.add(olderButtonTop);
    thePageNavigator.add(oldestButtonTop);

    thePageNavigator.setSpacing(3);

    myFilterEditor = buildFilterEditor();
    if (myFilterEditor != null) {
        myTopNavBar.add(myFilterEditor);
        myFilterEditor.addPageBrowser(thePageNavigator);
    } else {
        myTopNavBar.add(thePageNavigator);
    }

    // Create the 'navigation' bar at the bottom-right
    myBottomNavBar = buildBottomNavBar();
    if (myBottomNavBar != null) {
        myBottomNavBar.setStyleName(ITEM_LIST_NAVBAR_STYLE);
    }
    thePageNavigator = new HorizontalPanel();
    thePageNavigator.setStyleName(ITEM_LIST_PAGE_BOTTOM_NAVBAR_STYLE);
    // Create navigation handler.
    newestButtonBottom.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            // FIXME should use the HyperLink feature and let the ViewController
            // handle the reload.
            myBonitaDataSource.getItemFilter().setStartingIndex(0);
            myBonitaDataSource.reload();
        }
    });

    newerButtonBottom.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            int theStartingIndex = myBonitaDataSource.getItemFilter().getStartingIndex();
            if (theStartingIndex >= myMaximalSize) {
                myBonitaDataSource.getItemFilter().setStartingIndex(theStartingIndex - myMaximalSize);
                // FIXME should use the HyperLink feature and let the ViewController
                // handle the reload.
                myBonitaDataSource.reload();
            }
        }
    });

    olderButtonBottom.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            int theStartingIndex = myBonitaDataSource.getItemFilter().getStartingIndex();
            myBonitaDataSource.getItemFilter().setStartingIndex(theStartingIndex + myMaximalSize);
            // FIXME should use the HyperLink feature and let the ViewController
            // handle the reload.
            myBonitaDataSource.reload();
        }
    });

    oldestButtonBottom.addClickHandler(new ClickHandler() {
        /*
         * (non-Javadoc)
         * 
         * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google
         * .gwt.event.dom.client.ClickEvent)
         */
        public void onClick(ClickEvent aArg0) {
            myBonitaDataSource.getItemFilter()
                    .setStartingIndex(getIndexOfLastPage(myBonitaDataSource.getSize(), myMaximalSize));
            // FIXME should use the HyperLink feature and let the ViewController
            // handle the reload.
            myBonitaDataSource.reload();
        }
    });

    // Make the text looks like a link
    newestButtonBottom.setStylePrimaryName(ITEMS_LINK_STYLE);
    newerButtonBottom.setStylePrimaryName(ITEMS_LINK_STYLE);
    olderButtonBottom.setStylePrimaryName(ITEMS_LINK_STYLE);
    oldestButtonBottom.setStylePrimaryName(ITEMS_LINK_STYLE);

    thePageNavigator.add(newestButtonBottom);
    thePageNavigator.add(newerButtonBottom);
    thePageNavigator.add(myCountLabelBottom);
    thePageNavigator.add(olderButtonBottom);
    thePageNavigator.add(oldestButtonBottom);
    thePageNavigator.setSpacing(3);

    if (myBottomNavBar != null) {
        myBottomNavBar.add(thePageNavigator);
    }
}

From source file:org.bonitasoft.console.client.view.steps.StepsDefinitionListWidget.java

License:Open Source License

@Override
protected FlowPanel buildTopNavBar() {
    final FlowPanel theFirstCell = new FlowPanel();
    final HorizontalPanel theMenuPanel = new HorizontalPanel();

    Label theRefreshLink = new Label(constants.refresh());
    theRefreshLink.setStylePrimaryName(CSSClassManager.LINK_LABEL);
    theRefreshLink.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent aEvent) {
            myBonitaDataSource.reload();
        }/*w  ww .  ja  v a 2s .  c o m*/
    });

    // Create the Selector Widget
    HorizontalPanel theSelectorWidget = new HorizontalPanel();
    theSelectorWidget.add(new Label(constants.itemSelector()));
    Label theLinkLabel;
    for (final ItemSelector aSelector : ItemSelector.values()) {
        theLinkLabel = new Label(LocaleUtil.translate(aSelector));
        theLinkLabel.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent arg0) {
                myItemSelection.select(aSelector);
            }
        });
        theLinkLabel.setStyleName(CSSClassManager.LINK_LABEL);

        theSelectorWidget.add(theLinkLabel);
    }

    theSelectorWidget.setSpacing(3);

    theMenuPanel.add(theRefreshLink);
    DOM.setElementPropertyInt(theMenuPanel.getElement(), "cellPadding", 3);

    theFirstCell.add(theMenuPanel);
    theFirstCell.add(theSelectorWidget);

    return theFirstCell;
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.Clustering.java

License:Apache License

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    KmlDataSourceLoadStaticOptions kmlDataSourceOptions = KmlDataSourceLoadStaticOptions
            .create(csVPanel.getViewer().camera, csVPanel.getViewer().canvas());
    Promise<KmlDataSource, Void> dataSourcePromise = csVPanel.getViewer().dataSources().add(KmlDataSource
            .load(GWT.getModuleBaseURL() + "SampleData/kml/facilities/facilities.kml", kmlDataSourceOptions));
    dataSourcePromise.then(new Fulfill<KmlDataSource>() {
        @Override//w  w w .j  a v a 2  s  .  c o m
        public void onFulfilled(KmlDataSource dataSource) {
            int pixelRange = 25;
            int minimumClusterSize = 3;
            boolean enabled = true;

            dataSource.clustering.enabled = enabled;
            dataSource.clustering.pixelRange = pixelRange;
            dataSource.clustering.minimumClusterSize = minimumClusterSize;

            PinBuilder pinBuilder = new PinBuilder();
            pin50 = pinBuilder.fromText("50+", Color.RED(), 48).toDataUrl();
            pin40 = pinBuilder.fromText("40+", Color.ORANGE(), 48).toDataUrl();
            pin30 = pinBuilder.fromText("30+", Color.YELLOW(), 48).toDataUrl();
            pin20 = pinBuilder.fromText("20+", Color.GREEN(), 48).toDataUrl();
            pin10 = pinBuilder.fromText("10+", Color.BLUE(), 48).toDataUrl();

            singleDigitPins = new String[8];
            for (int i = 0; i < singleDigitPins.length; ++i) {
                singleDigitPins[i] = pinBuilder.fromText("" + (i + 2), Color.VIOLET(), 48).toDataUrl();
            }
            // start with custom style
            customStyle(dataSource);

            _dataSource = dataSource;
        }
    });

    pixelRangeSlider = new Slider("pixelRange", 1, 200, 15);
    pixelRangeSlider.setStep(1);
    pixelRangeSlider.setWidth("150px");
    pixelRangeSlider.addListener(new MSliderListener());
    pixelRangeTBox = new TextBox();
    pixelRangeTBox.addChangeHandler(new MChangeHandler());
    pixelRangeTBox.setText("" + 15);
    pixelRangeTBox.setSize("30px", "12px");

    HorizontalPanel pixelRangeHPanel = new HorizontalPanel();
    pixelRangeHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    pixelRangeHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    pixelRangeHPanel.setSpacing(10);
    pixelRangeHPanel.add(pixelRangeSlider);
    pixelRangeHPanel.add(pixelRangeTBox);

    minimumClusterSizeSlider = new Slider("minimumClusterSize", 1, 20, 3);
    minimumClusterSizeSlider.setStep(1);
    minimumClusterSizeSlider.setWidth("150px");
    minimumClusterSizeSlider.addListener(new MSliderListener());
    minimumClusterSizeTBox = new TextBox();
    pixelRangeTBox.addChangeHandler(new MChangeHandler());
    minimumClusterSizeTBox.setText("" + 3);
    minimumClusterSizeTBox.setSize("30px", "12px");

    HorizontalPanel minimumClusterSizeHPanel = new HorizontalPanel();
    minimumClusterSizeHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    minimumClusterSizeHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    minimumClusterSizeHPanel.setSpacing(10);
    minimumClusterSizeHPanel.add(minimumClusterSizeSlider);
    minimumClusterSizeHPanel.add(minimumClusterSizeTBox);

    CheckBox enabledCBox = new CheckBox();
    enabledCBox.setValue(true);
    enabledCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            _dataSource.clustering.enabled = valueChangeEvent.getValue();
        }
    });

    CheckBox customStyleCBox = new CheckBox();
    customStyleCBox.setValue(true);
    customStyleCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            customStyle(_dataSource);
        }
    });

    FlexTable flexTable = new FlexTable();
    flexTable.setHTML(1, 0, "<font color=\"white\">Pixel Range</font>");
    flexTable.setWidget(1, 1, pixelRangeHPanel);
    flexTable.setHTML(2, 0, "<font color=\"white\">Minimum Cluster Size</font>");
    flexTable.setWidget(2, 1, minimumClusterSizeHPanel);
    flexTable.setHTML(3, 0, "<font color=\"white\">Enabled</font>");
    flexTable.setWidget(3, 1, enabledCBox);
    flexTable.setHTML(4, 0, "<font color=\"white\">Custom Style</font>");
    flexTable.setWidget(4, 1, customStyleCBox);

    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(flexTable, 20, 20);

    contentPanel.add(new HTML("<p>Cluster labels, billboards and points.</p>"));
    contentPanel.add(aPanel);

    initWidget(contentPanel);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.CZML.java

License:Apache License

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    csVPanel.getViewer().dataSources()/*from   w  ww  .  j a  va2s .c  o m*/
            .add(CzmlDataSource.load(GWT.getModuleBaseURL() + "SampleData/simple.czml"));
    csVPanel.getViewer().camera.flyHome(0);

    Button satellitesBtn = new Button("Satellites");
    satellitesBtn.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            csVPanel.getViewer().dataSources()
                    .add(CzmlDataSource.load(GWT.getModuleBaseURL() + "SampleData/simple.czml"));
            csVPanel.getViewer().camera.flyHome(0);
        }
    });

    Button vehicleBtn = new Button("Vehicle");
    vehicleBtn.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            csVPanel.getViewer().dataSources()
                    .add(CzmlDataSource.load(GWT.getModuleBaseURL() + "SampleData/Vehicle.czml"));
            ViewOptions viewOptions = new ViewOptions();
            viewOptions.destinationPos = Cartesian3.fromDegrees(-116.52, 35.02, 95000);
            viewOptions.orientation = new HeadingPitchRoll(6, -Math.PI_OVER_TWO());
            csVPanel.getViewer().scene().camera().setView(viewOptions);
        }
    });

    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(10);
    hPanel.add(satellitesBtn);
    hPanel.add(vehicleBtn);

    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(hPanel, 20, 20);

    contentPanel.add(new HTML(
            "<p>A simple CZML example showing four satellites in orbit around the Earth, and some ground objects.</p>"));
    contentPanel.add(aPanel);

    initWidget(contentPanel);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.GeoJSONAndTopoJSON.java

License:Apache License

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();

    csVPanel.getViewer().dataSources().removeAll();
    csVPanel.getViewer().camera.lookAt(Cartesian3.fromDegrees(-98.0, 40.0),
            new Cartesian3(0.0, -4790000.0, 3930000.0));
    csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());

    Button defaultStylingBtn = new Button("Default styling");
    defaultStylingBtn.addClickHandler(new ClickHandler() {
        @Override// www  . j  ava2  s .c  om
        public void onClick(ClickEvent clickEvent) {
            reset();
            csVPanel.getViewer().dataSources().add(
                    GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson"));
        }
    });

    Button basicStylingBtn = new Button("Basic styling");
    basicStylingBtn.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            GeoJsonDataSourceOptions options = new GeoJsonDataSourceOptions();
            options.stroke = Color.HOTPINK();
            options.fill = Color.DEEPPINK().withAlpha(0.5f);
            options.strokeWidth = 3;
            csVPanel.getViewer().dataSources().add(GeoJsonDataSource
                    .load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson", options));
        }
    });

    Button customStylingBtn = new Button("Custom styling");
    customStylingBtn.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            Math.setRandomNumberSeed(0);

            Promise<GeoJsonDataSource, String> promise = GeoJsonDataSource
                    .load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson");
            promise.then(new Fulfill<GeoJsonDataSource>() {
                @Override
                public void onFulfilled(GeoJsonDataSource dataSource) {
                    reset();
                    csVPanel.getViewer().dataSources().add(dataSource);

                    Entity[] entities = dataSource.entities.values();
                    HashMap<String, Color> colorHash = new HashMap<>();
                    for (int i = 0; i < entities.length; i++) {
                        Entity entity = entities[i];
                        String name = entity.name;
                        Color color = colorHash.get(name);
                        if (color == null) {
                            ColorRandomOptions options = new ColorRandomOptions();
                            options.alpha = 1.0f;
                            color = Color.fromRandom(options);
                            colorHash.put(name, color);
                        }

                        entity.polygon.material = new ColorMaterialProperty(new ConstantProperty<>(color));
                        entity.polygon.outline = new ConstantProperty<>(false);
                        entity.polygon.extrudedHeight = new ConstantProperty<>(
                                JsObject.getObject(entity, "properties").getNumber("Population").doubleValue()
                                        / 50.);
                    }
                }
            }, new Reject<String>() {
                @Override
                public void onRejected(String value) {
                    Window.alert(value);
                }
            });
        }
    });

    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(5);
    hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    hPanel.add(defaultStylingBtn);
    hPanel.add(basicStylingBtn);
    hPanel.add(customStylingBtn);

    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(hPanel, 20, 20);

    contentPanel.add(new HTML("<p>Load GeoJSON or TopoJSON data and apply custom styling.</p>"));
    contentPanel.add(aPanel);

    initWidget(contentPanel);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.GroundAtmosphere.java

License:Apache License

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.sceneModePicker = false;
    csVPanel = new ViewerPanel(viewerOptions);

    scene = csVPanel.getViewer().scene();
    globe = scene.globe;/*from ww  w  .  j  a  va2 s  .  c  om*/

    lightingFadeOutDistance = globe.lightingFadeOutDistance;
    lightingFadeInDistance = globe.lightingFadeInDistance;
    nightFadeOutDistance = globe.nightFadeOutDistance;
    nightFadeInDistance = globe.nightFadeInDistance;

    HorizontalPanel lightingFadeOutDistanceHPanel = new HorizontalPanel();
    lightingFadeOutDistanceHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    lightingFadeOutDistanceHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    lightingFadeOutDistanceHPanel.setSpacing(10);
    lightingFadeOutDistanceSlider = new Slider("lightingFadeOutDistance", 1, 100, 10);
    lightingFadeOutDistanceSlider.setStep(1);
    lightingFadeOutDistanceSlider.setWidth("150px");
    lightingFadeOutDistanceSlider.addListener(new MSliderListener());
    lightingFadeOutDistanceTBox = new TextBox();
    lightingFadeOutDistanceTBox.addChangeHandler(new MChangeHandler());
    lightingFadeOutDistanceTBox.setText("" + 10 * 1e6);
    lightingFadeOutDistanceTBox.setSize("100px", "12px");
    lightingFadeOutDistanceHPanel.add(lightingFadeOutDistanceSlider);
    lightingFadeOutDistanceHPanel.add(lightingFadeOutDistanceTBox);

    HorizontalPanel lightingFadeInDistanceHPanel = new HorizontalPanel();
    lightingFadeInDistanceHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    lightingFadeInDistanceHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    lightingFadeInDistanceHPanel.setSpacing(10);
    lightingFadeInDistanceSlider = new Slider("lightingFadeInDistance", 1, 100, 20);
    lightingFadeInDistanceSlider.setStep(1);
    lightingFadeInDistanceSlider.setWidth("150px");
    lightingFadeInDistanceSlider.addListener(new MSliderListener());
    lightingFadeInDistanceTBox = new TextBox();
    lightingFadeInDistanceTBox.addChangeHandler(new MChangeHandler());
    lightingFadeInDistanceTBox.setText("" + 20 * 1e6);
    lightingFadeInDistanceTBox.setSize("100px", "12px");
    lightingFadeInDistanceHPanel.add(lightingFadeInDistanceSlider);
    lightingFadeInDistanceHPanel.add(lightingFadeInDistanceTBox);

    HorizontalPanel nightFadeOutDistanceHPanel = new HorizontalPanel();
    nightFadeOutDistanceHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    nightFadeOutDistanceHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    nightFadeOutDistanceHPanel.setSpacing(10);
    nightFadeOutDistanceSlider = new Slider("nightFadeOutDistance", 1, 100, 10);
    nightFadeOutDistanceSlider.setStep(1);
    nightFadeOutDistanceSlider.setWidth("150px");
    nightFadeOutDistanceSlider.addListener(new MSliderListener());
    nightFadeOutDistanceTBox = new TextBox();
    nightFadeOutDistanceTBox.addChangeHandler(new MChangeHandler());
    nightFadeOutDistanceTBox.setText("" + 10 * 1e6);
    nightFadeOutDistanceTBox.setSize("100px", "12px");
    nightFadeOutDistanceHPanel.add(nightFadeOutDistanceSlider);
    nightFadeOutDistanceHPanel.add(nightFadeOutDistanceTBox);

    HorizontalPanel nightFadeInDistanceHPanel = new HorizontalPanel();
    nightFadeInDistanceHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    nightFadeInDistanceHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    nightFadeInDistanceHPanel.setSpacing(10);
    nightFadeInDistanceSlider = new Slider("nightFadeInDistance", 1, 100, 50);
    nightFadeInDistanceSlider.setStep(1);
    nightFadeInDistanceSlider.setWidth("150px");
    nightFadeInDistanceSlider.addListener(new MSliderListener());
    nightFadeInDistanceTBox = new TextBox();
    nightFadeInDistanceTBox.addChangeHandler(new MChangeHandler());
    nightFadeInDistanceTBox.setText("" + 50 * 1e6);
    nightFadeInDistanceTBox.setSize("100px", "12px");
    nightFadeInDistanceHPanel.add(nightFadeInDistanceSlider);
    nightFadeInDistanceHPanel.add(nightFadeInDistanceTBox);

    CheckBox groundAtmosphereCBox = new CheckBox();
    groundAtmosphereCBox.setWidth("100px");
    groundAtmosphereCBox.setValue(true);
    groundAtmosphereCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            globe.showGroundAtmosphere = event.getValue();
        }
    });

    CheckBox lightingBox = new CheckBox();
    lightingBox.setWidth("100px");
    lightingBox.setValue(false);
    lightingBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            globe.enableLighting = event.getValue();
        }
    });

    ListBox terrainsLBox = new ListBox();
    terrainsLBox.setWidth("160px");
    terrainsLBox.addItem("Cesium World Terrain - no effects", "0");
    terrainsLBox.addItem("Cesium World Terrain w/ Vertex Normals", "1");
    terrainsLBox.addItem("Cesium World Terrain w/ Water", "2");
    terrainsLBox.addItem("Cesium World Terrain w/ Vertex Normals and Water", "3");
    terrainsLBox.addItem("EllipsoidTerrainProvider", "4");
    terrainsLBox.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            switch (source.getSelectedValue()) {
            case "0": {
                csVPanel.getViewer().terrainProvider = Cesium.createWorldTerrain();
            }
                break;
            case "1": {
                Cesium.CreateWorldTerrainOptions options = new Cesium.CreateWorldTerrainOptions();
                options.requestVertexNormals = true;
                csVPanel.getViewer().terrainProvider = Cesium.createWorldTerrain(options);
            }
                break;
            case "2": {
                Cesium.CreateWorldTerrainOptions options = new Cesium.CreateWorldTerrainOptions();
                options.requestWaterMask = true;
                csVPanel.getViewer().terrainProvider = Cesium.createWorldTerrain(options);
            }
                break;
            case "3": {
                Cesium.CreateWorldTerrainOptions options = new Cesium.CreateWorldTerrainOptions();
                options.requestVertexNormals = true;
                options.requestWaterMask = true;
                csVPanel.getViewer().terrainProvider = Cesium.createWorldTerrain(options);
            }
                break;
            case "4": {
                csVPanel.getViewer().terrainProvider = new EllipsoidTerrainProvider();
            }
                break;
            default:
                break;
            }
        }
    });

    PushButton resetFadeDistancesPBtn = new PushButton();
    resetFadeDistancesPBtn.setText("Reset Fade Distances");
    resetFadeDistancesPBtn.setWidth("160px");
    resetFadeDistancesPBtn.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            globe.lightingFadeOutDistance = lightingFadeOutDistance;
            globe.lightingFadeInDistance = lightingFadeInDistance;
            globe.nightFadeOutDistance = nightFadeOutDistance;
            globe.nightFadeInDistance = nightFadeInDistance;

            lightingFadeOutDistanceSlider.setValue((int) (lightingFadeOutDistance / 1e6));
            lightingFadeInDistanceSlider.setValue((int) (lightingFadeInDistance / 1e6));
            nightFadeOutDistanceSlider.setValue((int) (nightFadeOutDistance / 1e6));
            nightFadeInDistanceSlider.setValue((int) (nightFadeInDistance / 1e6));

            lightingFadeOutDistanceTBox.setValue(String.valueOf(lightingFadeOutDistance), true);
            lightingFadeInDistanceTBox.setValue(String.valueOf(lightingFadeInDistance), true);
            nightFadeOutDistanceTBox.setValue(String.valueOf(nightFadeOutDistance), true);
            nightFadeInDistanceTBox.setValue(String.valueOf(nightFadeInDistance), true);
        }
    });

    FlexTable flexTable = new FlexTable();
    flexTable.setHTML(1, 0, "<font color=\"white\">Lighting Fade Out Distance</font>");
    flexTable.setWidget(1, 1, lightingFadeOutDistanceHPanel);
    flexTable.setHTML(2, 0, "<font color=\"white\">Lighting Fade In Distance</font>");
    flexTable.setWidget(2, 1, lightingFadeInDistanceHPanel);
    flexTable.setHTML(3, 0, "<font color=\"white\">Night Fade Out Distance</font>");
    flexTable.setWidget(3, 1, nightFadeOutDistanceHPanel);
    flexTable.setHTML(4, 0, "<font color=\"white\">Night Fade In Distance</font>");
    flexTable.setWidget(4, 1, nightFadeInDistanceHPanel);
    flexTable.setHTML(5, 0, "<font color=\"white\">Ground atmosphere</font>");
    flexTable.setWidget(5, 1, groundAtmosphereCBox);
    flexTable.setHTML(6, 0, "<font color=\"white\">Lighting</font>");
    flexTable.setWidget(6, 1, lightingBox);
    flexTable.setWidget(7, 1, terrainsLBox);
    flexTable.setWidget(8, 1, resetFadeDistancesPBtn);

    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(flexTable, 20, 20);

    contentPanel.add(new HTML("<p>Adjust hue, saturation, and brightness of the sky/atmosphere.</p>"));
    contentPanel.add(aPanel);

    initWidget(contentPanel);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.ImageryAdjustment.java

License:Apache License

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    csVPanel.getViewer().imageryLayers().layerAdded.addEventListener(new UpdateViewModel());
    csVPanel.getViewer().imageryLayers().layerRemoved.addEventListener(new UpdateViewModel());
    csVPanel.getViewer().imageryLayers().layerMoved.addEventListener(new UpdateViewModel());

    brightnessSlider = new Slider("brightness", 0, 300, 100);
    brightnessSlider.setStep(1);/* w  w w  .  j a v a  2s  . co m*/
    brightnessSlider.setWidth("150px");
    brightnessSlider.addListener(new MSliderListener());
    brightnessTBox = new TextBox();
    brightnessTBox.addChangeHandler(new MChangeHandler());
    brightnessTBox.setText("" + 1);
    brightnessTBox.setSize("30px", "12px");

    HorizontalPanel brightnessHPanel = new HorizontalPanel();
    brightnessHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    brightnessHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    brightnessHPanel.setSpacing(10);
    brightnessHPanel.add(brightnessSlider);
    brightnessHPanel.add(brightnessTBox);

    contrastSlider = new Slider("contrast", 0, 300, 100);
    contrastSlider.setStep(1);
    contrastSlider.setWidth("150px");
    contrastSlider.addListener(new MSliderListener());
    contrastTBox = new TextBox();
    contrastTBox.addChangeHandler(new MChangeHandler());
    contrastTBox.setText("" + 1);
    contrastTBox.setSize("30px", "12px");

    HorizontalPanel contrastHPanel = new HorizontalPanel();
    contrastHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    contrastHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    contrastHPanel.setSpacing(10);
    contrastHPanel.add(contrastSlider);
    contrastHPanel.add(contrastTBox);

    hueSlider = new Slider("hue", 0, 300, 0);
    hueSlider.setStep(1);
    hueSlider.setWidth("150px");
    hueSlider.addListener(new MSliderListener());
    hueTBox = new TextBox();
    hueTBox.addChangeHandler(new MChangeHandler());
    hueTBox.setText("" + 0);
    hueTBox.setSize("30px", "12px");

    HorizontalPanel hueHPanel = new HorizontalPanel();
    hueHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    hueHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    hueHPanel.setSpacing(10);
    hueHPanel.add(hueSlider);
    hueHPanel.add(hueTBox);

    saturationSlider = new Slider("saturation", 0, 300, 100);
    saturationSlider.setStep(1);
    saturationSlider.setWidth("150px");
    saturationSlider.addListener(new MSliderListener());
    saturationTBox = new TextBox();
    saturationTBox.addChangeHandler(new MChangeHandler());
    saturationTBox.setText("" + 1);
    saturationTBox.setSize("30px", "12px");

    HorizontalPanel saturationHPanel = new HorizontalPanel();
    saturationHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    saturationHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    saturationHPanel.setSpacing(10);
    saturationHPanel.add(saturationSlider);
    saturationHPanel.add(saturationTBox);

    gammaSlider = new Slider("gamma", 0, 300, 100);
    gammaSlider.setStep(1);
    gammaSlider.setWidth("150px");
    gammaSlider.addListener(new MSliderListener());
    gammaTBox = new TextBox();
    gammaTBox.addChangeHandler(new MChangeHandler());
    gammaTBox.setText("" + 1);
    gammaTBox.setSize("30px", "12px");

    HorizontalPanel gammaHPanel = new HorizontalPanel();
    gammaHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    gammaHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    gammaHPanel.setSpacing(10);
    gammaHPanel.add(gammaSlider);
    gammaHPanel.add(gammaTBox);

    FlexTable flexTable = new FlexTable();
    flexTable.setCellSpacing(1);
    flexTable.setCellPadding(1);
    flexTable.setHTML(1, 0, "<font color=\"white\">Brightness</font>");
    flexTable.setWidget(1, 1, brightnessHPanel);
    flexTable.setHTML(2, 0, "<font color=\"white\">Contrast</font>");
    flexTable.setWidget(2, 1, contrastHPanel);
    flexTable.setHTML(3, 0, "<font color=\"white\">Hue</font>");
    flexTable.setWidget(3, 1, hueHPanel);
    flexTable.setHTML(4, 0, "<font color=\"white\">Saturation</font>");
    flexTable.setWidget(4, 1, saturationHPanel);
    flexTable.setHTML(5, 0, "<font color=\"white\">Gamma</font>");
    flexTable.setWidget(5, 1, gammaHPanel);

    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(flexTable, 20, 20);

    contentPanel.add(
            new HTML("<p>Adjust brightness, contrast, hue, saturation, and gamma of an imagery layer.</p>"));
    contentPanel.add(aPanel);

    initWidget(contentPanel);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.ImageryLayersManipulation.java

License:Apache License

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.baseLayerPicker = false;
    ViewerPanel csVPanel = new ViewerPanel(viewerOptions);

    imageryLayers = csVPanel.getViewer().imageryLayers();

    setupLayers();//from ww w.j  a va 2s.  c o  m
    updateLayerList();

    _callback.onSuccess(null);

    HorizontalPanel baseLayersHPanel = new HorizontalPanel();
    baseLayersHPanel.setSpacing(5);
    baseLayersHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    baseLayersHPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

    final ListBox baseLayersLBox = new ListBox();
    baseLayersHPanel.add(baseLayersLBox);

    Slider baseLayersSlider = new Slider("baseLayersAlpha", 0, 100, 100);
    baseLayersSlider.setWidth("200px");
    baseLayersSlider.addListener(new MSliderListener());
    baseLayersHPanel.add(baseLayersSlider);

    baseLayersLBox.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            ImageryLayer baseLayer = baseLayers.get(source.getSelectedValue());

            int activeLayerIndex = 0;
            int numLayers = layers.size();
            for (int i = 0; i < numLayers; ++i) {
                if (baseLayers.containsValue(layers.get(i))) {
                    activeLayerIndex = i;
                }
            }
            ImageryLayer activeLayer = layers.get(activeLayerIndex);
            float alpha = activeLayer.alpha;
            boolean show = activeLayer.show;
            imageryLayers.remove(activeLayer, false);
            imageryLayers.add(baseLayer, numLayers - activeLayerIndex - 1);
            baseLayer.show = show;
            baseLayer.alpha = alpha;
            updateLayerList();

            selectedLayer = baseLayer;
        }
    });

    Callback<Void, Void> cesiumCreated = new Callback<Void, Void>() {
        @Override
        public void onFailure(Void aVoid) {
            //
        }

        @Override
        public void onSuccess(Void aVoid) {
            for (Map.Entry<String, ImageryLayer> entry : baseLayers.entrySet()) {
                baseLayersLBox.addItem(entry.getKey(), entry.getKey());
            }
        }
    };
    addCallback(cesiumCreated);

    contentPanel.add(new HTML(
            "<p>Layer imagery from multiple sources, including WMS servers, Bing Maps, ArcGIS Online, OpenStreetMaps, and more, and adjust the alpha of each independently.</p>"));
    contentPanel.add(baseLayersHPanel);
    contentPanel.add(csVPanel);

    initWidget(contentPanel);
}