Java Code Examples for javafx.stage.FileChooser#showSaveDialog()

The following examples show how to use javafx.stage.FileChooser#showSaveDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartViewer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A handler for the export to PNG option in the context menu.
 */
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(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsPNG(this.chart, (int) getWidth(),
                    (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }        
}
 
Example 2
Source File: ChartViewer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A handler for the export to JPEG option in the context menu.
 */
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
        }
    }        
}
 
Example 3
Source File: EmulatorUILogic.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
@InvokableAction(
            name = "Save Screenshot",
            category = "general",
            description = "Save image of visible screen",
            alternatives = "Save image;save framebuffer;screenshot",
            defaultKeyMapping = "ctrl+shift+s")
    public static void saveScreenshot() throws IOException {
        FileChooser select = new FileChooser();
        Emulator.computer.pause();
        Image i = Emulator.computer.getVideo().getFrameBuffer();
//        BufferedImage bufImageARGB = SwingFXUtils.fromFXImage(i, null);
        File targetFile = select.showSaveDialog(JaceApplication.getApplication().primaryStage);
        if (targetFile == null) {
            return;
        }
        String filename = targetFile.getName();
        System.out.println("Writing screenshot to " + filename);
        String extension = filename.substring(filename.lastIndexOf(".") + 1);
//        BufferedImage bufImageRGB = new BufferedImage(bufImageARGB.getWidth(), bufImageARGB.getHeight(), BufferedImage.OPAQUE);
//
//        Graphics2D graphics = bufImageRGB.createGraphics();
//        graphics.drawImage(bufImageARGB, 0, 0, null);
//
//        ImageIO.write(bufImageRGB, extension, targetFile);
//        graphics.dispose();
    }
 
Example 4
Source File: ChartViewer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A handler for the export to PNG option in the context menu.
 */
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(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsPNG(this.chart, (int) getWidth(),
                    (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }        
}
 
Example 5
Source File: FileManager.java    From trex-stateless-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Return selected file
 *
 * @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 = FileChooserFactory.get();
    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);
    }
}
 
Example 6
Source File: GraphEditorPersistence.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Opens the file chooser and returns the selected {@link File}.
 *
 * @param graphEditor a graph editor instance with a not-null scene
 * @param save {@code true} to open a save dialog, {@code false} to open a load dialog
 * @return the chosen file
 */
private File showFileChooser(final Window window, final boolean save) {

    final FileChooser fileChooser = new FileChooser();

    final FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter(CHOOSER_TEXT, "*" + FILE_EXTENSION);
    fileChooser.getExtensionFilters().add(filter);

    if (initialDirectory != null && initialDirectory.exists()) {
        fileChooser.setInitialDirectory(initialDirectory);
    }

    if (save) {
        return fileChooser.showSaveDialog(window);
    } else {
        return fileChooser.showOpenDialog(window);
    }
}
 
Example 7
Source File: TaChartViewer.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * A handler for the export to JPEG option in the context menu.
 */
private void handleExportToJPEG() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Export to JPEG");
    FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("JPEG", "jpg");
    chooser.getExtensionFilters().add(filter);
    File file = chooser.showSaveDialog(getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsJPEG(this.canvas.getChart(), (int) getWidth(),
                    (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
            throw new RuntimeException(ex);
        }
    }
}
 
Example 8
Source File: IdeController.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private File chooseFileToSave(DocumentType type) {
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Save " + type.name() + " document");
    chooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter(type.name(), type.extensions),
            new FileChooser.ExtensionFilter("All Files", "*.*")
    );
    return chooser.showSaveDialog(JaceApplication.getApplication().primaryStage);
}
 
Example 9
Source File: RunnerActivityController.java    From curly with Apache License 2.0 5 votes vote down vote up
@FXML
void saveClicked(ActionEvent event) {
    FileChooser saveChooser = new FileChooser();
    File saveFile = saveChooser.showSaveDialog(null);
    if (saveFile != null) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile))) {
            writer.write(getReportHtml());
            writer.close();
        } catch (IOException ex) {
            Logger.getLogger(RunnerActivityController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
 
Example 10
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void handleExportMSP(Event event) {
  FileChooser fileChooser = new FileChooser();
  fileChooser.setTitle("Export to MSP");
  fileChooser.getExtensionFilters().add(new ExtensionFilter("NIST MSP format", "*.msp"));

  // Remember last directory
  if (lastSaveDirectory != null && lastSaveDirectory.isDirectory())
    fileChooser.setInitialDirectory(lastSaveDirectory);

  // Show the file chooser
  File file = fileChooser.showSaveDialog(chartNode.getScene().getWindow());

  // If nothing was chosen, quit
  if (file == null)
    return;

  // Save the last open directory
  lastSaveDirectory = file.getParentFile();

  final List<MsSpectrum> spectra = new ArrayList<>();
  for (MsSpectrumDataSet dataset : datasets) {
    spectra.add(dataset.getSpectrum());
  }

  // Do the export in a new thread
  final File finalFile = file;
  new Thread(() -> {
    try {
      MspExportAlgorithm.exportSpectra(finalFile, spectra);
    } catch (Exception e) {
      MZmineGUI.displayMessage("Unable to export: " + e.getMessage());
      e.printStackTrace();
    }
  }).start();
}
 
Example 11
Source File: MainController.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 保存文件的上传状态
 */
public void saveUploadStatus() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle(QiniuValueConsts.FILE_CHOOSER_TITLE);
    chooser.setInitialDirectory(new File(Utils.getCurrentWorkDir()));
    File file = chooser.showSaveDialog(QiniuApplication.getStage());
    QiniuUtils.saveFile(file, uploadStatusTA.getText());
}
 
Example 12
Source File: ChartViewer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A handler for the export to SVG option in the context menu.
 */
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(this.getScene().getWindow());
    if (file != null) {
        ExportUtils.writeAsSVG(this.chart, (int) getWidth(), 
                (int) getHeight(), file);
    }
}
 
Example 13
Source File: MainApp.java    From Corendon-LostLuggage with MIT License 5 votes vote down vote up
public static File selectFileToSave(String defaultFileName) {

        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Specify filename");

        //todo: provide the file selection dialog to the user
        File file = fileChooser.showSaveDialog(mainStage);

        //File selected? return the file, else return null
        if (file != null) {
            return file;
        } else {
            return null;
        }
    }
 
Example 14
Source File: ChartViewer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A handler for the export to PDF option in the context menu.
 */
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);
    } 
}
 
Example 15
Source File: KovatsIndexExtractionDialog.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void saveToFile() {
  // need to parse
  if (!parseValues()) {
    logger.log(Level.WARNING,
        "Parsing of Kovats values failed (text box). Maybe you have to select more markers: "
            + MIN_MARKERS + " (at least)");
    return;
  }
  final TreeMap<KovatsIndex, Double> values = parsedValues;

  File lastFile =
      parameterSet.getParameter(KovatsIndexExtractionParameters.lastSavedFile).getValue();

  FileChooser chooser = new FileChooser();
  chooser.getExtensionFilters().add(csvFilter);
  if (lastFile != null)
    chooser.setInitialFileName(lastFile.getAbsolutePath());

  File f = chooser.showSaveDialog(this.getScene().getWindow());

  if (f == null)
    return;

  // set last file
  setLastFile(f);
  f = FileAndPathUtil.getRealFilePath(f, "csv");
  try {
    // save to file in GNPS GC format
    String exp = getCsvTable(values);
    if (TxtWriter.write(exp, f, false))
      saveFileListener.accept(f);
  } catch (Exception e) {
    logger.log(Level.WARNING, "Error while saving Kovats file to " + f.getAbsolutePath(), e);
  }

}
 
Example 16
Source File: MainController.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@FXML
private void exportCrt(ActionEvent e) throws CertificateEncodingException, IOException {
    var generator = Context.getInstance().sslContextManager().getKeyStoreGenerator();
    byte[] data = generator.exportRootCert(false);
    FileChooser fileChooser = new FileChooser();
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Crt file", "*.crt"));
    fileChooser.setInitialFileName("CuteProxy.crt");
    File file = fileChooser.showSaveDialog(this.root.getScene().getWindow());
    if (file == null) {
        return;
    }
    Files.write(file.toPath(), data);
}
 
Example 17
Source File: ChartViewer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A handler for the export to SVG option in the context menu.
 */
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(this.getScene().getWindow());
    if (file != null) {
        ExportUtils.writeAsSVG(this.chart, (int) getWidth(), 
                (int) getHeight(), file);
    }
}
 
Example 18
Source File: EditorFrame.java    From JetUML with GNU General Public License v3.0 4 votes vote down vote up
private void saveAs() 
{
	DiagramTab diagramTab = getSelectedDiagramTab();
	Diagram diagram = diagramTab.getDiagram();

	FileChooser fileChooser = new FileChooser();
	fileChooser.getExtensionFilters().addAll(FileExtensions.all());
	fileChooser.setSelectedExtensionFilter(FileExtensions.forDiagramType(diagram.getType()));

	if(diagramTab.getFile().isPresent()) 
	{
		fileChooser.setInitialDirectory(diagramTab.getFile().get().getParentFile());
		fileChooser.setInitialFileName(diagramTab.getFile().get().getName());
	} 
	else 
	{
		fileChooser.setInitialDirectory(getLastDir(KEY_LAST_SAVEAS_DIR));
		fileChooser.setInitialFileName("");
	}

	try 
	{
		File result = fileChooser.showSaveDialog(aMainStage);
		if( result != null )
		{
			PersistenceService.save(diagram, result);
			addRecentFile(result.getAbsolutePath());
			diagramTab.setFile(result);
			diagramTab.setText(diagramTab.getFile().get().getName());
			diagramTab.diagramSaved();
			File dir = result.getParentFile();
			if( dir != null )
			{
				setLastDir(KEY_LAST_SAVEAS_DIR, dir);
			}
		}
	} 
	catch (IOException exception) 
	{
		Alert alert = new Alert(AlertType.ERROR, RESOURCES.getString("error.save_file"), ButtonType.OK);
		alert.initOwner(aMainStage);
		alert.showAndWait();
	}
}
 
Example 19
Source File: DirectoryService.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
public Path getSaveOutputPath(FileChooser.ExtensionFilter extensionFilter, boolean askPath) {

        if (!Platform.isFxApplicationThread()) {
            final CompletableFuture<Path> completableFuture = new CompletableFuture<>();

            completableFuture.runAsync(() -> {
                threadService.runActionLater(() -> {
                    try {
                        Path outputPath = getSaveOutputPath(extensionFilter, askPath);
                        completableFuture.complete(outputPath);
                    } catch (Exception e) {
                        completableFuture.completeExceptionally(e);
                    }
                });
            }, threadService.executor());

            return completableFuture.join();
        }

        boolean isNew = current.currentTab().isNew();

        if (isNew) {
            controller.saveDoc();
        }

        final Path currentTabPath = current.currentPath().get();
        final Path currentTabPathDir = currentTabPath.getParent();
        String tabText = current.getCurrentTabText().replace("*", "").trim();
        tabText = tabText.contains(".") ? tabText.split("\\.")[0] : tabText;

        if (!askPath) {
            return currentTabPathDir.resolve(extensionFilter.getExtensions().get(0).replace("*", tabText));
        }

        final FileChooser fileChooser = this.newFileChooser(String.format("Save %s file", extensionFilter.getDescription()));
        fileChooser.getExtensionFilters().addAll(extensionFilter);
        File file = fileChooser.showSaveDialog(null);

        if (Objects.isNull(file)) {
            return currentTabPathDir.resolve(extensionFilter.getExtensions().get(0).replace("*", tabText));
        }

        return file.toPath();
    }
 
Example 20
Source File: JFreeChartUtils.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static void showSaveDialog(ChartViewer chartNode, ImgFileType fileType) {
  FileChooser fileChooser = new FileChooser();
  switch (fileType) {

    case JPG:
      fileChooser.setTitle("Export to JPG");
      fileChooser.getExtensionFilters().add(new ExtensionFilter("JPEG", "*.jpg"));
      break;

    case PNG:
      fileChooser.setTitle("Export to PNG");
      fileChooser.getExtensionFilters()
          .add(new ExtensionFilter("Portable Network Graphics (PNG)", "*.png"));
      break;

    case SVG:
      fileChooser.setTitle("Export to SVG");
      fileChooser.getExtensionFilters()
          .add(new ExtensionFilter("Scalable Vector Graphics (SVG)", "*.svg"));
      break;

    case PDF:
      fileChooser.setTitle("Export to PDF");
      fileChooser.getExtensionFilters()
          .add(new ExtensionFilter("Portable Document Format (PDF)", "*.pdf"));
      break;

    case EMF:
      fileChooser.setTitle("Export to EMF");
      fileChooser.getExtensionFilters().add(new ExtensionFilter("EMF image", "*.emf"));
      break;

    case EPS:
      fileChooser.setTitle("Export to EPS");
      fileChooser.getExtensionFilters().add(new ExtensionFilter("EPS Image", "*.eps"));
      break;
  }

  // Remember last directory
  if (lastSaveDirectory != null && lastSaveDirectory.isDirectory())
    fileChooser.setInitialDirectory(lastSaveDirectory);

  // Show the file chooser
  File file = fileChooser.showSaveDialog(chartNode.getScene().getWindow());

  // If nothing was chosen, quit
  if (file == null)
    return;

  // Save the last open directory
  lastSaveDirectory = file.getParentFile();

  // Do the export in a new thread
  final File finalFile = file;
  new Thread(() -> {
    exportToImageFile(chartNode, finalFile, fileType);
  }).start();
}