List of usage examples for com.vaadin.ui Slider setValue
@Override public void setValue(Double value)
From source file:fi.vtt.RVaadin.RContainer.java
License:Apache License
/** * Internal function to build differently parameterized Sliders for * {@link RContainer#getSlider(String, double, double, int)} and * {@link RContainer#getSlider(String, int, int)}. * /*w ww .j a va 2 s.c o m*/ * @param parName * @param slider */ private void buildSlider(final String parName, Slider slider) { Double parValue = getDouble(parName); try { slider.setValue(parValue); assign(parName, parValue); } catch (ValueOutOfBoundsException e) { /* * The value must be between the min and max, and we indicate that * by disabling the slider */ slider.setEnabled(false); } ValueChangeListener sliderChanged = new ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { Double val = (Double) event.getProperty().getValue(); assign(parName, val); } }; slider.addValueChangeListener(sliderChanged); slider.setImmediate(true); }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
Layout getSliderPreviews() throws ValueOutOfBoundsException { Layout grid = getPreviewLayout("Sliders"); Slider s = new Slider(); s.setWidth("200px"); s.setValue(50); grid.addComponent(s);/*from w w w .ja va2s .co m*/ s = new Slider(); s.setOrientation(Slider.ORIENTATION_VERTICAL); s.setHeight("70px"); s.setValue(50); grid.addComponent(s); return grid; }
From source file:org.lunifera.examples.runtime.web.vaadin.databinding.DatabindingDemoUI.java
License:Open Source License
private void row4(GridLayout layout) { Slider slider = new Slider("width"); slider.setImmediate(true);//from w w w . ja va 2s .co m slider.setBuffered(false); slider.setWidth("150px"); layout.addComponent(slider, 0, 3); TextField heightInput = new TextField("height"); heightInput.setImmediate(true); heightInput.setBuffered(false); layout.addComponent(heightInput, 1, 3); slider.setMax(200); slider.setValue(20d); heightInput.setValue("10px"); TextField input2 = new TextField("sizeable"); layout.addComponent(input2, 2, 3); dbc.bindValue(VaadinObservables.observeWidth(input2), VaadinObservables.observeValue(slider), null, new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE).setConverter(new IConverter() { @Override public Object getToType() { return String.class; } @Override public Object getFromType() { return Object.class; } @Override public Object convert(Object fromObject) { double value = (Double) fromObject; return String.format("%s%s", Double.toString(value), Unit.PIXELS.getSymbol()); } })); dbc.bindValue(VaadinObservables.observeHeight(input2), VaadinObservables.observeValue(heightInput)); }
From source file:org.metawidget.vaadin.ui.widgetbuilder.VaadinWidgetBuilder.java
License:LGPL
public Component buildWidget(String elementName, Map<String, String> attributes, VaadinMetawidget metawidget) { // Hidden// w w w .j a v a2s. c om if (TRUE.equals(attributes.get(HIDDEN))) { return new Stub(); } // Action if (ACTION.equals(elementName)) { return new Button(); } // Lookup the Class Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class); // Support mandatory Booleans (can be rendered as a checkbox, even // though they have a Lookup) if (Boolean.class.equals(clazz) && TRUE.equals(attributes.get(REQUIRED))) { return new CheckBox(); } // Lookups String lookup = attributes.get(LOOKUP); if (lookup != null && !"".equals(lookup)) { return createSelectComponent(attributes, lookup, metawidget); } if (clazz != null) { // Primitives if (clazz.isPrimitive()) { // booleans if (boolean.class.equals(clazz)) { return new CheckBox(); } // chars if (char.class.equals(clazz)) { TextField textField = new TextField(); textField.setMaxLength(1); return textField; } // Ranged String minimumValue = attributes.get(MINIMUM_VALUE); String maximumValue = attributes.get(MAXIMUM_VALUE); if (minimumValue != null && !"".equals(minimumValue) && maximumValue != null && !"".equals(maximumValue)) { Slider slider = new Slider(); slider.setMin(Double.parseDouble(minimumValue)); try { // Use big 'D' Double for Vaadin 6/7 compatibility slider.setValue(Double.valueOf(slider.getMin())); } catch (ValueOutOfBoundsException e) { throw WidgetBuilderException.newException(e); } slider.setMax(Double.parseDouble(maximumValue)); return slider; } // Not-ranged return createTextField(attributes); } // Strings if (String.class.equals(clazz)) { if (TRUE.equals(attributes.get(MASKED))) { return new PasswordField(); } if (TRUE.equals(attributes.get(LARGE))) { return new TextArea(); } return createTextField(attributes); } // Characters if (Character.class.isAssignableFrom(clazz)) { TextField textField = new TextField(); textField.setMaxLength(1); return textField; } // Dates if (Date.class.equals(clazz)) { return new PopupDateField(); } // Numbers // // Note: we use a text field, not a JSpinner or JSlider, because // BeansBinding gets upset at doing 'setValue( null )' if the Integer // is null. We can still use JSpinner/JSliders for primitives, though. if (Number.class.isAssignableFrom(clazz)) { return createTextField(attributes); } // Collections if (Collection.class.isAssignableFrom(clazz)) { return new Stub(); } } // Not simple, but don't expand if (TRUE.equals(attributes.get(DONT_EXPAND))) { return createTextField(attributes); } return null; }
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/*w w w.ja va 2 s .c om*/ 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.vaadin.miki.widgets.ItemGridUI.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w ww .j av a 2s .co m protected void init(VaadinRequest request) { this.primary.addContainerProperty("text", String.class, ""); this.primary.addContainerProperty("number", Integer.class, 0); this.primary.addContainerProperty("bool", Boolean.class, false); for (int zmp1 = 0; zmp1 < 15; zmp1++) { Item item = this.primary.addItem(zmp1); item.getItemProperty("text").setValue("number " + zmp1); item.getItemProperty("number").setValue(zmp1 * 3); item.getItemProperty("bool").setValue((zmp1 % 3) == 1); } this.secondary.addContainerProperty("caption", String.class, "default"); this.secondary.addContainerProperty("price", Double.class, 1.99); for (int zmp1 = 5; zmp1 < 60; zmp1 += 3) { Item item = this.secondary.addItem(zmp1); item.getItemProperty("caption").setValue("this is item with id " + zmp1); item.getItemProperty("price").setValue(1.0 / zmp1); } final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); this.setContent(layout); final ItemGrid grid = new ItemGrid(); grid.setContainerDataSource(this.primary); grid.setItemComponentGenerator(this.generator); layout.addComponent(grid); Slider slider = new Slider(1, 20); slider.setCaption("Select number of columns:"); slider.setValue(new Double(grid.getColumnCount())); slider.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140509; @Override public void valueChange(Property.ValueChangeEvent event) { Object number = event.getProperty().getValue(); if (number != null) grid.setColumnCount((int) Math.round((Double) number)); } }); slider.setSizeFull(); layout.addComponent(slider); CheckBox selectable = new CheckBox("Selectable?", grid.isSelectable()); selectable.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140510; @Override public void valueChange(Property.ValueChangeEvent event) { grid.setSelectable((Boolean) event.getProperty().getValue()); } }); layout.addComponent(selectable); CheckBox nullSelection = new CheckBox("Null selection allowed?", grid.isNullSelectionAllowed()); nullSelection.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140512; @Override public void valueChange(Property.ValueChangeEvent event) { grid.setNullSelectionAllowed((Boolean) event.getProperty().getValue()); } }); layout.addComponent(nullSelection); CheckBox multiSelection = new CheckBox("Multiple selection allowed?", grid.isMultiSelect()); multiSelection.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140512; @Override public void valueChange(Property.ValueChangeEvent event) { grid.setMultiSelect((Boolean) event.getProperty().getValue()); } }); layout.addComponent(multiSelection); CheckBox defaultGenerator = new CheckBox("Use ItemGrid's default component generator?"); defaultGenerator.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140513; @Override public void valueChange(Property.ValueChangeEvent event) { if ((Boolean) event.getProperty().getValue()) grid.setItemComponentGenerator(null); else grid.setItemComponentGenerator(ItemGridUI.this.generator); } }); layout.addComponent(defaultGenerator); ListSelect container = new ListSelect("Container data source", Arrays.asList(this.primary, this.secondary)); container.setNullSelectionAllowed(false); container.setItemCaption(this.primary, "Primary container"); container.setItemCaption(this.secondary, "Backup container"); container.select(this.primary); container.setImmediate(true); container.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140514; @Override public void valueChange(ValueChangeEvent event) { grid.setContainerDataSource((Container) event.getProperty().getValue()); } }); layout.addComponent(container); Button addItem = new Button("Add item to current container", new Button.ClickListener() { private static final long serialVersionUID = 20140515; @Override public void buttonClick(ClickEvent event) { grid.getContainerDataSource().addItem(grid.getContainerDataSource().size() + 0.5); } }); layout.addComponent(addItem); }