Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.fatalix.lighty.web.component; import com.vaadin.event.LayoutEvents; import com.vaadin.server.Page; import com.vaadin.ui.Alignment; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; import de.fatalix.lighty.web.LightyLabels; import de.fatalix.lighty.web.LightyPage; import de.fatalix.lighty.web.LightyTheme; /** * * @author Fatalix */ public class LightyNavigation extends HorizontalLayout { public LightyNavigation() { addStyleName(LightyTheme.HEADER_BACKGROUND); setWidth(100, Unit.PERCENTAGE); for (LightyPage lightyPage : LightyPage.values()) { NavigationButton navigationButton = new NavigationButton(lightyPage.getCaption(), lightyPage.getUrl()); addComponent(navigationButton); setComponentAlignment(navigationButton, Alignment.MIDDLE_CENTER); } } private class NavigationButton extends VerticalLayout { private final String fragment; public NavigationButton(String caption, String fragment) { setWidth(150, Unit.PIXELS); addStyleName(LightyTheme.CLICK_LAYOUT); this.fragment = fragment; Label captionLabel = new Label(caption); captionLabel.setSizeUndefined(); captionLabel.addStyleName(LightyLabels.NAVIGATION_BUTTON); addComponent(captionLabel); setComponentAlignment(captionLabel, Alignment.MIDDLE_CENTER); addLayoutClickListener(new LayoutEvents.LayoutClickListener() { @Override public void layoutClick(LayoutEvents.LayoutClickEvent event) { Page.getCurrent().setUriFragment("!" + NavigationButton.this.fragment); } }); } } }