List of usage examples for com.vaadin.ui Slider getValue
@Override
public Double getValue()
From source file:com.cerebro.gorgone.landingpage.SignInWindow.java
private Component setFirstStep() { VerticalLayout firstStep = new VerticalLayout(); firstStep.setMargin(true);/*from w w w . j a v a 2 s.co m*/ // Body HorizontalLayout body = new HorizontalLayout(); FormLayout datiIniziali = new FormLayout(); TextField nomePG = new TextField("Nome del Personaggio"); nomePG.setRequired(true); TextField cognomePG = new TextField("Cognome del Personaggio"); cognomePG.setRequired(true); OptionGroup sessoPG = new OptionGroup("Sesso del Personaggio"); sessoPG.setRequired(true); sessoPG.addItems("Maschio", "Femmina"); ComboBox razzaPG = new ComboBox("Razza"); razzaPG.setRequired(true); Slider age = new Slider("Et"); age.setImmediate(true); age.setWidth("200px"); age.setVisible(false); HorizontalLayout ageDescription = new HorizontalLayout(); ageDescription.setHeight("250px"); Label ageText = new Label("Valore dell'et: "); Label ageValue = new Label(age.getValue().toString()); Label periodoVita = new Label(""); ageDescription.addComponents(ageText, ageValue, periodoVita); age.addValueChangeListener((Property.ValueChangeEvent event) -> { System.out.println("Valore: " + age.getValue().toString()); ageValue.setValue(age.getValue().toString()); Double value = (100 * (age.getValue()) / (age.getMax())); if (value < 14) { periodoVita.setValue("Bambino"); } else if (value > 14 && value < 24) { periodoVita.setValue("Adolescenza"); } else if (value > 24 && value < 73) { periodoVita.setValue("Et adulta"); } else if (value > 73) { periodoVita.setValue("Et anziana"); } }); ageDescription.addComponents(ageText, ageValue, periodoVita); ageDescription.setVisible(false); datiIniziali.addComponents(nomePG, cognomePG, sessoPG, razzaPG, age, ageDescription); Panel descrizioneRazza = new Panel(); CssLayout descrizioneRazzaContent = new CssLayout(); descrizioneRazza.setWidth("400px"); descrizioneRazza.setHeight("500px"); descrizioneRazza.setContent(descrizioneRazzaContent); // Dettagli di popolazione e comportamento ComboBox TableQuery tq_races = new TableQuery(DatabaseTables.RACES_TABLE, connPool); tq_races.setVersionColumn(DatabaseTables.RACES_VERSION); SQLContainer container_races = null; try { container_races = new SQLContainer(tq_races); } catch (Exception ex) { logger.error(ex.getMessage()); } razzaPG.setContainerDataSource(container_races); razzaPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY); razzaPG.setItemCaptionPropertyId(DatabaseTables.RACES_NAME); razzaPG.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { if (razzaPG.getValue() != null) { logger.info("Razza selezionata: " + razzaPG.getValue()); age.setVisible(true); ageDescription.setVisible(true); descrizioneRazzaContent.removeAllComponents(); Item item = razzaPG.getContainerDataSource().getItem(razzaPG.getValue()); race = (String) item.getItemProperty(DatabaseTables.RACES_NAME).getValue(); Label nameRace = new Label(race); FileResource imageSrc = new FileResource( new File(MyUI.basePath + item.getItemProperty(DatabaseTables.RACES_IMAGE).getValue())); Image imageRace = new Image(null, imageSrc); imageRace.setWidth("200px"); Label descriptionRace = new Label( (String) item.getItemProperty(DatabaseTables.RACES_DESCRIPTION).getValue(), ContentMode.HTML); min_age = (int) item.getItemProperty(DatabaseTables.RACES_MIN_AGE).getValue(); max_age = (int) item.getItemProperty(DatabaseTables.RACES_MAX_AGE).getValue(); age.setMin(min_age); age.setMax(max_age); strenght = (int) item.getItemProperty(DatabaseTables.RACES_STRENGHT).getValue(); resistance = (int) item.getItemProperty(DatabaseTables.RACES_RESISTANCE).getValue(); agility = (int) item.getItemProperty(DatabaseTables.RACES_AGILITY).getValue(); intelligence = (int) item.getItemProperty(DatabaseTables.RACES_INTELLIGENCE).getValue(); wisdom = (int) item.getItemProperty(DatabaseTables.RACES_WISDOM).getValue(); charm = (int) item.getItemProperty(DatabaseTables.RACES_CHARM).getValue(); Label min_ageL = new Label("Et minima: " + min_age); Label max_ageL = new Label("Et masima " + max_age); // Panel levels = new Panel(); // VerticalLayout levelsContent = new VerticalLayout(); // levels.setContent(levelsContent); // Label strenghtL = new Label("Forza: " + strenght); // levelsContent.addComponents(strenghtL); String levelTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>" + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght + "</td>" + "<td>" + resistance + "</td>" + "<td>" + agility + "</td>" + "<td>" + intelligence + "</td>" + "<td>" + wisdom + "</td>" + "<td>" + charm + "</td>" + "</tr></table>"; Label levels = new Label(levelTable, ContentMode.HTML); descrizioneRazzaContent.addComponents(nameRace, imageRace, descriptionRace, min_ageL, max_ageL, levels); } } }); body.addComponents(datiIniziali, descrizioneRazza); CssLayout footer = new CssLayout(); Button next = new Button("Avanti ->"); next.addClickListener((Button.ClickEvent event) -> { user.setNomePG(nomePG.getValue()); user.setCognomePG(cognomePG.getValue()); user.setSessoPG(sessoPG.getValue().toString()); user.setRazzaPG(race); user.setEtaPG(age.getValue().toString()); user.setForzaPG(strenght); user.setResistenzaPG(resistance); user.setAgilitaPG(agility); user.setIntelligenzaPG(intelligence); user.setSaggezzaPG(wisdom); user.setCarismaPG(charm); this.setContent(setSecondStep()); }); footer.addComponents(next, createCancelButton()); firstStep.addComponents(setHeader("2/4"), body, footer); return firstStep; }
From source file:com.cerebro.provevaadin.SignIn.java
private VerticalLayout setSecondStep() { VerticalLayout secondStep = new VerticalLayout(); CssLayout header = new CssLayout(); Label title = new Label("Benvenuto " + u.getNomeUtente() + "!"); Label istructions = new Label("Crea il tuo personaggio"); Label step = new Label("2/*"); header.addComponents(title, istructions, step); VerticalLayout body = new VerticalLayout(); Label ageIstruction = new Label("Indica l'et del tuo personaggio in anni"); // Cambiare i parametri in base alla razza Slider age = new Slider(1, 150); age.setImmediate(true);/*from w w w . j a v a 2s. c o m*/ age.setSizeFull(); HorizontalLayout ageDescription = new HorizontalLayout(); ageDescription.setHeight("250px"); Label ageText = new Label("Valore dell'et: "); Label ageValue = new Label(age.getValue().toString()); Label periodoVita = new Label(""); ageDescription.addComponents(ageText, ageValue, periodoVita); age.addValueChangeListener((Property.ValueChangeEvent event) -> { System.out.println("Valore: " + age.getValue().toString()); ageValue.setValue(age.getValue().toString()); Double value = (100 * (age.getValue()) / (age.getMax())); if (value < 14) { periodoVita.setValue("Bambino"); } else if (value > 14 && value < 24) { periodoVita.setValue("Adolescenza"); } else if (value > 24 && value < 73) { periodoVita.setValue("Et adulta"); } else if (value > 73) { periodoVita.setValue("Et anziana"); } }); body.addComponents(ageIstruction, age, ageDescription); CssLayout footer = new CssLayout(); Button next = new Button("Avanti ->"); next.addClickListener((Button.ClickEvent event) -> { u.setEtaPG(age.getValue().toString()); this.setContent(setThirdStep()); }); footer.addComponents(next, createCancelButton()); secondStep.addComponents(header, body, footer); return secondStep; }
From source file:com.foo01.ui.ReservationDetailView.java
@Override protected final void onBecomingVisible() { getNavigationBar().setCaption("Detail Rezervace"); //buttony pod navbarem HorizontalLayout buttonsLayout = new HorizontalLayout(); buttonsLayout.setStyleName("buttonToolBarLayout"); buttonsLayout.setWidth("100%"); Button deleteButton = new Button(); deleteButton.setCaption("SMAZAT"); deleteButton.setWidth(null);//from w w w . j av a 2 s . c o m buttonsLayout.addComponent(deleteButton); Label plug = new Label(); buttonsLayout.addComponent(plug); Button saveButton = new Button(); saveButton.setCaption("ULOIT"); saveButton.setWidth(null); buttonsLayout.addComponent(saveButton); buttonsLayout.setExpandRatio(plug, 1.0f); List<Source> sourcesList = MockSource.mockSources(); //combobox na zdroje a jmeno uzivatele HorizontalLayout sourceAndNameLayout = new HorizontalLayout(); sourceAndNameLayout.setWidth("100%"); sourceAndNameLayout.setStyleName("sourceAndNameLayout"); NativeSelect select = new NativeSelect(); select.setNullSelectionAllowed(false); System.out.println(Page.getCurrent().getBrowserWindowWidth()); String width = Page.getCurrent().getBrowserWindowWidth() / 2.5 + "px"; select.setWidth(width); select.addItems(sourcesList); for (Source s : sourcesList) { if (reservation.getSource().equals(s)) { select.select(s); break; } } sourceAndNameLayout.addComponent(select); Label plug2 = new Label(); sourceAndNameLayout.addComponent(plug2); Label name = new Label(reservation.getUser()); name.setWidth(null); sourceAndNameLayout.addComponent(name); sourceAndNameLayout.setExpandRatio(plug2, 1.0f); //datepickery DatePicker dateFrom = new DatePicker(); dateFrom.setStyleName("datePickerDetailView"); dateFrom.setValue(reservation.getBeginning()); dateFrom.setUseNative(true); dateFrom.setResolution(Resolution.TIME); dateFrom.setWidth("100%"); DatePicker dateTo = new DatePicker(); dateTo.setStyleName("datePickerDetailView"); dateTo.setValue(reservation.getEnding()); dateTo.setUseNative(true); dateTo.setResolution(Resolution.TIME); dateTo.setWidth("100%"); //layout pro slider a popisky HorizontalLayout sliderLayout = new HorizontalLayout(); sliderLayout.setStyleName("sliderLayout"); sliderLayout.setWidth("100%"); sliderLayout.setSpacing(true); Label sliderCaption = new Label("Po?et: "); sliderCaption.addStyleName("sliderCaption"); sliderCaption.setWidth(null); sliderLayout.addComponent(sliderCaption); final Label horvalue = new Label(); horvalue.setWidth("45px"); horvalue.setStyleName("value"); sliderLayout.addComponent(horvalue); final Slider horslider = new Slider(1, 10); horslider.setOrientation(SliderOrientation.HORIZONTAL); horslider.setValue(Double.valueOf(1)); horslider.getState(); horslider.getValue(); horslider.setImmediate(true); horslider.setWidth("100%"); sliderLayout.addComponent(horslider); sliderLayout.setExpandRatio(horslider, 1.0f); horvalue.setValue(String.valueOf(horslider.getValue().intValue())); horslider.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { int value = horslider.getValue().intValue(); horvalue.setValue(String.valueOf(value)); } }); //switch schvaleno HorizontalLayout switchLayout = new HorizontalLayout(); switchLayout.setStyleName("switchLayout"); switchLayout.addComponent(new Label("Schvleno:")); switchLayout.setSpacing(true); Switch checkbox = new Switch(null, true); switchLayout.addComponent(checkbox); //popis rezervace TextArea description = new TextArea(); description.setStyleName("descriptionDetailView"); description.setWidth("100%"); description.setImmediate(false); description.setCaption("Popis:"); description.setValue(reservation.getDescription()); //description.setRequired(true); description.setRequiredError("Popis mus bt zadn!"); description.setNullRepresentation(""); description.setReadOnly(true); //description.setRows(0); final VerticalLayout content = new VerticalLayout(); content.setMargin(true); content.setSpacing(true); content.setStyleName(width); content.addComponent(buttonsLayout); content.addComponent(sourceAndNameLayout); content.addComponent(dateFrom); content.addComponent(dateTo); content.addComponent(sliderLayout); content.addComponent(switchLayout); content.addComponent(description); setContent(content); }
From source file:com.foo01.ui.ReservationView.java
@Override protected final void onBecomingVisible() { getNavigationBar().setCaption("Detail Rezervace"); //buttony pod navbarem // HorizontalLayout buttonsLayout = new HorizontalLayout(); // buttonsLayout.setStyleName("buttonToolBarLayout"); // buttonsLayout.setWidth("100%"); ////from w ww. ja v a2s . c o m // Button deleteButton = new Button(); // deleteButton.setCaption("SMAZAT"); // deleteButton.setWidth(null); // buttonsLayout.addComponent(deleteButton); // // Label plug = new Label(); // buttonsLayout.addComponent(plug); // // Button saveButton = new Button(); // saveButton.setCaption("ULOIT"); // saveButton.setWidth(null); // buttonsLayout.addComponent(saveButton); // buttonsLayout.setExpandRatio(plug, 1.0f); //combobox na zdroje a jmeno uzivatele List<Source> sourcesList = MockSource.mockSources(); HorizontalLayout sourceAndNameLayout = new HorizontalLayout(); sourceAndNameLayout.setWidth("100%"); sourceAndNameLayout.setStyleName("sourceAndNameLayout"); NativeSelect select = new NativeSelect(); select.setNullSelectionAllowed(false); System.out.println(Page.getCurrent().getBrowserWindowWidth()); String width = Page.getCurrent().getBrowserWindowWidth() / 2.5 + "px"; select.setWidth(width); select.addItems(sourcesList); for (Source s : sourcesList) { if (reservation.getSource().equals(s)) { select.select(s); break; } } sourceAndNameLayout.addComponent(select); Label plug2 = new Label(); sourceAndNameLayout.addComponent(plug2); Label name = new Label(reservation.getUser()); name.setWidth(null); sourceAndNameLayout.addComponent(name); sourceAndNameLayout.setExpandRatio(plug2, 1.0f); //datepickery DatePicker dateFrom = new DatePicker(); dateFrom.setStyleName("datePickerDetailView"); dateFrom.setValue(reservation.getBeginning()); dateFrom.setUseNative(true); dateFrom.setResolution(Resolution.TIME); dateFrom.setWidth("100%"); DatePicker dateTo = new DatePicker(); dateTo.setStyleName("datePickerDetailView"); dateTo.setValue(reservation.getEnding()); dateTo.setUseNative(true); dateTo.setResolution(Resolution.TIME); dateTo.setWidth("100%"); //layout pro slider a popisky HorizontalLayout sliderLayout = new HorizontalLayout(); sliderLayout.setStyleName("sliderLayout"); sliderLayout.setWidth("100%"); sliderLayout.setSpacing(true); Label sliderCaption = new Label("Po?et: "); sliderCaption.addStyleName("sliderCaption"); sliderCaption.setWidth(null); sliderLayout.addComponent(sliderCaption); final Label horvalue = new Label(); horvalue.setWidth("45px"); horvalue.setStyleName("value"); sliderLayout.addComponent(horvalue); final Slider horslider = new Slider(1, 10); horslider.setOrientation(SliderOrientation.HORIZONTAL); horslider.setValue(Double.valueOf(1)); horslider.getState(); horslider.getValue(); horslider.setImmediate(true); horslider.setWidth("100%"); sliderLayout.addComponent(horslider); sliderLayout.setExpandRatio(horslider, 1.0f); horvalue.setValue(String.valueOf(horslider.getValue().intValue())); horslider.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { int value = horslider.getValue().intValue(); horvalue.setValue(String.valueOf(value)); } }); //switch schvaleno HorizontalLayout switchLayout = new HorizontalLayout(); switchLayout.setStyleName("switchLayout"); switchLayout.addComponent(new Label("Schvleno:")); switchLayout.setSpacing(true); Switch checkbox = new Switch(null, true); switchLayout.addComponent(checkbox); //popis rezervace TextArea description = new TextArea(); description.setStyleName("descriptionDetailView"); description.setWidth("100%"); description.setImmediate(false); description.setCaption("Popis:"); description.setValue(reservation.getDescription()); //description.setRequired(true); description.setRequiredError("Popis mus bt zadn!"); description.setNullRepresentation(""); description.setReadOnly(true); //description.setRows(0); final VerticalLayout content = new VerticalLayout(); content.setMargin(true); content.setSpacing(true); content.addComponent(new ButtonToolBarLayout(this)); content.addComponent(sourceAndNameLayout); content.addComponent(dateFrom); content.addComponent(dateTo); content.addComponent(sliderLayout); content.addComponent(switchLayout); content.addComponent(description); setContent(content); }
From source file:com.wcs.wcslib.vaadin.widget.multifileupload.WidgetTestApplication.java
License:Apache License
private void addUploadSpeedSlider() { final Slider slider = new Slider("Delay (ms)"); slider.setWidth("200px"); slider.setImmediate(true);//from w ww. ja v a 2 s. c o m slider.setMin(0); slider.setMax(1000); slider.setValue(uploadSpeed); slider.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { uploadSpeed = slider.getValue(); } }); form.addComponent(slider); }
From source file:org.inakirj.imagerulette.screens.DiceURLSetupView.java
License:Open Source License
/** * Sets the layout./*www . j a v a2s . co m*/ */ private void setLayout() { imagesLayout = new VerticalComponentGroup(); imagesLayout.setWidth(100, Unit.PERCENTAGE); ImageUtils.getAllImageURL().stream().forEach(i -> { HorizontalLayout sliderLAyout = new HorizontalLayout(); if (imagesLayout.getComponentCount() % 2 == 0) { sliderLAyout.addStyleName("dice-banner-1"); } else { sliderLAyout.addStyleName("dice-banner-2"); } sliderLAyout.setWidth(100, Unit.PERCENTAGE); Image img = new Image("", i.getSource()); img.addStyleName("dice-image"); img.setData(i.getData()); Slider slider = new Slider(); slider.addStyleName("dice-slider"); Label total = new Label(); total.addStyleName("size-24");// TODO is not working // Adding image sliderLAyout.addComponent(img); // Adding slider slider.setMin(0); slider.setMax(5); slider.setWidth(80, Unit.PERCENTAGE); slider.addValueChangeListener(s -> { total.setValue("x " + slider.getValue().intValue()); enableDiceTabOrNot(); }); sliderLAyout.addComponent(slider); // Adding label total.setValue("x 0"); sliderLAyout.addComponent(total); sliderLAyout.setExpandRatio(img, 2); sliderLAyout.setExpandRatio(slider, 7); sliderLAyout.setExpandRatio(total, 1); sliderLAyout.setComponentAlignment(img, Alignment.BOTTOM_LEFT); sliderLAyout.setComponentAlignment(slider, Alignment.BOTTOM_LEFT); sliderLAyout.setComponentAlignment(total, Alignment.BOTTOM_LEFT); // Adding layout imagesLayout.addComponent(sliderLAyout); }); addComponent(imagesLayout); }
From source file:org.inakirj.imagerulette.screens.DiceURLSetupView.java
License:Open Source License
/** * Generate lottery list./*from ww w . j a va 2s.c o m*/ * * @return the list */ private List<Object> generateLotteryList() { List<Object> randomList = new ArrayList<>(); Iterator<Component> iterator = imagesLayout.iterator(); while (iterator.hasNext()) { HorizontalLayout hl = (HorizontalLayout) iterator.next(); Image imageSelected = (Image) hl.getComponent(0); Image img = new Image("", imageSelected.getSource()); img.setData(imageSelected.getData()); Slider slider = (Slider) hl.getComponent(1); int rep = slider.getValue().intValue(); while (rep > 0) { randomList.add(img); rep--; } } return randomList; }
From source file:org.inakirj.imagerulette.screens.DiceURLSetupView.java
License:Open Source License
/** * Enable dice tab or not./*from w w w . j a va2 s. c o m*/ */ private void enableDiceTabOrNot() { Iterator<Component> iterator = imagesLayout.iterator(); while (iterator.hasNext()) { HorizontalLayout hl = (HorizontalLayout) iterator.next(); Slider slider = (Slider) hl.getComponent(1); if (slider.getValue().intValue() > 0) { tabContent3.setEnabled(true); MyUI ui = (MyUI) UI.getCurrent(); ui.setLottery(generateLotteryList()); return; } } tabContent3.setEnabled(false); }
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/* www .jav a 2s. co 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.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 w w.ja v a 2s .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;"); }