List of usage examples for com.vaadin.ui NativeButton setDescription
public void setDescription(String description)
From source file:edu.kit.dama.ui.commons.util.PaginationLayout.java
License:Apache License
/** * Update the layout. This method is either called internally when scrolling * or/*from w w w . j av a 2 s. c o m*/ */ public final void update() { //remove all components (old result page and navigation) removeAllComponents(); //add current results renderPage(); //build pagination int pages = overallEntries / entriesPerPage; if (overallEntries % entriesPerPage > 0) { pages++; } final int overallPages = pages; HorizontalLayout navigation = new HorizontalLayout(); //add "JumpToFirstPage" button final NativeButton first = new NativeButton(); first.setIcon(firstIcon); if (firstIcon == null) { first.setCaption("<<"); } first.setDescription("First Page"); first.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { currentPage = 0; update(); } }); //add "PreviousPage" button final NativeButton prev = new NativeButton(); prev.setIcon(prevIcon); if (prevIcon == null) { prev.setCaption("<"); } prev.setDescription("Previous Page"); prev.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (currentPage > 0) { currentPage--; update(); } } }); //add "NextPage" button final NativeButton next = new NativeButton(); next.setIcon(nextIcon); if (nextIcon == null) { next.setCaption(">"); } next.setDescription("Next Page"); next.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (currentPage + 1 < overallPages) { currentPage++; update(); } } }); //add "JumpToLastPage" button final NativeButton last = new NativeButton(); last.setIcon(endIcon); if (endIcon == null) { next.setCaption(">>"); } last.setDescription("Last Page"); last.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { currentPage = overallPages - 1; update(); } }); //enable/disable buttons depending on the current page if (overallPages == 0) { first.setEnabled(false); prev.setEnabled(false); next.setEnabled(false); last.setEnabled(false); } else { first.setEnabled(!(currentPage == 0) || !(overallPages < 2)); prev.setEnabled(!(currentPage == 0) || !(overallPages < 2)); next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2)); last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2)); } //at first, put the page size selection box into the navigation final ComboBox entriesPerPageBox = new ComboBox(); entriesPerPageBox.setItemCaptionPropertyId("name"); entriesPerPageBox.addContainerProperty("name", String.class, null); entriesPerPageBox.addItem(5); entriesPerPageBox.getContainerProperty(5, "name").setValue("5 Entries / Page"); entriesPerPageBox.addItem(10); entriesPerPageBox.getContainerProperty(10, "name").setValue("10 Entries / Page"); entriesPerPageBox.addItem(15); entriesPerPageBox.getContainerProperty(15, "name").setValue("15 Entries / Page"); entriesPerPageBox.addItem(20); entriesPerPageBox.getContainerProperty(20, "name").setValue("20 Entries / Page"); entriesPerPageBox.setValue(entriesPerPage); entriesPerPageBox.setNullSelectionAllowed(false); entriesPerPageBox.setImmediate(true); entriesPerPageBox.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { entriesPerPage = (Integer) entriesPerPageBox.getValue(); update(); } }); navigation.addComponent(entriesPerPageBox); //filler labels are added to the beginning and to the end to keep the navigation in the middle Label leftFiller = new Label(); leftFiller.setWidth("25px"); navigation.addComponent(leftFiller); navigation.addComponent(first); navigation.addComponent(prev); //Show max. 10 pages at once for performance and layout reasons. //If there are more than 10 pages, "move" the to show 10 pages based on the current page. int start = currentPage - 5; start = (start < 0) ? 0 : start; int end = start + 10; end = (end > pages) ? pages : end; if (end - start < 10 && pages > 10) { start = end - 10; } if (overallPages == 0) { Label noEntryLabel = new Label("<i>No entries</i>", Label.CONTENT_XHTML); //noEntryLabel.setWidth("80px"); noEntryLabel.setSizeUndefined(); navigation.addComponent(noEntryLabel); navigation.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER); } //build the actual page entries for (int i = start; i < end; i++) { if (i == currentPage) { //the current page is marked with a special style Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", Label.CONTENT_XHTML); pageLink.setStyleName("currentpage"); pageLink.setWidth("15px"); navigation.addComponent(pageLink); navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER); } else { //otherwise normal links are added, click-events are handled via LayoutClickListener Link pageLink = new Link(Integer.toString(i + 1), null); navigation.addComponent(pageLink); navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER); } } //add right navigation buttons navigation.addComponent(next); navigation.addComponent(last); //...and fill the remaining space Label rightFiller = new Label(); navigation.addComponent(rightFiller); // navigation.setExpandRatio(leftFiller, 1.0f); navigation.setExpandRatio(rightFiller, 1.0f); navigation.setSpacing(true); //put everything ot the middle navigation.setComponentAlignment(first, Alignment.MIDDLE_CENTER); navigation.setComponentAlignment(prev, Alignment.MIDDLE_CENTER); navigation.setComponentAlignment(next, Alignment.MIDDLE_CENTER); navigation.setComponentAlignment(last, Alignment.MIDDLE_CENTER); //add layout click listener to be able to navigate by clicking the single pages navigation.addListener(new LayoutEvents.LayoutClickListener() { @Override public void layoutClick(LayoutEvents.LayoutClickEvent event) { // Get the child component which was clicked Component child = event.getChildComponent(); if (child == null) { // Not over any child component } else { // Over a child component if (child instanceof Link) { // Over a valid child element currentPage = Integer.parseInt(((Link) child).getCaption()) - 1; update(); } } } }); //finalize navigation.setWidth("100%"); navigation.setHeight("25px"); //add navigation and align it right below the result page addComponent(page); setExpandRatio(page, 1f); if (overallEntries > 0) { addComponent(navigation); setComponentAlignment(navigation, Alignment.BOTTOM_CENTER); setExpandRatio(navigation, .05f); } requestRepaint(); }
From source file:edu.kit.dama.ui.repo.components.PaginationPanel.java
License:Apache License
/** * Build the navigation layout including the appropriate buttons to navigate * through the pagination pages./*from www . java 2 s.co m*/ * * @return The navigation layout component. */ private HorizontalLayout buildNavigationComponent() { HorizontalLayout result = new HorizontalLayout(); //add "JumpToFirstPage" button final NativeButton first = new NativeButton(); first.setIcon(new ThemeResource("img/16x16/beginning.png")); first.setDescription("First Page"); first.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { currentPage = 0; updatePage(); } }); //add "PreviousPage" button final NativeButton prev = new NativeButton(); prev.setIcon(new ThemeResource("img/16x16/prev.png")); prev.setDescription("Previous Page"); prev.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (currentPage > 0) { currentPage--; updatePage(); } } }); //add "NextPage" button final NativeButton next = new NativeButton(); next.setDescription("Next Page"); next.setIcon(new ThemeResource("img/16x16/next.png")); next.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (currentPage + 1 < overallPages) { currentPage++; updatePage(); } } }); //add "JumpToLastPage" button final NativeButton last = new NativeButton(); last.setDescription("Last Page"); last.setIcon(new ThemeResource("img/16x16/end.png")); last.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { currentPage = overallPages - 1; updatePage(); } }); //enable/disable buttons depending on the current page if (overallPages == 0) { first.setEnabled(false); prev.setEnabled(false); next.setEnabled(false); last.setEnabled(false); } else { first.setEnabled(!(currentPage == 0) || !(overallPages < 2)); prev.setEnabled(!(currentPage == 0) || !(overallPages < 2)); next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2)); last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2)); } Label leftFiller = new Label(); result.addComponent(leftFiller); result.setExpandRatio(leftFiller, 1.0f); result.addComponent(first); result.addComponent(prev); int start = currentPage - 5; start = (start < 0) ? 0 : start; int end = start + 10; end = (end > overallPages) ? overallPages : end; if (end - start < 10 && overallPages > 10) { start = end - 10; } if (overallPages == 0) { Label noEntryLabel = new Label("<i>No entries</i>", ContentMode.HTML); //noEntryLabel.setWidth("80px"); noEntryLabel.setSizeUndefined(); result.addComponent(noEntryLabel); result.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER); } //build the actual page entries for (int i = start; i < end; i++) { if (i == currentPage) { //the current page is marked with a special style Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", ContentMode.HTML); pageLink.setStyleName("currentpage"); pageLink.setWidth("15px"); result.addComponent(pageLink); result.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER); } else { //otherwise normal links are added, click-events are handled via LayoutClickListener Link pageLink = new Link(Integer.toString(i + 1), null); result.addComponent(pageLink); result.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER); } } //add right navigation buttons result.addComponent(next); result.addComponent(last); //...and fill the remaining space Label rightFiller = new Label(); result.addComponent(rightFiller); result.setExpandRatio(rightFiller, 1.0f); result.setSpacing(true); //put everything ot the middle result.setComponentAlignment(first, Alignment.MIDDLE_CENTER); result.setComponentAlignment(prev, Alignment.MIDDLE_CENTER); result.setComponentAlignment(next, Alignment.MIDDLE_CENTER); result.setComponentAlignment(last, Alignment.MIDDLE_CENTER); //add layout click listener to be able to navigate by clicking the single pages result.addLayoutClickListener(new LayoutEvents.LayoutClickListener() { @Override public void layoutClick(LayoutEvents.LayoutClickEvent event) { // Get the child component which was clicked Component child = event.getChildComponent(); if (child == null) { // Not over any child component } else // Over a child component { if (child instanceof Link) { } } } }); //finalize result.setWidth("100%"); result.setHeight("25px"); return result; }
From source file:edu.nps.moves.mmowgli.modules.cards.CallToActionPage.java
License:Open Source License
public void initGui() { Object sessKey = HSess.checkInit(); Label spacer = new Label(); spacer.setWidth(CALLTOACTION_HOR_OFFSET_STR); addComponent(spacer);// w ww . jav a 2 s . co m VerticalLayout mainVl = new VerticalLayout(); addComponent(mainVl); mainVl.setSpacing(true); mainVl.setWidth("100%"); MovePhase phase = MovePhase.getCurrentMovePhaseTL(); String sum = phase.getCallToActionBriefingSummary(); String tx = phase.getCallToActionBriefingText(); Media v = phase.getCallToActionBriefingVideo(); Embedded headerImg = new Embedded(null, Mmowgli2UI.getGlobals().mediaLocator().getCallToActionBang()); headerImg.setDescription("Review motivation and purpose of this game"); NativeButton needButt = new NativeButton(); needButt.setStyleName("m-weNeedYourHelpButton"); vidPan = new VideoWithRightTextPanel(v, headerImg, sum, tx, needButt); // needImg); vidPan.initGui(); mainVl.addComponent(vidPan); String playCardString = Game.getTL().getCurrentMove().getCurrentMovePhase().getPlayACardTitle(); NativeButton butt; if (!mockupOnly) butt = new IDNativeButton(playCardString, MmowgliEvent.PLAYIDEACLICK); else butt = new NativeButton(playCardString); // no listener butt.addStyleName("borderless"); butt.addStyleName("m-calltoaction-playprompt"); butt.setDescription("View existing cards and play new ones"); mainVl.addComponent(butt); mainVl.setComponentAlignment(butt, Alignment.MIDDLE_CENTER); HSess.checkClose(sessKey); }
From source file:edu.nps.moves.mmowgli.modules.userprofile.UserProfile3Top.java
License:Open Source License
private void displayBadgesAndAwards(Object uid, Session sess) { MediaLocator loc = Mmowgli2UI.getGlobals().getMediaLocator(); ClickListener lis = new BadgeListener(); Game g = Game.get(sess);/* www .ja v a 2s . com*/ MSysOut.println(DEBUG_LOGS, "User.get(sess) from UserProfile3Top.displayBadgesAndAwards(sess)"); User u = User.get(uid, sess); Set<Badge> badges = u.getBadges(); badgeLayout.removeAllComponents(); @SuppressWarnings("unchecked") List<Badge> list = (List<Badge>) sess.createCriteria(Badge.class).addOrder(Order.asc("badge_pk")).list(); int nDefinedBadges = list.size(); for (int b = 0; b < nDefinedBadges; b++) { Badge bd = getBadgeById(badges, b + 1); badgeButts[b] = new NativeButton(); badgeButts[b].addStyleName("m-badgeButton"); badgeLayout.addComponent(badgeButts[b]); if (bd != null) { badgeButts[b].setIcon(loc.locate(bd.getMedia())); badgeButts[b].setDescription(getBadgeDescription(g, bd)); // check for undesired action plan mention badgeButts[b].addClickListener(lis); } else { badgeButts[b].setIcon(loc.getEmptyBadgeImage()); if (!((b + 1) == BADGE_EIGHT_ID)) badgeButts[b].setDescription(getBadgeDescription(g, list.get(b))); // check for undesired action plan mention } } List<AwardButton> ablis = getAwardButtons(u, sess); Iterator<AwardButton> bItr = ablis.iterator(); for (int i = 0; i < 4; i++) { NativeButton awb = bItr.hasNext() ? bItr.next() : null; if (awb == null) { awb = new NativeButton(); awb.addStyleName("m-badgeButton"); awb.setDescription("Game-specific awards"); awb.setIcon(loc.getEmptyBadgeImage()); } badgeLayout.addComponent(awb); } }
From source file:org.jdal.vaadin.ui.FormUtils.java
License:Apache License
/** * Create a new {@link NativeButton} from an {@link ButtonListener} * @param action button listener/*from ww w . ja v a 2 s. c o m*/ * @return a new native button. */ public static NativeButton newNativeButton(ButtonListener action) { NativeButton b = new NativeButton(action.getCaption(), action); b.setIcon(action.getIcon()); b.setDescription(action.getDescription()); return b; }
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.j av a 2 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; }