List of usage examples for javafx.stage FileChooser showSaveDialog
public File showSaveDialog(final Window ownerWindow)
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
@FXML private void exportToCSV(ActionEvent evt) { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().setAll(new FileChooser.ExtensionFilter("CSV file", "*.csv"), new FileChooser.ExtensionFilter("Tab-delimited file", "*.txt")); File file = chooser.showSaveDialog(datasetDiffView.getStage()); if (file != null) { CSVFormat format = CSVFormat.RFC4180; String outputFormat = chooser.getSelectedExtensionFilter().getDescription(); if (outputFormat.equalsIgnoreCase("Tab-delimited file")) format = CSVFormat.TDF;//w w w.ja v a 2 s . com try { List<List<String>> dataAsTable = getDataAsTable(); fillCSVFormat(format, new FileWriter(file), dataAsTable); Alert window = new Alert(Alert.AlertType.CONFIRMATION, "CSV file '" + file + "' saved with " + (dataAsTable.get(0).size() - 1) + " rows."); window.showAndWait(); } catch (IOException e) { Alert window = new Alert(Alert.AlertType.ERROR, "Could not save CSV to '" + file + "': " + e); window.showAndWait(); } } }
From source file:com.esri.geoevent.test.performance.ui.OrchestratorController.java
/** * Displays a file chooser to select a file location to save the * configuration file.//from w w w .j a va2 s . c o m */ private void saveFixturesFile() { File currentDir = Paths.get("").toAbsolutePath().toFile(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_SAVE_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); fileChooser.setInitialFileName(DEFAULT_FIXTURES_FILE); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { saveFile(file); } catch (Exception error) { //TODO: Improve error handling and reporting error.printStackTrace(); } } }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
private void handleExportAsStlFile(ActionEvent e) { if (csgObject == null) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export STL. There is no geometry !"); alert.setContentText("Please verify that your code generates a valid CSG object."); alert.showAndWait();//w ww . j av a 2 s .c o m return; } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export STL File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("STL files (*.stl)", "*.stl")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".stl")) { fName += ".stl"; } try { eu.mihosoft.vrl.v3d.FileUtil.write(Paths.get(fName), csgObject.toStlString()); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export STL. There went something wrong writing the file."); alert.setContentText( "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace."); alert.showAndWait(); } }
From source file:view.EditorView.java
@FXML void menuItemSaveAsOnAction(@SuppressWarnings("unused") ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save game file"); File file = fileChooser.showSaveDialog(stage); if (file != null) { // if file == null the action was aborted try {/* w w w .j a v a2 s . c o m*/ getCurrentGame().save(file); } catch (IOException e) { FOKLogger.log(MainWindow.class.getName(), Level.SEVERE, "Could not save the game from the \"Save As\" menu", e); new Alert(Alert.AlertType.ERROR, "Could not save the game file: \n\n" + ExceptionUtils.getRootCauseMessage(e)).show(); } } }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
private void handleExportAsPngFile(ActionEvent e) { if (csgObject == null) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There is no geometry !"); alert.setContentText("Please verify that your code generates a valid CSG object."); alert.showAndWait();/*from w w w . ja v a 2 s. co m*/ return; } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There went something wrong writing the file."); alert.setContentText( "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace."); alert.showAndWait(); } }
From source file:com.ggvaidya.scinames.ui.DataReconciliatorController.java
@FXML private void exportToCSV(ActionEvent evt) { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().setAll(new FileChooser.ExtensionFilter("CSV file", "*.csv"), new FileChooser.ExtensionFilter("Tab-delimited file", "*.txt")); File file = chooser.showSaveDialog(dataReconciliatorView.getStage()); if (file != null) { CSVFormat format = CSVFormat.RFC4180; String outputFormat = chooser.getSelectedExtensionFilter().getDescription(); if (outputFormat.equalsIgnoreCase("Tab-delimited file")) format = CSVFormat.TDF;//from w ww.j a v a2 s . c o m try { List<List<String>> dataAsTable = getDataAsTable(); fillCSVFormat(format, new FileWriter(file), dataAsTable); Alert window = new Alert(Alert.AlertType.CONFIRMATION, "CSV file '" + file + "' saved with " + (dataAsTable.get(0).size() - 1) + " rows."); window.showAndWait(); } catch (IOException e) { Alert window = new Alert(Alert.AlertType.ERROR, "Could not save CSV to '" + file + "': " + e); window.showAndWait(); } } }
From source file:com.rvantwisk.cnctools.controllers.CNCToolsController.java
@FXML public void generateGCode(ActionEvent event) throws Exception { if (v_projectList.getSelectionModel().selectedItemProperty().get() != null) { final Project p = v_projectList.getSelectionModel().selectedItemProperty().get(); if (p.postProcessorProperty().get() == null) { MonologFX dialog = new MonologFX(MonologFX.Type.QUESTION); dialog.setTitleText("No postprocessor"); dialog.setMessage("No post processor configured, please select a post processor first!"); dialog.show();/*w w w .j a va 2 s. co m*/ } else { final GCodeCollection gCode = p.getGCode(toolDBManager); gCode.merge(); FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("NC File", "*.tap", "*.ngc")); fileChooser.setTitle("Save GCode"); File choosenName = fileChooser.showSaveDialog(null); if (choosenName != null) { choosenName.delete(); if (!p.getPostProcessor().isHasToolChanger()) { final GCodeCollection.GeneratedGCode preAmble = gCode.get(0); final GCodeCollection.GeneratedGCode postAmble = gCode.get(gCode.size() - 1); for (int i = 1; i <= (gCode.size() - 2); i++) { final String[] path = choosenName.getPath().split("\\.(?=[^\\.]+$)"); File thisSet = new File(path[0] + "-" + i + "." + path[1]); thisSet.delete(); // Concate all g-code String file = preAmble.getGCode().toString() + SEPERATOR + gCode.get(i).getGCode().toString() + SEPERATOR + postAmble.getGCode().toString() + SEPERATOR; saveGCode(file, thisSet); } } else { saveGCode(gCode.concate().toString(), choosenName); } } } } }
From source file:org.noroomattheinn.visibletesla.MainController.java
private void exportStats(String[] columns) { String initialDir = prefs.storage().get(App.LastExportDirKey, System.getProperty("user.home")); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export Data"); fileChooser.setInitialDirectory(new File(initialDir)); File file = fileChooser.showSaveDialog(app.stage); if (file != null) { String enclosingDirectory = file.getParent(); if (enclosingDirectory != null) prefs.storage().put(App.LastExportDirKey, enclosingDirectory); Range<Long> exportPeriod = DateRangeDialog.getExportPeriod(app.stage); if (exportPeriod == null) return; if (vtData.export(file, exportPeriod, columns)) { Dialogs.showInformationDialog(app.stage, "Your data has been exported", "Data Export Process", "Export Complete"); } else {// ww w.j ava 2 s. c o m Dialogs.showErrorDialog(app.stage, "Unable to save to: " + file, "Data Export Process", "Export Failed"); } } }
From source file:ninja.javafx.smartcsv.fx.SmartCSVController.java
@FXML public void export(ActionEvent actionEvent) { final FileChooser fileChooser = new FileChooser(); //Set extension filter final FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(EXPORT_LOG_FILTER_TEXT, EXPORT_LOG_FILTER_EXTENSION); fileChooser.getExtensionFilters().add(extFilter); fileChooser.setTitle("Save"); //Show open file dialog File file = fileChooser.showSaveDialog(applicationPane.getScene().getWindow()); if (file != null) { errorExport.setCsvFilename(currentCsvFile.getFile().getName()); errorExport.setModel(currentCsvFile.getContent()); errorExport.setFile(file);//w w w. ja v a2 s. c o m errorExport.setResourceBundle(resourceBundle); errorExport.restart(); } }
From source file:org.noroomattheinn.visibletesla.MainController.java
private void exportCycles(String cycleType) { String initialDir = prefs.storage().get(App.LastExportDirKey, System.getProperty("user.home")); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export " + cycleType + " Data"); fileChooser.setInitialDirectory(new File(initialDir)); Stage stage = app.stage;/*w w w. ja va 2 s . com*/ File file = fileChooser.showSaveDialog(stage); if (file != null) { String enclosingDirectory = file.getParent(); if (enclosingDirectory != null) prefs.storage().put(App.LastExportDirKey, enclosingDirectory); Range<Long> exportPeriod = DateRangeDialog.getExportPeriod(stage); if (exportPeriod == null) return; boolean exported; if (cycleType.equals("Charge")) { exported = vtData.exportCharges(file, exportPeriod); } else { exported = vtData.exportRests(file, exportPeriod); } if (exported) { Dialogs.showInformationDialog(stage, "Your data has been exported", "Data Export Process", "Export Complete"); } else { Dialogs.showErrorDialog(stage, "Unable to save to: " + file, "Data Export Process", "Export Failed"); } } }