List of usage examples for com.vaadin.server FileResource FileResource
public FileResource(File sourceFile)
From source file:com.squadd.chat.ChatController.java
private void configureImages() { if (userFromImageFile == null) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resource = new FileResource(new java.io.File(basepath + "/VAADIN/images/user_icon.png")); userFromImageEmbedded = new Embedded("", resource); } else {/* www . j a va2 s .co m*/ FileResource imageResource = ResourceManager.open(userFromImageFile); userFromImageEmbedded = new Embedded("", imageResource); } if (userToImageFile == null) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resource = new FileResource(new java.io.File(basepath + "/VAADIN/images/user_icon.png")); userToImageEmbedded = new Embedded("", resource); } else { FileResource imageResource = ResourceManager.open(userToImageFile); userToImageEmbedded = new Embedded("", imageResource); } userFromImageEmbedded.setHeight("50px"); userFromImageEmbedded.setWidth("50px"); userToImageEmbedded.setHeight("50px"); userToImageEmbedded.setWidth("50px"); }
From source file:com.squadd.UI.UploadGroupImageWindow.java
protected void configureDownload() { // Show uploaded file in this placeholder image = new Image(""); image.setVisible(false);//w w w .ja va 2s .co 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:cz.zcu.pia.social.network.frontend.components.profile.profile.ComponentProfile.java
/** * Reload user profile image//from w ww . ja v a2s. c o m */ public void reloadImage() { image.setVisible(true); image.setSource(new FileResource( new File(Constants.BASE_PATH_RESIZED + securityHelper.getLogedInUser().getUserImageName()))); layout.addComponent(image, "picture"); }
From source file:cz.zcu.pia.social.network.frontend.components.profile.profile.ComponentProfilePost.java
/** * Post Construct/*from www . j av a 2 s . com*/ */ @PostConstruct public void postConstruct() { setLabels(user); if (user.getUserImageName() != null) { image.setVisible(true); image.setSource(new FileResource(new File(Constants.BASE_PATH_RESIZED + user.getUserImageName()))); layout.addComponent(image, "picture"); } fullname = new Label(user.getFullname()); layout.addComponent(fullname, "name"); Label usernameLabel = new Label(msgs.getMessage("username") + ":"); Label postsLabel = new Label(msgs.getMessage("number-of-posts") + ":"); Label followersLabel = new Label(msgs.getMessage("number-of-followers") + ":"); usernameLabel.setWidth(LABEL_WIDTH, Sizeable.Unit.PIXELS); postsLabel.setWidth(LABEL_WIDTH, Sizeable.Unit.PIXELS); followersLabel.setWidth(LABEL_WIDTH, Sizeable.Unit.PIXELS); layout.addComponent(usernameLabel, "usernameLabel"); layout.addComponent(postsLabel, "numberPostsLabel"); layout.addComponent(followersLabel, "numberFollowersLabel"); layout.addComponent(username, "username"); layout.addComponent(numberOfposts, "numberPosts"); layout.addComponent(numberOfFollowers, "numberFollowers"); layout.addComponent(createButtons(), "button"); }
From source file:de.metas.procurement.webui.ui.view.LoginView.java
License:Open Source License
private Resource getLogoResource() { if (logoFilename == null) { return Constants.RESOURCE_Logo; }/*from ww w . j a va 2 s .c o m*/ if (logoFilename.trim().isEmpty()) { return Constants.RESOURCE_Logo; } final File logoFile = new File(logoFilename.trim()); if (!logoFile.isFile() || !logoFile.canRead()) { logger.warn("Using default log because {} does not exist or it's not readable", logoFile); return Constants.RESOURCE_Logo; } return new FileResource(logoFile); }
From source file:dhbw.clippinggorilla.userinterface.views.DocumentsView.java
private Component generateLine(Path file, GridLayout layout) { Label fileName = new Label(file.getFileName().toString()); layout.addComponent(fileName);/*from w w w .ja v a2s .com*/ layout.setComponentAlignment(fileName, Alignment.MIDDLE_LEFT); Button downloadButton = new Button(); downloadButton.setIcon(VaadinIcons.DOWNLOAD); FileDownloader downloader = new FileDownloader(new FileResource(file.toFile())); downloader.extend(downloadButton); layout.addComponent(downloadButton); layout.setComponentAlignment(downloadButton, Alignment.MIDDLE_CENTER); if (file.getFileName().toString().endsWith("pdf")) { Button viewButton = new Button(); viewButton.setIcon(VaadinIcons.EYE); viewButton.addClickListener(ce -> UI.getCurrent().addWindow(PDFWindow.get(file))); layout.addComponent(viewButton); layout.setComponentAlignment(viewButton, Alignment.MIDDLE_CENTER); } else { layout.addComponent(new Label(" ")); } return layout; }
From source file:dhbw.clippinggorilla.userinterface.views.FooterBar.java
public FooterBar() { setColumns(6);/*from w w w . j a v a2 s . c o m*/ setRows(1); addStyleName("menubar"); setWidth("100%"); setHeightUndefined(); setColumnExpandRatio(4, 5); setSpacing(true); setMargin(true); Image logo = new Image(); try { logo.setSource(new FileResource(FileUtils.getFile("images/logo_small.png").toFile())); } catch (FileNotFoundException ex) { Log.error("Could not find logo!", ex); } logo.setHeight("100%"); addComponent(logo); setComponentAlignment(logo, Alignment.MIDDLE_CENTER); Button aboutUs = new Button(); Language.set(Word.ABOUT_US, aboutUs); aboutUs.addClickListener((ce) -> { ClippingGorillaUI.getCurrent().setMainContent(AboutUsView.getCurrent()); }); aboutUs.setIcon(VaadinIcons.USERS); aboutUs.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(aboutUs); setComponentAlignment(aboutUs, Alignment.MIDDLE_CENTER); Button docs = new Button(); Language.set(Word.DOCUMENTS, docs); docs.addClickListener(ce -> { ClippingGorillaUI.getCurrent().setMainContent(DocumentsView.getCurrent()); }); docs.setIcon(VaadinIcons.ARCHIVE); docs.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(docs); setComponentAlignment(docs, Alignment.MIDDLE_CENTER); Button impressum = new Button(); Language.set(Word.IMPRESSUM, impressum); impressum.addClickListener(ce -> { ClippingGorillaUI.getCurrent().setMainContent(ImpressumView.getCurrent()); }); impressum.setIcon(VaadinIcons.SCALE); impressum.addStyleName(ValoTheme.BUTTON_BORDERLESS); addComponent(impressum); setComponentAlignment(impressum, Alignment.MIDDLE_CENTER); Label spacing = new Label(); addComponent(spacing); setComponentAlignment(spacing, Alignment.MIDDLE_CENTER); ComboBox<Locale> languages = new ComboBox<>(null, Language.getAllLanguages().keySet()); languages.setItemCaptionGenerator(loc -> loc.getDisplayLanguage(loc)); if (!Language.getAllLanguages().containsKey(VaadinSession.getCurrent().getLocale())) { languages.setValue(Locale.ENGLISH); } else { languages.setValue(VaadinSession.getCurrent().getLocale()); } languages.setEmptySelectionAllowed(false); languages.setItemIconGenerator(FooterBar::getIcon); languages.addValueChangeListener( (HasValue.ValueChangeEvent<Locale> loc) -> Language.setLanguage(loc.getValue())); languages.setTextInputAllowed(false); addComponent(languages); setComponentAlignment(languages, Alignment.MIDDLE_CENTER); SESSIONS.put(VaadinSession.getCurrent(), this); }
From source file:dhbw.clippinggorilla.userinterface.views.MenuBar.java
public MenuBar() { setColumns(7);/*w w w. j av a 2 s .c o m*/ setRows(1); addStyleName("menubar"); setWidth("100%"); setHeightUndefined(); setColumnExpandRatio(1, 5); setSpacing(true); setMargin(true); logo = new Image(); try { logo.setSource(new FileResource(FileUtils.getFile("images/logowide_small.png").toFile())); } catch (FileNotFoundException ex) { Log.error("Could not find logo!", ex); } logo.setHeight("100%"); spacing1 = new Label(); spacing2 = new Label(); username = new TextField(); username.focus(); Language.setCustom(Word.USERNAME_OR_EMAIL, null, v -> username.setPlaceholder(v)); username.setMaxLength(255); password = new PasswordField(); Language.setCustom(Word.PASSWORD, null, v -> password.setPlaceholder(v)); password.setMaxLength(50); passwordForgotten = new Button(VaadinIcons.KEY); Language.set(Word.PASSWORD_FORGOTTEN, passwordForgotten); passwordForgotten.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED); passwordForgotten.addClickListener(ce -> UI.getCurrent().addWindow(PasswordRecoveryWindow.create())); login = new Button(); Language.set(Word.LOGIN, login); register = new Button(); login.setClickShortcut(KeyCode.ENTER, null); login.addClickListener(ce -> logInActions()); login.addStyleName(ValoTheme.BUTTON_PRIMARY); login.setIcon(VaadinIcons.SIGN_IN); Language.set(Word.REGISTER, register); register.addClickListener(ce -> UI.getCurrent().addWindow(RegisterWindow.get())); register.setIcon(VaadinIcons.USER_CHECK); home = new Button(); home.setIcon(VaadinIcons.HOME); home.addClickListener(ce -> ClippingGorillaUI.getCurrent().setMainContent(ClippingView.getCurrent())); profile = new Button(Language.get(Word.PROFILES)); profile.setIcon(VaadinIcons.USER); Language.set(Word.PROFILES, profile); profile.addClickListener( ce -> ClippingGorillaUI.getCurrent().setMainContent(InterestProfileView.getCurrent())); groups = new Button(Language.get(Word.GROUPS)); groups.setIcon(VaadinIcons.GROUP); Language.set(Word.GROUPS, groups); groups.addClickListener(ce -> ClippingGorillaUI.getCurrent().setMainContent(GroupView.getCurrent())); userBar = new com.vaadin.ui.MenuBar(); addComponents(logo, spacing1, spacing2, username, password, login, register); SESSIONS.put(VaadinSession.getCurrent(), this); }
From source file:dhbw.clippinggorilla.userinterface.windows.PDFWindow.java
public static Window get(Path pdfFile) { Window window = new Window(); window.setModal(true);/* www. j av a 2 s .co m*/ window.setResizable(false); window.setWidth("90%"); window.setHeight("90%"); window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null); BrowserFrame e = new BrowserFrame(pdfFile.getFileName().toString(), new FileResource(pdfFile.toFile())); e.setSizeFull(); window.setContent(e); return window; }
From source file:edu.kit.dama.ui.commons.util.UIUtils7.java
License:Apache License
public static void openResourceSubWindow(File sourceFile) { boolean fileAccessible = sourceFile != null && sourceFile.exists() && sourceFile.canRead(); // Set subwindow for displaying file resource final Window window = new Window(fileAccessible ? sourceFile.getName() : "Information"); window.center();//w w w . j av a 2 s. c o m // Set window layout VerticalLayout windowLayout = new VerticalLayout(); windowLayout.setSizeFull(); if (fileAccessible) { // Set resource that has to be embedded final Embedded resource = new Embedded(null, new FileResource(sourceFile)); if ("application/octet-stream".equals(resource.getMimeType())) { window.setWidth("570px"); window.setHeight("150px"); windowLayout.setMargin(true); Label attentionNote = new Label( "A file preview is not possible as the file type is not supported by your browser."); attentionNote.setContentMode(ContentMode.HTML); Link fileURL = new Link("Click here for downloading the file.", new FileResource(sourceFile)); windowLayout.addComponent(attentionNote); windowLayout.addComponent(fileURL); windowLayout.setComponentAlignment(attentionNote, Alignment.MIDDLE_CENTER); windowLayout.setComponentAlignment(fileURL, Alignment.MIDDLE_CENTER); } else { window.setResizable(true); window.setWidth("800px"); window.setHeight("500px"); final Image image = new Image(null, new FileResource(sourceFile)); image.setSizeFull(); windowLayout.addComponent(image); } } else { //file is not accessible window.setWidth("570px"); window.setHeight("150px"); windowLayout.setMargin(true); Label attentionNote = new Label("Provided file cannot be accessed."); attentionNote.setContentMode(ContentMode.HTML); windowLayout.addComponent(attentionNote); windowLayout.setComponentAlignment(attentionNote, Alignment.MIDDLE_CENTER); } window.setContent(windowLayout); UI.getCurrent().addWindow(window); }