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

The following examples show how to use javafx.stage.FileChooser#setInitialDirectory() . 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: FilesCompareController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
    public void selectFile2() {
        try {
            final FileChooser fileChooser = new FileChooser();
            File path = AppVariables.getUserConfigPath(sourcePathKey);
            if (path.exists()) {
                fileChooser.setInitialDirectory(path);
            }
            fileChooser.getExtensionFilters().addAll(sourceExtensionFilter);
            File file = fileChooser.showOpenDialog(myStage);
            if (file == null || !file.exists()) {
                return;
            }
            file2Input.setText(file.getAbsolutePath());
        } catch (Exception e) {
//            logger.error(e.toString());
        }
    }
 
Example 2
Source File: MainController.java    From KorgPackage with GNU General Public License v3.0 6 votes vote down vote up
public void savePkgAction() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(lastFileChooserPath);
    fileChooser.setTitle("Save PKG/UPD File");
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("PKG/UPD file", "*.pkg", "*.upd"),
            new FileChooser.ExtensionFilter("All files", "*.*")
    );
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {
        lastFileChooserPath = file.getParentFile();
        PackageWriter packageWriter = new PackageWriter(file);
        List<Chunk> chunks = new ArrayList<>(chunksListView.getItems());
        packageWriter.save(chunks);
        statusLabel.setText("Finished saving package");
    }
}
 
Example 3
Source File: ProjectLoaderParameters.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ExitCode showSetupDialog(boolean valueCheckRequired) {

  FileChooser fileChooser = new FileChooser();
  fileChooser.setTitle("Open MZmine project");
  fileChooser.getExtensionFilters().addAll(filters);

  File currentFile = getParameter(projectFile).getValue();
  if (currentFile != null) {
    File currentDir = currentFile.getParentFile();
    if ((currentDir != null) && (currentDir.exists()))
      fileChooser.setInitialDirectory(currentDir);
  }

  File selectedFile = fileChooser.showOpenDialog(null);
  if (selectedFile == null)
    return ExitCode.CANCEL;
  getParameter(projectFile).setValue(selectedFile);

  return ExitCode.OK;

}
 
Example 4
Source File: ImageConverterOptionsController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public void selectIccFile(File path) {
        try {
            final FileChooser fileChooser = new FileChooser();
            if (path != null && path.exists()) {
                fileChooser.setInitialDirectory(path);
            }
            fileChooser.getExtensionFilters().addAll(CommonFxValues.IccProfileExtensionFilter);
            File file = fileChooser.showOpenDialog(myStage);
            if (file == null || !file.exists()) {
                return;
            }
            iccFileSelected(file);
        } catch (Exception e) {
//            logger.error(e.toString());
        }
    }
 
Example 5
Source File: FileTrendController.java    From OEE-Designer with MIT License 6 votes vote down vote up
@FXML
private void onBrowseFile() {
	// show file chooser
	FileChooser fileChooser = new FileChooser();

	if (initialDirectory != null) {
		fileChooser.setInitialDirectory(initialDirectory);
	}
	File selectedFile = fileChooser.showOpenDialog(null);

	if (selectedFile == null) {
		return;
	}
	initialDirectory = selectedFile.getParentFile();

	tfFilePath.setUserData(selectedFile);
	tfFilePath.setText(selectedFile.getAbsolutePath());
}
 
Example 6
Source File: ArtWorkController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
@FXML
private void addImage(ActionEvent actionEvent) {
    FileChooser fileChooser = new FileChooser();
    String sourceFolder = AppProperties.getProperty("source.folder");
    fileChooser.setInitialDirectory(Utils.getInitialDirecotory(sourceFolder));
    fileChooser.setTitle("Select JPG or PNG file");
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("jpg", "*.jpg", "*.jpeg", "*.jfif"),
            new FileChooser.ExtensionFilter("png", "*.png"),
            new FileChooser.ExtensionFilter("bmp", "*.bmp"));

    File file = fileChooser.showOpenDialog(ConverterApplication.getEnv().getWindow());
    logger.debug("Opened dialog for art image in folder: {}", new Object[]{sourceFolder});
    if (file != null) {
        imageList.getItems().add(new ArtWorkBean(file.getAbsolutePath()));
        logger.info("Added art work from file: {}", new Object[]{file});
    }
}
 
Example 7
Source File: OpenScheduleActionHandler.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handle(javafx.event.ActionEvent t) {
    if(confirmClear()) {
        FileChooser chooser = new FileChooser();
        if (QueleaProperties.get().getLastScheduleFileDirectory() != null) {
            chooser.setInitialDirectory(QueleaProperties.get().getLastScheduleFileDirectory());
        }
        chooser.getExtensionFilters().add(FileFilters.SCHEDULE);
        File file = chooser.showOpenDialog(QueleaApp.get().getMainWindow());
        if(file!=null) {
            QueleaProperties.get().setLastScheduleFileDirectory(file.getParentFile());
            QueleaApp.get().openSchedule(file);
            QueleaApp.get().getMainWindow().getMainPanel().getSchedulePanel().getThemeNode().refresh();
        }
    }
}
 
Example 8
Source File: GameElimniationController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
    public void selectSoundFile() {
        try {
            if (!checkBeforeNextAction()) {
                return;
            }
            final FileChooser fileChooser = new FileChooser();
            File path = AppVariables.getUserConfigPath("MusicPath");
            if (path.exists()) {
                fileChooser.setInitialDirectory(path);
            }
            fileChooser.getExtensionFilters().addAll(CommonFxValues.Mp3WavExtensionFilter);
            File file = fileChooser.showOpenDialog(getMyStage());
            if (file == null || !file.exists()) {
                return;
            }
            selectSoundFile(file);
        } catch (Exception e) {
//            logger.error(e.toString());
        }
    }
 
Example 9
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 10
Source File: FilesController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
private static String selectOutputFile(AudioBookInfo audioBookInfo) {
    JfxEnv env = ConverterApplication.getEnv();

    final FileChooser fileChooser = new FileChooser();
    String outputFolder = AppProperties.getProperty("output.folder");
    fileChooser.setInitialDirectory(Utils.getInitialDirecotory(outputFolder));
    fileChooser.setInitialFileName(Utils.getOuputFilenameSuggestion(audioBookInfo));
    fileChooser.setTitle("Save AudioBook");
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter(M4B, "*." + M4B),
            new FileChooser.ExtensionFilter(M4A, "*." + M4A),
            new FileChooser.ExtensionFilter(MP3, "*." + MP3),
            new FileChooser.ExtensionFilter(OGG, "*." + OGG)
    );
    File file = fileChooser.showSaveDialog(env.getWindow());
    if (file == null) return null;
    File parentFolder = file.getParentFile();
    AppProperties.setProperty("output.folder", parentFolder.getAbsolutePath());
    return file.getPath();
}
 
Example 11
Source File: PortraitInfoPane.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialDirectory(new File(PCGenSettings.getPortraitsDir()));
	fileChooser.setTitle(LanguageBundle.getString("in_loadPortrait"));

	// TODO: set extension filter - list of supported images

	File file = GuiUtility.runOnJavaFXThreadNow(() ->
			fileChooser.showOpenDialog(null));
	if (file != null)
	{
		character.setPortrait(file);
	}
}
 
Example 12
Source File: JavaFXFileChooserView.java    From standalone-app with Apache License 2.0 5 votes vote down vote up
private FileChooser get() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle(getTitle());
    for (FileFilter filter : getFilters()) {
        FileChooser.ExtensionFilter javafxFilter = new FileChooser.ExtensionFilter(filter.getName(), filter.getFilters());
        if (filter == getDefaultFilter()) {
            chooser.setSelectedExtensionFilter(javafxFilter);
        }
        chooser.getExtensionFilters().add(javafxFilter);
    }
    chooser.setInitialDirectory(getInitialDir());
    chooser.setInitialFileName(getInitialFile());
    return chooser;
}
 
Example 13
Source File: MainController.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 显示选择文件的弹窗
 */
public void showOpenFileDialog() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle(QiniuValueConsts.FILE_CHOOSER_TITLE);
    chooser.setInitialDirectory(new File(Utils.getCurrentWorkDir()));
    appendFile(chooser.showOpenMultipleDialog(QiniuApplication.getStage()));
}
 
Example 14
Source File: OutputPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void onOutputSheetSpellsDefaultButton(final ActionEvent actionEvent)
{
	FileChooser fileChooser = new FileChooser();
	fileChooser.setTitle(LanguageBundle.getString("in_Prefs_outputSpellSheetDefault"));
	fileChooser.setInitialDirectory(new File(ConfigurationSettings.getOutputSheetsDir()));
	fileChooser.setInitialFileName(PCGenSettings.getSelectedSpellSheet());
	File newTemplate = GuiUtility.runOnJavaFXThreadNow(() -> fileChooser.showOpenDialog(null));

	if (newTemplate != null)
	{
		if (newTemplate.getName().startsWith("csheet"))
		{
			PCGenSettings.getInstance().setProperty(
					PCGenSettings.SELECTED_SPELL_SHEET_PATH,
					newTemplate.getAbsolutePath()
			);
		}
		else
		{
			ShowMessageDelegate.showMessageDialog(
					LanguageBundle.getString("in_Prefs_outputSheetDefaultError"), //$NON-NLS-1$
					Constants.APPLICATION_NAME, MessageType.ERROR
			);
		}
	}

	outputSheetSpellsDefault.setText(PCGenSettings.getSelectedSpellSheet());
}
 
Example 15
Source File: TailingReader.java    From pikatimer with GNU General Public License v3.0 5 votes vote down vote up
public void selectInput() {
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select File");
    
    if (sourceFile != null && sourceFile.exists()) {
        fileChooser.setInitialDirectory(sourceFile.getParentFile()); 
        fileChooser.setInitialFileName(sourceFile.getName());
    } else {
        fileChooser.setInitialDirectory(PikaPreferences.getInstance().getCWD()); 
    }
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("Text Files", "*.txt"),
            new FileChooser.ExtensionFilter("All files", "*")
        );
    
    sourceFile = fileChooser.showOpenDialog(inputButton.getScene().getWindow());
    if (sourceFile != null) {
        // if we are auto-importing, stop that
        readingStatus.set(false);
        
        fileName.setValue(sourceFile.getAbsolutePath());
        // save the filename 
        timingListener.setAttribute("TailingReader:filename", sourceFile.getAbsolutePath());
        
        // set the text field to the filename
        inputTextField.textProperty().setValue(fileName.getValueSafe());
        // read the file
        if (!sourceFile.canRead()){
            statusLabel.setText("Unable to open file: " + fileName.getValueSafe());
        } else readOnce();
    }                
}
 
Example 16
Source File: RichTextDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void loadDocument() {
    String initialDir = System.getProperty("user.dir");
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Load document");
    fileChooser.setInitialDirectory(new File(initialDir));
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Arbitrary RTFX file", "*" + RTFX_FILE_EXTENSION));
    File selectedFile = fileChooser.showOpenDialog(mainStage);
    if (selectedFile != null) {
        area.clear();
        load(selectedFile);
    }
}
 
Example 17
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 18
Source File: RawDataImportParameters.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExitCode showSetupDialog(boolean valueCheckRequired) {

  FileChooser fileChooser = new FileChooser();
  fileChooser.setTitle("Import raw data files");
  fileChooser.getExtensionFilters().addAll(
      new ExtensionFilter("All raw data files", "*.cdf", "*.nc", "*.mzData", "*.mzML", "*.mzXML",
          "*.xml", "*.raw", "*.csv", "*.zip", "*.gz"), //
      new ExtensionFilter("NetCDF files", "*.cdf", "*.nc"), //
      new ExtensionFilter("mzML files", "*.mzML"), //
      new ExtensionFilter("mzData files", "*.mzData"), //
      new ExtensionFilter("mzXML files", "*.mzXML"), //
      new ExtensionFilter("Thermo RAW files", "*.raw"), //
      new ExtensionFilter("Waters RAW folders", "*.raw"), //
      new ExtensionFilter("Agilent CSV files", "*.csv"), //
      new ExtensionFilter("Compressed files", "*.zip", "*.gz"), //
      new ExtensionFilter("All Files", "*.*"));

  // We need to allow directories, because Waters raw data come in
  // directories, not files
  // chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

  File lastFiles[] = getParameter(fileNames).getValue();
  if ((lastFiles != null) && (lastFiles.length > 0)) {
    File currentDir = lastFiles[0].getParentFile();
    if ((currentDir != null) && (currentDir.exists()))
      fileChooser.setInitialDirectory(currentDir);
  }

  List<File> selectedFiles = fileChooser.showOpenMultipleDialog(null);
  if (selectedFiles == null)
    return ExitCode.CANCEL;
  getParameter(fileNames).setValue(selectedFiles.toArray(new File[0]));

  return ExitCode.OK;

}
 
Example 19
Source File: SpellSupportFacadeImpl.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void exportSpells()
{
	final String template = PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
	if (StringUtils.isEmpty(template))
	{
		delegate.showErrorMessage(
			Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); //$NON-NLS-1$
		return;
	}

	FileChooser fxExport = new FileChooser();
	fxExport.setTitle(LanguageBundle.getString("InfoSpells.export.spells.for") + charDisplay.getDisplayName());
	fxExport.setInitialDirectory(new File(PCGenSettings.getPcgDir()));
	File file = GuiUtility.runOnJavaFXThreadNow(() -> fxExport.showSaveDialog(null));
	if (file == null)
	{
		return;
	}

	try
	{
		final String aFileName = file.getAbsolutePath();
		final File outFile = new File(aFileName);

		if (outFile.exists())
		{
			int reallyClose = JOptionPane.showConfirmDialog(null,
				LanguageBundle.getFormattedString("InfoSpells.confirm.overwrite", outFile.getName()), //$NON-NLS-1$
				LanguageBundle.getFormattedString("InfoSpells.overwriting", //$NON-NLS-1$
					outFile.getName()),
				JOptionPane.YES_NO_OPTION);

			if (reallyClose != JOptionPane.YES_OPTION)
			{
				return;
			}
		}

		// Output the file
		File templateFile = new File(template);
		boolean success;
		if (ExportUtilities.isPdfTemplate(templateFile))
		{
			success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile);
		}
		else
		{
			success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile);
		}

		if (!success)
		{
			delegate.showErrorMessage(Constants.APPLICATION_NAME,
				LanguageBundle.getFormattedString(
					"InfoSpells.export.failed", charDisplay.getDisplayName())); //$NON-NLS-1$ 
		}
	}
	catch (Exception ex)
	{
		Logging.errorPrint(
			LanguageBundle.getFormattedString(
				"InfoSpells.export.failed", charDisplay.getDisplayName()), ex); //$NON-NLS-1$
		delegate.showErrorMessage(Constants.APPLICATION_NAME,
			LanguageBundle.getFormattedString(
				"InfoSpells.export.failed.retry", charDisplay.getDisplayName())); //$NON-NLS-1$ 
	}
}
 
Example 20
Source File: PCGenFrame.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This brings up a file chooser allows the user to select
 * the location that a character should be saved to.
 * @param character the character to be saved
 */
boolean showSaveCharacterChooser(CharacterFacade character)
{
	PCGenSettings context = PCGenSettings.getInstance();
	String parentPath = lastCharacterPath;
	if (parentPath == null)
	{
		parentPath = context.getProperty(PCGenSettings.PCG_SAVE_PATH);
	}

	FileChooser fileChooser = new FileChooser();
	fileChooser.setTitle("Save PCGen Character File");
	FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter(
			"character files only", '*' + Constants.EXTENSION_CHARACTER_FILE
	);
	fileChooser.getExtensionFilters().add(extensionFilter);
	fileChooser.setSelectedExtensionFilter(extensionFilter);

	File prevFile = character.getFileRef().get();
	if (prevFile == null || StringUtils.isEmpty(prevFile.getName()))
	{
		fileChooser.setInitialDirectory(new File(parentPath));
		fileChooser.setInitialFileName(character.getNameRef().get() + Constants.EXTENSION_CHARACTER_FILE);
	}

	File file = GuiUtility.runOnJavaFXThreadNow(() ->
			fileChooser.showSaveDialog(null));

	if (file != null)
	{
		UIDelegate delegate = character.getUIDelegate();
		if (file.isDirectory())
		{
			delegate.showErrorMessage(Constants.APPLICATION_NAME,
				LanguageBundle.getString("in_savePcDirOverwrite")); //$NON-NLS-1$
			return showSaveCharacterChooser(character);
		}

		if (file.exists() && (prevFile == null || !file.getName().equals(prevFile.getName())))
		{
			boolean overwrite = delegate.showWarningConfirm(
				LanguageBundle.getFormattedString("in_savePcConfirmOverTitle", //$NON-NLS-1$
					file.getName()),
				LanguageBundle.getFormattedString("in_savePcConfirmOverMsg", //$NON-NLS-1$
					file.getName()));

			if (!overwrite)
			{
				return showSaveCharacterChooser(character);
			}
		}

		try
		{
			character.setFile(file);
			prepareForSave(character, false);
			if (!reallySaveCharacter(character))
			{
				return showSaveCharacterChooser(character);
			}

			lastCharacterPath = file.getParent();
			return true;
		}
		catch (Exception e)
		{
			Logging.errorPrint("Error saving character to new file " + file, e); //$NON-NLS-1$
			delegate.showErrorMessage(Constants.APPLICATION_NAME,
				LanguageBundle.getFormattedString("in_saveFailMsg", file.getName())); //$NON-NLS-1$
		}
	}
	return false;
}