List of usage examples for javafx.stage FileChooser showSaveDialog
public File showSaveDialog(final Window ownerWindow)
From source file:Main.StaticTools.java
public static File getFile(File dir) { FileChooser chooser = new FileChooser(); if (Files.exists(dir.toPath())) chooser.setInitialDirectory(dir); else//from w w w. j ava2 s.co m chooser.setInitialDirectory(new File("C:\\")); return chooser.showSaveDialog(null); }
From source file:com.exalttech.trex.util.files.FileManager.java
/** * Return selected file/* w w w . j a v a2 s . c o m*/ * * @param windowTitle * @param fileName * @param window * @param type * @param filePath * @param isExport * @return */ public static File getSelectedFile(String windowTitle, String fileName, Window window, FileType type, String filePath, boolean isExport) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(windowTitle); fileChooser.setInitialFileName(fileName); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(type.getFilterDescription(), type.getFilterExtension()); fileChooser.getExtensionFilters().add(extFilter); FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*"); fileChooser.getExtensionFilters().add(allFilesFilter); if (!Util.isNullOrEmpty(filePath) && new File(filePath).exists()) { fileChooser.setInitialDirectory(new File(filePath)); } if (isExport) { return fileChooser.showSaveDialog(window); } else { return fileChooser.showOpenDialog(window); } }
From source file:UI.MainPageController.java
/** * This will select the file to say to and then call the pdf's build function * to export the updated pdf// ww w . j a va2 s . c o m */ @FXML private void exportPDFPress() { FileChooser chooser = new FileChooser(); File file = chooser.showSaveDialog(new Stage()); if (file == null) { showWarning("No file selected or created"); filename = ""; } else { try { if (!file.exists()) { file.createNewFile(); } } catch (Exception e) { ; } filename = file.getPath(); try { pdf.buildPDF(filename); } catch (Exception e) { System.out.println("Export PDF FAIL"); } } }
From source file:com.coolchick.translatortemplater.Main.java
public boolean spitNewDatabase() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Choose destination"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON file(*.json)", "*.json")); File file = fileChooser.showSaveDialog(getStage()); return file != null && spitDatabase(file); }
From source file:org.cryptomator.ui.controllers.MainController.java
@FXML private void didClickCreateNewVault(ActionEvent event) { final FileChooser fileChooser = new FileChooser(); final File file = fileChooser.showSaveDialog(mainWindow); if (file == null) { return;// ww w.jav a 2 s.c om } try { final Path vaultDir = file.toPath(); if (!Files.exists(vaultDir)) { Files.createDirectory(vaultDir); } addVault(vaultDir, true); } catch (IOException e) { LOG.error("Unable to create vault", e); } }
From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java
public PerformUpdateDialog(RemoteVersionResult newVersion) { this.chosen = new SimpleObjectProperty<>( Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile()); this.setHeaderText("Updating to " + newVersion.getVersion()); this.setTitle("Skadi Updater"); this.getDialogPane().getStyleClass().add("alert"); this.getDialogPane().getStyleClass().add("information"); final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE); this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL); Node btn = this.getDialogPane().lookupButton(restartButtonType); btn.setDisable(true);/*from w w w .j ava2 s . co m*/ Label lbPath = new Label("Save as"); TextField tfPath = new TextField(); tfPath.textProperty() .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen)); tfPath.setPrefColumnCount(40); tfPath.setEditable(false); Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse..."); btChangePath.setOnAction(event -> { FileChooser fc = new FileChooser(); fc.setTitle("Save downloaded jar.."); fc.setInitialFileName(this.chosen.getValue().getName()); fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar")); fc.setInitialDirectory(this.chosen.getValue().getParentFile()); File selected = fc.showSaveDialog(this.getOwner()); if (selected != null) { this.chosen.set(selected); } }); ProgressBar pbDownload = new ProgressBar(0); pbDownload.setDisable(true); pbDownload.setMaxWidth(Double.MAX_VALUE); Label lbDownload = new Label("Download"); Label lbDownloadValue = new Label(); Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start"); btDownload.setMaxWidth(Double.MAX_VALUE); btDownload.setOnAction(event -> { btChangePath.setDisable(true); btDownload.setDisable(true); this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue()); lbDownloadValue.textProperty().bind(this.downloadService.messageProperty()); pbDownload.progressProperty().bind(this.downloadService.progressProperty()); this.downloadService.setOnSucceeded(dlEvent -> { btn.setDisable(false); }); this.downloadService.setOnFailed(dlFailed -> { LOGGER.error("new version download failed", dlFailed.getSource().getException()); lbDownloadValue.textProperty().unbind(); lbDownloadValue.setText("Download failed, check log file for details."); }); this.downloadService.start(); }); final GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.add(lbPath, 0, 0); grid.add(tfPath, 1, 0); grid.add(btChangePath, 2, 0); grid.add(new Separator(), 0, 1, 3, 1); grid.add(lbDownload, 0, 2); grid.add(pbDownload, 1, 2); grid.add(btDownload, 2, 2); grid.add(lbDownloadValue, 1, 3); this.getDialogPane().setContent(grid); this.setResultConverter(btnType -> { if (btnType == restartButtonType) { return this.chosen.getValue(); } if (btnType == ButtonType.CANCEL) { if (this.downloadService.isRunning()) { this.downloadService.cancel(); } } return null; }); }
From source file:de.pixida.logtest.designer.MainWindow.java
private boolean handleSaveDocumentAs() { final FileChooser fileChooser = this.createFileDialog(this.getCurrentEditor().getType(), "Save"); final File selectedFile = fileChooser.showSaveDialog(this.primaryStage); if (selectedFile == null) { return false; } else {/* w w w .ja va2s .c o m*/ this.applyFolderOfSelectedFileInOpenOrSaveAsFileDialog(selectedFile); boolean overwriteIfPresent = true; final Tab openedDocument = this.findTabThatIsAssignedToFile(selectedFile); if (openedDocument != null) { final Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Confirm overwrite"); alert.setHeaderText("The file is already opened."); alert.setContentText("Do you want to overwrite the file?"); final Optional<ButtonType> choice = alert.showAndWait(); if (choice.get() != ButtonType.OK) { overwriteIfPresent = false; } } if (overwriteIfPresent) { this.getCurrentEditor().assignDocumentToFile(selectedFile); return this.saveDocument(); } else { return false; } } }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java
/** * A handler for the export to JPEG option in the context menu. *//*w ww .j a v a 2s . c o m*/ private void handleExportToJPEG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to JPEG"); fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("JPEG", "jpg")); File file = fileChooser.showSaveDialog(this.getScene().getWindow()); if (file != null) { try { ExportUtils.writeAsJPEG(this.chart, (int) getWidth(), (int) getHeight(), file); } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:ExcelFx.FXMLDocumentController.java
@FXML private void Print(ActionEvent event) throws IOException { System.out.println("Pressed print button"); FileChooser chooser = new FileChooser(); chooser.setTitle("Open File"); File file = chooser.showSaveDialog(this.SplitPane.getScene().getWindow()); System.out.println(file.getAbsolutePath()); printXls(file.getAbsolutePath(), sortProf); System.out.println("Print finished"); System.out.println("-----------------------------------------------------------"); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java
/** * A handler for the export to PDF option in the context menu. *//*w w w .ja v a2s . com*/ private void handleExportToPDF() { FileChooser fileChooser = new FileChooser(); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Document Format (PDF)", "pdf")); fileChooser.setTitle("Export to PDF"); File file = fileChooser.showSaveDialog(this.getScene().getWindow()); if (file != null) { ExportUtils.writeAsPDF(this.chart, (int) getWidth(), (int) getHeight(), file); } }