List of usage examples for com.vaadin.ui Image getHeight
@Override public float getHeight()
From source file:com.foc.vaadin.gui.components.FVBlobDisplay.java
License:Apache License
private Image displayImage(BlobResource blobResource) { Image image = new Image(); image.setSource(blobResource);//from ww w . ja v a2 s . c o m FVImageField imageField = new FVImageField(null, getAttributes()); image = imageField.resizeImage(image, MAX_WIDTH, MAX_HEIGHT); setWidth(image.getWidth() + "px"); setHeight(image.getHeight() + "px"); return image; }
From source file:com.foc.vaadin.gui.components.FVImageField.java
License:Apache License
public Image resizeImage(Image image, int maxWidth, int maxHeight) { if (image != null) { double ratio = getRatio(image, maxWidth, maxHeight); String newHeight = Integer.toString((int) (image.getHeight() * ratio)); String newWidth = Integer.toString((int) (image.getWidth() * ratio)); image.setWidth(newWidth + "px"); image.setHeight(newHeight + "px"); setWidth(newWidth + "px"); setHeight(newHeight + "px"); }/*from w w w. j ava 2 s.c om*/ return image; }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
/** * If no value present, choose a empty string * * @param title//from w ww .ja v a2 s. c om * @param link * @param description * @param language * @param imageUrl * @return */ private Component getSecondStage(Source s) { Label header = new Label(Language.get(Word.SOURCE)); header.addStyleName(ValoTheme.LABEL_H1); FormLayout forms = new FormLayout(); forms.setSizeFull(); TextField textFieldId = new TextField(Language.get(Word.ID)); textFieldId.setEnabled(false); textFieldId.setValue(s.getId()); textFieldId.setWidth("750px"); TextField textFieldName = new TextField(Language.get(Word.NAME)); textFieldName.setValue(s.getName()); textFieldName.setWidth("750px"); TextField textFieldDescription = new TextField(Language.get(Word.DESCRIPTION)); textFieldDescription.setValue(s.getDescription()); textFieldDescription.setWidth("750px"); TextField textFieldURL = new TextField(Language.get(Word.URL)); if (s.getUrl() != null) { textFieldURL.setValue(s.getUrl().toExternalForm()); } textFieldURL.setWidth("750px"); ComboBox<Category> comboBoxCategories = new ComboBox<>(Language.get(Word.CATEGORY), EnumSet.allOf(Category.class)); comboBoxCategories.setItemCaptionGenerator(c -> c.getName()); comboBoxCategories.setItemIconGenerator(c -> c.getIcon()); comboBoxCategories.setEmptySelectionAllowed(false); comboBoxCategories.setTextInputAllowed(false); comboBoxCategories.setWidth("375px"); if (s.getCategory() != null) { comboBoxCategories.setSelectedItem(s.getCategory()); } ComboBox<Locale> comboBoxLanguage = new ComboBox<>(Language.get(Word.LANGUAGE), getLanguages()); comboBoxLanguage.setItemCaptionGenerator(l -> l.getDisplayLanguage(VaadinSession.getCurrent().getLocale())); comboBoxLanguage.setEmptySelectionAllowed(false); comboBoxLanguage.setWidth("375px"); if (!s.getLanguage().isEmpty()) { Locale selected = new Locale(s.getLanguage()); comboBoxLanguage.setSelectedItem(selected); } Locale loc = VaadinSession.getCurrent().getLocale(); Map<String, Locale> countries = getCountries(); List<Locale> locales = countries.values().parallelStream() .sorted((l1, l2) -> l1.getDisplayCountry(loc).compareTo(l2.getDisplayCountry(loc))) .collect(Collectors.toList()); ComboBox<Locale> comboBoxCountry = new ComboBox<>(Language.get(Word.COUNTRY), locales); comboBoxCountry.setItemCaptionGenerator(l -> l.getDisplayCountry(VaadinSession.getCurrent().getLocale())); comboBoxCountry.setItemIconGenerator(l -> FamFamFlags.fromLocale(l)); comboBoxCountry.setEmptySelectionAllowed(false); comboBoxCountry.setWidth("375px"); if (!s.getCountry().isEmpty()) { comboBoxCountry.setSelectedItem(countries.getOrDefault(s.getCountry(), Locale.ROOT)); } Image imageLogo = new Image(Language.get(Word.LOGO)); TextField textFieldLogo = new TextField(Language.get(Word.LOGO_URL)); if (s.getLogo() != null) { textFieldLogo.setValue(s.getLogo().toExternalForm()); imageLogo.setSource(new ExternalResource(s.getLogo())); } textFieldLogo.addValueChangeListener(ce -> imageLogo.setSource(new ExternalResource(ce.getValue()))); textFieldLogo.setWidth("750px"); if (imageLogo.getHeight() > 125) { imageLogo.setHeight("125px"); } forms.addComponents(textFieldId, textFieldName, textFieldDescription, textFieldURL, comboBoxCategories, comboBoxLanguage, comboBoxCountry, textFieldLogo, imageLogo); Runnable cancel = () -> close(); Runnable next = () -> validateSecondStage(s, textFieldId.getValue(), textFieldName.getValue(), textFieldURL.getValue(), textFieldDescription.getValue(), comboBoxCategories.getSelectedItem().orElse(null), comboBoxLanguage.getSelectedItem().orElse(Locale.ROOT), comboBoxCountry.getSelectedItem().orElse(Locale.ROOT), textFieldLogo.getValue()); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.addComponents(header, forms, getFooter(cancel, next)); windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER); return windowLayout; }