Search in sources :

Example 66 with Component

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

the class LayerGroupTest method setup.

@Override
protected void setup() {
    super.setup();
    addMarkers = new CheckBox("Add markers");
    content.addComponentAsFirst(addMarkers);
    delete = new CheckBox("Delete on click");
    content.addComponentAsFirst(delete);
    showLayerGroupCB = new CheckBox("Show first layer (switch on/off from server side)");
    showLayerGroupCB.setValue(true);
    content.addComponentAsFirst(showLayerGroupCB);
    showLayerGroupCB.addValueChangeListener(new HasValue.ValueChangeListener<Boolean>() {

        @Override
        public void valueChange(ValueChangeEvent<Boolean> event) {
            if (event.getValue()) {
                if (!leafletMap.hasComponent(llg)) {
                    leafletMap.addComponent(llg);
                }
            } else {
                leafletMap.removeComponent(llg);
            }
        }
    });
    Button button = new Button("Delete first component from map (may also be a layer containing many components)");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            for (Component c : leafletMap) {
                if (!(c instanceof LTileLayer)) {
                    leafletMap.removeComponent(c);
                    break;
                }
            }
        }
    });
    content.addComponentAsFirst(button);
    button = new Button("Delete first component from first layer group (may also be a layer containing many components)");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            LLayerGroup group = null;
            for (Component c : leafletMap) {
                if (c instanceof LLayerGroup) {
                    group = (LLayerGroup) c;
                    break;
                }
            }
            if (group.getComponentCount() > 0) {
                Component next = group.iterator().next();
                group.removeComponent(next);
            } else {
                Notification.show("No component in first component group");
            }
        }
    });
    content.addComponentAsFirst(button);
    button = new Button("Add polyline to first group on map (creates if does not exist)");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            LLayerGroup group = null;
            for (Component c : leafletMap) {
                if (c instanceof LLayerGroup) {
                    group = (LLayerGroup) c;
                    break;
                }
            }
            if (group == null) {
                group = new LLayerGroup();
                leafletMap.addOverlay(group, "new group");
            }
            LPolyline lPolyline = new LPolyline(new Point(60.44, 22.30), new Point(60.456, 22.304));
            lPolyline.addClickListener(listener);
            group.addComponent(lPolyline);
        }
    });
    content.addComponentAsFirst(button);
}
Also used : LTileLayer(org.vaadin.addon.leaflet.LTileLayer) LPolyline(org.vaadin.addon.leaflet.LPolyline) ClickEvent(com.vaadin.ui.Button.ClickEvent) LeafletClickEvent(org.vaadin.addon.leaflet.LeafletClickEvent) Point(org.vaadin.addon.leaflet.shared.Point) HasValue(com.vaadin.data.HasValue) LLayerGroup(org.vaadin.addon.leaflet.LLayerGroup) Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) Component(com.vaadin.ui.Component) ClickListener(com.vaadin.ui.Button.ClickListener) LeafletClickListener(org.vaadin.addon.leaflet.LeafletClickListener)

Example 67 with Component

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

the class MapInGridDetailsRow method getTestComponent.

@Override
public Component getTestComponent() {
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    final Grid<String> grid = new Grid<>();
    grid.setSizeFull();
    // Define some columns
    grid.addColumn(r -> r).setCaption("Name");
    grid.addColumn(r -> "").setCaption("Born");
    // Add some data rows
    grid.setItems("Nicolaus Copernicus", "Galileo Galilei", "Johannes Kepler");
    grid.setDetailsGenerator((DetailsGenerator<String>) s -> {
        final LMap leafletMap = new LMap();
        final LTileLayer baselayer = new LTileLayer();
        baselayer.setAttributionString("OpenStreetMap");
        baselayer.setUrl("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
        leafletMap.addLayer(baselayer);
        leafletMap.setWidth("100%");
        leafletMap.setHeight("100px");
        leafletMap.setZoomLevel(3);
        LMarker leafletMarker = new LMarker(-21.54, 30.76);
        leafletMap.addComponent(leafletMarker);
        leafletMap.zoomToContent();
        return leafletMap;
    });
    grid.addItemClickListener((ItemClickListener<String>) event -> grid.setDetailsVisible(event.getItem(), !grid.isDetailsVisible(event.getItem())));
    vl.addComponent(grid);
    return vl;
}
Also used : VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) AbstractTest(org.vaadin.addonhelpers.AbstractTest) DetailsGenerator(com.vaadin.ui.components.grid.DetailsGenerator) Component(com.vaadin.ui.Component) Grid(com.vaadin.ui.Grid) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) Grid(com.vaadin.ui.Grid) VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker)

Example 68 with Component

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

the class FractionalZoom method getTestComponent.

@Override
public Component getTestComponent() {
    leafletMap = new LMap();
    leafletMap.setWidth("300px");
    leafletMap.setHeight("300px");
    leafletMap.setCenter(0, 0);
    leafletMap.setZoomLevel(2.5);
    leafletMap.addLayer(new LOpenStreetMapLayer());
    final Slider slider = new Slider("ZoomLevel");
    slider.setWidth("200px");
    slider.setMin(1);
    slider.setMax(16);
    slider.setResolution(1);
    slider.addValueChangeListener((HasValue.ValueChangeListener<Double>) event -> {
        leafletMap.setZoomLevel(event.getValue());
        Notification.show("Zoom level: " + event.getValue(), Notification.Type.TRAY_NOTIFICATION);
    });
    return new VerticalLayout(leafletMap, slider);
}
Also used : HasValue(com.vaadin.data.HasValue) Notification(com.vaadin.ui.Notification) Slider(com.vaadin.ui.Slider) VerticalLayout(com.vaadin.ui.VerticalLayout) LMap(org.vaadin.addon.leaflet.LMap) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) AbstractTest(org.vaadin.addonhelpers.AbstractTest) Component(com.vaadin.ui.Component) LMap(org.vaadin.addon.leaflet.LMap) Slider(com.vaadin.ui.Slider) LOpenStreetMapLayer(org.vaadin.addon.leaflet.LOpenStreetMapLayer) VerticalLayout(com.vaadin.ui.VerticalLayout) HasValue(com.vaadin.data.HasValue)

Example 69 with Component

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

the class BasicTest method setup.

@Override
protected void setup() {
    super.setup();
    addMarkers = new CheckBox("Add markers");
    content.addComponentAsFirst(addMarkers);
    delete = new CheckBox("Delete on click");
    content.addComponentAsFirst(delete);
    Button openPopup = new Button("Open popup", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            leafletMarker.openPopup();
        }
    });
    Button closePopup = new Button("Close popup", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            leafletMarker.closePopup();
        }
    });
    content.addComponentAsFirst(closePopup);
    content.addComponentAsFirst(openPopup);
    Button button = new Button("Delete first component from map");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Component next = leafletMap.iterator().next();
            leafletMap.removeComponent(next);
        }
    });
    content.addComponentAsFirst(button);
    button = new Button("Add polyline to map");
    button.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            LPolyline lPolyline = new LPolyline(new Point(60.44, 22.30), new Point(60.456, 22.304));
            lPolyline.addClickListener(listener);
            leafletMap.addComponent(lPolyline);
        }
    });
    content.addComponentAsFirst(button);
}
Also used : Button(com.vaadin.ui.Button) CheckBox(com.vaadin.ui.CheckBox) ClickEvent(com.vaadin.ui.Button.ClickEvent) Point(org.vaadin.addon.leaflet.shared.Point) Component(com.vaadin.ui.Component) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 70 with Component

use of com.vaadin.ui.Component in project Activiti by Activiti.

the class ChartGenerator method createChart.

protected static Component createChart(JsonNode dataNode, String[] names, Number[] values) {
    String type = dataNode.get("type").textValue();
    JsonNode xAxisNode = dataNode.get("xaxis");
    String xAxis = null;
    if (xAxisNode != null) {
        xAxis = xAxisNode.textValue();
    }
    JsonNode yAxisNode = dataNode.get("yaxis");
    String yAxis = null;
    if (yAxisNode != null) {
        yAxis = yAxisNode.textValue();
    }
    Component chart = null;
    if (CHART_TYPE_BAR_CHART.equals(type)) {
        DataSeries dataSeries = new DataSeries().add((Object[]) values);
        SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.BAR);
        Axes axes = new Axes().addAxis(new XYaxis().setRenderer(AxisRenderers.CATEGORY).setTicks(new Ticks().add((Object[]) names)));
        Highlighter highlighter = new Highlighter().setShow(false);
        Options options = new Options().setSeriesDefaults(seriesDefaults).setAxes(axes).setHighlighter(highlighter);
        options.setAnimate(true);
        options.setAnimateReplot(true);
        chart = new DCharts().setDataSeries(dataSeries).setOptions(options);
    } else if (CHART_TYPE_PIE_CHART.equals(type)) {
        DataSeries dataSeries = new DataSeries().newSeries();
        for (int i = 0; i < names.length; i++) {
            dataSeries.add(names[i], values[i]);
        }
        SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.PIE);
        Options options = new Options().setSeriesDefaults(seriesDefaults);
        options.setAnimate(true);
        options.setAnimateReplot(true);
        Legend legend = new Legend().setShow(true).setPlacement(LegendPlacements.INSIDE);
        options.setLegend(legend);
        Highlighter highlighter = new Highlighter().setShow(true);
        options.setHighlighter(highlighter);
        chart = new DCharts().setDataSeries(dataSeries).setOptions(options);
    } else if (CHART_TYPE_LINE_CHART.equals(type)) {
        AxesDefaults axesDefaults = new AxesDefaults().setLabelRenderer(LabelRenderers.CANVAS);
        Axes axes = new Axes().addAxis(new XYaxis().setLabel(xAxis != null ? xAxis : "").setMin(names[0]).setMax(names[values.length - 1]).setDrawMajorTickMarks(true)).addAxis(new XYaxis(XYaxes.Y).setLabel(yAxis != null ? yAxis : "").setDrawMajorTickMarks(true));
        Options options = new Options().setAxesDefaults(axesDefaults).setAxes(axes);
        DataSeries dataSeries = new DataSeries().newSeries();
        for (int i = 0; i < names.length; i++) {
            //        if (parseLong(names[i]) != null) {
            //          dataSeries.add(parseLong(names[i]), values[i]);
            //        } else if (parseDouble(names[i]) != null) {
            //          dataSeries.add(parseDouble(names[i]), values[i]);
            //        } else {
            //          dataSeries.add(names[i], values[i]);
            //        }
            dataSeries.add(names[i], values[i]);
        }
        Series series = new Series().addSeries(new XYseries().setShowLine(true).setMarkerOptions(new MarkerRenderer().setShadow(true).setSize(7).setStyle(MarkerStyles.CIRCLE)));
        options.setSeries(series);
        options.setAnimate(true);
        options.setAnimateReplot(true);
        Highlighter highlighter = new Highlighter().setShow(true);
        options.setHighlighter(highlighter);
        chart = new DCharts().setDataSeries(dataSeries).setOptions(options);
    } else if (CHART_TYPE_LIST.equals(type)) {
        GridLayout grid = new GridLayout(2, names.length);
        grid.setSpacing(true);
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            Label nameLabel = new Label(name);
            nameLabel.addStyleName(ExplorerLayout.STYLE_LABEL_BOLD);
            grid.addComponent(nameLabel, 0, i);
            Number value = values[i];
            Label valueLabel = new Label(value + "");
            grid.addComponent(valueLabel, 1, i);
        }
        chart = grid;
    }
    if (chart instanceof DCharts) {
        // Needed, otherwise the chart will not be shown
        ((DCharts) chart).show();
    }
    return chart;
}
Also used : Options(org.dussan.vaadin.dcharts.options.Options) MarkerRenderer(org.dussan.vaadin.dcharts.base.renderers.MarkerRenderer) Legend(org.dussan.vaadin.dcharts.options.Legend) Ticks(org.dussan.vaadin.dcharts.data.Ticks) Label(com.vaadin.ui.Label) JsonNode(com.fasterxml.jackson.databind.JsonNode) XYseries(org.dussan.vaadin.dcharts.base.elements.XYseries) AxesDefaults(org.dussan.vaadin.dcharts.options.AxesDefaults) DataSeries(org.dussan.vaadin.dcharts.data.DataSeries) Series(org.dussan.vaadin.dcharts.options.Series) SeriesDefaults(org.dussan.vaadin.dcharts.options.SeriesDefaults) GridLayout(com.vaadin.ui.GridLayout) DataSeries(org.dussan.vaadin.dcharts.data.DataSeries) Axes(org.dussan.vaadin.dcharts.options.Axes) DCharts(org.dussan.vaadin.dcharts.DCharts) Component(com.vaadin.ui.Component) XYaxis(org.dussan.vaadin.dcharts.base.elements.XYaxis) Highlighter(org.dussan.vaadin.dcharts.options.Highlighter)

Aggregations

Component (com.vaadin.ui.Component)146 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)23 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)13 ComponentContainer (com.vaadin.ui.ComponentContainer)12 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)12 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)11 HorizontalLayout (com.vaadin.ui.HorizontalLayout)11 VerticalLayout (com.vaadin.ui.VerticalLayout)11 Button (com.vaadin.ui.Button)9 Window (com.haulmont.cuba.gui.components.Window)8 Label (com.vaadin.ui.Label)8 Test (org.junit.Test)8 WebWindow (com.haulmont.cuba.web.gui.WebWindow)7 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)6 CssLayout (com.vaadin.ui.CssLayout)6 List (java.util.List)6 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)5 CubaUI (com.haulmont.cuba.web.widgets.CubaUI)5 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)5 Item (com.vaadin.data.Item)5