List of usage examples for com.vaadin.ui Image Image
public Image(String caption)
From source file:com.esofthead.mycollab.mobile.ui.MobileAttachmentUtils.java
License:Open Source License
public static Component renderAttachmentRow(final Content attachment) { String docName = attachment.getPath(); int lastIndex = docName.lastIndexOf("/"); HorizontalLayout attachmentRow = new HorizontalLayout(); attachmentRow.setStyleName("attachment-row"); attachmentRow.setWidth("100%"); attachmentRow.setSpacing(true);//from www . j a v a 2 s . c o m attachmentRow.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); CssLayout thumbnailWrap = new CssLayout(); thumbnailWrap.setWidth("25px"); thumbnailWrap.setHeight("40px"); thumbnailWrap.setStyleName("thumbnail-wrap"); Image thumbnail = new Image(null); if (org.apache.commons.lang3.StringUtils.isBlank(attachment.getThumbnail())) { thumbnail.setSource(DEFAULT_SOURCE); } else { thumbnail.setSource(VaadinResourceManager.getResourceManager() .getImagePreviewResource(attachment.getThumbnail(), DEFAULT_SOURCE)); } thumbnail.setWidth("100%"); thumbnailWrap.addComponent(thumbnail); attachmentRow.addComponent(thumbnailWrap); if (lastIndex != -1) { docName = docName.substring(lastIndex + 1, docName.length()); } if (MimeTypesUtil.isImageType(docName)) { Button b = new Button(attachment.getTitle(), new Button.ClickListener() { private static final long serialVersionUID = -1713187920922886934L; @Override public void buttonClick(Button.ClickEvent event) { AttachmentPreviewView previewView = new AttachmentPreviewView(VaadinResourceManager .getResourceManager().getImagePreviewResource(attachment.getPath(), DEFAULT_SOURCE)); EventBusFactory.getInstance().post(new ShellEvent.PushView(this, previewView)); } }); b.setWidth("100%"); attachmentRow.addComponent(b); attachmentRow.setExpandRatio(b, 1.0f); } else { Label l = new Label(attachment.getTitle()); l.setWidth("100%"); attachmentRow.addComponent(l); attachmentRow.setExpandRatio(l, 1.0f); } return attachmentRow; }
From source file:com.esofthead.mycollab.mobile.ui.MobileAttachmentUtils.java
License:Open Source License
public static Component renderAttachmentFieldRow(final Content attachment, Button.ClickListener additionalListener) { String docName = attachment.getPath(); int lastIndex = docName.lastIndexOf("/"); if (lastIndex != -1) { docName = docName.substring(lastIndex + 1, docName.length()); }/*from w ww .j a v a 2 s .c o m*/ final HorizontalLayout attachmentLayout = new HorizontalLayout(); attachmentLayout.setSpacing(true); attachmentLayout.setStyleName("attachment-row"); attachmentLayout.setWidth("100%"); attachmentLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); CssLayout thumbnailWrap = new CssLayout(); thumbnailWrap.setWidth("25px"); thumbnailWrap.setHeight("40px"); thumbnailWrap.setStyleName("thumbnail-wrap"); Image thumbnail = new Image(null); if (org.apache.commons.lang3.StringUtils.isBlank(attachment.getThumbnail())) { thumbnail.setSource(DEFAULT_SOURCE); } else { thumbnail.setSource(VaadinResourceManager.getResourceManager() .getImagePreviewResource(attachment.getThumbnail(), DEFAULT_SOURCE)); } thumbnail.setWidth("100%"); thumbnailWrap.addComponent(thumbnail); attachmentLayout.addComponent(thumbnailWrap); Label attachmentLink = new Label(docName); attachmentLayout.addComponent(attachmentLink); attachmentLayout.setExpandRatio(attachmentLink, 1.0f); Button removeAttachment = new Button( "<span aria-hidden=\"true\" data-icon=\"" + IconConstants.DELETE + "\"></span>", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { ConfirmDialog.show(UI.getCurrent(), AppContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT), AppContext.getMessage(GenericI18Enum.BUTTON_YES), AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.CloseListener() { private static final long serialVersionUID = 1L; @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { ResourceService attachmentService = ApplicationContextUtil .getSpringBean(ResourceService.class); attachmentService.removeResource(attachment.getPath(), AppContext.getUsername(), AppContext.getAccountId()); ((ComponentContainer) attachmentLayout.getParent()) .removeComponent(attachmentLayout); } } }); } }); if (additionalListener != null) { removeAttachment.addClickListener(additionalListener); } removeAttachment.setHtmlContentAllowed(true); removeAttachment.setStyleName("link"); attachmentLayout.addComponent(removeAttachment); return attachmentLayout; }
From source file:com.esofthead.mycollab.vaadin.ui.AddViewLayout.java
License:Open Source License
public AddViewLayout(String viewTitle, Resource viewIcon) { super("addView"); this.viewIcon = viewIcon; this.header = new MHorizontalLayout().withWidth("100%"); this.header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); this.titleLbl = new Label("", ContentMode.HTML); this.titleLbl.setStyleName("headerName"); if (!(viewIcon instanceof FontAwesome)) { Image icon = new Image(null); icon.setIcon(viewIcon);/*from w ww. j ava2 s .com*/ icon.addStyleName(UIConstants.BUTTON_ICON_ONLY); this.header.with(icon); } this.header.with(titleLbl).expand(titleLbl); setHeader(viewTitle); this.addComponent(this.header, "addViewHeader"); }
From source file:com.esofthead.mycollab.vaadin.ui.AttachmentDisplayComponent.java
License:Open Source License
public static Component constructAttachmentRow(final Content attachment) { String docName = attachment.getPath(); int lastIndex = docName.lastIndexOf("/"); if (lastIndex != -1) { docName = docName.substring(lastIndex + 1, docName.length()); }/* ww w . j av a2 s .co m*/ final AbsoluteLayout attachmentLayout = new AbsoluteLayout(); attachmentLayout.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH); attachmentLayout.setHeight(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_HEIGHT); attachmentLayout.setStyleName("attachment-block"); CssLayout thumbnailWrap = new CssLayout(); thumbnailWrap.setSizeFull(); thumbnailWrap.setStyleName("thumbnail-wrap"); Image thumbnail = new Image(null); if (org.apache.commons.lang3.StringUtils.isBlank(attachment.getThumbnail())) { thumbnail.setSource(DEFAULT_SOURCE); } else { thumbnail.setSource(VaadinResourceManager.getResourceManager() .getImagePreviewResource(attachment.getThumbnail(), DEFAULT_SOURCE)); } thumbnail.setDescription(docName); thumbnail.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH); thumbnailWrap.addComponent(thumbnail); attachmentLayout.addComponent(thumbnailWrap, "top: 0px; left: 0px; bottom: 0px; right: 0px; z-index: 0;"); if (MimeTypesUtil.isImageType(docName)) { thumbnail.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = -2853211588120500523L; @Override public void click(MouseEvents.ClickEvent event) { Resource previewResource = VaadinResourceManager.getResourceManager() .getImagePreviewResource(attachment.getPath(), DEFAULT_SOURCE); UI.getCurrent().addWindow(new AttachmentPreviewWindow(previewResource)); } }); } CssLayout attachmentNameWrap = new CssLayout(); attachmentNameWrap.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH); attachmentNameWrap.setStyleName("attachment-name-wrap"); Label attachmentName = new Label(StringUtils.trim(docName, 60, true)); attachmentName.setStyleName("attachment-name"); attachmentNameWrap.addComponent(attachmentName); attachmentLayout.addComponent(attachmentNameWrap, "bottom: 0px; left: 0px; right: 0px; z-index: 1;"); Button trashBtn = new Button(null, new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { ConfirmDialogExt.show(UI.getCurrent(), AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, SiteConfiguration.getSiteName()), AppContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT), AppContext.getMessage(GenericI18Enum.BUTTON_YES), AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() { private static final long serialVersionUID = 1L; @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { ResourceService attachmentService = ApplicationContextUtil .getSpringBean(ResourceService.class); attachmentService.removeResource(attachment.getPath(), AppContext.getUsername(), AppContext.getAccountId()); ((ComponentContainer) attachmentLayout.getParent()) .removeComponent(attachmentLayout); } } }); } }); trashBtn.setIcon(FontAwesome.TRASH_O); trashBtn.setStyleName("attachment-control"); attachmentLayout.addComponent(trashBtn, "top: 9px; left: 9px; z-index: 1;"); Button downloadBtn = new Button(); FileDownloader fileDownloader = new FileDownloader( VaadinResourceManager.getResourceManager().getStreamResource(attachment.getPath())); fileDownloader.extend(downloadBtn); downloadBtn.setIcon(FontAwesome.DOWNLOAD); downloadBtn.setStyleName("attachment-control"); attachmentLayout.addComponent(downloadBtn, "right: 9px; top: 9px; z-index: 1;"); return attachmentLayout; }
From source file:com.esofthead.mycollab.vaadin.web.ui.AddViewLayout.java
License:Open Source License
public AddViewLayout(String viewTitle, Resource viewIcon) { super("addView"); this.viewIcon = viewIcon; header = new MHorizontalLayout().withFullWidth().withMargin(new MarginInfo(true, false, true, false)); header.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); titleLbl = ELabel.h2(""); if (!(viewIcon instanceof FontAwesome)) { Image icon = new Image(null); icon.setIcon(viewIcon);/*from w w w . ja va2 s . com*/ icon.addStyleName(UIConstants.BUTTON_ICON_ONLY); header.with(icon); } header.with(titleLbl).expand(titleLbl); setHeader(viewTitle); addComponent(header, "addViewHeader"); }
From source file:com.squadd.UI.UploadGroupImageWindow.java
protected void configureDownload() { // Show uploaded file in this placeholder image = new Image(""); image.setVisible(false);//from w ww. ja v a 2 s.c o m image.setHeight("256px"); // Implement both receiver that saves upload in a file and // listener for successful upload class ImageReceiver implements Upload.Receiver, Upload.SucceededListener { private static final long serialVersionUID = -1276759102490466761L; public java.io.File file; public OutputStream receiveUpload(String filename, String mimeType) { // Create upload stream FileOutputStream fos = null; // Stream to write to try { // Open the file for writing. grp.setLastUploadDate(System.currentTimeMillis()); String path = new ImageGetter().getPath(grp); file = new java.io.File(path); fos = new FileOutputStream(file); } catch (final java.io.FileNotFoundException e) { new Notification("Could not open file<br/>", e.getMessage(), Notification.Type.ERROR_MESSAGE) .show(Page.getCurrent()); return null; } return fos; // Return the output stream to write to } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer userImageFile = new File(); userImageFile.setPath(file.getPath()); image.setVisible(true); image.setSource(new FileResource(file)); } } ; ImageReceiver receiver = new ImageReceiver(); // Create the upload with a caption and set receiver later upload = new Upload("", receiver); //upload.setButtonCaption("Ok"); upload.addSucceededListener(receiver); }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
/** * If no value present, choose a empty string * * @param title/*from w w w . jav a 2s.c o m*/ * @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; }
From source file:edu.nps.moves.mmowgli.modules.userprofile.EditAwardTypeDialog.java
License:Open Source License
@SuppressWarnings("serial") private EditAwardTypeDialog(AwardType awt, EditAwardResultListener lis) { Object sessKey = HSess.checkInit(); listener = lis;//from ww w . j a v a 2 s .co m awardType = awt; setCaption("Edit Award Type"); setModal(true); setWidth("450px"); VerticalLayout vLay = new VerticalLayout(); setContent(vLay); vLay.setMargin(true); vLay.setSpacing(true); vLay.addStyleName("m-greybackground"); FormLayout formLay; vLay.addComponent(formLay = new FormLayout()); formLay.setSizeFull(); formLay.addComponent( nameTF = new MTextField("Award Title").withFullWidth().withNullRepresentation("required field")); nameTF.setRequired(true); nameTF.setRequiredError("Required field"); nameTF.setSizeFull(); formLay.addComponent( descTF = new MTextField("Description").withFullWidth().withNullRepresentation("required field")); descTF.setRequired(true); descTF.setRequiredError("Required field"); Label sp; formLay.addComponent(hLay55 = new HorizontalLayout()); hLay55.setWidth("100%"); hLay55.setCaption("55x55 pixel icon"); hLay55.setSpacing(true); hLay55.addComponent(lab55 = new HtmlLabel("<i>image name</i>")); hLay55.setComponentAlignment(lab55, Alignment.MIDDLE_CENTER); hLay55.addComponent(butt55 = new NativeButton("Choose 55x55 image")); hLay55.setComponentAlignment(butt55, Alignment.MIDDLE_CENTER); hLay55.addComponent(sp = new Label()); hLay55.setExpandRatio(sp, 1.0f); hLay55.addComponent(image55 = new Image(null)); image55.setWidth("55px"); image55.setHeight("55px"); image55.addStyleName("m-greyborder3"); formLay.addComponent(hLay300 = new HorizontalLayout()); hLay300.setWidth("100%"); hLay300.setCaption("300x300 pixel icon"); hLay300.setSpacing(true); hLay300.addComponent(lab300 = new HtmlLabel("<i>image name</i>")); hLay300.setComponentAlignment(lab300, Alignment.MIDDLE_CENTER); hLay300.addComponent(butt300 = new NativeButton("Choose 300x300 image")); hLay300.setComponentAlignment(butt300, Alignment.MIDDLE_CENTER); hLay300.addComponent(sp = new Label()); hLay300.setExpandRatio(sp, 1.0f); hLay300.addComponent(image300 = new Image(null)); image300.setWidth("55px"); image300.setHeight("55px"); image300.addStyleName("m-greyborder3"); ClickListener chooseIconListener = new ClickListener() { boolean is55 = false; @Override public void buttonClick(ClickEvent event) { is55 = (event.getButton() == butt55); String txt = (is55 ? pix55text : pix300text); InstallImageResultListener lis = new InstallImageResultListener() { @Override public void doneTL(MediaImage mimg) { Media m = null; if (mimg != null) m = mimg.media; if (m != null) { MediaLocator mediaLoc = Mmowgli2UI.getGlobals().getMediaLocator(); String handle = m.getHandle(); if (handle != null && handle.trim().length() <= 0) handle = null; if (is55) { media55 = m; if (handle == null) { m.setHandle("55x55"); Media.updateTL(m); } lab55.setValue(m.getUrl()); image55.setSource(mediaLoc.locate(m)); } else { media300 = m; if (handle == null) { m.setHandle("300x300"); Media.updateTL(m); } lab300.setValue(m.getUrl()); image300.setSource(mediaLoc.locate(m)); } } } }; InstallImageDialog.show(txt, lis, is55 ? pix55filter : pix300filter); } }; butt55.addClickListener(chooseIconListener); butt300.addClickListener(chooseIconListener); HorizontalLayout buttHL = new HorizontalLayout(); vLay.addComponent(buttHL); buttHL.setWidth("100%"); buttHL.addComponent(sp = new Label()); sp.setWidth("1px"); buttHL.setExpandRatio(sp, 1.0f); buttHL.addComponent(new NativeButton("Cancel", new ClickListener() { @Override public void buttonClick(ClickEvent event) { awardType = null; doneHereTL(); } })); buttHL.addComponent(new NativeButton("Close", new ClickListener() { @Override public void buttonClick(ClickEvent event) { String title = nameTF.getValue().trim(); String description = descTF.getValue().trim(); if (title.length() <= 0 || description.length() <= 0 || media300 == null || media55 == null) { Notification.show("All fields must be completed", Notification.Type.ERROR_MESSAGE); return; } HSess.init(); boolean save = false; if (awardType == null) { awardType = new AwardType(); save = true; } awardType.setName(nameTF.getValue().trim()); awardType.setDescription(descTF.getValue().trim()); awardType.setIcon300x300(media300); awardType.setIcon55x55(media55); if (save) HSess.get().save(awardType); else HSess.get().update(awardType); doneHereTL(); HSess.close(); } })); HSess.checkClose(sessKey); }
From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle(pageTitle);/* w w w.ja v a2 s .c o m*/ final VerticalLayout margin = new VerticalLayout(); setContent(margin); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); layout.setWidth("658px"); margin.addComponent(layout); margin.setComponentAlignment(layout, Alignment.TOP_CENTER); final Label header1 = new Label(pageTitle); header1.addStyleName("h1"); header1.setSizeUndefined(); layout.addComponent(header1); layout.setComponentAlignment(header1, Alignment.TOP_CENTER); final TabSheet tabSheet = new TabSheet(); tabSheet.setWidth("100%"); layout.addComponent(tabSheet); layout.setComponentAlignment(tabSheet, Alignment.TOP_CENTER); final Panel signaturePanel = new Panel(); signaturePanel.addStyleName("signature-panel"); signaturePanel.setWidth("100%"); tabSheet.addTab(signaturePanel, "Demo"); final VerticalLayout signatureLayout = new VerticalLayout(); signatureLayout.setMargin(true); signatureLayout.setSpacing(true); signatureLayout.setSizeFull(); signaturePanel.setContent(signatureLayout); final SignatureField signatureField = new SignatureField(); signatureField.setWidth("100%"); signatureField.setHeight("318px"); signatureField.setPenColor(Color.ULTRAMARINE); signatureField.setBackgroundColor("white"); signatureField.setConverter(new StringToDataUrlConverter()); signatureField.setPropertyDataSource(dataUrlProperty); signatureField.setVelocityFilterWeight(0.7); signatureLayout.addComponent(signatureField); signatureLayout.setComponentAlignment(signatureField, Alignment.MIDDLE_CENTER); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); signatureLayout.addComponent(buttonLayout); final Button clearButton = new Button("Clear", new ClickListener() { @Override public void buttonClick(ClickEvent event) { signatureField.clear(); } }); buttonLayout.addComponent(clearButton); buttonLayout.setComponentAlignment(clearButton, Alignment.MIDDLE_LEFT); final Label message = new Label("Sign above"); message.setSizeUndefined(); buttonLayout.addComponent(message); buttonLayout.setComponentAlignment(message, Alignment.MIDDLE_CENTER); final ButtonLink saveButtonLink = new ButtonLink("Save", null); saveButtonLink.setTargetName("_blank"); buttonLayout.addComponent(saveButtonLink); buttonLayout.setComponentAlignment(saveButtonLink, Alignment.MIDDLE_RIGHT); final Panel optionsPanel = new Panel(); optionsPanel.setSizeFull(); tabSheet.addTab(optionsPanel, "Options"); final FormLayout optionsLayout = new FormLayout(); optionsLayout.setMargin(true); optionsLayout.setSpacing(true); optionsPanel.setContent(optionsLayout); final ComboBox mimeTypeComboBox = new ComboBox(null, mimeTypeContainer); optionsLayout.addComponent(mimeTypeComboBox); mimeTypeComboBox.setItemCaptionPropertyId("mimeType"); mimeTypeComboBox.setNullSelectionAllowed(false); mimeTypeComboBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { MimeType mimeType = (MimeType) event.getProperty().getValue(); signatureField.setMimeType(mimeType); } }); mimeTypeComboBox.setValue(MimeType.PNG); mimeTypeComboBox.setCaption("Result MIME-Type"); final CheckBox immediateCheckBox = new CheckBox("immediate", false); optionsLayout.addComponent(immediateCheckBox); immediateCheckBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean immediate = (Boolean) event.getProperty().getValue(); signatureField.setImmediate(immediate); } }); final CheckBox readOnlyCheckBox = new CheckBox("readOnly", false); optionsLayout.addComponent(readOnlyCheckBox); readOnlyCheckBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean readOnly = (Boolean) event.getProperty().getValue(); signatureField.setReadOnly(readOnly); mimeTypeComboBox.setReadOnly(readOnly); clearButton.setEnabled(!readOnly); } }); final CheckBox requiredCheckBox = new CheckBox("required (causes bug that clears field)", false); optionsLayout.addComponent(requiredCheckBox); requiredCheckBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean required = (Boolean) event.getProperty().getValue(); signatureField.setRequired(required); } }); final CheckBox clearButtonEnabledButton = new CheckBox("clearButtonEnabled", false); optionsLayout.addComponent(clearButtonEnabledButton); clearButtonEnabledButton.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean clearButtonEnabled = (Boolean) event.getProperty().getValue(); signatureField.setClearButtonEnabled(clearButtonEnabled); } }); final Panel resultPanel = new Panel("Results:"); resultPanel.setWidth("100%"); layout.addComponent(resultPanel); final VerticalLayout resultLayout = new VerticalLayout(); resultLayout.setMargin(true); resultPanel.setContent(resultLayout); final Image stringPreviewImage = new Image("String preview image:"); stringPreviewImage.setWidth("500px"); resultLayout.addComponent(stringPreviewImage); final Image dataUrlPreviewImage = new Image("DataURL preview image:"); dataUrlPreviewImage.setWidth("500px"); resultLayout.addComponent(dataUrlPreviewImage); final TextArea textArea = new TextArea("DataURL:"); textArea.setWidth("100%"); textArea.setHeight("300px"); resultLayout.addComponent(textArea); final Label emptyLabel = new Label(); emptyLabel.setCaption("Is Empty:"); emptyLabel.setValue(String.valueOf(signatureField.isEmpty())); resultLayout.addComponent(emptyLabel); signatureField.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { String signature = (String) event.getProperty().getValue(); stringPreviewImage.setSource(signature != null ? new ExternalResource(signature) : null); textArea.setValue(signature); emptyLabel.setValue(String.valueOf(signatureField.isEmpty())); } }); dataUrlProperty.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { try { final DataUrl signature = (DataUrl) event.getProperty().getValue(); dataUrlPreviewImage.setSource( signature != null ? new ExternalResource(serializer.serialize(signature)) : null); StreamResource streamResource = null; if (signature != null) { StreamSource streamSource = new StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream(signature.getData()); } }; MimeType mimeType = MimeType.valueOfMimeType(signature.getMimeType()); String extension = null; switch (mimeType) { case JPEG: extension = "jpg"; break; case PNG: extension = "png"; break; } streamResource = new StreamResource(streamSource, "signature." + extension); streamResource.setMIMEType(signature.getMimeType()); streamResource.setCacheTime(0); } saveButtonLink.setResource(streamResource); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } } }); }