public SpellChoiceForm(Character character, DSClass dsClass) { super(CharacterClass.class); this.character = character; this.chosenClass = dsClass; String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resource = new FileResource(new File(basepath + "/WEB-INF/sound/selectSpell.mp3")); spellSound = new Audio(); spellSound.setSource(resource); spellSound.setShowControls(false); spellSound.setAutoplay(false); setSavedHandler(this); }
private Resource getLogoResource() { if (logoFilename == null) { return Constants.RESOURCE_Logo; } 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); }
public FileResource createFileResource(File file) { return new FileResource(file) { private static final long serialVersionUID = -4183674760353232866L; @Override public DownloadStream getStream() { try { final DownloadStream ds = new DownloadStream(new FileInputStream(getSourceFile()), getMIMEType(), getFilename()); ds.setParameter("Content-Length", String.valueOf(getSourceFile().length())); ds.setCacheTime(getCacheTime()); return ds; } catch (final FileNotFoundException e) { return null; }//end try-catch block... }//end method... }; }
@Override public void setValue(byte[] imageData) { this.imageData = imageData; if (imageData != null) { File file; try { file = File.createTempFile("imageDisplay", "png"); try (FileOutputStream fis = new FileOutputStream(file)) { fis.write(imageData); } image.setSource(new FileResource(file)); } catch (IOException e) { e.printStackTrace(); image.setSource(null); } } else { image.setSource(null); } }
@Override public void buttonClick(ClickEvent event) { if(event.getButton().equals(downloadButton)) { FileResource resource = new FileResource((File) filesTable.getValue()); EnterpriseApplication.getInstance().getMainWindow().open(resource, "", true); updateTable(); } else if(event.getButton().equals(deleteButton)) { Utils.yesNoDialog(this, Constants.uiConfirmDeletion, new ConfirmDialog.Listener() { public void onClose(ConfirmDialog dialog) { if(dialog.isConfirmed()) { File file = (File) filesTable.getValue(); file.delete(); updateTable(); } } }); } }
private Image createEmailIcon(EmailContact emailContact) { final String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); final FileResource resource = new FileResource(new File(basepath + "/images/email.png")); Image image = new Image(null, resource); image.setDescription("Click to send an email"); image.setVisible(false); image.addClickListener(new MouseEventLogged.ClickListener() { private static final long serialVersionUID = 1L; @Override public void clicked(final com.vaadin.event.MouseEvents.ClickEvent event) { showMailForm(emailContact); } }); return image; }
/** * Zips project. * * @param projectName the name of the project to be zipped */ protected void zipProject() { try { File zipFile = File.createTempFile("mideaas-"+project.getName(), ".zip"); zipProjectToFile(zipFile, settings); FileResource zip = new FileResource(zipFile); FileDownloader fd = new FileDownloader(zip); Button downloadButton = new Button("Download project"); fd.extend(downloadButton); //filedonwnloader can not be connected to menuitem :( So I connected it to popupwindow :) Window zipButtonWindow = new Window(); zipButtonWindow.setCaption("Zip and download project"); zipButtonWindow.setWidth(200, Unit.PIXELS); zipButtonWindow.setContent(downloadButton); UI.getCurrent().addWindow(zipButtonWindow); } catch (IOException e) { e.printStackTrace(); Notification.show("Error: " + e.getMessage(), Notification.Type.ERROR_MESSAGE); } }
@Override public void sourceGenerationExecuted(final Source source, final TestGenerationType generationType, final long testsCreated) { UI.getCurrent().access(() -> { Item item = resultsTable.getItem(source); if (testsCreated == 0 || item == null) return; String column = (generationType.equals(TestGenerationType.AutoGenerated) ? "Automatic" : "Manual"); Property<Link> statusProperty = item.getItemProperty(column); String fileName; if (generationType.equals(TestGenerationType.AutoGenerated)) { fileName = CacheUtils.getSourceAutoTestFile(RDFUnitDemoSession.getBaseDir() + "tests/", source); statusProperty.setValue(new Link("" + testsCreated, new FileResource(new File(fileName)))); } else { fileName = CacheUtils.getSourceManualTestFile("/org/aksw/rdfunit/tests/", source); statusProperty.setValue(new Link("" + testsCreated, new ClassResource(fileName))); } CommonAccessUtils.pushToClient(); }); }
private FileResource getFileResource(String path,String type){ InputStream inputStream = null; try { ClassPathResource resource = new ClassPathResource(path); inputStream = resource.getInputStream(); File tempFile = File.createTempFile("ds_" + System.currentTimeMillis(), type); FileUtils.copyInputStreamToFile(inputStream, tempFile); return new FileResource(tempFile); } catch (Exception e) { e.printStackTrace(); return null; } finally { IOUtils.closeQuietly(inputStream); } }
private void addImageToLayout(HorizontalLayout layout, FileResource resource){ imageView = new Image(); imageView.setWidth(imageWidth); imageView.setHeight(imageHeight); imageView.setSource(resource); imageView.setCaption(imageName); layout.addComponent(imageView); layout.setComponentAlignment(imageView, Alignment.MIDDLE_CENTER); }
private void showCharacterInfo() { Messages messages = Messages.getInstance(); Character character = wizard.getCharacter(); if (character.getId() == null) { FormLayout infoLayout = new FFormLayout().withMargin(true); Panel infoPanel = new Panel(messages.getMessage("summaryStep.info.label"), infoLayout); layout.addComponent(infoPanel); File imageFile = new File(DSConstant.getImageDir() + character.getImage()); FileResource resource = new FileResource(imageFile); Image image = new Image("Image", resource); DSLabel nameLabel = new DSLabel(messages.getMessage("summaryStep.name.label"), character.getName()); DSLabel genderLabel = new DSLabel(messages.getMessage("summaryStep.sex.label"), character.getGender().toString()); DSLabel ageLabel = new DSLabel(messages.getMessage("summaryStep.age.label"), String.valueOf(character.getAge())); DSLabel weightLabel = new DSLabel(messages.getMessage("summaryStep.weight.label"), character.getWeight() + " lbs"); DSLabel heightLabel = new DSLabel(messages.getMessage("summaryStep.height.label"), character.getHeight()); DSLabel alignmentLabel = new DSLabel(messages.getMessage("summaryStep.alignment.label"), character.getAlignment().toString()); DSLabel regionLabel = new DSLabel(messages.getMessage("summaryStep.region.label"), character.getRegion().toString()); DSLabel backgroundLabel = new DSLabel(messages.getMessage("summaryStep.background.label"), character.getBackground().getBackground().toString()); DSLabel goldLabel = new DSLabel(messages.getMessage("summaryStep.startingGold.label"), character.getGold()); infoLayout.addComponents(image, nameLabel, genderLabel, ageLabel, weightLabel, heightLabel, alignmentLabel, regionLabel, backgroundLabel, goldLabel); } }
private void loadImages() { File imageDir = new File(DSConstant.getImageDir()); Collection<File> listFiles = FileUtils.listFiles(imageDir, ImageFilter.getImgExtensions(), true); for (File file : listFiles) { String fullPath = file.getAbsolutePath(); int lastSlash = fullPath.lastIndexOf(File.separator); int second = fullPath.lastIndexOf(File.separator, lastSlash - 1); String directory = fullPath.substring(second + 1, lastSlash); String filename = fullPath.substring(lastSlash + 1); DSImage image = new DSImage(new FileResource(file), directory, filename); images.add(image); } }
@Override protected void doSetValue(String value) { if (value != null && !value.equals(this.imagePath)) { this.imagePath = value; File imageFile = new File(DSConstant.getImageDir() + value); FileResource resource = new FileResource(imageFile); image.setSource(resource); } }
public DSImage addImage(FileResource fileResource) { String fullPath = fileResource.getSourceFile().getAbsolutePath(); int lastSlash = fullPath.lastIndexOf(File.separator); int second = fullPath.lastIndexOf(File.separator, lastSlash - 1); String directory = fullPath.substring(second + 1, lastSlash); String filename = fullPath.substring(lastSlash + 1); DSImage image = new DSImage(fileResource, directory, filename); addImage(image); return image; }
private Image getImage(String imageFilename) { String basePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); String filePath = basePath + "/" + imageFilename; File imageFile = new File(filePath); BufferedImage bufferedImage; Image image = new Image(null, new FileResource(imageFile)); if (imageFilename == BODY_IMAGE || imageFilename == BODY_IMAGE_FEMALE || imageFilename == BODY_IMAGE_MALE) { image.setHeight(Math.round(scaleFactor*BODY_IMAGE_HEIGHT), Unit.PIXELS); image.setWidth(Math.round(scaleFactor*BODY_IMAGE_WIDTH), Unit.PIXELS); } else if (imageFilename == SELECTION_INDICATOR || imageFilename == WOUND_INDICATOR || imageFilename == WOUND_HEALED_INDICATOR || imageFilename == WOUND_SELECTION_INDICATOR) { image.setHeight(Math.round(scaleFactor*INDICATOR_HEIGHT), Unit.PIXELS); image.setWidth(Math.round(scaleFactor*INDICATOR_WIDTH), Unit.PIXELS); } else { // We need to load the image and get the size since Vaadin Touchkit cannot read the size itself try { bufferedImage = ImageIO.read(imageFile); image.setHeight(Math.round(scaleFactor*bufferedImage.getHeight()), Unit.PIXELS); image.setWidth(Math.round(scaleFactor*bufferedImage.getWidth()), Unit.PIXELS); } catch (IOException e) { // we fail silently and let Vaadin use autosizing } } return image; }
private void addImage(final File imageFile) { FileResource imageResource = new FileResource(imageFile); // Frame list Image image = new Image(null, imageResource); image.setWidth("104px"); final CssLayout wrapper = new CssLayout(); wrapper.addComponent(image); image.addClickListener(new ClickListener() { @Override public void click(ClickEvent event) { framesLayout.removeComponent(wrapper); preview.removeImage(imageFiles.indexOf(imageFile)); imageFiles.remove(imageFile); downloadButton.setEnabled(!imageFiles.isEmpty()); } }); framesLayout.addComponent(wrapper); // Add to preview animation preview.addImage(imageResource); // Add to our internal list imageFiles.add(imageFile); if (imageFiles.size() > 1) { webcamAndGif.replaceComponent(gifImage, preview); downloadButton.setEnabled(true); } }
private void addLogo(final VerticalLayout viewLayout) { final VerticalLayout layout = new VerticalLayout(); HorizontalLayout buttons = getLoginAccountButtons(); HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setWidth("100%"); buttonLayout.addComponent(buttons); buttonLayout.setComponentAlignment(buttons, Alignment.TOP_RIGHT); layout.addComponent(buttonLayout); // So the logo final HorizontalLayout logoLayout = new HorizontalLayout(); logoLayout.setWidth("100%"); final String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); final FileResource resource = new FileResource(new File(basepath + "/images/scoutmaster-logo.png")); final Image image = new Image(null, resource); image.setAlternateText("Scoutmaster Logo"); logoLayout.addComponent(image); layout.addComponent(logoLayout); layout.setComponentAlignment(logoLayout, Alignment.TOP_LEFT); viewLayout.addComponent(layout); }
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * * The constructor will not be automatically regenerated by the * visual editor. */ public PanelEncabezado() { buildMainLayout(); setCompositionRoot(mainLayout); // TODO add user code here // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource FileResource headerResource = new FileResource(new File(basepath + "/WEB-INF/images/header.png")); headerImage.setSource(headerResource); }
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * * The constructor will not be automatically regenerated by the * visual editor. */ public PanelPieDePagina() { buildMainLayout(); setCompositionRoot(mainLayout); // TODO add user code here // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource FileResource footerResource = new FileResource(new File(basepath + "/WEB-INF/images/footer.png")); footerImage.setSource(footerResource); }
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * * The constructor will not be automatically regenerated by the * visual editor. */ public PanelEncabezado() { buildMainLayout(); setCompositionRoot(mainLayout); // User code // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource FileResource headerResource = new FileResource(new File(basepath + "/WEB-INF/images/header.png")); headerImage.setSource(headerResource); }
/** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * * The constructor will not be automatically regenerated by the * visual editor. */ public PanelPieDePagina() { buildMainLayout(); setCompositionRoot(mainLayout); // User code // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource FileResource footerResource = new FileResource(new File(basepath + "/WEB-INF/images/footer.png")); footerImage.setSource(footerResource); }
@SuppressWarnings("serial") public SpreadSheetDownload(DataFrame df, String[] columnNames, String fileName, String sheetName, SpreadSheetFactory ssf) { this.df = df; this.columnNames = columnNames; this.fileName = fileName; this.sheetName = sheetName; this.ssf = ssf; /* Intiate this UI element */ setCompositionRoot(root); xlsxButton = new Button("XLSX", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { /* * Generate the xlsx file only when the button is clicked */ createFile(); resource = new FileResource(file); fileLink = new Link("xlsx", resource); root.removeComponent(xlsxButton); root.addComponent(fileLink); root.setComponentAlignment(fileLink, Alignment.MIDDLE_LEFT); } }); xlsxButton.setDisableOnClick(true); xlsxButton.setStyleName(Reindeer.BUTTON_SMALL); root.addComponent(xlsxButton); }
private Link createDownloadLink(File archiveFile) { return new Link("Download " + archiveFile, new FileResource(archiveFile)); }
private void createDownloadLink(File backupFile) { this.downloadBackup = new Link("Download Backup: " + backupFile.getName(), new FileResource(backupFile)); this.linkContainer.addComponent(this.downloadBackup); }
private Window getDeleteConfirmWindow(DeviceDTO deviceDTO) { final String[] exportFileName = {""}; Window confirmWindow = new Window("Delete"); confirmWindow.setResizable(false); confirmWindow.setModal(true); confirmWindow.setDraggable(false); confirmWindow.setClosable(true); confirmWindow.addCloseListener(e -> { if (!exportFileName[0].isEmpty()) { new File(exportFileName[0]).delete(); } }); Label areYouSureLabel = new Label("Are you sure you want to delete the device?"); Label ifWantExport = new Label("If you wish, you can export all recorded data for the device."); VerticalLayout contentLayout = new VerticalLayout(areYouSureLabel, ifWantExport); Button saveAndDeleteButton = new Button("Export and Delete", event -> { exportFileName[0] = statisticDeviceDataService .exportDataToCsv(deviceDTO.getDevId(), deviceDTO.getType(), deviceDTO.getName()); if (!exportFileName[0].isEmpty()) { contentLayout.addComponent(new Link("Download export, click before exiting!", new FileResource(new File(exportFileName[0])))); deleteDevice(deviceDTO); } else { contentLayout.addComponent( new Label("Export failed, please try again! The device has not been deleted.")); } }); Button deleteOnly = new Button("Delete only", event -> { deleteDevice(deviceDTO); confirmWindow.close(); }); confirmWindow.setContent( new VerticalLayout(contentLayout, new HorizontalLayout(saveAndDeleteButton, deleteOnly))); return confirmWindow; }
private Window getExportWindow() { final String[] fileName = {""}; Window selectWindow = new Window("Export data"); selectWindow.setClosable(true); selectWindow.setDraggable(false); selectWindow.setModal(true); selectWindow.setResizable(false); selectWindow.setWidth(300, Unit.PIXELS); selectWindow.addCloseListener(e -> { if (!fileName[0].isEmpty()) { new File(fileName[0]).delete(); } }); VerticalLayout windowRoot = new VerticalLayout(); ComboBox devicesComboBox = new ComboBox("Devices"); devicesComboBox.setWidth(100, Unit.PERCENTAGE); devicesComboBox.setNullSelectionItemId(false); devicesComboBox.setContainerDataSource( new BeanItemContainer<>( DeviceViewDTO.class, deviceSetupService.getAllDeviceDtos().stream() .map(deviceDTO -> new DeviceViewDTO(deviceDTO.getDevId(), deviceDTO.getType(), deviceDTO.getName())) .collect(Collectors.toList()) ) ); windowRoot.addComponent(devicesComboBox); Button toExportButton = new Button("Export", event -> { DeviceViewDTO selectedDto = (DeviceViewDTO) devicesComboBox.getValue(); fileName[0] = statisticDeviceDataService.exportDataToCsv(selectedDto.getDevId(), selectedDto.getType(), selectedDto.getName()); if (!fileName[0].isEmpty()) { windowRoot .addComponent(new Link("Download CSV", new FileResource(new File(fileName[0])))); } else { windowRoot.addComponent(new Label("Export failed! Please Try again!")); } }); windowRoot.addComponent(toExportButton); selectWindow.setContent(windowRoot); return selectWindow; }
public DSImage addImage(File imageFile) { return addImage(new FileResource(imageFile)); }
protected void setLink(File file) { downloadButton.setEnabled(false); fileDownloader = new FileDownloader(new FileResource(file)); fileDownloader.extend(downloadButton); downloadButton.setEnabled(true); }
public static Resource getResource(String path) { return new FileResource(new File(path)); }
public LoginView() { setSizeFull(); // The view root layout final VerticalLayout viewLayout = new VerticalLayout(); viewLayout.setSizeFull(); // viewLayout.setStyleName(ValoTheme.LAYOUT_BLACK); final HorizontalLayout logo = new HorizontalLayout(); logo.setWidth("100%"); final String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); final FileResource resource = new FileResource(new File(basepath + "/images/scoutmaster-logo.png")); final Image image = new Image(null, resource); image.setAlternateText("Scoutmaster Logo"); logo.addComponent(image); logo.setComponentAlignment(image, Alignment.TOP_RIGHT); viewLayout.addComponent(logo); final VerticalLayout fields = new VerticalLayout(); fields.setSpacing(true); fields.setMargin(new MarginInfo(true, true, true, true)); fields.setSizeUndefined(); // Add both to a panel final Label label = new Label("<H1>Login to Scoutmaster</H1>"); label.setContentMode(ContentMode.HTML); fields.addComponent(label); // Create the user input field this.usernameField = new TextField("Username:"); this.usernameField.setWidth("300px"); this.usernameField.setRequired(true); this.usernameField.setInputPrompt("Your username"); this.usernameField.setImmediate(true); this.usernameField.setInvalidAllowed(false); fields.addComponent(this.usernameField); // Create the password input field this.passwordField = new PasswordField("Password:"); this.passwordField.setWidth("300px"); this.passwordField.setRequired(true); this.passwordField.setNullRepresentation(""); fields.addComponent(this.passwordField); // Buttons final HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); // Create login button this.loginButton = new Button("Login", new ClickEventLogged.ClickAdaptor(this)); this.loginButton.setClickShortcut(KeyCode.ENTER); this.loginButton.addStyleName(Reindeer.BUTTON_DEFAULT); buttons.addComponent(this.loginButton); buttons.setComponentAlignment(this.loginButton, Alignment.MIDDLE_LEFT); this.forgottenButton = new Button("Forgotten Password", new ClickEventLogged.ClickAdaptor(this)); buttons.addComponent(this.forgottenButton); buttons.setComponentAlignment(this.forgottenButton, Alignment.MIDDLE_RIGHT); fields.addComponent(buttons); viewLayout.addComponent(fields); viewLayout.setComponentAlignment(fields, Alignment.MIDDLE_CENTER); setCompositionRoot(viewLayout); viewLayout.addComponent(fields); }
private void initUI() { VerticalLayout mainLayout = new VerticalLayout(); setContent(mainLayout); VerticalLayout layout = new VerticalLayout(); layout.setWidth("1000px"); layout.setMargin(true); mainLayout.addComponent(layout); mainLayout.setComponentAlignment(layout, Alignment.TOP_CENTER); // // add components // layout.addComponents( new Image( null, new FileResource(new File(IfcApplication.WEB_INF_DIR_PATH + "/images/drumbeat_banner.jpg")) ), new Label( "<center><h1>IFC2LD Converter</h1></center>", ContentMode.HTML ) ); TabSheet tabSheet = new TabSheet(); layout.addComponent(tabSheet); try { tabSheet.addTab(new ConfigView(), "Config"); tabSheet.addTab(new ConvertSchemaView(), "Convert Schema"); tabSheet.addTab(new ConvertModelView(), "Convert Data"); // tabSheet.setSelectedTab(2); } catch (Exception e) { e.printStackTrace(); layout.addComponent(new Label(e.getMessage())); // Notification.show(e.getMessage() != null ? e.getMessage() : "Unexpected error", Type.ERROR_MESSAGE); } }