List of usage examples for com.vaadin.ui Image setVisible
@Override public void setVisible(boolean visible)
From source file:annis.gui.ReportBugWindow.java
License:Apache License
private void addScreenshotPreview(Layout layout, final byte[] rawImage, String mimeType) { StreamResource res = new StreamResource(new ScreenDumpStreamSource(rawImage), "screendump_" + UUID.randomUUID().toString() + ".png"); res.setMIMEType(mimeType);// w ww. j a v a 2 s.com final Image imgScreenshot = new Image("Attached screenshot", res); imgScreenshot.setAlternateText( "Screenshot of the ANNIS browser window, " + "no other window or part of the desktop is captured."); imgScreenshot.setVisible(false); imgScreenshot.setWidth("100%"); Button btShowScreenshot = new Button("Show attached screenshot", new ShowScreenshotClickListener(imgScreenshot)); btShowScreenshot.addStyleName(BaseTheme.BUTTON_LINK); btShowScreenshot.setIcon(FontAwesome.PLUS_SQUARE_O); layout.addComponent(btShowScreenshot); layout.addComponent(imgScreenshot); }
From source file:com.adonis.ui.menu.Menu.java
private void createViewButtonWithEditableImage(final String name, String caption, String nameImage) { Button button = new Button(caption, new ClickListener() { @Override/* w w w . j av a 2 s . co m*/ public void buttonClick(ClickEvent event) { navigator.navigateTo(name); } }); button.setPrimaryStyleName(ValoTheme.BUTTON_FRIENDLY); // button.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); FileReader.createDirectoriesFromCurrent(getInitialPath()); final Image image = new Image("", new ThemeResource("img/" + nameImage)); try { FileReader.copyFile(VaadinUtils.getResourcePath(nameImage), VaadinUtils.getInitialPath() + File.separator + nameImage); image.setSource(new FileResource(new File(VaadinUtils.getInitialPath() + File.separator + nameImage))); } catch (IOException e) { e.printStackTrace(); image.setSource(new ThemeResource("img/" + nameImage)); } // image.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setPrimaryStyleName(ValoTheme.MENU_ITEM); horizontalLayout.addComponents(image, button); image.addClickListener(new MouseEvents.ClickListener() { @Override public void click(MouseEvents.ClickEvent event) { uploadFieldImage = new UploadField(); uploadFieldImage.setAcceptFilter("image/*"); uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.FailedListener() { @Override public void uploadFailed(com.vaadin.v7.ui.Upload.FailedEvent event) { uploadFieldImage.clearDefaulLayout(); horizontalLayout.removeComponent(uploadFieldImage); } private static final long serialVersionUID = 1L; }); horizontalLayout.addComponent(uploadFieldImage, 2); uploadFieldImage.getUpload().addListener(new com.vaadin.v7.ui.Upload.SucceededListener() { @Override public void uploadSucceeded(com.vaadin.v7.ui.Upload.SucceededEvent event) { File file = (File) uploadFieldImage.getValue(); try { showUploadedImage(uploadFieldImage, image, file.getName(), nameImage); } catch (IOException e) { e.printStackTrace(); } uploadFieldImage.clearDefaulLayout(); horizontalLayout.removeComponent(uploadFieldImage); } }); uploadFieldImage.setFieldType(UploadField.FieldType.FILE); horizontalLayout.markAsDirty(); // image.setWidth(50, Unit.PERCENTAGE); image.setWidth(90, Unit.PIXELS); image.setHeight(90, Unit.PIXELS); image.setVisible(false); image.markAsDirty(); horizontalLayout.addComponent(image, 0); } }); button.setVisible(true); image.setVisible(true); menuItemsLayout.addComponents(horizontalLayout); viewButtons.put(name, button); }
From source file:com.adonis.ui.menu.Menu.java
private void showUploadedImage(UploadField upload, Image image, String fileName, String newNameFile) throws IOException { File value = (File) upload.getValue(); //copy to resources FileReader.copyFile(value.getAbsolutePath().toString(), VaadinUtils.getResourcePath(newNameFile)); //copy to server directory FileReader.createDirectoriesFromCurrent(getInitialPath()); FileReader.copyFile(value.getAbsolutePath().toString(), VaadinUtils.getInitialPath() + File.separator + newNameFile); FileInputStream fileInputStream = new FileInputStream(value); long byteLength = value.length(); //bytecount of the file-content byte[] filecontent = new byte[(int) byteLength]; fileInputStream.read(filecontent, 0, (int) byteLength); final byte[] data = filecontent; StreamResource resource = new StreamResource(new StreamResource.StreamSource() { @Override/*w w w .ja v a2 s . c o m*/ public InputStream getStream() { return new ByteArrayInputStream(data); } }, fileName); image.setSource(resource); image.setVisible(true); }
From source file:org.vaadin.easyuploads.ImagePreviewField.java
License:Apache License
@Override protected void updateDisplayComponent() { try {//from w ww . jav a2 s .c om Image image = (Image) display; // check if upload is an image if (getValue() != null && ImageIO.read(new ByteArrayInputStream(getValue())) != null) { // Update the image according to // https://vaadin.com/book/vaadin7/-/page/components.embedded.html SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String filename = df.format(new Date()) + getLastFileName(); StreamResource resource = new StreamResource(new ImageSource(getValue()), filename); resource.setCacheTime(0); image.setSource(resource); image.setVisible(true); } else { image.setVisible(false); image.setSource(null); setValue(null); } image.markAsDirty(); if (display.getParent() == null) { getRootLayout().addComponent(display); } } catch (IOException e) { e.printStackTrace(); } }