List of usage examples for com.vaadin.ui Label setStyleName
@Override public void setStyleName(String style)
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/* w w w . j a v 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 ww w. j a v a 2 s. c o 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.mmowgliMobile.ui.FullEntryView2.java
License:Open Source License
public void setEntry(final ListEntry ent, ListView2 messageList) { entry = ent;/* www .j av a2 s . c om*/ //currentMessageList = messageList; if (ent != null) { renderer = getRenderer(ent); removeStyleName("no-message"); renderer.setMessage(this, ent, messageList, layout); } else { layout.removeAllComponents(); Label noMessageLbl = new Label("No Message Selected"); noMessageLbl.setStyleName(Reindeer.LABEL_SMALL); noMessageLbl.addStyleName(Reindeer.LABEL_H1); layout.addComponent(noMessageLbl); addStyleName("no-message"); } updateNewListItems(); }
From source file:edu.nps.moves.mmowgliMobile.ui.UserRenderer2.java
License:Open Source License
public void addRow(GridLayout lay, String label, String value) { Label lbl; lay.addComponent(lbl = new Label(label)); lbl.setStyleName("light-text"); lbl.setSizeUndefined();/*from w w w . j a v a 2 s .c o m*/ lay.setComponentAlignment(lbl, Alignment.TOP_RIGHT); lay.addComponent(new HtmlLabel(value)); }
From source file:eu.livotov.labs.webskel.app.MainUI.java
License:Apache License
protected void init(final VaadinRequest vaadinRequest) { Label hello = new Label("Hello Web Skeleton WebApp User !"); hello.setStyleName(ValoTheme.LABEL_H1); Button b = new Button("Log me now !"); b.setStyleName(ValoTheme.BUTTON_DANGER); b.addClickListener(new Button.ClickListener() { public void buttonClick(final Button.ClickEvent event) { logsDao.addLogEntry("Hello, it is me you looking for..."); }/*from www . ja va 2 s.com*/ }); VerticalLayout root = new VerticalLayout(); root.setSizeFull(); root.setMargin(true); root.setSpacing(true); root.addComponent(hello); root.addComponent(b); root.setExpandRatio(hello, 1.0f); setContent(root); }
From source file:fi.jasoft.draganddrop.demos.DragDemo.java
License:Apache License
@Override protected Component getDemoContent() { HorizontalLayout hl = new HorizontalLayout(); hl.setSizeFull();//ww w . j av a 2 s . c o m // source-start // Create image Image image = new Image(null, new ThemeResource("graphics/bin.jpg")); // Enable dropping items on image DragAndDrop.enable(image, DragAndDropOperation.DROP) // Set custom drop handler .onDrop(new DropHandler<Image>() { @Override protected void onDrop(Component component) { // Restor trash bin getSource().setSource(new ThemeResource("graphics/bin.jpg")); // Remove item ((ComponentContainer) component.getParent()).removeComponent(component); } }) // Set custom over handler .onOver(new DragOverHandler<Image>() { @Override protected void onOver(Component component) { // Add color to trash bin getSource().setSource(new ThemeResource("graphics/bin2.jpg")); } }) // Set custom out handler .onOut(new DragOutHandler<Image>() { @Override protected void onOut(Component component) { // Restore trash bin getSource().setSource(new ThemeResource("graphics/bin.jpg")); } }); // source-end hl.addComponent(image); hl.setComponentAlignment(image, Alignment.TOP_CENTER); VerticalLayout vl = new VerticalLayout(); vl.setSizeUndefined(); vl.setSpacing(true); hl.addComponent(vl); hl.setComponentAlignment(vl, Alignment.TOP_CENTER); // source-start /* * Create item list to drag from */ for (int i = 0; i < 5; i++) { Label item = new Label("Item " + (i + 1)); item.setStyleName("item"); item.setSizeUndefined(); // Enable dragging the items DragAndDrop.enable(item, DragAndDropOperation.DRAG); vl.addComponent(item); } // source-end return hl; }
From source file:fi.jasoft.draganddrop.demos.ListDemo.java
License:Apache License
@Override protected Component getDemoContent() { // start-source // Create shopping list VerticalLayout list = new VerticalLayout(); list.setSpacing(true);/*ww w . j av a2 s. co m*/ // Add some items List<String> items = Arrays.asList("Carrots", "Apples", "Lemons", "Broccoli", "Ginger"); for (String caption : items) { Label item = new Label(caption); item.setStyleName("item"); list.addComponent(item); } // Enable drag and drop reordering for the list DragAndDrop.enable(list); // end-source return list; }
From source file:fi.jasoft.draganddrop.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { Panel showcase = new Panel(); showcase.setSizeUndefined();// w w w.j a v a 2 s. c o m navigator = new Navigator(this, showcase); for (DemoView view : views) { navigator.addView(view.getViewPath(), view); } // default openView(views.get(0)); MenuBar demos = new MenuBar(); demos.setStyleName(ValoTheme.MENUBAR_BORDERLESS); for (final DemoView view : views) { demos.addItem(view.getViewCaption(), new Command() { @Override public void menuSelected(MenuItem selectedItem) { openView(view); } }); } VerticalLayout root = new VerticalLayout(demos, showcase); root.setSizeFull(); root.setExpandRatio(showcase, 1); root.setComponentAlignment(showcase, Alignment.MIDDLE_CENTER); setContent(root); HorizontalLayout sourceWrapperLayout = new HorizontalLayout(); Label caption = new Label("Source code for example"); caption.setStyleName("source-caption"); sourceWrapperLayout.addComponent(caption); Panel sourceWrapper = new Panel(codeLabel); sourceWrapper.setStyleName(ValoTheme.PANEL_BORDERLESS); sourceWrapper.setHeight(getPage().getBrowserWindowHeight() + "px"); sourceWrapperLayout.addComponent(sourceWrapper); sourceWrapperLayout.setExpandRatio(sourceWrapper, 1); Toolbox sourceBox = new Toolbox(); sourceBox.setOrientation(ORIENTATION.RIGHT_CENTER); sourceBox.setContent(sourceWrapperLayout); sourceBox.setOverflowSize(30); root.addComponent(sourceBox); }
From source file:fi.jasoft.dragdroplayouts.demo.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { VerticalLayout content = new VerticalLayout(); content.setSizeFull();//from ww w . j a v a 2 s .c om setContent(content); Label header = new Label("DragDropLayouts for Vaadin 8"); header.setStyleName(ValoTheme.LABEL_H1); content.addComponent(header); HorizontalLayout hl = new HorizontalLayout(); hl.setSizeFull(); content.addComponent(hl); content.setExpandRatio(hl, 1); VerticalSplitPanel split = new VerticalSplitPanel(); hl.addComponent(split); hl.setExpandRatio(split, 1); CssLayout placeHolder = new CssLayout(new Label("No view selected.")); placeHolder.setSizeFull(); split.setFirstComponent(placeHolder); Panel codePanel = new Panel(codeLabel); codePanel.setSizeFull(); split.setSecondComponent(codePanel); navigator = new Navigator(this, placeHolder); navigator.addViewChangeListener(new ViewChangeListener() { @Override public boolean beforeViewChange(ViewChangeEvent event) { DemoView view = (DemoView) event.getNewView(); selection.getSelectionModel().select(view); codeLabel.setValue(getFormattedSourceCode(view.getSource())); return true; } @Override public void afterViewChange(ViewChangeEvent event) { // TODO Auto-generated method stub } }); try { addView(new DragdropAbsoluteLayoutDemo(navigator)); addView(new DragdropVerticalLayoutDemo(navigator)); addView(new DragdropHorizontalLayoutDemo(navigator)); addView(new DragdropGridLayoutDemo(navigator)); addView(new DragdropCssLayoutDemo(navigator)); addView(new DragdropFormLayoutDemo(navigator)); addView(new DragdropPanelDemo(navigator)); addView(new DragdropLayoutDraggingDemo(navigator)); addView(new DragdropHorizontalSplitPanelDemo(navigator)); addView(new DragdropVerticalSplitPanelDemo(navigator)); addView(new DragdropTabsheetDemo(navigator)); addView(new DragdropAccordionDemo(navigator)); addView(new DragdropDragFilterDemo(navigator)); addView(new DragdropCaptionModeDemo(navigator)); addView(new DragdropV7VerticalLayoutDemo(navigator)); addView(new DragdropV7HorizontalLayoutDemo(navigator)); // addView(new DragdropIframeDragging(navigator)); } catch (Exception e) { e.printStackTrace(); return; } hl.addComponent(selection = createViewSelection(), 0); String fragment = Page.getCurrent().getUriFragment(); if (fragment == null || fragment.equals("")) { navigator.navigateTo(DragdropAbsoluteLayoutDemo.NAME); } }
From source file:fi.jasoft.feedreader.ui.ReaderUI.java
License:Apache License
/** * Set the content of the feed entry window. * /*from w ww.ja va2 s . co m*/ * @param entry * The feed entry to show */ private void setContent(FeedEntry entry) { VerticalLayout content = new VerticalLayout(); content.setMargin(true); if (entry != null) { Label title = new Label(entry.getTitle()); title.setStyleName(Reindeer.LABEL_H1); content.addComponent(title); Label entryContent = new Label(entry.getContent(), ContentMode.HTML); content.addComponent(entryContent); } entryPanel.setContent(content); }