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 dhbw.clippinggorilla.userinterface.views; import com.vaadin.data.HasValue; import com.vaadin.icons.VaadinIcons; import com.vaadin.server.FileResource; import com.vaadin.server.VaadinSession; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.ComboBox; import com.vaadin.ui.Component; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Image; import com.vaadin.ui.Label; import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; import dhbw.clippinggorilla.ClippingGorillaUI; import dhbw.clippinggorilla.utilities.language.Language; import dhbw.clippinggorilla.utilities.language.Word; import eu.maxschuster.vaadin.famfamflags.FamFamFlags; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Locale; import dhbw.clippinggorilla.utilities.ressources.FileUtils; import dhbw.clippinggorilla.utilities.log.Log; /** * This is the class for the Footerbar at the bottom of the screen * * @author frank */ public class FooterBar extends GridLayout { private static final HashMap<VaadinSession, FooterBar> SESSIONS = new HashMap<>(); public static FooterBar getCurrent() { return new FooterBar(); } public FooterBar() { setColumns(6); setRows(1); addStyleName("menubar"); setWidth("100%"); setHeightUndefined(); setColumnExpandRatio(4, 5); setSpacing(true); setMargin(true); Image logo = new Image(); try { logo.setSource(new FileResource(FileUtils.getFile("images/logo_small.png").toFile())); } catch (FileNotFoundException ex) { Log.error("Could not find logo!", ex); } logo.setHeight("100%"); addComponent(logo); setComponentAlignment(logo, Alignment.MIDDLE_CENTER); Button aboutUs = new Button(); Language.set(Word.ABOUT_US, aboutUs); aboutUs.addClickListener((ce) -> { ClippingGorillaUI.getCurrent().setMainContent(AboutUsView.getCurrent()); }); aboutUs.setIcon(VaadinIcons.USERS); aboutUs.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(aboutUs); setComponentAlignment(aboutUs, Alignment.MIDDLE_CENTER); Button docs = new Button(); Language.set(Word.DOCUMENTS, docs); docs.addClickListener(ce -> { ClippingGorillaUI.getCurrent().setMainContent(DocumentsView.getCurrent()); }); docs.setIcon(VaadinIcons.ARCHIVE); docs.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(docs); setComponentAlignment(docs, Alignment.MIDDLE_CENTER); Button impressum = new Button(); Language.set(Word.IMPRESSUM, impressum); impressum.addClickListener(ce -> { ClippingGorillaUI.getCurrent().setMainContent(ImpressumView.getCurrent()); }); impressum.setIcon(VaadinIcons.SCALE); impressum.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(impressum); setComponentAlignment(impressum, Alignment.MIDDLE_CENTER); Label spacing = new Label(); addComponent(spacing); setComponentAlignment(spacing, Alignment.MIDDLE_CENTER); ComboBox<Locale> languages = new ComboBox<>(null, Language.getAllLanguages().keySet()); languages.setItemCaptionGenerator(loc -> loc.getDisplayLanguage(loc)); if (!Language.getAllLanguages().containsKey(VaadinSession.getCurrent().getLocale())) { languages.setValue(Locale.ENGLISH); } else { languages.setValue(VaadinSession.getCurrent().getLocale()); } languages.setEmptySelectionAllowed(false); languages.setItemIconGenerator(FooterBar::getIcon); languages.addValueChangeListener( (HasValue.ValueChangeEvent<Locale> loc) -> Language.setLanguage(loc.getValue())); languages.setTextInputAllowed(false); addComponent(languages); setComponentAlignment(languages, Alignment.MIDDLE_CENTER); SESSIONS.put(VaadinSession.getCurrent(), this); } public static FamFamFlags getIcon(Locale locale) { FamFamFlags flag = FamFamFlags.fromCountry(locale.getLanguage().toUpperCase()); if (flag != null) { return flag; } else { switch (locale.getLanguage().toUpperCase()) { case "EN": return FamFamFlags.UNITED_KINGDOM; default: return FamFamFlags.FAM; } } } }