Example usage for com.vaadin.ui Slider setResolution

List of usage examples for com.vaadin.ui Slider setResolution

Introduction

In this page you can find the example usage for com.vaadin.ui Slider setResolution.

Prototype

public void setResolution(int resolution) 

Source Link

Document

Set a new resolution for the slider.

Usage

From source file:com.cavisson.gui.dashboard.components.controls.Sliders.java

License:Apache License

public Sliders() {
    setMargin(true);//  w  w w  .ja  v  a 2  s.  com

    Label h1 = new Label("Sliders");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Slider slider = new Slider("Horizontal");
    slider.setValue(50.0);
    row.addComponent(slider);

    slider = new Slider("Horizontal, sized");
    slider.setValue(50.0);
    slider.setWidth("200px");
    row.addComponent(slider);

    slider = new Slider("Custom handle");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color1");
    row.addComponent(slider);

    slider = new Slider("Custom track");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color2");
    row.addComponent(slider);

    slider = new Slider("Custom indicator");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color3");
    row.addComponent(slider);

    slider = new Slider("No indicator");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("no-indicator");
    row.addComponent(slider);

    slider = new Slider("With ticks (not in IE8 & IE9)");
    slider.setValue(3.0);
    slider.setWidth("200px");
    slider.setMax(4);
    slider.addStyleName("ticks");
    row.addComponent(slider);

    slider = new Slider("Toggle imitation");
    slider.setWidth("50px");
    slider.setResolution(0);
    slider.setMin(0);
    slider.setMax(1);
    row.addComponent(slider);

    slider = new Slider("Vertical");
    slider.setValue(50.0);
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Vertical, sized");
    slider.setValue(50.0);
    slider.setOrientation(SliderOrientation.VERTICAL);
    slider.setHeight("200px");
    row.addComponent(slider);

    slider = new Slider("Custom handle");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color1");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Custom track");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color2");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Custom indicator");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color3");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("No indicator");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("no-indicator");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("With ticks");
    slider.setValue(3.0);
    slider.setHeight("200px");
    slider.setMax(4);
    slider.addStyleName("ticks");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Disabled");
    slider.setValue(50.0);
    slider.setEnabled(false);
    row.addComponent(slider);

    h1 = new Label("Progress Bars");
    h1.addStyleName("h1");
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    pb = new ProgressBar();
    pb.setCaption("Default");
    pb.setWidth("300px");
    // pb.setValue(0.6f);
    row.addComponent(pb);

    pb2 = new ProgressBar();
    pb2.setCaption("Point style");
    pb2.setWidth("300px");
    pb2.addStyleName("point");
    // pb2.setValue(0.6f);
    row.addComponent(pb2);

    if (!ValoThemeUI.isTestMode()) {
        ProgressBar pb3 = new ProgressBar();
        pb3.setIndeterminate(true);
        pb3.setCaption("Indeterminate");
        row.addComponent(pb3);
    }
}

From source file:com.etest.valo.Sliders.java

License:Apache License

public Sliders() {
    setMargin(true);/*from w  ww .  ja va  2 s .com*/

    Label h1 = new Label("Sliders");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Slider slider = new Slider("Horizontal");
    slider.setValue(50.0);
    row.addComponent(slider);

    slider = new Slider("Horizontal, sized");
    slider.setValue(50.0);
    slider.setWidth("200px");
    row.addComponent(slider);

    slider = new Slider("Custom handle");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color1");
    row.addComponent(slider);

    slider = new Slider("Custom track");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color2");
    row.addComponent(slider);

    slider = new Slider("Custom indicator");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color3");
    row.addComponent(slider);

    slider = new Slider("No indicator");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("no-indicator");
    row.addComponent(slider);

    slider = new Slider("With ticks (not in IE8 & IE9)");
    slider.setValue(3.0);
    slider.setWidth("200px");
    slider.setMax(4);
    slider.addStyleName("ticks");
    row.addComponent(slider);

    slider = new Slider("Toggle imitation");
    slider.setWidth("50px");
    slider.setResolution(0);
    slider.setMin(0);
    slider.setMax(1);
    row.addComponent(slider);

    slider = new Slider("Vertical");
    slider.setValue(50.0);
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Vertical, sized");
    slider.setValue(50.0);
    slider.setOrientation(SliderOrientation.VERTICAL);
    slider.setHeight("200px");
    row.addComponent(slider);

    slider = new Slider("Custom handle");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color1");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Custom track");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color2");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Custom indicator");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color3");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("No indicator");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("no-indicator");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("With ticks");
    slider.setValue(3.0);
    slider.setHeight("200px");
    slider.setMax(4);
    slider.addStyleName("ticks");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Disabled");
    slider.setValue(50.0);
    slider.setEnabled(false);
    row.addComponent(slider);

    h1 = new Label("Progress Bars");
    h1.addStyleName("h1");
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    pb = new ProgressBar();
    pb.setCaption("Default");
    pb.setWidth("300px");
    // pb.setValue(0.6f);
    row.addComponent(pb);

    pb2 = new ProgressBar();
    pb2.setCaption("Point style");
    pb2.setWidth("300px");
    pb2.addStyleName("point");
    // pb2.setValue(0.6f);
    row.addComponent(pb2);

    if (!MainUI.isTestMode()) {
        ProgressBar pb3 = new ProgressBar();
        pb3.setIndeterminate(true);
        pb3.setCaption("Indeterminate");
        row.addComponent(pb3);
    }
}

From source file:com.rex.components.valo.Sliders.java

License:Apache License

public Sliders() {
    setMargin(true);/*from   ww  w  .  j  a  v a 2s  .  c  om*/

    Label h1 = new Label("Sliders");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    Slider slider = new Slider("Horizontal");
    slider.setValue(50.0);
    row.addComponent(slider);

    slider = new Slider("Horizontal, sized");
    slider.setValue(50.0);
    slider.setWidth("200px");
    row.addComponent(slider);

    slider = new Slider("Custom handle");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color1");
    row.addComponent(slider);

    slider = new Slider("Custom track");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color2");
    row.addComponent(slider);

    slider = new Slider("Custom indicator");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("color3");
    row.addComponent(slider);

    slider = new Slider("No indicator");
    slider.setValue(50.0);
    slider.setWidth("200px");
    slider.addStyleName("no-indicator");
    row.addComponent(slider);

    slider = new Slider("With ticks (not in IE8 & IE9)");
    slider.setValue(3.0);
    slider.setWidth("200px");
    slider.setMax(4);
    slider.addStyleName("ticks");
    row.addComponent(slider);

    slider = new Slider("Toggle imitation");
    slider.setWidth("50px");
    slider.setResolution(0);
    slider.setMin(0);
    slider.setMax(1);
    row.addComponent(slider);

    slider = new Slider("Vertical");
    slider.setValue(50.0);
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Vertical, sized");
    slider.setValue(50.0);
    slider.setOrientation(SliderOrientation.VERTICAL);
    slider.setHeight("200px");
    row.addComponent(slider);

    slider = new Slider("Custom handle");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color1");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Custom track");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color2");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Custom indicator");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("color3");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("No indicator");
    slider.setValue(50.0);
    slider.setHeight("200px");
    slider.addStyleName("no-indicator");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("With ticks");
    slider.setValue(3.0);
    slider.setHeight("200px");
    slider.setMax(4);
    slider.addStyleName("ticks");
    slider.setOrientation(SliderOrientation.VERTICAL);
    row.addComponent(slider);

    slider = new Slider("Disabled");
    slider.setValue(50.0);
    slider.setEnabled(false);
    row.addComponent(slider);

    h1 = new Label("Progress Bars");
    h1.addStyleName("h1");
    addComponent(h1);

    row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);

    pb = new ProgressBar();
    pb.setCaption("Default");
    pb.setWidth("300px");
    // pb.setValue(0.6f);
    row.addComponent(pb);

    pb2 = new ProgressBar();
    pb2.setCaption("Point style");
    pb2.setWidth("300px");
    pb2.addStyleName("point");
    // pb2.setValue(0.6f);
    row.addComponent(pb2);

    if (!ReportEngineUI.isTestMode()) {
        ProgressBar pb3 = new ProgressBar();
        pb3.setIndeterminate(true);
        pb3.setCaption("Indeterminate");
        row.addComponent(pb3);
    }
}

From source file:org.opennms.features.topology.app.internal.TopologyUI.java

License:Open Source License

private Component createMapLayout() {
    final Property<Double> scale = m_graphContainer.getScaleProperty();

    m_lastUpdatedTimeLabel = new LastUpdatedLabel();
    m_lastUpdatedTimeLabel.setImmediate(true);

    m_zoomLevelLabel.setHeight(20, Unit.PIXELS);
    m_zoomLevelLabel.setWidth(22, Unit.PIXELS);
    m_zoomLevelLabel.addStyleName("center-text");
    m_zoomLevelLabel.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override//from ww  w  . j  a  va2 s  . c o m
        public void textChange(FieldEvents.TextChangeEvent event) {
            try {
                int zoomLevel = Integer.parseInt(event.getText());
                setSemanticZoomLevel(zoomLevel);
            } catch (NumberFormatException e) {
                setSemanticZoomLevel(m_graphContainer.getSemanticZoomLevel());
            }

        }
    });

    m_topologyComponent = new TopologyComponent(m_graphContainer, m_iconRepositoryManager, this);
    m_topologyComponent.setSizeFull();
    m_topologyComponent.addMenuItemStateListener(this);
    m_topologyComponent.addVertexUpdateListener(this);

    final Slider slider = new Slider(0, 1);
    slider.setPropertyDataSource(scale);
    slider.setResolution(1);
    slider.setHeight("200px");
    slider.setOrientation(SliderOrientation.VERTICAL);

    slider.setImmediate(true);

    final NativeButton showFocusVerticesBtn = new NativeButton(FontAwesomeIcons.Icon.eye_open.variant());
    showFocusVerticesBtn.setDescription("Toggle Highlight Focus Nodes");
    showFocusVerticesBtn.setHtmlContentAllowed(true);
    showFocusVerticesBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (showFocusVerticesBtn.getCaption().equals(FontAwesomeIcons.Icon.eye_close.variant())) {
                showFocusVerticesBtn.setCaption(FontAwesomeIcons.Icon.eye_open.variant());
            } else {
                showFocusVerticesBtn.setCaption(FontAwesomeIcons.Icon.eye_close.variant());
            }
            m_topologyComponent.getState()
                    .setHighlightFocus(!m_topologyComponent.getState().isHighlightFocus());
            m_topologyComponent.updateGraph();
        }
    });

    final NativeButton magnifyBtn = new NativeButton();
    magnifyBtn.setHtmlContentAllowed(true);
    magnifyBtn.setCaption("<i class=\"" + FontAwesomeIcons.Icon.zoom_in.stylename() + "\" ></i>");
    magnifyBtn.setStyleName("icon-button");
    magnifyBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (slider.getValue() < 1) {
                slider.setValue(Math.min(1, slider.getValue() + 0.25));
            }
        }
    });

    final NativeButton demagnifyBtn = new NativeButton();
    demagnifyBtn.setHtmlContentAllowed(true);
    demagnifyBtn.setCaption("<i class=\"" + FontAwesomeIcons.Icon.zoom_out.stylename() + "\" ></i>");
    demagnifyBtn.setStyleName("icon-button");
    demagnifyBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (slider.getValue() != 0) {
                slider.setValue(Math.max(0, slider.getValue() - 0.25));
            }
        }
    });

    VerticalLayout sliderLayout = new VerticalLayout();
    sliderLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    sliderLayout.addComponent(magnifyBtn);
    sliderLayout.addComponent(slider);
    sliderLayout.addComponent(demagnifyBtn);

    m_szlOutBtn = new Button();
    m_szlOutBtn.setHtmlContentAllowed(true);
    m_szlOutBtn.setCaption(FontAwesomeIcons.Icon.arrow_down.variant());
    m_szlOutBtn.setDescription("Collapse Semantic Zoom Level");
    m_szlOutBtn.setEnabled(m_graphContainer.getSemanticZoomLevel() > 0);
    m_szlOutBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            int szl = m_graphContainer.getSemanticZoomLevel();
            if (szl > 0) {
                szl--;
                setSemanticZoomLevel(szl);
                saveHistory();
            }
        }
    });

    final Button szlInBtn = new Button();
    szlInBtn.setHtmlContentAllowed(true);
    szlInBtn.setCaption(FontAwesomeIcons.Icon.arrow_up.variant());
    szlInBtn.setDescription("Expand Semantic Zoom Level");
    szlInBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            int szl = m_graphContainer.getSemanticZoomLevel();
            szl++;
            setSemanticZoomLevel(szl);
            saveHistory();
        }
    });

    m_panBtn = new Button();
    m_panBtn.setIcon(FontAwesome.ARROWS);
    m_panBtn.setDescription("Pan Tool");
    m_panBtn.setStyleName("toolbar-button down");

    m_selectBtn = new Button();
    m_selectBtn.setIcon(new ThemeResource("images/selection.png"));
    m_selectBtn.setDescription("Selection Tool");
    m_selectBtn.setStyleName("toolbar-button");
    m_selectBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            m_selectBtn.setStyleName("toolbar-button down");
            m_panBtn.setStyleName("toolbar-button");
            m_topologyComponent.setActiveTool("select");
        }
    });

    m_panBtn.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            m_panBtn.setStyleName("toolbar-button down");
            m_selectBtn.setStyleName("toolbar-button");
            m_topologyComponent.setActiveTool("pan");
        }
    });

    final Button historyBackBtn = new Button(FontAwesomeIcons.Icon.arrow_left.variant());
    historyBackBtn.setHtmlContentAllowed(true);
    historyBackBtn.setDescription("Click to go back");
    historyBackBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            com.vaadin.ui.JavaScript.getCurrent().execute("window.history.back()");
        }
    });

    final Button historyForwardBtn = new Button(FontAwesomeIcons.Icon.arrow_right.variant());
    historyForwardBtn.setHtmlContentAllowed(true);
    historyForwardBtn.setDescription("Click to go forward");
    historyForwardBtn.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            com.vaadin.ui.JavaScript.getCurrent().execute("window.history.forward()");
        }
    });

    m_searchBox = new SearchBox(m_serviceManager, new CommandManager.DefaultOperationContext(this,
            m_graphContainer, OperationContext.DisplayLocation.SEARCH));

    //History Button Layout
    HorizontalLayout historyButtonLayout = new HorizontalLayout();
    historyButtonLayout.setSpacing(true);
    historyButtonLayout.addComponent(historyBackBtn);
    historyButtonLayout.addComponent(historyForwardBtn);

    //Semantic Controls Layout
    HorizontalLayout semanticLayout = new HorizontalLayout();
    semanticLayout.setSpacing(true);
    semanticLayout.addComponent(szlInBtn);
    semanticLayout.addComponent(m_zoomLevelLabel);
    semanticLayout.addComponent(m_szlOutBtn);
    semanticLayout.setComponentAlignment(m_zoomLevelLabel, Alignment.MIDDLE_CENTER);

    VerticalLayout historyCtrlLayout = new VerticalLayout();
    historyCtrlLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    historyCtrlLayout.addComponent(historyButtonLayout);

    HorizontalLayout controlLayout = new HorizontalLayout();
    controlLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    controlLayout.addComponent(m_panBtn);
    controlLayout.addComponent(m_selectBtn);

    VerticalLayout semanticCtrlLayout = new VerticalLayout();
    semanticCtrlLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    semanticCtrlLayout.addComponent(semanticLayout);

    HorizontalLayout locationToolLayout = createLocationToolLayout();

    //Vertical Layout for all tools on right side
    VerticalLayout toollayout = new VerticalLayout();
    toollayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    toollayout.setSpacing(true);

    toollayout.addComponent(historyCtrlLayout);
    toollayout.addComponent(locationToolLayout);
    toollayout.addComponent(showFocusVerticesBtn);
    toollayout.addComponent(sliderLayout);
    toollayout.addComponent(controlLayout);
    toollayout.addComponent(semanticCtrlLayout);

    AbsoluteLayout mapLayout = new AbsoluteLayout();
    mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;");
    mapLayout.addComponent(m_lastUpdatedTimeLabel, "top: 5px; right: 10px;");
    mapLayout.addComponent(toollayout, "top: 25px; right: 10px;");
    mapLayout.setSizeFull();

    m_infoPanel = new InfoPanel(m_searchBox, mapLayout);
    return m_infoPanel;
}

From source file:org.opennms.features.topology.app.internal.TopologyWidgetTestApplication.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from w w w .  j  ava2s.c om
public void init() {
    setTheme("topo_default");

    m_rootLayout = new AbsoluteLayout();
    m_rootLayout.setSizeFull();

    m_window = new Window("OpenNMS Topology");
    m_window.setContent(m_rootLayout);
    setMainWindow(m_window);

    m_uriFragUtil = new UriFragmentUtility();
    m_window.addComponent(m_uriFragUtil);
    m_uriFragUtil.addListener(this);

    m_layout = new AbsoluteLayout();
    m_layout.setSizeFull();
    m_rootLayout.addComponent(m_layout);

    if (m_showHeader) {
        HEADER_HEIGHT = 100;
        Panel header = new Panel("header");
        header.setCaption(null);
        header.setSizeUndefined();
        header.addStyleName("onmsheader");
        m_rootLayout.addComponent(header, "top: 0px; left: 0px; right:0px;");

        try {
            CustomLayout customLayout = new CustomLayout(getHeaderLayout());
            header.setContent(customLayout);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        HEADER_HEIGHT = 0;
    }

    Refresher refresher = new Refresher();
    refresher.setRefreshInterval(5000);
    getMainWindow().addComponent(refresher);

    m_graphContainer.setLayoutAlgorithm(new FRLayoutAlgorithm());

    final Property scale = m_graphContainer.getScaleProperty();

    m_topologyComponent = new TopologyComponent(m_graphContainer, m_iconRepositoryManager, m_selectionManager,
            this);
    m_topologyComponent.setSizeFull();
    m_topologyComponent.addMenuItemStateListener(this);
    m_topologyComponent.addVertexUpdateListener(this);

    final Slider slider = new Slider(0, 1);

    slider.setPropertyDataSource(scale);
    slider.setResolution(1);
    slider.setHeight("300px");
    slider.setOrientation(Slider.ORIENTATION_VERTICAL);

    slider.setImmediate(true);

    final Button zoomInBtn = new Button();
    zoomInBtn.setIcon(new ThemeResource("images/plus.png"));
    zoomInBtn.setDescription("Expand Semantic Zoom Level");
    zoomInBtn.setStyleName("semantic-zoom-button");
    zoomInBtn.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            int szl = (Integer) m_graphContainer.getSemanticZoomLevel();
            szl++;
            m_graphContainer.setSemanticZoomLevel(szl);
            setSemanticZoomLevel(szl);
            saveHistory();
        }
    });

    Button zoomOutBtn = new Button();
    zoomOutBtn.setIcon(new ThemeResource("images/minus.png"));
    zoomOutBtn.setDescription("Collapse Semantic Zoom Level");
    zoomOutBtn.setStyleName("semantic-zoom-button");
    zoomOutBtn.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            int szl = (Integer) m_graphContainer.getSemanticZoomLevel();
            if (szl > 0) {
                szl--;
                m_graphContainer.setSemanticZoomLevel(szl);
                setSemanticZoomLevel(szl);
                saveHistory();
            }

        }
    });

    final Button panBtn = new Button();
    panBtn.setIcon(new ThemeResource("images/cursor_drag_arrow.png"));
    panBtn.setDescription("Pan Tool");
    panBtn.setStyleName("toolbar-button down");

    final Button selectBtn = new Button();
    selectBtn.setIcon(new ThemeResource("images/selection.png"));
    selectBtn.setDescription("Selection Tool");
    selectBtn.setStyleName("toolbar-button");
    selectBtn.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            selectBtn.setStyleName("toolbar-button down");
            panBtn.setStyleName("toolbar-button");
            m_topologyComponent.setActiveTool("select");
        }
    });

    panBtn.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            panBtn.setStyleName("toolbar-button down");
            selectBtn.setStyleName("toolbar-button");
            m_topologyComponent.setActiveTool("pan");
        }
    });

    VerticalLayout toolbar = new VerticalLayout();
    toolbar.setWidth("31px");
    toolbar.addComponent(panBtn);
    toolbar.addComponent(selectBtn);

    HorizontalLayout semanticLayout = new HorizontalLayout();
    semanticLayout.addComponent(zoomInBtn);
    semanticLayout.addComponent(m_zoomLevelLabel);
    semanticLayout.addComponent(zoomOutBtn);
    semanticLayout.setComponentAlignment(m_zoomLevelLabel, Alignment.MIDDLE_CENTER);

    AbsoluteLayout mapLayout = new AbsoluteLayout();

    mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;");
    mapLayout.addComponent(slider, "top: 5px; left: 20px; z-index:1000;");
    mapLayout.addComponent(toolbar, "top: 324px; left: 12px;");
    mapLayout.addComponent(semanticLayout, "top: 380px; left: 2px;");
    mapLayout.setSizeFull();

    m_treeMapSplitPanel = new HorizontalSplitPanel();
    m_treeMapSplitPanel.setFirstComponent(createWestLayout());
    m_treeMapSplitPanel.setSecondComponent(mapLayout);
    m_treeMapSplitPanel.setSplitPosition(222, Sizeable.UNITS_PIXELS);
    m_treeMapSplitPanel.setSizeFull();

    m_commandManager.addCommandUpdateListener(this);

    menuBarUpdated(m_commandManager);
    if (m_widgetManager.widgetCount() != 0) {
        updateWidgetView(m_widgetManager);
    } else {
        m_layout.addComponent(m_treeMapSplitPanel, getBelowMenuPosition());
    }

    if (m_treeWidgetManager.widgetCount() != 0) {
        updateAccordionView(m_treeWidgetManager);
    }
}

From source file:org.opennms.features.vaadin.app.TopologyWidgetTestApplication.java

License:Open Source License

@Override
public void init() {
    //This timer is a hack at the moment to disable and enable menuItems
    m_timer.scheduleAtFixedRate(new TimerTask() {

        @Override/*w ww  . ja va  2 s  . c  o  m*/
        public void run() {
            List<MenuItem> items = m_menuBar.getItems();
            for (MenuItem item : items) {
                if (item.getText().equals("Device")) {
                    List<MenuItem> children = item.getChildren();
                    for (MenuItem child : children) {
                        if (m_graphContainer.getSelectedVertexIds().size() > 0) {
                            if (!child.isEnabled()) {
                                child.setEnabled(true);
                            }
                        } else {
                            if (child.isEnabled()) {
                                child.setEnabled(false);
                            }

                        }
                    }

                }
            }
        }
    }, 1000, 1000);

    m_commandManager.addCommand(new Command("Redo Layout") {
        ;

        @Override
        public void doCommand(Object target) {
            m_graphContainer.redoLayout();
        }

        @Override
        public boolean appliesToTarget(Object target) {
            //Applies to background as a whole
            return target == null;
        }
    }, true);

    m_commandManager.addCommand(new Command("Open") {

        @Override
        public void doCommand(Object target) {
            m_graphContainer.load("graph.xml");
        }

    }, false, "File");

    m_commandManager.addCommand(new Command("Save") {

        @Override
        public void doCommand(Object target) {
            m_graphContainer.save("graph.xml");
        }

    }, false, "File");

    m_commandManager.addCommand(new Command("Add Vertex") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            return itemId == null || m_graphContainer.getVertexContainer().containsId(itemId);
        }

        @Override
        public void doCommand(Object vertexId) {
            if (vertexId == null) {
                addRandomVertex();
            } else {
                connectNewVertexTo(vertexId.toString(), SERVER_ICON);
            }
            m_graphContainer.redoLayout();
        }

    }, true, "File");

    m_commandManager.addCommand(new Command("Lock") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            if (m_graphContainer.getVertexContainer().containsId(itemId)) {
                Item v = m_graphContainer.getVertexContainer().getItem(itemId);
                return !(Boolean) v.getItemProperty("locked").getValue();
            }
            return false;
        }

        @Override
        public void doCommand(Object vertexId) {
            Item v = m_graphContainer.getVertexContainer().getItem(vertexId);
            v.getItemProperty("locked").setValue(true);
        }

    }, true);

    m_commandManager.addCommand(new Command("Unlock") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            if (m_graphContainer.getVertexContainer().containsId(itemId)) {
                Item v = m_graphContainer.getVertexContainer().getItem(itemId);
                return (Boolean) v.getItemProperty("locked").getValue();
            }
            return false;
        }

        @Override
        public void doCommand(Object vertexId) {
            Item v = m_graphContainer.getVertexContainer().getItem(vertexId);
            v.getItemProperty("locked").setValue(false);
        }

    }, true);
    m_commandManager.addCommand(new Command("Add Switch Vertex") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            return itemId == null || m_graphContainer.getVertexContainer().containsId(itemId);
        }

        @Override
        public void doCommand(Object vertexId) {
            if (vertexId == null) {
                addRandomVertex();
            } else {
                connectNewVertexTo(vertexId.toString(), SWITCH_ICON);
            }
            m_graphContainer.redoLayout();
        }

    }, true);

    m_commandManager.addCommand(new Command("Remove Vertex") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            return itemId == null || m_graphContainer.getVertexContainer().containsId(itemId);
        }

        @Override
        public void doCommand(Object vertexId) {
            if (vertexId == null) {
                System.err.println("need to handle selection!!!");
            } else {
                m_graphContainer.removeVertex(vertexId.toString());
                m_graphContainer.redoLayout();
            }
        }

    }, true, "File");

    m_commandManager.addCommand(new Command("Connect") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            return m_graphContainer.getSelectedVertexIds().size() == 2;
        }

        @Override
        public void doCommand(Object unused) {
            List<Object> endPoints = new ArrayList<Object>(m_graphContainer.getSelectedVertexIds());

            m_graphContainer.connectVertices(m_graphContainer.getNextEdgeId(), (String) endPoints.get(0),
                    (String) endPoints.get(1));
        }

    }, true, "File");
    m_commandManager.addCommand(new Command("Create Group") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            return m_graphContainer.getSelectedVertexIds().size() > 0;
        }

        @Override
        public void doCommand(Object vertexId) {
            String groupId = m_graphContainer.getNextGroupId();
            m_graphContainer.addGroup(groupId, GROUP_ICON);
            m_graphContainer.getVertexContainer().setParent(groupId, ROOT_GROUP_ID);

            for (Object itemId : m_graphContainer.getSelectedVertexIds()) {
                m_graphContainer.getVertexContainer().setParent(itemId, groupId);
            }
        }

    }, true, "Edit");

    m_commandManager.addCommand(new Command("Manual Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new ManualLayoutAlgorithm());
        }

    }, false, "Edit|Layout");

    m_commandManager.addCommand(new Command("Balloon Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new BalloonLayoutAlgorithm(CENTER_VERTEX_ID));
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("Circle Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new CircleLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("DAG Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new DAGLayoutAlgorithm(CENTER_VERTEX_ID));
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("Radial Tree Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new RadialTreeLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");
    m_commandManager.addCommand(new Command("Tree Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new TreeLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("Simple Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new SimpleLayoutAlgorithm());
        }

    }, false, "Edit|Layout");

    m_commandManager.addCommand(new Command("Spring Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new SpringLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("KK Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new KKLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("ISOM Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new ISOMLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("FR Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new FRLayoutAlgorithm());
        }

    }, false, "Edit|Layout|JUNG");

    m_commandManager.addCommand(new Command("Other Layout") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            m_graphContainer.setLayoutAlgorithm(new AlternativeLayoutAlgorithm());
        }

    }, false, "Edit|Layout");

    m_commandManager.addCommand(new Command("Reset") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {

            resetView();
        }

    }, false, null);

    m_commandManager.addCommand(new Command("History") {

        @Override
        public boolean appliesToTarget(Object target) {
            return true;
        }

        @Override
        public void doCommand(Object target) {
            showHistoryList(m_commandManager.getHistoryList());
        }

    }, false, null);

    m_commandManager.addCommand(new Command("Show Map") {

        @Override
        public void doCommand(Object target) {
            getMainWindow().showNotification("This has not been implemented yet");

        }

    }, false, "View");

    m_commandManager.addCommand(new Command("Get Info") {

        @Override
        public boolean appliesToTarget(Object itemId) {
            return itemId == null || m_graphContainer.getEdgeContainer().containsId(itemId);
        }

        @Override
        public void doCommand(Object target) {
            getMainWindow().showNotification("This has not been implemented yet");
        }

    }, true, "Device");

    AbsoluteLayout layout = new AbsoluteLayout();
    layout.setSizeFull();

    m_window = new Window("Topology Widget Test");
    m_window.setContent(layout);
    setMainWindow(m_window);

    m_graphContainer.addGroup(ROOT_GROUP_ID, GROUP_ICON);
    m_graphContainer.addVertex(CENTER_VERTEX_ID, 50, 50, SERVER_ICON);
    m_graphContainer.getVertexContainer().setParent(CENTER_VERTEX_ID, ROOT_GROUP_ID);
    m_graphContainer.setLayoutAlgorithm(new KKLayoutAlgorithm());

    m_topologyComponent = new TopologyComponent(m_graphContainer);
    m_commandManager.addActionHandlers(m_topologyComponent);
    m_topologyComponent.setSizeFull();

    final Property scale = m_graphContainer.getProperty("scale");
    final Slider slider = new Slider(1, 4);
    slider.setResolution(2);
    slider.setHeight("300px");
    slider.setOrientation(Slider.ORIENTATION_VERTICAL);

    slider.addListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent event) {
            scale.setValue((Double) slider.getValue());
        }
    });

    slider.setImmediate(true);

    m_tree = createTree();
    Label semanticZoomLabel = new Label();
    final Property zoomLevel = m_graphContainer.getProperty("semanticZoomLevel");
    semanticZoomLabel.setPropertyDataSource(zoomLevel);

    Button zoomInBtn = new Button("Zoom In");
    zoomInBtn.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            int szl = (Integer) zoomLevel.getValue();
            szl++;
            zoomLevel.setValue(szl);
            m_graphContainer.redoLayout();
        }
    });

    Button zoomOutBtn = new Button("Zoom Out");
    zoomOutBtn.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            int szl = (Integer) zoomLevel.getValue();
            szl--;
            zoomLevel.setValue(szl);
            m_graphContainer.redoLayout();
        }
    });

    VerticalLayout vLayout = new VerticalLayout();
    vLayout.setWidth("100%");
    vLayout.setHeight("100%");
    vLayout.addComponent(m_tree);

    AbsoluteLayout mapLayout = new AbsoluteLayout();

    mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;");
    mapLayout.addComponent(slider, "top: 20px; left: 20px; z-index:1000;");
    mapLayout.addComponent(semanticZoomLabel, "bottom: 10px; right: 10px; z-index: 2000;");
    mapLayout.setSizeFull();

    HorizontalSplitPanel treeMapSplitPanel = new HorizontalSplitPanel();
    treeMapSplitPanel.setFirstComponent(vLayout);
    treeMapSplitPanel.setSecondComponent(mapLayout);
    treeMapSplitPanel.setSplitPosition(100, Sizeable.UNITS_PIXELS);
    treeMapSplitPanel.setSizeFull();

    VerticalSplitPanel bottomLayoutBar = new VerticalSplitPanel();
    bottomLayoutBar.setFirstComponent(treeMapSplitPanel);

    VerticalLayout zoomLayout = new VerticalLayout();
    zoomLayout.addComponent(zoomInBtn);
    zoomLayout.addComponent(zoomOutBtn);

    bottomLayoutBar.setSecondComponent(zoomLayout);
    bottomLayoutBar.setSplitPosition(80, Sizeable.UNITS_PERCENTAGE);
    bottomLayoutBar.setSizeFull();

    m_menuBar = m_commandManager.getMenuBar();
    m_menuBar.setWidth("100%");
    layout.addComponent(m_menuBar, "top: 0px; left: 0px; right:0px;");
    layout.addComponent(bottomLayoutBar, "top: 23px; left: 0px; right:0px; bottom:0px;");

}