Java Code Examples for com.vaadin.ui.HorizontalLayout.setExpandRatio()

The following are Jave code examples for showing how to use setExpandRatio() of the com.vaadin.ui.HorizontalLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: esup-ecandidat   File: CtrCandFormationView.java   Source Code and License Vote up 6 votes
/**
 * @param txtCode
 * @return une ligne de légende
 */
private HorizontalLayout getLegendLineLayout(String txtCode) {
	HorizontalLayout hlLineLegend = new HorizontalLayout();
	hlLineLegend.setWidth(100, Unit.PERCENTAGE);
	hlLineLegend.setSpacing(true);

	Image flagImg = new Image(null, new ThemeResource("images/icon/Flag-" + txtCode + "-icon.png"));
	Label label = new Label(applicationContext.getMessage("formation.table.flagEtat.tooltip." + txtCode, null,
			UI.getCurrent().getLocale()));
	hlLineLegend.addComponent(flagImg);
	hlLineLegend.setComponentAlignment(flagImg, Alignment.MIDDLE_LEFT);
	hlLineLegend.addComponent(label);
	hlLineLegend.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
	hlLineLegend.setExpandRatio(label, 1);
	return hlLineLegend;
}
 
Example 2
Project: javamagazin-009-microkernel   File: MainView.java   Source Code and License Vote up 5 votes
private HorizontalLayout mainLayout() {
  menuLayout = new VerticalLayout();
  menuLayout.setStyleName(ValoTheme.MENU_ROOT);
  menuLayout.setWidth(100, Unit.PERCENTAGE);
  menuLayout.setHeight(100, Unit.PERCENTAGE);
  menuLayout.setSizeFull();

  final CssLayout menuButtons = new CssLayout();
  menuButtons.setSizeFull();
  menuButtons.addStyleName(ValoTheme.MENU_PART);
  menuButtons.addStyleName(ValoTheme.MENU_PART_LARGE_ICONS);

  menuButtons.addComponents(
      createMenuButton(VaadinIcons.VIEWPORT, "Dashboard", DashboardComponent::new),
      createMenuButton(VaadinIcons.SITEMAP, "Sitemap", DashboardComponent::new),
      createMenuButton(VaadinIcons.CALC_BOOK, "Calculate", CalcComponent::new),
      createMenuButton(VaadinIcons.NOTEBOOK, "Write", WriteComponent::new),
      createMenuButtonForNotification(VaadinIcons.EXIT, "Logout", "You want to go?")
  );
  menuLayout.addComponent(menuButtons);

  contentLayout = new CssLayout(new Label("Content"));
  contentLayout.setSizeFull();

  final HorizontalLayout layout = new HorizontalLayout();
  layout.setSizeFull();
  layout.addComponent(menuLayout);
  layout.addComponent(contentLayout);

  layout.setExpandRatio(menuLayout, 0.20f);
  layout.setExpandRatio(contentLayout, 0.80f);

  return layout;
}
 
Example 3
Project: esup-ecandidat   File: RequiredColorPickerField.java   Source Code and License Vote up 5 votes
/**
 * Constructeur, initialisation du champs
 */
public RequiredColorPickerField(String caption) {
	super();
	layout = new HorizontalLayout();
	layout.setWidth(100, Unit.PERCENTAGE);
	layout.setSpacing(true);
	colorTextField = new TextField();
	colorTextField.addValueChangeListener(e->showOrHideError());
	colorTextField.setNullRepresentation("");
	colorTextField.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
	colorTextField.setReadOnly(true);

	btnColor = new ColorPicker("Couleur de l'alerte");
	btnColor.addColorChangeListener(e->{
		changeFieldValue(e.getColor().getCSS());
	});
	btnColor.setPosition(Page.getCurrent().getBrowserWindowWidth() / 2 - 246/2,
               Page.getCurrent().getBrowserWindowHeight() / 2 - 507/2);
	btnColor.setSwatchesVisibility(true);
	btnColor.setHistoryVisibility(false);
	btnColor.setTextfieldVisibility(true);
	btnColor.setHSVVisibility(false);
	layout.addComponent(btnColor);
	layout.addComponent(colorTextField);
	layout.setExpandRatio(colorTextField, 1);
	
}
 
Example 4
Project: esup-ecandidat   File: I18nField.java   Source Code and License Vote up 5 votes
/** Renvoie un layout contenant un choix de langue et une traduction
 * @param traductionOther
 * @return le layout
 */
private HorizontalLayout getLangueLayout(I18nTraduction traductionOther){
	/*Le layout renvoyé*/
	HorizontalLayout hlLangueOther = new HorizontalLayout();
	listLayoutTraductions.add(hlLangueOther);
	hlLangueOther.setSpacing(true);
	hlLangueOther.setWidth(100, Unit.PERCENTAGE);
	
	/*La combobox avec les icones de drapeaux*/
	ComboBoxLangue cbLangue = new ComboBoxLangue(listeLangueEnService,false);
	cbLangue.selectLangue((traductionOther==null?null:traductionOther.getLangue()));
	cbLangue.setWidth(75, Unit.PIXELS);
	hlLangueOther.addComponent(cbLangue);
	
	/*Le textField... ou */
	AbstractField<String> tfValOther = getNewValueComponent();		
	tfValOther.setWidth(100, Unit.PERCENTAGE);
	if (traductionOther!=null){
		tfValOther.setValue(traductionOther.getValTrad());
	}		
	hlLangueOther.addComponent(tfValOther);
	hlLangueOther.setExpandRatio(tfValOther,1);
	
	/*Le bouton de suppression de la langue*/
	OneClickButton removeLangue = new OneClickButton(FontAwesome.MINUS_SQUARE_O);
	removeLangue.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
	removeLangue.addStyleName(ValoTheme.BUTTON_BORDERLESS);
	removeLangue.addClickListener(e->{layoutLangue.removeComponent(hlLangueOther);listLayoutTraductions.remove(hlLangueOther);checkVisibleAddLangue();centerWindow();});
	hlLangueOther.addComponent(removeLangue);
	return hlLangueOther;
}
 
Example 5
Project: osc-core   File: ViewUtil.java   Source Code and License Vote up 5 votes
/**
 * @param caption
 *            Caption Text Representing Header
 * @param guid
 *            Help GUID for caller view
 * @return
 *         Horizontal Layout containing Caption text and Help button
 */
public static HorizontalLayout createSubHeader(String caption, String guid) {

    HorizontalLayout subHeader = new HorizontalLayout();
    subHeader.setWidth("100%");
    subHeader.setHeight("35px");
    subHeader.setSpacing(true);
    subHeader.addStyleName("toolbar");
    final Label title = new Label(caption);
    title.setSizeUndefined();
    subHeader.addComponent(title);
    subHeader.setComponentAlignment(title, Alignment.MIDDLE_LEFT);
    subHeader.setExpandRatio(title, 1);

    // create help button if we have some GUID else do not add this button
    if (guid != null) {

        Button helpButton = new Button();
        helpButton.setImmediate(true);
        helpButton.setStyleName(Reindeer.BUTTON_LINK);
        helpButton.setDescription("Help");
        helpButton.setIcon(new ThemeResource("img/Help.png"));
        subHeader.addComponent(helpButton);
        helpButton.addClickListener(new HelpButtonListener(guid));
    }

    return subHeader;
}
 
Example 6
Project: vaadin-016-helloworld-14   File: MainView.java   Source Code and License Vote up 5 votes
@Override
protected Component createComponent() {
  final CssLayout contentLayout = new CssLayout(new Label("Content"));
  contentLayout.setSizeFull();
  contentLayout.setId(cssLayoutID().apply(MainUI.class, "Content"));

  final VerticalLayout menuLayout = new VerticalLayout();
  menuLayout.setId(verticalLayoutID().apply(MainUI.class, "MenuLayout"));
  menuLayout.setStyleName(ValoTheme.MENU_ROOT);
  menuLayout.setWidth(100, Unit.PERCENTAGE);
  menuLayout.setHeight(100, Unit.PERCENTAGE);
  menuLayout.setSizeFull();

  // to hard bound
  menuLayout.addComponent(new MenuComponent(contentLayout));


  final HorizontalLayout mainLayout = new HorizontalLayout();
  mainLayout.setId(horizontalLayoutID().apply(MainUI.class, "MainLayout"));
  mainLayout.setSizeFull();
  mainLayout.addComponent(menuLayout);
  mainLayout.addComponent(contentLayout);

  mainLayout.setExpandRatio(menuLayout, 0.20f);
  mainLayout.setExpandRatio(contentLayout, 0.80f);

  return mainLayout;
}
 
Example 7
Project: esup-ecandidat   File: CandidatCompteMinimaView.java   Source Code and License Vote up 4 votes
/**
 * Initialise la vue
 */
@PostConstruct
public void init() {
	/* Style */
	setMargin(true);
	setSpacing(true);
	setSizeFull();
	
	/* Titre */
	HorizontalLayout hlLangue = new HorizontalLayout();
	hlLangue.setWidth(100, Unit.PERCENTAGE);
	hlLangue.setSpacing(true);
	
	/*Le titre*/
	labelTitle.addStyleName(StyleConstants.VIEW_TITLE);
	hlLangue.addComponent(labelTitle);
	hlLangue.setExpandRatio(labelTitle, 1);
	hlLangue.setComponentAlignment(labelTitle, Alignment.MIDDLE_LEFT);
	
	if (cacheController.getLangueEnServiceWithoutDefault().size()>0){
		Langue langueDef = cacheController.getLangueDefault();
		Image flagDef = new Image(null, new ThemeResource("images/flags/"+langueDef.getCodLangue()+".png"));
		flagDef.addClickListener(e->updateLangue(langueDef));
		flagDef.addStyleName(StyleConstants.CLICKABLE);
		hlLangue.addComponent(flagDef);
		hlLangue.setComponentAlignment(flagDef, Alignment.MIDDLE_CENTER);
		cacheController.getLangueEnServiceWithoutDefault().forEach(langue->{
			Image flag = new Image(null, new ThemeResource("images/flags/"+langue.getCodLangue()+".png"));
			flag.addClickListener(e->updateLangue(langue));
			flag.addStyleName(StyleConstants.CLICKABLE);
			hlLangue.addComponent(flag);
			hlLangue.setComponentAlignment(flag, Alignment.MIDDLE_CENTER);
			
		});
	}

	addComponent(hlLangue);
	
	/*Panel scrollable de contenu*/
	Panel panelContent = new Panel();
	panelContent.setSizeFull();
	panelContent.addStyleName(ValoTheme.PANEL_BORDERLESS);
	addComponent(panelContent);
	setExpandRatio(panelContent, 1);
	
	VerticalLayout vlContent = new VerticalLayout();
	vlContent.setSpacing(true);
	panelContent.setContent(vlContent);
	
	
	restResult.setContentMode(ContentMode.HTML);
	restResult.addStyleName(StyleConstants.LABEL_MORE_BOLD);
	restResult.addStyleName(ValoTheme.LABEL_COLORED);
	restResult.setValue("");
	vlContent.addComponent(restResult);
	
	/* Texte */		
	labelAccueil.setValue("");
	labelAccueil.setContentMode(ContentMode.HTML);		
	vlContent.addComponent(labelAccueil);
	
	connexionLayout.addStyleName(StyleConstants.MAX_WIDTH_500);
	connexionLayout.addCasListener(()->userController.connectCAS());
	connexionLayout.addStudentListener((user,pwd)->userController.connectCandidatInterne(user, pwd));
	connexionLayout.addForgotPasswordListener(()->{UI.getCurrent().addWindow(new CandidatIdOublieWindow(ConstanteUtils.FORGOT_MODE_ID_OUBLIE));});
	connexionLayout.addForgotCodeActivationListener(()->{UI.getCurrent().addWindow(new CandidatIdOublieWindow(ConstanteUtils.FORGOT_MODE_CODE_ACTIVATION));});
	vlContent.addComponent(connexionLayout);
}
 
Example 8
Project: esup-ecandidat   File: I18nField.java   Source Code and License Vote up 4 votes
/** Renvoie un layout contenant un choix de langue et une traduction
 * @param traductionInactive
 * @return le layout
 */
private HorizontalLayout getLangueLayoutInactive(I18nTraduction traductionInactive){
	Langue langueInactive = traductionInactive.getLangue();
	/*Ajout de la langue par defaut*/
	HorizontalLayout hlLangueInactive = new HorizontalLayout();
	listLayoutTraductions.add(hlLangueInactive);
	hlLangueInactive.setSpacing(true);
	hlLangueInactive.setWidth(100, Unit.PERCENTAGE);
	layoutLangue.addComponent(hlLangueInactive);
	
	Image flag = new Image(null, new ThemeResource("images/flags/"+langueInactive.getCodLangue()+".png"));
	HorizontalLayout hlFlag = new HorizontalLayout();
	hlFlag.setWidth(75,Unit.PIXELS);
	hlFlag.addComponent(flag);
	hlFlag.setComponentAlignment(flag, Alignment.MIDDLE_CENTER);
	hlLangueInactive.addComponent(hlFlag);
	
	/*La valeur de la traduction*/
	AbstractField<String> tfVal = getNewValueComponent();
	tfVal.setId(langueInactive.getCodLangue());
	tfVal.setWidth(100, Unit.PERCENTAGE);
	
	/*Recuperation de la valeur de la traduction par defaut dans la liste des traductions*/
	if (listeTraduction.size() != 0){
		Optional<I18nTraduction> opt = listeTraduction.stream().filter(l->l.getLangue().getCodLangue().equals(langueInactive.getCodLangue())).findFirst();
		if (opt.isPresent()){
			tfVal.setValue(opt.get().getValTrad());
		}
	}

	hlLangueInactive.addComponent(tfVal);
	hlLangueInactive.setExpandRatio(tfVal,1);
	
	/*Le bouton de suppression de la langue*/
	OneClickButton removeLangue = new OneClickButton(FontAwesome.MINUS_SQUARE_O);
	removeLangue.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
	removeLangue.addStyleName(ValoTheme.BUTTON_BORDERLESS);
	removeLangue.addClickListener(e->{layoutLangue.removeComponent(hlLangueInactive);listLayoutTraductions.remove(hlLangueInactive);checkVisibleAddLangue();centerWindow();});
	hlLangueInactive.addComponent(removeLangue);
	
	return hlLangueInactive;
}
 
Example 9
Project: osc-core   File: PageInformationComponent.java   Source Code and License Vote up 4 votes
private Component buildMainLayout() {
    // top-level component properties
    setWidth("100.0%");
    setHeight("-1px");
    setStyleName(StyleConstants.PAGE_INFO_COMPONENT_COMMON);

    // infoLabel
    this.titleLabel = new Label();
    initializeLabel(this.titleLabel);

    final Button collapseButton = new Button();
    collapseButton.setStyleName(Reindeer.BUTTON_LINK);
    collapseButton.setIcon(new ThemeResource(StyleConstants.EXPAND_IMAGE));
    collapseButton.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            PageInformationComponent.this.contentLabel.setVisible(!PageInformationComponent.this.contentLabel
                    .isVisible());
            if (PageInformationComponent.this.contentLabel.isVisible()) {
                collapseButton.setIcon(new ThemeResource(StyleConstants.COLLAPSE_IMAGE));
            } else {
                collapseButton.setIcon(new ThemeResource(StyleConstants.EXPAND_IMAGE));
            }
        }
    });

    HorizontalLayout titleLayout = new HorizontalLayout();
    initializeLayout(titleLayout);
    titleLayout.setStyleName(StyleConstants.PAGE_INFO_TITLE_LAYOUT);

    titleLayout.addComponent(this.titleLabel);
    titleLayout.addComponent(collapseButton);
    titleLayout.setExpandRatio(this.titleLabel, 1.0f);

    this.contentLabel = new Label();
    initializeLabel(this.contentLabel);
    this.contentLabel.setVisible(false);

    this.contentLabel.setStyleName(StyleConstants.PAGE_INFO_CONTENT_LABEL);
    this.contentLabel.setContentMode(ContentMode.HTML);

    VerticalLayout mainLayout = new VerticalLayout();
    initializeLayout(mainLayout);
    mainLayout.addComponent(titleLayout);
    mainLayout.addComponent(this.contentLabel);

    return mainLayout;
}
 
Example 10
Project: md-stepper   File: StepLabel.java   Source Code and License Vote up 4 votes
/**
 * Construct a new label with the given caption, description and icon.
 *
 * @param caption
 *     The caption to show
 * @param description
 *     The description to show
 * @param icon
 *     The icon to show
 */
public StepLabel(String caption, String description, FontIcon icon) {
  active = false;
  nexted = false;
  skipped = false;
  editable = false;
  clickable = false;

  iconLabel = new Label();
  iconLabel.setWidthUndefined();
  iconLabel.setContentMode(ContentMode.HTML);
  iconLabel.addStyleName(STYLE_STEP_ICON);

  captionLabel = new Label();
  captionLabel.setWidth(100, Unit.PERCENTAGE);
  captionLabel.addStyleName(STYLE_STEP_CAPTION);

  descriptionLabel = new Label();
  descriptionLabel.setWidth(100, Unit.PERCENTAGE);
  descriptionLabel.addStyleName(ValoTheme.LABEL_LIGHT);
  descriptionLabel.addStyleName(ValoTheme.LABEL_SMALL);
  descriptionLabel.addStyleName(STYLE_STEP_DESCRIPTION);

  captionWrapper = new VerticalLayout();
  captionWrapper.setSpacing(false);
  captionWrapper.setMargin(false);
  captionWrapper.setSizeFull();
  captionWrapper.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
  captionWrapper.addComponent(captionLabel);
  captionWrapper.addComponent(descriptionLabel);

  rootLayout = new HorizontalLayout();
  rootLayout.setSpacing(false);
  rootLayout.setMargin(false);
  rootLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
  rootLayout.setWidth(100, Unit.PERCENTAGE);
  rootLayout.addComponent(iconLabel);
  rootLayout.addComponent(captionWrapper);
  rootLayout.setExpandRatio(captionWrapper, 1);

  setCompositionRoot(rootLayout);
  addStyleName(STYLE_ROOT_LAYOUT);
  setIcon(icon);
  setCaption(caption);
  setDescription(description);

  setIconNexted(DEFAULT_ICON_NEXTED);
  setIconSkipped(DEFAULT_ICON_SKIPPED);
  setIconEditable(DEFAULT_ICON_EDITABLE);
  setIconError(DEFAULT_ICON_ERROR);
}
 
Example 11
Project: history-api-navigation   File: DemoUI.java   Source Code and License Vote up 4 votes
@Override
protected void init(VaadinRequest request)
{
    setLocale(Locale.US);

    final HorizontalLayout rootLayout = new HorizontalLayout();
    rootLayout.setSpacing(false);
    rootLayout.setSizeFull();

    final VerticalLayout navigationLayout = new VerticalLayout();
    navigationLayout.setWidth(null);
    final Label title = new Label("HTML5 History API<br>Navigation", ContentMode.HTML);
    title.setStyleName(ValoTheme.LABEL_H1);
    title.addStyleName(ValoTheme.TEXTFIELD_ALIGN_CENTER);
    navigationLayout.addComponent(title);
    rootLayout.addComponent(navigationLayout);

    final TextField param1Field = new TextField("Parameter 1");
    final TextField param2Field = new TextField("Parameter 2");

    final Button homeButton = new Button("Home View",
            event -> getNavigator().navigateTo(HomeView.VIEW_NAME + "/" +
                    getParameters(param1Field.getValue(), param2Field.getValue())));
    navigationLayout.addComponent(homeButton);

    final Button parameterButton = new Button("Other View",
            event -> getNavigator().navigateTo(OtherView.VIEW_NAME + "/" +
                    getParameters(param1Field.getValue(), param2Field.getValue())));
    navigationLayout.addComponents(parameterButton, param1Field, param2Field);

    final Panel contentPanel = new Panel();
    contentPanel.setSizeFull();
    rootLayout.addComponent(contentPanel);
    rootLayout.setExpandRatio(contentPanel, 1.0f);

    setNavigator(HistoryApiNavigatorFactory.createHistoryApiNavigator(this, new CustomViewDisplay(contentPanel)));

    final HomeView homeView = new HomeView();
    getNavigator().addView(HomeView.VIEW_NAME, homeView);
    getNavigator().addView(OtherView.VIEW_NAME, new OtherView());

    setContent(rootLayout);
}