private void save(DSSDocument signedDocument) { FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName(signedDocument.getName()); MimeType mimeType = signedDocument.getMimeType(); ExtensionFilter extFilter = new ExtensionFilter(mimeType.getMimeTypeString(), "*." + MimeType.getExtension(mimeType)); fileChooser.getExtensionFilters().add(extFilter); File fileToSave = fileChooser.showSaveDialog(stage); if (fileToSave != null) { try { FileOutputStream fos = new FileOutputStream(fileToSave); Utils.copy(signedDocument.openStream(), fos); Utils.closeQuietly(fos); } catch (Exception e) { Alert alert = new Alert(AlertType.ERROR, "Unable to save file : " + e.getMessage(), ButtonType.CLOSE); alert.showAndWait(); return; } } }
public void selectmultifiles(ActionEvent event) { FileChooser fc = new FileChooser(); // fc.setInitialDirectory(new File("C:\\PdfBox_Examples")); fc.getExtensionFilters().addAll(new ExtensionFilter("PDF Files", "*.pdf")); selectedFiles = fc.showOpenMultipleDialog(null); // FIX - Repeating files in list if ReADDED if (selectedFiles != null) { for (int i = 0; i < selectedFiles.size(); i++) { fileslist.getItems().add(selectedFiles.get(i).getAbsolutePath()); mylist.add(selectedFiles.get(i).getAbsolutePath()); NOOFFILES++; } } else { // Provide Error in window System.out.println("Invalid File"); } }
/** * Generates a PDF report for the * user to save wherever they choose */ private void generateReport() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Copy of Report"); fileChooser.setInitialDirectory( new File(System.getProperty("user.home")) ); fileChooser.setInitialFileName("Log Entries.pdf"); FileChooser.ExtensionFilter pdfExtensionFilter = new FileChooser.ExtensionFilter( "PDF - Portable Document Format (.pdf)", "*.pdf"); fileChooser.getExtensionFilters().add(pdfExtensionFilter); fileChooser.setSelectedExtensionFilter(pdfExtensionFilter); File file = fileChooser.showSaveDialog(currentStage); if (file != null) { try { exportTableAsPDF(file); } catch (Exception e) { e.printStackTrace(); } } }
private void initView() { centerArea.getChildren().add(centerBtn); centerArea.setAlignment(Pos.CENTER); fileTree.setEditable(true); fileTree.setCellFactory((TreeView<FileTreeItemModel> tree) -> new FileTreeItemCell()); mainArea.setTop(topArea); mainArea.setCenter(centerArea); chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("All Torrent", "*.torrent")); //将菜单栏添加到顶部 topArea.getChildren().add(menuBar); errorDialog.setTitle("错误"); infoDialog.setTitle("提示"); centerBtn.setOnAction(event -> openFile()); }
public void addImage(){ FileChooser fc = new FileChooser(); fc.setTitle("Select an image for this object!"); fc.getExtensionFilters().addAll(filts); // figure out who the owner is here... File selectedFile = fc.showOpenDialog(App.getMainController().getStage()); File addedFile = null; if(selectedFile == null){ // they couldn't decide what they want. return; } else { addedFile = App.worldFileUtil.addMultimedia(selectedFile); } if(addedFile == null){ log.error("Added file was null!"); } else { setImageTwo(addedFile); changeEvent(); } }
public static void saveFile(Stage stage, byte[] bytes) { FileChooser chooser = new FileChooser(); FileChooser.ExtensionFilter lzFilter = new FileChooser.ExtensionFilter("Compressed Bin File (*.bin.lz)", "*.bin.lz"); FileChooser.ExtensionFilter binFilter = new FileChooser.ExtensionFilter("Bin File (*.bin)", "*.bin"); FileChooser.ExtensionFilter allFilter = new FileChooser.ExtensionFilter("All Files", "*"); chooser.getExtensionFilters().addAll(lzFilter, binFilter, allFilter); File file = chooser.showSaveDialog(stage); if (file != null) { try { if (file.getName().endsWith("lz")) { byte[] compressed = CompressionUtils.compress(bytes); Path path = Paths.get(file.getCanonicalPath()); Files.write(path, compressed); } else Files.write(Paths.get(file.getCanonicalPath()), bytes); } catch (IOException ex) { ex.printStackTrace(); } } }
/** * Choose a new file and save the dashboard to that file. */ @FXML private void saveAs() throws IOException { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().setAll( new FileChooser.ExtensionFilter("Shuffleboard Save File (.json)", "*.json")); if (currentFile == null) { chooser.setInitialDirectory(Storage.getStorageDir()); chooser.setInitialFileName("shuffleboard.json"); } else { chooser.setInitialDirectory(currentFile.getAbsoluteFile().getParentFile()); chooser.setInitialFileName(currentFile.getName()); } File selected = chooser.showSaveDialog(root.getScene().getWindow()); saveFile(selected); }
@SuppressWarnings("unused") @FXML private void export() { FileChooser chooser = new FileChooser(); FileChooser.ExtensionFilter lzFilter = new FileChooser.ExtensionFilter("Compressed Bin File (*.bin.lz)", "*.bin.lz"); FileChooser.ExtensionFilter binFilter = new FileChooser.ExtensionFilter("Bin File (*.bin)", "*.bin"); FileChooser.ExtensionFilter allFilter = new FileChooser.ExtensionFilter("All Files", "*"); chooser.getExtensionFilters().addAll(lzFilter, binFilter, allFilter); File file = chooser.showSaveDialog(GuiData.getInstance().getStage()); if (file != null) { try { if (file.getName().endsWith("lz")) { byte[] compressed = CompressionUtils.compress(bin.toBin()); Path path = Paths.get(file.getCanonicalPath()); Files.write(path, compressed); } else Files.write(Paths.get(file.getCanonicalPath()), bin.toBin()); } catch (IOException ex) { ex.printStackTrace(); } } }
private void openSpec(ActionEvent t) { FileChooser fileChooser = FileChooserFactory .createOpenFileChooser(SPECIFICATION, rootModel.get().getWorkingdir()); File chosenFile = fileChooser .showOpenDialog(view.getScene().getWindow()); if (chosenFile == null) { return; } try { HybridSpecification spec = ImporterFacade .importHybridSpec(chosenFile, ImporterFacade.ImportFormat.XML); this.rootModel.get().getHybridSpecifications().add(spec); this.rootModel.get().getHistory() .addFilename(chosenFile.getAbsolutePath()); setWorkingDir(chosenFile); } catch (IOException | ImportException e) { AlertFactory.createAlert(e).showAndWait(); } }
@FXML private void handleFileSaveAction(ActionEvent event) { FileChooser fileChooser = new FileChooser(); File file = fileChooser.showSaveDialog(null); if (file != null) { try { WritableImage writableImage = new WritableImage((int) drawingCanvas.getWidth(), (int) drawingCanvas.getHeight()); drawingCanvas.snapshot(null, writableImage); RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null); ImageIO.write(renderedImage, "png", file); } catch (IOException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); } } }
public static File showFileChooser(Scene scene, FileChooser.ExtensionFilter filter) { String home = System.getProperty("user.home"); File[] downloads = { new File(home + "/Downloads/"), new File(home + "/Загрузки/"), new File(home) }; FileChooser fileChooser = new FileChooser(); for (File download : downloads) { if (download.exists()) { fileChooser.setInitialDirectory(download); break; } } fileChooser.setSelectedExtensionFilter(filter); return fileChooser.showOpenDialog(scene.getWindow()); }
@FXML protected void btnTDClickedFile() throws Exception{ String path2 = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); path2 = path2.substring(1, path2.lastIndexOf("/")) + "/"; FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open encTitleKeys.bin"); fileChooser.setInitialDirectory(new File(path2)); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("encTitleKeys", "*.bin")); File selectedFile = fileChooser.showOpenDialog(btnCancel.getScene().getWindow()); if(selectedFile != null){ String path = selectedFile.getPath(); textTDFile.setText(path); path = path.replaceAll(":", "!"); PropertiesHandler.setProperties(path, "tdfile"); } }
/** * Asks the user for a filename with a save file dialog, and saves a CSV with the entity clusters */ public void exportBtnHandler() { FileChooser fileChooser = new FileChooser(); // Set extension filter FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("CSV File", "*.csv"); fileChooser.getExtensionFilters().add(extFilter); // Show save file dialog File file = fileChooser.showSaveDialog(containerVBox.getScene().getWindow()); if (file != null) { // Results export to CSV try { PrintToFile.toCSV(entityClusters, file.getAbsolutePath()); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
public static File selectSquid25TaskFile(SquidProject squidProject, Window ownerWindow) throws SquidException, IOException, JAXBException, SAXException { File retVal = null; FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Select Squid 2.5 Task File in Excel '.xls"); fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Squid 2.5 Excel Task Files", "*.xls")); File squidTaskFile = fileChooser.showOpenDialog(ownerWindow); if (squidTaskFile != null) { if (squidTaskFile.getName().toLowerCase(Locale.US).endsWith(".xls")) { retVal = squidTaskFile; } else { throw new SquidException("Filename does not end with '.xls'"); } } return retVal; }
public static File saveExpressionFileXML(Expression expression, Window ownerWindow) throws IOException { File retVal = null; FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Expression '.xml' file"); fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Expression '.xml' files", "*.xml")); File mruFolder = new File(squidPersistentState.getMRUExpressionFolderPath()); fileChooser.setInitialDirectory(mruFolder.isDirectory() ? mruFolder : null); fileChooser.setInitialFileName(expression.getName() + ".xml"); File expressionFileXML = fileChooser.showSaveDialog(ownerWindow); if (expressionFileXML != null) { retVal = expressionFileXML; squidPersistentState.setMRUExpressionFolderPath(expressionFileXML.getParent()); ((XMLSerializerInterface) expression) .serializeXMLObject(expressionFileXML.getAbsolutePath()); } return retVal; }
public static File selectExpressionXMLFile(Window ownerWindow) throws IOException, JAXBException, SAXException { File retVal = null; FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Select Expression xml File '.xml"); fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Expression xml Files", "*.xml")); File mruFolder = new File(squidPersistentState.getMRUExpressionFolderPath()); fileChooser.setInitialDirectory(mruFolder.isDirectory() ? mruFolder : null); File expressionFileXML = fileChooser.showOpenDialog(ownerWindow); if (expressionFileXML != null) { if (expressionFileXML.getName().toLowerCase(Locale.US).endsWith(".xml")) { squidPersistentState.setMRUExpressionFolderPath(expressionFileXML.getParent()); retVal = expressionFileXML; } else { throw new IOException("Filename does not end with '.xml'"); } } return retVal; }
public FileVariableSetter(String variableName) { super(variableName); Button fileChooser= new Button("Choose file"); fileLabel=new Label("No file chosen"); FileChooser chooser=new FileChooser(); chooser.setInitialDirectory(baseDirectory); fileChooser.setOnMouseClicked((event)->{ File file=chooser.showOpenDialog(new Stage()); if(file!=null){ File relativePath=new File(baseDirectory.toURI().relativize(file.toURI()).getPath()); setField(relativePath); } }); this.getChildren().addAll(fileChooser,fileLabel); ; }
private boolean saveCode(ActionEvent t) { // Set the code filename, if no filename set yet Code code = rootModel.get().getScenario().getCode(); if (code.getFilename().isEmpty()) { FileChooser fileChooser = FileChooserFactory .createSaveFileChooser(CODE, rootModel.get().getWorkingdir()); File chosenFile = fileChooser .showSaveDialog(view.getScene().getWindow()); if (chosenFile == null) { return false; } code.setFilename(chosenFile.getAbsolutePath()); } // Export the code to the file try { ExporterFacade.exportCode(code, false); return true; } catch (IOException e) { AlertFactory.createAlert(e).showAndWait(); return false; } }
public static File chooseFile(){ FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("��ѡ���ļ�"); if(justVisitedDir == null) { // ���ó�ʼĿ¼ fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); } else { fileChooser.setInitialDirectory(justVisitedDir); } fileChooser.getExtensionFilters().addAll(new ExtensionFilter[]{new ExtensionFilter("Image Files", new String[]{"*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp"}), new ExtensionFilter("JPG", new String[]{"*.jpg"}), new ExtensionFilter("JPEG", new String[]{"*.jpeg"}), new ExtensionFilter("BMP", new String[]{"*.bmp"}), new ExtensionFilter("PNG", new String[]{"*.png"}), new ExtensionFilter("GIF", new String[]{"*.gif"})}); File file = fileChooser.showOpenDialog(null); if(file != null){ justVisitedDir = file.getParentFile(); } return file; }
/** * Opens a {@link FileChooser} and sets the parent {@link javafx.stage.Window} as * {@link Hygene#getPrimaryStage()#getOwner()}. * * @param fileChooser the file chooser that needs to be shown to the user * @param type a descriptive type name of the file that needs to be opened * @return a file object or {@code null} if no file was selected * @throws IOException if unable to open or parse the file * @throws UIInitialisationException if this method was called before {@link Hygene} was instantiated */ private File openFileAction(final FileChooser fileChooser, final String type) throws UIInitialisationException, IOException { final Stage primaryStage = Hygene.getInstance().getPrimaryStage(); final File recentDirectory = RecentDirectory.get(type); if (recentDirectory.exists()) { fileChooser.setInitialDirectory(recentDirectory); } final File file = fileChooser.showOpenDialog(primaryStage.getScene().getWindow()); if (file == null) { return null; } if (file.getParentFile() != null) { RecentDirectory.store(type, file.getParentFile()); } return file; }
@FXML private void saveNewAppListToXml(ActionEvent event) { JAXBContext context; try { context = JAXBContext.newInstance(UserAppList.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); FileChooser fc = new FileChooser(); File file = fc.showSaveDialog(null); if (file != null) { marshaller.marshal(userAppList, file); JFXSnackbar info = new JFXSnackbar(root); info.show(I18n.getMessage("savedtoxml") + file.getAbsolutePath(), 3000); prefs.put(PreferencesKeys.SAVE_PATH.toString(), file.getAbsolutePath()); } } catch (JAXBException e) { e.printStackTrace(); } }
public void handleSelectImage(MouseEvent mouseEvent) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(imageChooserTitle); fileChooser.getExtensionFilters().add(new ExtensionFilter("PNG", "*.png")); final File file = fileChooser .showOpenDialog(((Node) mouseEvent.getSource()).getScene().getWindow()); if (file == null) { return; } try { final byte[] image = ImageUtils.readImage(file); model.imageRaw.set(image); } catch (IOException e) { e.printStackTrace(); } }
/** * 保存数据按钮被点击 */ @FXML public void onSaveDataBtnClicked() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("保存到..."); File file = fileChooser.showSaveDialog(AppDelegate.static_stage); if (file == null) { receivedToFileCbox.setSelected(false); return; } //解除文件占用 unlockFile(file); //统一换行符 String data = dataTextArea.getText().replace("\r", ""); data = data.replace("\n", "\r\n"); //写入文件 writeToFile(data, file); }
private void saveMatches() { Path path = Gui.requestFile("Save matches file", gui.getScene().getWindow(), Arrays.asList(new FileChooser.ExtensionFilter("Matches", "*.match")), false); if (path == null) return; if (!path.getFileName().toString().toLowerCase(Locale.ENGLISH).endsWith(".match")) { path = path.resolveSibling(path.getFileName().toString()+".match"); } try { if (Files.isDirectory(path)) { gui.showAlert(AlertType.ERROR, "Save error", "Invalid file selection", "The selected file is a directory."); } else if (Files.exists(path)) { Files.deleteIfExists(path); } if (!gui.getMatcher().saveMatches(path)) { gui.showAlert(AlertType.WARNING, "Matches save warning", "No matches to save", "There are currently no matched classes, so saving was aborted."); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } }
@Override public void setAcceptAllFileFilterUsed(boolean bool) { boolean differs = isAcceptAllFileFilterUsed() ^ bool; super.setAcceptAllFileFilterUsed(bool); if (!FX_AVAILABLE) { return; } if (differs) { if (bool) { fileChooser.getExtensionFilters() .add(new FileChooser.ExtensionFilter("All files", "*.*")); } else { for (Iterator<FileChooser.ExtensionFilter> it = fileChooser.getExtensionFilters().iterator(); it.hasNext();) { FileChooser.ExtensionFilter filter = it.next(); if (filter.getExtensions().size() == 1 && filter.getExtensions().contains("*.*")) { it.remove(); } } } } }
private void loadDungeon(Stage stage) { FileChooser chooser = new FileChooser(); chooser.setInitialFileName("dungeon.json"); File file = chooser.showOpenDialog(stage); if (file != null) { try { JSONObject data; BufferedReader reader = new BufferedReader(new FileReader(file)); JSONFormatParser parser = new JSONFormatParser(256); data = (JSONObject) parser.parse(reader); reader.close(); this.dungeon = Dungeon.loadFromJSON(data); this.dungeonHandler = new DungeonHandler(this.dungeon); } catch (IOException e) { e.printStackTrace(); } } }
protected void createSelectButton() { selectButton = new Button("Select..."); selectButton.setOnAction(event -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Select file"); if (LastVisitedDirectory.getInstance().wasVisited()) { fileChooser.setInitialDirectory(new File(LastVisitedDirectory.getInstance().getPath())); } try { String newPath = getFilePath(fileChooser, primaryStage); LastVisitedDirectory.getInstance().setLastVisitedDirectory(newPath); pathTextField.setText(newPath); } catch (NullPointerException e) { System.out.println("Canceled"); } }); }
public String getRestore(){ String backuppath =""; File file; FileChooser fileChooser= new FileChooser(); file = fileChooser.showOpenDialog(stage); fileChooser.setTitle("Select Photo"); if (file != null) { fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("All Images", "*.*"), new FileChooser.ExtensionFilter("SQL", "*.sql") ); backuppath = file.getAbsolutePath(); } return backuppath; }
public void exportMjlog(ActionEvent actionEvent) throws IOException { if (this.tableView.getSelectionModel().getSelectedItem() != null) { InfoSchema infoSchema = this.tableView.getSelectionModel().getSelectedItem(); String content = this.databaseService.findMjlogById(infoSchema.getId()); if (content != null) { FileChooser fileChooser = new FileChooser(); fileChooser.setInitialFileName(infoSchema.getId()); fileChooser.setTitle("Save mjlog File"); fileChooser.getExtensionFilters().add( new FileChooser.ExtensionFilter("mjlog Files", "*.mjlog")); File selectedFile = fileChooser.showSaveDialog(this.dateListView.getScene().getWindow()); if (selectedFile != null) { Files.copy(new ByteArrayInputStream(content.getBytes()), selectedFile.toPath()); } } } }
@FXML private void handleButtonBrowseAbbott(ActionEvent event) { Stage stage = (Stage) ap.getScene().getWindow(); File lastPath = new File(prefs.get(Constants.IMPORTER_ABBOTT_IMPORT_PATH_KEY + 0, "")); FileChooser fileChooser = new FileChooser(); configureFileChooser(fileChooser, lastPath, Constants.TXT_EXTENSION_FILTER); List<File> files = fileChooser.showOpenMultipleDialog(stage); if (files != null && !files.isEmpty()) { StringBuilder sb = new StringBuilder(); files.forEach((item) -> { sb.append(item.getAbsolutePath()).append(Constants.MULTI_FILE_PATH_DELIMITER); }); abbottTextField.setText(sb.toString().substring(0, sb.length() - 1)); abbottCheckBox.setSelected(true); } }
@FXML private void handleButtonBrowseGoogleFit(ActionEvent event) { Stage stage = (Stage) ap.getScene().getWindow(); File lastPath = new File(prefs.get(Constants.IMPORTER_GOOGLE_FIT_IMPORT_PATH_KEY + 0, "")); FileChooser fileChooser = new FileChooser(); configureFileChooser(fileChooser, lastPath, Constants.CSV_EXTENSION_FILTER); List<File> files = fileChooser.showOpenMultipleDialog(stage); if (files != null && !files.isEmpty()) { StringBuilder sb = new StringBuilder(); files.forEach((item) -> { sb.append(item.getAbsolutePath()).append(Constants.MULTI_FILE_PATH_DELIMITER); }); googleFitTextField.setText(sb.toString().substring(0, sb.length() - 1)); googleFitCheckBox.setSelected(true); } }
@FXML private void handleButtonBrowseGoogleTracks(ActionEvent event) { Stage stage = (Stage) ap.getScene().getWindow(); File lastPath = new File(prefs.get(Constants.IMPORTER_GOOGLE_TRACKS_IMPORT_PATH_KEY + 0, "")); FileChooser fileChooser = new FileChooser(); configureFileChooser(fileChooser, lastPath, Constants.JSON_EXTENSION_FILTER); List<File> files = fileChooser.showOpenMultipleDialog(stage); if (files != null && !files.isEmpty()) { StringBuilder sb = new StringBuilder(); files.forEach((item) -> { sb.append(item.getAbsolutePath()).append(Constants.MULTI_FILE_PATH_DELIMITER); }); googleGatheredTextField.setText(sb.toString().substring(0, sb.length() - 1)); googleGatheredCheckBox.setSelected(true); } }
@FXML private void handleButtonBrowseRoche(ActionEvent event) { Stage stage = (Stage) ap.getScene().getWindow(); File lastPath = new File(prefs.get(Constants.IMPORTER_ROCHE_IMPORT_PATH_KEY + 0, "")); FileChooser fileChooser = new FileChooser(); configureFileChooser(fileChooser, lastPath, Constants.CSV_EXTENSION_FILTER); List<File> files = fileChooser.showOpenMultipleDialog(stage); if (files != null && !files.isEmpty()) { StringBuilder sb = new StringBuilder(); files.forEach((item) -> { sb.append(item.getAbsolutePath()).append(Constants.MULTI_FILE_PATH_DELIMITER); }); sonyTextField.setText(sb.toString().substring(0, sb.length() - 1)); sonyCheckBox.setSelected(true); } }
@FXML private void handleButtonBrowseOpenDiabetesVault(ActionEvent event) { Stage stage = (Stage) ap.getScene().getWindow(); File lastPath = new File(prefs.get(Constants.IMPORTER_ODV_IMPORT_PATH_KEY + 0, "")); FileChooser fileChooser = new FileChooser(); configureFileChooser(fileChooser, lastPath, Constants.JSON_EXTENSION_FILTER); List<File> files = fileChooser.showOpenMultipleDialog(stage); if (files != null && !files.isEmpty()) { StringBuilder sb = new StringBuilder(); files.forEach((item) -> { sb.append(item.getAbsolutePath()).append(Constants.MULTI_FILE_PATH_DELIMITER); }); odvTextField.setText(sb.toString().substring(0, sb.length() - 1)); odvCheckBox.setSelected(true); } }
public ImageVariableSetter(String variableName) { super(variableName); myImagePath=new SimpleStringProperty(); myContents=new VBox(); getChildren().add(myContents); Button button= new Button("Choose Image File"); button.setOnMouseClicked((event)->{ FileChooser chooser=new FileChooser(); chooser.setInitialDirectory(base); File imageFile=chooser.showOpenDialog(new Stage()); if(imageFile!=null){ File relativePath=new File(base.toURI().relativize(imageFile.toURI()).getPath()); myImagePath.set(relativePath.toString()); System.out.println(relativePath); } }); myContents.getChildren().addAll(new ImageDisplay(),button); myContents.setSpacing(20); System.out.println(base); }
/** * Save image. */ @FXML public void saveImage(){ FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Image"); fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("PNG File","*.png"), new FileChooser.ExtensionFilter("GIF File","*.gif")); File image = fileChooser.showSaveDialog(saveNode.getScene().getWindow()); int fileExtensionLength = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).length(); String fileExt = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).substring(2,fileExtensionLength); try { ImageIO.write(getSnapshot(saveNode),fileExt,image); } catch (IOException e) { e.printStackTrace(); } }
private Button createSaveFlightButton(Stage stage){ Button btnSaveFlight = new Button(); btnSaveFlight.setLayoutX(10); btnSaveFlight.setLayoutY(60);; btnSaveFlight.setText("Save Flight"); btnSaveFlight.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent e) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Flight plan (xml)"); File file = fileChooser.showSaveDialog(stage); if (file != null) { System.out.println("Selected " + file); try { fzv.setPlanningMode(false); new SaveXMLFlight(file.getAbsolutePath(),wayPoints); } catch (IOException | FlightZoneException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }}); return btnSaveFlight; }
/** * Load flight plans from file * @param flightZoneView * @param btnText * @param stage * @return */ Button makeFlightPickerButton(final FlightZoneView flightZoneView, String btnText, Stage stage){ Button btnFlights = createButton(btnText, 120); btnFlights.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent e) { // File file = fileChooser.showOpenDialog(stage); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Flight plan (xml)"); fileChooser.getExtensionFilters().addAll( new ExtensionFilter("XML Files", "*.xml")); File selectedFile = fileChooser.showOpenDialog(stage); if (selectedFile != null) { System.out.println("Selected " + selectedFile); flightZoneView.flightManager.loadFlightFromXML(selectedFile.toString()); } } }); return btnFlights; }
@FXML void exportTypeSummaries(ActionEvent event) throws IOException { FileChooser saveChooser = new FileChooser(); saveChooser.setTitle("Export (Save) data"); saveChooser.setInitialFileName(pkg.getName() + "_type_summary.xlsx"); File saveFile = saveChooser.showSaveDialog(null); if (saveFile != null) { FileOutputStream out = new FileOutputStream(saveFile); String[] headers = new String[]{ "Type", "Count" }; ReportUtil.exportSpreadsheet(out, pkgContents.getFilesByType().entrySet(), headers, Map.Entry::getKey, e->e.getValue().size() ); out.close(); } }
public void exportPackagesButtonPressed(ActionEvent evt) throws FileNotFoundException, IOException { FileChooser saveChooser = new FileChooser(); saveChooser.setTitle("Export (Save) data"); saveChooser.setInitialFileName("package_list.xlsx"); File saveFile = saveChooser.showSaveDialog(null); if (saveFile != null) { FileOutputStream out = new FileOutputStream(saveFile); String[] headers = new String[]{ "Group", "Package Name", "Package File", "Size", "Version", "Created", "Created By", "Last Modified", "Modified By", "Last Unpacked", "Unpacked By" }; ReportUtil.exportSpreadsheet(out, packageList, headers, PackageType::getGroup, PackageType::getName, PackageType::getDownloadName, PackageType::getSize, PackageOps::getInformativeVersion, PackageType::getCreated, PackageType::getCreatedBy, PackageType::getLastModified, PackageType::getLastModifiedBy, PackageType::getLastUnpacked, PackageType::getLastUnpackedBy ); out.close(); } }