Search in sources :

Example 36 with CheckBox

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

the class DynamicExtremes method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.LINE);
    configuration.getChart().setMarginRight(130);
    configuration.getChart().setMarginBottom(25);
    configuration.getTitle().setText("Monthly Average Temperature");
    configuration.getSubTitle().setText("Source: WorldClimate.com");
    configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setMin(-10d);
    yAxis.setMax(30d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.HIGH);
    configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-10d);
    legend.setY(100d);
    legend.setBorderWidth(0);
    ListSeries ls = new ListSeries();
    ls.setName("Tokyo");
    ls.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("New York");
    ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Berlin");
    ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("London");
    ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
    configuration.addSeries(ls);
    chart.drawChart(configuration);
    final CheckBox extremes = new CheckBox("Switch extremes");
    extremes.addValueChangeListener(e -> {
        if (e.getValue()) {
            chart.getConfiguration().getyAxes().getAxis(0).setExtremes(10, 15);
        } else {
            chart.getConfiguration().getyAxes().getAxis(0).setExtremes(-10, 30);
        }
    });
    VerticalLayout layout = new VerticalLayout(chart, extremes);
    return layout;
}
Also used : Legend(com.vaadin.addon.charts.model.Legend) DataLabels(com.vaadin.addon.charts.model.DataLabels) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsLine(com.vaadin.addon.charts.model.PlotOptionsLine) ListSeries(com.vaadin.addon.charts.model.ListSeries) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 37 with CheckBox

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

the class ClickToAddPoint method setup.

@Override
protected void setup() {
    super.setup();
    final CheckBox checkbox = new CheckBox("Animate additions");
    checkbox.setValue(true);
    checkbox.addValueChangeListener(event -> {
        chart.getConfiguration().getChart().setAnimation(checkbox.getValue());
    });
    addComponentAsFirst(checkbox);
}
Also used : CheckBox(com.vaadin.ui.CheckBox)

Example 38 with CheckBox

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

the class ServerSideEvents method addToggleForListener.

private void addToggleForListener(String caption, String id, final ListenerToggle listenerToggle) {
    final CheckBox checkBox = new CheckBox(caption);
    checkBox.setId(id);
    checkBox.addValueChangeListener(e -> {
        if (checkBox.getValue()) {
            listenerToggle.add();
        } else {
            listenerToggle.remove();
        }
    });
    checkBox.setValue(true);
    eventListeners.addComponent(checkBox);
}
Also used : CheckBox(com.vaadin.ui.CheckBox)

Example 39 with CheckBox

use of com.vaadin.ui.CheckBox in project v-leaflet by mstahv.

the class DynamicChanges method setup.

@Override
protected void setup() {
    super.setup();
    HorizontalLayout tools = new HorizontalLayout();
    Button button = new Button("Random new point");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            ArrayList<Point> arrayList = new ArrayList<Point>(Arrays.asList(polyline.getPoints()));
            arrayList.add(new Point(60 + r.nextInt(10), 20 + r.nextInt(10)));
            polyline.setPoints(arrayList.toArray(new Point[0]));
        }
    });
    tools.addComponent(button);
    button = new Button("Zoom to polyline");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            leafletMap.zoomToExtent(new Bounds(polyline.getPoints()));
        }
    });
    tools.addComponent(button);
    button = new Button("Center to last point ");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Point[] points = polyline.getPoints();
            leafletMap.setCenter(points[points.length - 1]);
        }
    });
    tools.addComponent(button);
    button = new Button("Zoom to last point");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Point[] points = polyline.getPoints();
            leafletMap.zoomToExtent(new Bounds(points[points.length - 1]));
        }
    });
    tools.addComponent(button);
    button = new Button("Show current zoom");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Double zoomLevel = leafletMap.getZoomLevel();
            Notification.show("Zoomlevel is " + zoomLevel);
        }
    });
    tools.addComponent(button);
    button = new Button("Show current center point");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show("Center point is " + leafletMap.getCenter());
        }
    });
    tools.addComponent(button);
    button = new Button("Show current size of the map");
    button.addClickListener((e) -> leafletMap.getSize(point -> Notification.show("Map size: " + point)));
    tools.addComponent(button);
    final LeafletMoveEndListener moveEndListener = new LeafletMoveEndListener() {

        @Override
        public void onMoveEnd(LeafletMoveEndEvent event) {
            Notification.show("Moved or zoomed", Type.TRAY_NOTIFICATION);
        }
    };
    final CheckBox checkBox = new CheckBox("Toggle move listener");
    checkBox.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() {

        @Override
        public void valueChange(ValueChangeEvent<Boolean> event) {
            if (event.getValue()) {
                registration = leafletMap.addMoveEndListener(moveEndListener);
            } else if (registration != null) {
                registration.remove();
            }
        }
    });
    tools.addComponent(checkBox);
    content.addComponentAsFirst(tools);
}
Also used : Arrays(java.util.Arrays) ClickListener(com.vaadin.ui.Button.ClickListener) ClickEvent(com.vaadin.ui.Button.ClickEvent) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener) Point(org.vaadin.addon.leaflet.shared.Point) Random(java.util.Random) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent) ArrayList(java.util.ArrayList) LPolyline(org.vaadin.addon.leaflet.LPolyline) Button(com.vaadin.ui.Button) HasValue(com.vaadin.data.HasValue) Type(com.vaadin.ui.Notification.Type) LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) CheckBox(com.vaadin.ui.CheckBox) Registration(com.vaadin.shared.Registration) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Notification(com.vaadin.ui.Notification) LMap(org.vaadin.addon.leaflet.LMap) Bounds(org.vaadin.addon.leaflet.shared.Bounds) ValueChangeEvent(com.vaadin.data.HasValue.ValueChangeEvent) AbstractTest(org.vaadin.addonhelpers.AbstractTest) Component(com.vaadin.ui.Component) ClickEvent(com.vaadin.ui.Button.ClickEvent) LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) Bounds(org.vaadin.addon.leaflet.shared.Bounds) ArrayList(java.util.ArrayList) LeafletMoveEndEvent(org.vaadin.addon.leaflet.LeafletMoveEndEvent) Point(org.vaadin.addon.leaflet.shared.Point) HorizontalLayout(com.vaadin.ui.HorizontalLayout) HasValue(com.vaadin.data.HasValue) LeafletMoveEndListener(org.vaadin.addon.leaflet.LeafletMoveEndListener) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) ClickListener(com.vaadin.ui.Button.ClickListener) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener)

Example 40 with CheckBox

use of com.vaadin.ui.CheckBox in project tutorials by eugenp.

the class VaadinUI method init.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);
    final GridLayout gridLayout = new GridLayout(3, 2);
    gridLayout.setSpacing(true);
    gridLayout.setMargin(true);
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);
    final FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(true);
    formLayout.setMargin(true);
    final GridLayout buttonLayout = new GridLayout(3, 5);
    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    final Label label = new Label();
    label.setId("Label");
    label.setValue("Label Value");
    label.setCaption("Label");
    gridLayout.addComponent(label);
    final Link link = new Link("Baeldung", new ExternalResource("http://www.baeldung.com/"));
    link.setId("Link");
    link.setTargetName("_blank");
    gridLayout.addComponent(link);
    final TextField textField = new TextField();
    textField.setId("TextField");
    textField.setCaption("TextField:");
    textField.setValue("TextField Value");
    textField.setIcon(FontAwesome.USER);
    gridLayout.addComponent(textField);
    final TextArea textArea = new TextArea();
    textArea.setCaption("TextArea");
    textArea.setId("TextArea");
    textArea.setValue("TextArea Value");
    gridLayout.addComponent(textArea);
    final DateField dateField = new DateField("DateField", new Date(0));
    dateField.setId("DateField");
    gridLayout.addComponent(dateField);
    final PasswordField passwordField = new PasswordField();
    passwordField.setId("PasswordField");
    passwordField.setCaption("PasswordField:");
    passwordField.setValue("password");
    gridLayout.addComponent(passwordField);
    final RichTextArea richTextArea = new RichTextArea();
    richTextArea.setCaption("Rich Text Area");
    richTextArea.setValue("<h1>RichTextArea</h1>");
    richTextArea.setSizeFull();
    Panel richTextPanel = new Panel();
    richTextPanel.setContent(richTextArea);
    final InlineDateField inlineDateField = new InlineDateField();
    inlineDateField.setValue(new Date(0));
    inlineDateField.setCaption("Inline Date Field");
    horizontalLayout.addComponent(inlineDateField);
    Button normalButton = new Button("Normal Button");
    normalButton.setId("NormalButton");
    normalButton.addClickListener(e -> {
        label.setValue("CLICK");
    });
    buttonLayout.addComponent(normalButton);
    Button tinyButton = new Button("Tiny Button");
    tinyButton.addStyleName("tiny");
    buttonLayout.addComponent(tinyButton);
    Button smallButton = new Button("Small Button");
    smallButton.addStyleName("small");
    buttonLayout.addComponent(smallButton);
    Button largeButton = new Button("Large Button");
    largeButton.addStyleName("large");
    buttonLayout.addComponent(largeButton);
    Button hugeButton = new Button("Huge Button");
    hugeButton.addStyleName("huge");
    buttonLayout.addComponent(hugeButton);
    Button disabledButton = new Button("Disabled Button");
    disabledButton.setDescription("This button cannot be clicked");
    disabledButton.setEnabled(false);
    buttonLayout.addComponent(disabledButton);
    Button dangerButton = new Button("Danger Button");
    dangerButton.addStyleName("danger");
    buttonLayout.addComponent(dangerButton);
    Button friendlyButton = new Button("Friendly Button");
    friendlyButton.addStyleName("friendly");
    buttonLayout.addComponent(friendlyButton);
    Button primaryButton = new Button("Primary Button");
    primaryButton.addStyleName("primary");
    buttonLayout.addComponent(primaryButton);
    NativeButton nativeButton = new NativeButton("Native Button");
    buttonLayout.addComponent(nativeButton);
    Button iconButton = new Button("Icon Button");
    iconButton.setIcon(FontAwesome.ALIGN_LEFT);
    buttonLayout.addComponent(iconButton);
    Button borderlessButton = new Button("BorderLess Button");
    borderlessButton.addStyleName("borderless");
    buttonLayout.addComponent(borderlessButton);
    Button linkButton = new Button("Link Button");
    linkButton.addStyleName("link");
    buttonLayout.addComponent(linkButton);
    Button quietButton = new Button("Quiet Button");
    quietButton.addStyleName("quiet");
    buttonLayout.addComponent(quietButton);
    horizontalLayout.addComponent(buttonLayout);
    final CheckBox checkbox = new CheckBox("CheckBox");
    checkbox.setValue(true);
    checkbox.addValueChangeListener(e -> checkbox.setValue(!checkbox.getValue()));
    formLayout.addComponent(checkbox);
    List<String> numbers = new ArrayList<String>();
    numbers.add("One");
    numbers.add("Ten");
    numbers.add("Eleven");
    ComboBox comboBox = new ComboBox("ComboBox");
    comboBox.addItems(numbers);
    formLayout.addComponent(comboBox);
    ListSelect listSelect = new ListSelect("ListSelect");
    listSelect.addItems(numbers);
    listSelect.setRows(2);
    formLayout.addComponent(listSelect);
    NativeSelect nativeSelect = new NativeSelect("NativeSelect");
    nativeSelect.addItems(numbers);
    formLayout.addComponent(nativeSelect);
    TwinColSelect twinColSelect = new TwinColSelect("TwinColSelect");
    twinColSelect.addItems(numbers);
    Grid grid = new Grid("Grid");
    grid.setColumns("Column1", "Column2", "Column3");
    grid.addRow("Item1", "Item2", "Item3");
    grid.addRow("Item4", "Item5", "Item6");
    Panel panel = new Panel("Panel");
    panel.setContent(grid);
    panel.setSizeUndefined();
    Panel serverPushPanel = new Panel("Server Push");
    FormLayout timeLayout = new FormLayout();
    timeLayout.setSpacing(true);
    timeLayout.setMargin(true);
    currentTime = new Label("No TIME...");
    timeLayout.addComponent(currentTime);
    serverPushPanel.setContent(timeLayout);
    serverPushPanel.setSizeUndefined();
    ScheduledExecutorService scheduleExecutor = Executors.newScheduledThreadPool(1);
    Runnable task = () -> {
        currentTime.setValue("Current Time : " + Instant.now());
    };
    scheduleExecutor.scheduleWithFixedDelay(task, 0, 1, TimeUnit.SECONDS);
    FormLayout dataBindingLayout = new FormLayout();
    dataBindingLayout.setSpacing(true);
    dataBindingLayout.setMargin(true);
    BindData bindData = new BindData("BindData");
    BeanFieldGroup beanFieldGroup = new BeanFieldGroup(BindData.class);
    beanFieldGroup.setItemDataSource(bindData);
    TextField bindedTextField = (TextField) beanFieldGroup.buildAndBind("BindName", "bindName");
    bindedTextField.setWidth("250px");
    dataBindingLayout.addComponent(bindedTextField);
    FormLayout validatorLayout = new FormLayout();
    validatorLayout.setSpacing(true);
    validatorLayout.setMargin(true);
    HorizontalLayout textValidatorLayout = new HorizontalLayout();
    textValidatorLayout.setSpacing(true);
    textValidatorLayout.setMargin(true);
    TextField stringValidator = new TextField();
    stringValidator.setNullSettingAllowed(true);
    stringValidator.setNullRepresentation("");
    stringValidator.addValidator(new StringLengthValidator("String must have 2-5 characters lenght", 2, 5, true));
    stringValidator.setValidationVisible(false);
    textValidatorLayout.addComponent(stringValidator);
    Button buttonStringValidator = new Button("Validate String");
    buttonStringValidator.addClickListener(e -> {
        try {
            stringValidator.setValidationVisible(false);
            stringValidator.validate();
        } catch (InvalidValueException err) {
            stringValidator.setValidationVisible(true);
        }
    });
    textValidatorLayout.addComponent(buttonStringValidator);
    validatorLayout.addComponent(textValidatorLayout);
    verticalLayout.addComponent(gridLayout);
    verticalLayout.addComponent(richTextPanel);
    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(formLayout);
    verticalLayout.addComponent(twinColSelect);
    verticalLayout.addComponent(panel);
    verticalLayout.addComponent(serverPushPanel);
    verticalLayout.addComponent(dataBindingLayout);
    verticalLayout.addComponent(validatorLayout);
    setContent(verticalLayout);
}
Also used : NativeButton(com.vaadin.ui.NativeButton) BeanFieldGroup(com.vaadin.data.fieldgroup.BeanFieldGroup) InlineDateField(com.vaadin.ui.InlineDateField) TextArea(com.vaadin.ui.TextArea) RichTextArea(com.vaadin.ui.RichTextArea) Grid(com.vaadin.ui.Grid) Label(com.vaadin.ui.Label) ArrayList(java.util.ArrayList) TwinColSelect(com.vaadin.ui.TwinColSelect) HorizontalLayout(com.vaadin.ui.HorizontalLayout) InvalidValueException(com.vaadin.data.Validator.InvalidValueException) RichTextArea(com.vaadin.ui.RichTextArea) GridLayout(com.vaadin.ui.GridLayout) NativeButton(com.vaadin.ui.NativeButton) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.ui.TextField) PasswordField(com.vaadin.ui.PasswordField) FormLayout(com.vaadin.ui.FormLayout) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ComboBox(com.vaadin.ui.ComboBox) StringLengthValidator(com.vaadin.data.validator.StringLengthValidator) ListSelect(com.vaadin.ui.ListSelect) ExternalResource(com.vaadin.server.ExternalResource) Date(java.util.Date) Panel(com.vaadin.ui.Panel) CheckBox(com.vaadin.ui.CheckBox) NativeSelect(com.vaadin.ui.NativeSelect) InlineDateField(com.vaadin.ui.InlineDateField) DateField(com.vaadin.ui.DateField) Link(com.vaadin.ui.Link)

Aggregations

CheckBox (com.vaadin.ui.CheckBox)40 Button (com.vaadin.ui.Button)8 ClickListener (com.vaadin.ui.Button.ClickListener)7 HorizontalLayout (com.vaadin.ui.HorizontalLayout)6 ClickEvent (com.vaadin.ui.Button.ClickEvent)5 VerticalLayout (com.vaadin.ui.VerticalLayout)5 SplitCheckBox (au.com.vaadinutils.crud.splitFields.SplitCheckBox)4 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)4 ValueChangeListener (com.vaadin.data.Property.ValueChangeListener)4 TextField (com.vaadin.ui.TextField)4 Test (org.junit.Test)4 Item (com.vaadin.data.Item)3 Property (com.vaadin.data.Property)3 ComboBox (com.vaadin.ui.ComboBox)3 Component (com.vaadin.ui.Component)3 Label (com.vaadin.ui.Label)3 ArrayList (java.util.ArrayList)3 Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 DataLabels (com.vaadin.addon.charts.model.DataLabels)2