List of usage examples for javafx.stage FileChooser showSaveDialog
public File showSaveDialog(final Window ownerWindow)
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to SVG option in the context menu. *//*from ww w.j a v a 2 s.com*/ private void handleExportToSVG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to SVG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Scalable Vector Graphics (SVG)", "svg")); File file = fileChooser.showSaveDialog(stage); if (file != null) { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); SVGGraphics2D sVGGraphics2D = new SVGGraphics2D((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight); Graphics2D graphics2D = (Graphics2D) sVGGraphics2D.create(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { ((Drawable) canvas.chart).draw(graphics2D, canvasPositionAndSize.positionsAndSizes.get(index)); index++; } try { SVGUtils.writeToSVG(file, sVGGraphics2D.getSVGElement()); } catch (IOException ex) { Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to PNG option in the context menu. *//*from ww w .jav a 2 s . co m*/ private void handleExportToPNG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to PNG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png")); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { ImageIO.write(image, "png", out); } } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:mesclasses.view.RootLayoutController.java
@FXML public void onExport() { File archive;//ww w .j a v a 2s . c om try { archive = FileSaveUtil.archive(); } catch (IOException e) { notif(e); return; } FileChooser chooser = new FileChooser(); chooser.setTitle("Sauvegardez les donnes"); chooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Archive MesClasses", "*.zip")); LOG.info("archiving in " + archive.getPath()); chooser.setInitialFileName(FilenameUtils.getName(archive.getPath())); File file = chooser.showSaveDialog(primaryStage); if (file != null) { try { FileUtils.moveFile(archive, file); } catch (IOException ex) { notif(ex); } displayNotification(MessageEvent.SUCCESS, "Donnes sauvegardes"); } }
From source file:org.martus.client.swingui.PureFxMainWindow.java
protected File showFileSaveDialog(String title, File directory, String defaultFilename, FormatFilter filter) { FileChooser fileChooser = createFileChooser(title, directory, filter); fileChooser.setInitialFileName(defaultFilename); return fileChooser.showSaveDialog(getActiveStage()); }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to PDF option in the context menu. *//* w ww . j av a 2 s . c om*/ 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(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); PDDocument doc = new PDDocument(); PDPage page = new PDPage(new PDRectangle((float) canvasPositionAndSize.totalWidth, (float) canvasPositionAndSize.totalHeight)); doc.addPage(page); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false); PDXObjectImage pdImage = new PDPixelMap(doc, image); contentStream.drawImage(pdImage, 0, 0); PDPageContentStream cos = new PDPageContentStream(doc, page); cos.drawXObject(pdImage, 0, 0, pdImage.getWidth(), pdImage.getHeight()); cos.close(); doc.save(file); } catch (IOException | COSVisitorException ex) { Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex); } /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(), (int)canvas.getHeight(), file);*/ /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(), (int)canvas.getHeight(), file);*/ } }
From source file:org.martus.client.swingui.PureFxMainWindow.java
protected File showFileSaveDialog(String title, File directory, Vector<FormatFilter> filters) { while (true) { FileChooser fileChooser = createFileChooser(title, directory, filters.toArray(new FormatFilter[filters.size()])); File selectedFile = fileChooser.showSaveDialog(getActiveStage()); if (selectedFile == null) return null; List<String> extensions = fileChooser.getSelectedExtensionFilter().getExtensions(); String extension = extensions.get(0).replace("*", ""); String fileName = selectedFile.getName(); if (!fileName.toLowerCase().endsWith(extension.toLowerCase())) { selectedFile = getFileWithExtension(selectedFile, extension); if (!selectedFile.exists()) return selectedFile; if (confirmDlg(getCurrentActiveFrame().getSwingFrame(), "OverWriteExistingFile")) return selectedFile; } else {// w ww . j ava2 s .com return selectedFile; } directory = selectedFile.getParentFile(); } }
From source file:org.craftercms.social.migration.controllers.MainController.java
@Override public void initialize(final URL location, final ResourceBundle resources) { configTable();//from www . j av a 2 s. c o m mnuQuit.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { stopTasks(); Platform.exit(); } }); ctxClearLog.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { logTable.getItems().clear(); } }); ctxClearProfileSelection.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstProfileScripts.getSelectionModel().clearSelection(); } }); ctxClearSocialSelection.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstSocialScripts.getSelectionModel().clearSelection(); } }); lstProfileScripts.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); lstSocialScripts.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); lstProfileScripts.setCellFactory(new Callback<ListView, ListCell>() { @Override public ListCell call(final ListView listView) { return new FileListCell(); } }); lstSocialScripts.setCellFactory(new Callback<ListView, ListCell>() { @Override public ListCell call(final ListView listView) { return new FileListCell(); } }); ctxReloadProfileScrp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstProfileScripts.getItems().clear(); try { extractBuildInScripts("profile", lstProfileScripts); } catch (MigrationException e) { log.error("Unable to extract BuildIn scripts"); } loadScripts(MigrationTool.systemProperties.getString("crafter.migration.profile.scripts"), lstProfileScripts); } }); ctxReloadSocialScrp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstSocialScripts.getItems().clear(); try { extractBuildInScripts("profile", lstSocialScripts); } catch (MigrationException e) { log.error("Unable to extract BuildIn scripts"); } loadScripts(MigrationTool.systemProperties.getString("crafter.migration.social.scripts"), lstSocialScripts); } }); final MigrationSelectionAction selectionEventHandler = new MigrationSelectionAction(); rbtMigrateProfile.setOnAction(selectionEventHandler); rbtMigrateSocial.setOnAction(selectionEventHandler); loadScripts(); loadDefaultValues(); saveLog.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)); saveLog.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Migration Log"); fileChooser.setInitialFileName("Crafter-Migration-" + new SimpleDateFormat("yyyy-MM-dd@HH_mm").format(new Date()) + ".html"); final File savedFile = fileChooser.showSaveDialog(scene.getWindow()); if (savedFile == null) { return; } try { getHtml(new FileWriter(savedFile)); log.info("Saved Html log file"); } catch (IOException | TransformerException ex) { log.error("Unable to save file", ex); } } }); mnuStart.setAccelerator(new KeyCodeCombination(KeyCode.F5)); mnuStart.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent event) { if (currentTask == null || !currentTask.isRunning()) { ObservableList scriptsToRun; if (rbtMigrateProfile.isSelected()) { scriptsToRun = lstProfileScripts.getSelectionModel().getSelectedItems(); } else { scriptsToRun = lstSocialScripts.getSelectionModel().getSelectedItems(); } currentTask = new MigrationPipeService(logTable, pgbTaskProgress, srcHost.getText(), srcPort.getText(), srcDb.getText(), dstHost.getText(), dstPort.getText(), dstDb.getText(), scriptsToRun); } if (!currentTask.isRunning()) { final Thread t = new Thread(currentTask, "Migration Task"); t.start(); } } }); }
From source file:com.ggvaidya.scinames.complexquery.ComplexQueryViewController.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(scene.getWindow()); if (file != null) { CSVFormat format = CSVFormat.RFC4180; String outputFormat = chooser.getSelectedExtensionFilter().getDescription(); if (outputFormat.equalsIgnoreCase("Tab-delimited file")) format = CSVFormat.TDF;/* 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:ipat_fx.FXMLDocumentController.java
@FXML private void saveOption(ActionEvent event) { FileChooser fc = new FileChooser(); File file = new File(contextPath + "Saves/"); if (!file.exists()) { file.mkdirs();/*from w w w . jav a 2s. c o m*/ } fc.setInitialDirectory(file); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); Date date = new Date(); fc.setInitialFileName("Ipat_" + dateFormat.format(date)); File dest = fc.showSaveDialog(null); File src = new File(dataPath); try { FileUtils.copyDirectory(src, dest); } catch (IOException ex) { Logger.getLogger(IPAT_FX.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java
@FXML private void convertFileClicked(MouseEvent event) { fileToConvert = new File(sourceFileText.getText()); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Specify a file to save"); fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); convertedFile = fileChooser.showSaveDialog(mainAnchorPane.getScene().getWindow()); if (convertedFile != null) { try {//from www. j ava 2 s.com conversionFileHandler.setCurrentFileLocation(fileToConvert.getCanonicalPath()); convertButton.setDisable(false); } catch (IOException ex) { Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex); if (!conversionFileHandler.currentFileLocationToConvertIsFile()) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("Not a file."); alert.showAndWait(); } } if (bulkConversionChooser.getValue().equals(bulkConversionChooser.getItems().get(0))) { try { conversionFileHandler.writeConversionsUTMToLatLong(convertedFile); openConvertedFileButton.setDisable(false); } catch (Exception ex) { Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("Conversion could not be completed."); alert.setContentText("Check if csv file is formatted properly."); alert.showAndWait(); } } else if (bulkConversionChooser.getValue().equals(bulkConversionChooser.getItems().get(1))) { try { conversionFileHandler.writeConversionsLatLongToUTM(convertedFile); openConvertedFileButton.setDisable(false); } catch (Exception ex) { Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("Conversion could not be completed."); alert.setContentText("Check if csv file is formatted properly."); alert.showAndWait(); } } else { try { conversionFileHandler.writeConversionsLatLongToLatLong(convertedFile); openConvertedFileButton.setDisable(false); } catch (Exception ex) { Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("Conversion could not be completed."); alert.setContentText("Check if csv file is formatted properly."); alert.showAndWait(); } } } }