List of usage examples for com.vaadin.ui Image getSource
public Resource getSource()
From source file:org.inakirj.imagerulette.screens.DicePlayView.java
License:Open Source License
/** * Calculate stats./*from w ww . jav a 2s. c om*/ */ @SuppressWarnings("unchecked") private void calculateStats() { long totalImagesRendered = statsImageIdOcurrencesMap.values().stream().reduce(0, Integer::sum); Map<Image, Double> statsRowsMap = new HashMap<Image, Double>(); Iterator<Entry<String, Integer>> iterator = statsImageIdOcurrencesMap.entrySet().iterator(); while (iterator.hasNext()) { // Left fake column Entry<String, Integer> entry = iterator.next(); // @formatter:off Image img = lotteryList.stream().map(i -> (Image) i).filter(i -> entry.getKey().equals((i.getData()))) .findFirst().orElse(null); // @formatter:on Image imgCopy = new Image("", img.getSource()); imgCopy.addStyleName("dice-image-stats"); double label = getCalculation(entry.getValue(), totalImagesRendered); statsRowsMap.put(imgCopy, label); } Table popupContent; if (statsLayout == null) { popupContent = new Table() { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -7151527404141301908L; @Override protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) { if (colId.equals(oddCol)) { return super.formatPropertyValue(rowId, colId, property) + " %"; } return super.formatPropertyValue(rowId, colId, property); } }; popupContent.setSortEnabled(false); popupContent.addStyleName("stats-table"); popupContent.setWidth(100, Unit.PERCENTAGE); popupContent.addContainerProperty(imageCol, Image.class, null); popupContent.addContainerProperty(oddCol, BigDecimal.class, null); popupContent.setColumnExpandRatio(imageCol, 3); popupContent.setColumnExpandRatio(oddCol, 7); } else { popupContent = statsLayout; popupContent.removeAllItems(); } statsRowsMap.entrySet().stream().forEach(entry -> { Item row1 = popupContent.getItem(popupContent.addItem()); row1.getItemProperty(imageCol).setValue(entry.getKey()); BigDecimal bg = BigDecimal.valueOf(entry.getValue()); row1.getItemProperty(oddCol).setValue(bg); }); popupContent.setPageLength(statsRowsMap.size()); popupContent.sort(new String[] { oddCol }, new boolean[] { false }); if (statsLayout == null) { mainLayout.addComponent(popupContent); } else { mainLayout.replaceComponent(statsLayout, popupContent); } statsLayout = popupContent; }
From source file:org.inakirj.imagerulette.screens.DiceURLSetupView.java
License:Open Source License
/** * Generate lottery list./*from ww w .j a v a 2s . co m*/ * * @return the list */ private List<Object> generateLotteryList() { List<Object> randomList = new ArrayList<>(); Iterator<Component> iterator = imagesLayout.iterator(); while (iterator.hasNext()) { HorizontalLayout hl = (HorizontalLayout) iterator.next(); Image imageSelected = (Image) hl.getComponent(0); Image img = new Image("", imageSelected.getSource()); img.setData(imageSelected.getData()); Slider slider = (Slider) hl.getComponent(1); int rep = slider.getValue().intValue(); while (rep > 0) { randomList.add(img); rep--; } } return randomList; }