List of usage examples for com.vaadin.ui NativeSelect setItemCaptionGenerator
@Override public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
From source file:fi.jasoft.qrcode.demo.QRCodeDemo.java
License:Apache License
private NativeSelect<Color> createPrimaryColorSelect() { List<Color> colors = Arrays.asList(Color.BLACK, Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); NativeSelect<Color> fgColor = new NativeSelect<Color>("Primary color"); fgColor.setWidth("100px"); fgColor.setItemCaptionGenerator(color -> { switch (colors.indexOf(color)) { case 0:/*from w w w . j av a 2 s.c om*/ return "Black"; case 1: return "Red"; case 2: return "Green"; case 3: return "Blue"; case 4: return "Yellow"; } return "Black"; }); fgColor.setItems(colors); fgColor.setValue(Color.BLACK); fgColor.addValueChangeListener(e -> code.setPrimaryColor(e.getValue())); return fgColor; }
From source file:fi.jasoft.qrcode.demo.QRCodeDemo.java
License:Apache License
private NativeSelect<Color> createSecondaryColorSelect() { List<Color> colors = Arrays.asList(Color.WHITE, new Color(255, 0, 0, 50), new Color(0, 255, 0, 50), new Color(0, 0, 255, 50), new Color(255, 255, 0, 50)); final NativeSelect<Color> bgColor = new NativeSelect<Color>("Secondary color"); bgColor.setWidth("100px"); bgColor.setItemCaptionGenerator(color -> { switch (colors.indexOf(color)) { case 0:/*from ww w . j a v a 2s . c o m*/ return "White"; case 1: return "Red"; case 2: return "Green"; case 3: return "Blue"; case 4: return "Yellow"; } return "White"; }); bgColor.setItems(colors); bgColor.setValue(Color.WHITE); bgColor.addValueChangeListener(e -> code.setSecondaryColor(e.getValue())); return bgColor; }
From source file:fi.jasoft.qrcode.demo.QRCodeDemo.java
License:Apache License
private NativeSelect<Integer> createSizeSelect() { final NativeSelect<Integer> size = new NativeSelect<Integer>("Size"); size.setWidth("100px"); size.setItemCaptionGenerator(s -> s + "x" + s); size.setItems(50, 100, 150, 300, 500, 750, 1000); size.setValue(100);//from w w w. j ava2s.c o m size.addValueChangeListener(e -> { code.setWidth(e.getValue(), Unit.PIXELS); code.setHeight(e.getValue(), Unit.PIXELS); }); return size; }