Search in sources :

Example 1 with ColorPicker

use of com.vaadin.ui.ColorPicker in project charts by vaadin.

the class ModifyOnePoint method setup.

@Override
protected void setup() {
    super.setup();
    FormLayout formLayout = new FormLayout();
    formLayout.setCaption("Special point settings, only updated point state is sent to client.");
    formLayout.setMargin(true);
    final Slider sliderX = new Slider();
    sliderX.setMin(3);
    sliderX.setMax(8);
    sliderX.setResolution(1);
    sliderX.setValue(4d);
    sliderX.setCaption("X");
    sliderX.addValueChangeListener(event -> {
        dataSeriesItem.setX(sliderX.getValue());
        series.update(dataSeriesItem);
    });
    sliderX.setWidth("200px");
    formLayout.addComponent(sliderX);
    final Slider sliderY = new Slider();
    sliderY.setMin(0);
    sliderY.setMax(10);
    sliderY.setResolution(1);
    sliderY.setValue(4d);
    sliderY.setCaption("Y");
    sliderY.addValueChangeListener(event -> {
        dataSeriesItem.setY(sliderY.getValue());
        updateItemInChart();
    });
    sliderY.setWidth("200px");
    formLayout.addComponent(sliderY);
    final ColorPicker colorPicker = new ColorPicker();
    colorPicker.setValue(new com.vaadin.shared.ui.colorpicker.Color(255, 0, 0));
    colorPicker.setCaption("Marker color");
    colorPicker.addValueChangeListener(event -> {
        dataSeriesItem.getMarker().setFillColor(new SolidColor(event.getValue().getCSS()));
        updateItemInChart();
    });
    formLayout.addComponent(colorPicker);
    Button c = new Button("Pseudorandom", new Button.ClickListener() {

        Random r = new Random(0);

        @Override
        public void buttonClick(ClickEvent event) {
            sliderX.setValue(r.nextDouble() * 5 + 3);
            sliderY.setValue(r.nextDouble() * 10);
            colorPicker.setValue(new com.vaadin.shared.ui.colorpicker.Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
        }
    });
    c.setId("random");
    formLayout.addComponent(c);
    addComponentAsFirst(formLayout);
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Slider(com.vaadin.ui.Slider) ColorPicker(com.vaadin.ui.ColorPicker) ClickEvent(com.vaadin.ui.Button.ClickEvent) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Random(java.util.Random) Button(com.vaadin.ui.Button)

Aggregations

Color (com.vaadin.addon.charts.model.style.Color)1 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ColorPicker (com.vaadin.ui.ColorPicker)1 FormLayout (com.vaadin.ui.FormLayout)1 Slider (com.vaadin.ui.Slider)1 Random (java.util.Random)1