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

The following examples show how to use javafx.stage.DirectoryChooser#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: FrontController.java    From ns-usbloader with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Functionality for selecting Split NSP button.
 * */
private void selectSplitBtnAction(){
    File splitFile;
    DirectoryChooser dirChooser = new DirectoryChooser();
    dirChooser.setTitle(resourceBundle.getString("btn_OpenFile"));

    File validator = new File(previouslyOpenedPath);
    if (validator.exists() && validator.isDirectory())
        dirChooser.setInitialDirectory(validator);
    else
        dirChooser.setInitialDirectory(new File(System.getProperty("user.home")));

    splitFile = dirChooser.showDialog(usbNetPane.getScene().getWindow());

    if (splitFile != null && splitFile.getName().toLowerCase().endsWith(".nsp")) {
        tableFilesListController.setFile(splitFile);
        uploadStopBtn.setDisable(false);    // Is it useful?
        previouslyOpenedPath = splitFile.getParent();
    }
}
 
Example 2
Source File: Controller.java    From blobsaver with GNU General Public License v3.0 6 votes vote down vote up
public void filePickerHandler() {
    DirectoryChooser dirChooser = new DirectoryChooser();
    dirChooser.setTitle("Choose a folder to save Blobs in");
    File startIn = new File(pathField.getText());
    if (startIn.exists()) {
        dirChooser.setInitialDirectory(startIn);
    } else if (startIn.getParentFile().exists()) {
        dirChooser.setInitialDirectory(startIn.getParentFile());
    } else {
        dirChooser.setInitialDirectory(new File(System.getProperty("user.home")));
    }
    File result = dirChooser.showDialog(primaryStage);
    if (result != null) {
        pathField.setText(result.toString());
    }
}
 
Example 3
Source File: GuiController.java    From BlockMap with MIT License 6 votes vote down vote up
@FXML
public void showFolderDialog() {
	DirectoryChooser dialog = new DirectoryChooser();
	File f = (worldSettingsController.lastBrowsedPath == null) ? DotMinecraft.DOTMINECRAFT.resolve("saves").toFile()
			: worldSettingsController.lastBrowsedPath.getParent().toFile();
	if (!f.isDirectory())
		f = DotMinecraft.DOTMINECRAFT.resolve("saves").toFile();
	if (!f.isDirectory())
		f = null;
	dialog.setInitialDirectory(f);
	f = dialog.showDialog(null);
	if (f != null) {
		worldSettingsController.lastBrowsedPath = f.toPath();
		loadLocal(worldSettingsController.lastBrowsedPath);
		worldInput.setText(f.toString());
	}
}
 
Example 4
Source File: FilesController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
public void selectFolderDialog() {
    Window window = ConverterApplication.getEnv().getWindow();
    DirectoryChooser directoryChooser = new DirectoryChooser();
    String sourceFolder = AppProperties.getProperty("source.folder");
    directoryChooser.setInitialDirectory(Utils.getInitialDirecotory(sourceFolder));

    StringJoiner filetypes = new StringJoiner("/");

    Arrays.stream(FILE_EXTENSIONS).map(String::toUpperCase).forEach(filetypes::add);

    directoryChooser.setTitle("Select folder with " + filetypes.toString() + " files for conversion");
    File selectedDirectory = directoryChooser.showDialog(window);
    if (selectedDirectory != null) {
        processFiles(Collections.singleton(selectedDirectory));
        AppProperties.setProperty("source.folder", selectedDirectory.getAbsolutePath());
        if (!chaptersMode.get()) {
            filesChapters.getTabs().add(filesTab);
            filesChapters.getSelectionModel().select(filesTab);
        }
    }
}
 
Example 5
Source File: OptionStage.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
private void editLocation ()
{
  DirectoryChooser chooser = new DirectoryChooser ();
  chooser.setTitle ("Choose Spy Folder");
  File currentLocation = spyFolder.isEmpty () ? null : new File (spyFolder);
  if (currentLocation != null && currentLocation.exists ())
    chooser.setInitialDirectory (currentLocation);

  File selectedDirectory = chooser.showDialog (this);
  if (selectedDirectory != null)
  {
    spyFolder = selectedDirectory.getAbsolutePath ();
    fileComboBox.getItems ().clear ();
    ObservableList<String> files = getSessionFiles (spyFolder);
    fileComboBox.setItems (files);
    if (files.size () > 0)
      fileComboBox.getSelectionModel ().select (0);
  }
}
 
Example 6
Source File: SettingsController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
protected void setOCRPath(ActionEvent event) {
    try {
        DirectoryChooser chooser = new DirectoryChooser();
        String dataPath = AppVariables.getUserConfigValue("TessDataPath", null);
        if (dataPath != null) {
            chooser.setInitialDirectory(new File(dataPath));
        }
        File directory = chooser.showDialog(getMyStage());
        if (directory == null) {
            return;
        }
        recordFileWritten(directory);
        ocrDirInput.setText(directory.getPath());
    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 7
Source File: BaseController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
public void selectSourcePath() {
    try {
        DirectoryChooser chooser = new DirectoryChooser();
        File path = AppVariables.getUserConfigPath(sourcePathKey);
        if (path != null) {
            chooser.setInitialDirectory(path);
        }
        File directory = chooser.showDialog(getMyStage());
        if (directory == null) {
            return;
        }
        selectSourcePath(directory);
    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 8
Source File: MainController.java    From KorgPackage with GNU General Public License v3.0 6 votes vote down vote up
public void exportChunkAction() {
        Chunk chunk = (Chunk) chunksListView.getSelectionModel().getSelectedItem();
        if (chunk != null) {
//            FileChooser fileChooser = new FileChooser();
//            fileChooser.setTitle("Save File");
            DirectoryChooser directoryChooser = new DirectoryChooser();
            directoryChooser.setInitialDirectory(lastFileChooserPath);
            directoryChooser.setTitle("Choose directory");
            File dir = directoryChooser.showDialog(stage);
            if (dir != null) {
                try {
                    lastFileChooserPath = dir;
                    ObservableList<Chunk> chunks = chunksListView.getSelectionModel().getSelectedItems();
                    for (Chunk c : chunks) {
                        c.export(dir.getPath());
                    }
                } catch (IOException e) {
                    System.err.println(e.getMessage());
                }
            }
        }
    }
 
Example 9
Source File: NxdtController.java    From ns-usbloader with GNU General Public License v3.0 5 votes vote down vote up
@FXML
private void bntSelectSaveTo(){
    DirectoryChooser dc = new DirectoryChooser();
    dc.setTitle(rb.getString("tabSplMrg_Btn_SelectFolder"));
    dc.setInitialDirectory(new File(saveToLocationLbl.getText()));
    File saveToDir = dc.showDialog(saveToLocationLbl.getScene().getWindow());
    if (saveToDir != null)
        saveToLocationLbl.setText(saveToDir.getAbsolutePath());
}
 
Example 10
Source File: OpenAssetAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Open asset folder using native file chooser.
 */
@FxThread
private void openAssetByNative() {

    final DirectoryChooser chooser = new DirectoryChooser();
    chooser.setTitle(Messages.EDITOR_MENU_FILE_OPEN_ASSET_DIRECTORY_CHOOSER);

    final EditorConfig config = EditorConfig.getInstance();
    final Path currentAsset = config.getCurrentAsset();
    final File currentFolder = currentAsset == null ? null : currentAsset.toFile();

    if (currentFolder == null) {
        chooser.setInitialDirectory(new File(System.getProperty("user.home")));
    } else {
        chooser.setInitialDirectory(currentFolder);
    }

    GAnalytics.sendPageView("AssetChooseDialog", null, "/dialog/AssetChooseDialog");
    GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_OPENED, "AssetChooseDialog");

    final File folder = chooser.showDialog(EditorUtil.getFxLastWindow());

    GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_CLOSED, "AssetChooseDialog");

    if (folder == null) {
        return;
    }

    openAssetFolder(folder.toPath());
}
 
Example 11
Source File: SettingsController.java    From VickyWarAnalyzer with MIT License 5 votes vote down vote up
@FXML
void directoryIssueFired(ActionEvent event) {
	DirectoryChooser chooser = new DirectoryChooser();
	chooser.setTitle("Victoria II directory");
	/* Only if there is a path is it given to the chooser */
	if (!utilServ.getInstallFolder().equals("")) {
		chooser.setInitialDirectory(new File(utilServ.getInstallFolder()));
	}
	// Throws error when user cancels selection
	try {
		File file = chooser.showDialog(null);
		installTextField.setText(file.getPath());
	} catch (NullPointerException e) {
	}
}
 
Example 12
Source File: LocationPanel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Ask for a path, and return it (possibly return the currentPath.)
 * @param currentPath when entering the method
 * @param dialogTitle to show
 * @param textField to update with the path information
 */
private static void askForPath(final File currentPath, final String dialogTitle, final TextField textField)
{
	GuiAssertions.assertIsJavaFXThread();
	DirectoryChooser directoryChooser = new DirectoryChooser();
	directoryChooser.setInitialDirectory(currentPath);
	directoryChooser.setTitle(dialogTitle);
	File returnFile = directoryChooser.showDialog(null);
	if (returnFile == null)
	{
		returnFile = currentPath;
	}

	textField.setText(returnFile.toString());
}
 
Example 13
Source File: OptionsPathDialogController.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@FXML
private void doChooser(final ActionEvent actionEvent)
{
	DirectoryChooser directoryChooser = new DirectoryChooser();
	String modelDirectory = model.directoryProperty().getValue();
	if (!modelDirectory.isBlank())
	{
		directoryChooser.setInitialDirectory(new File(model.directoryProperty().getValue()));
	}

	File dir = directoryChooser.showDialog(optionsPathDialogScene.getWindow());

	if (dir != null)
	{
		if (dir.listFiles().length > 0)
		{
			Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
			alert.setTitle("Directory Not Empty");
			alert.setContentText("The folder " + dir.getAbsolutePath() + " is not empty.\n"
					+ "All ini files in this directory may be overwritten. " + "Are you sure?");
			Optional<ButtonType> buttonType = alert.showAndWait();
			buttonType.ifPresent(option -> {
				if (option != ButtonType.YES)
				{
					return;
				}
			});
		}
		model.directoryProperty().setValue(dir.getAbsolutePath());
	}
}
 
Example 14
Source File: ConfigController.java    From logbook-kai with MIT License 5 votes vote down vote up
@FXML
void selectApiStart2Dir(ActionEvent event) {
    DirectoryChooser dc = new DirectoryChooser();
    dc.setTitle("api_start2の保存先");
    if (Files.exists(Paths.get(this.storeApiStart2Dir.getText()))) {
        dc.setInitialDirectory(Paths.get(this.storeApiStart2Dir.getText()).toAbsolutePath().toFile());
    }
    Optional.ofNullable(dc.showDialog(this.getWindow()))
            .filter(File::exists)
            .map(File::getAbsolutePath)
            .ifPresent(this.storeApiStart2Dir::setText);
}
 
Example 15
Source File: FileSystem.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private void updateFromDirectoryChooser(final File initialDirectory, final Window ownerWindow) {

		final DirectoryChooser directoryChooser = new DirectoryChooser();
		directoryChooser.setInitialDirectory(initialDirectory);
		final File updatedRoot = directoryChooser.showDialog(ownerWindow);

		LOG.debug("Updating root to {} (was {})", updatedRoot, container.get());

		try {
			if (updatedRoot != null && !isN5Container(updatedRoot.getAbsolutePath())) {
				final Alert alert = PainteraAlerts.alert(Alert.AlertType.INFORMATION);
				alert.setHeaderText("Selected directory is not a valid N5 container.");
				final TextArea ta = new TextArea("The selected directory \n\n" + updatedRoot.getAbsolutePath() + "\n\n" +
						"A valid N5 container is a directory that contains a file attributes.json with a key \"n5\".");
				ta.setEditable(false);
				ta.setWrapText(true);
				alert.getDialogPane().setContent(ta);
				alert.show();
			}
		}
		catch (final IOException e) {
			LOG.error("Failed to notify about invalid N5 container: {}", updatedRoot.getAbsolutePath(), e);
		}

		if (updatedRoot != null && updatedRoot.exists() && updatedRoot.isDirectory()) {
			// set null first to make sure that container will be invalidated even if directory is the same
			container.set(null);
			container.set(updatedRoot.getAbsolutePath());
		}

	}
 
Example 16
Source File: DirectorySelectorPreference.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initializeParts() {
    super.initializeParts();

    node = new StackPane();
    node.getStyleClass().add("simple-text-control");

    editableField = new TextField(field.getValue());

    DirectoryChooser directoryChooser = new DirectoryChooser();

    if (initialDirectory != null) {
        directoryChooser.setInitialDirectory(initialDirectory);
    }

    directoryChooserButton.setOnAction(event -> {
        File dir = directoryChooser.showDialog(getNode().getScene().getWindow());
        if (dir != null) {
            editableField.setText(dir.getAbsolutePath());
        }
    });

    directoryChooserButton.setText(buttonText);

    editableField.setPromptText(field.placeholderProperty().getValue());

    hBox.getChildren().addAll(editableField, directoryChooserButton);
}
 
Example 17
Source File: BrowseButton.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public void browse(File from) {
    DirectoryChooser folderChooser = new DirectoryChooser();
    folderChooser.setInitialDirectory(from);

    new JFXPanel(); // Init JFX Platform
    Platform.runLater(() -> {
        File file = folderChooser.showDialog(null);
        if (file != null && file.exists()) {
            File parent = file.getParentFile();
            if (parent == null) parent = file;
            Preferences.userRoot().node(Fawe.class.getName()).put("LAST_USED_FOLDER" + id, parent.getPath());
            onSelect(file);
        }
    });
}
 
Example 18
Source File: FileDirChooserFactory.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
/**
 * 文件夹选择器
 */
public static File createDirectoryScan(String title, String initDirectory) {
    DirectoryChooser directoryChooser = new DirectoryChooser();
    directoryChooser.setTitle(title);
    if (StringUtils.isNotEmpty(initDirectory)) {
        directoryChooser.setInitialDirectory(new File(initDirectory));
    }
    Stage fileStage = new Stage();
    return directoryChooser.showDialog(fileStage);
}
 
Example 19
Source File: ConfigController.java    From logbook-kai with MIT License 4 votes vote down vote up
@FXML
void selectBouyomiDir(ActionEvent event) {
    DirectoryChooser dc = new DirectoryChooser();
    dc.setTitle("BouyomiChan.exeがあるフォルダを選択してください");

    String pathText = this.bouyomiPath.getText();
    if (pathText != null && !pathText.isEmpty() && Files.exists(Paths.get(pathText))) {
        dc.setInitialDirectory(Paths.get(pathText).toFile());
    }
    Path baseDir = Optional.ofNullable(dc.showDialog(this.getWindow()))
            .filter(File::exists)
            .map(File::toPath)
            .orElse(null);
    if (baseDir == null)
        return;

    Path bouyomichanPath = null;
    Path tryPath = baseDir.resolve("BouyomiChan.exe");
    if (Files.exists(tryPath)) {
        bouyomichanPath = tryPath;
    } else {
        // 1つ下のサブフォルダを見てみる
        try (DirectoryStream<Path> ds = Files.newDirectoryStream(baseDir, Files::isDirectory)) {
            for (Path path : ds) {
                tryPath = path.resolve("BouyomiChan.exe");
                if (Files.exists(tryPath)) {
                    bouyomichanPath = tryPath;
                    break;
                }
            }
        } catch (Exception e) {
        }
    }
    if (bouyomichanPath != null) {
        this.bouyomiPath.setText(bouyomichanPath.toString());
    } else {
        Tools.Conrtols.alert(AlertType.INFORMATION,
                "BouyomiChan.exeが見つかりません",
                "選択されたフォルダにBouyomiChan.exeが見つかりませんでした。",
                this.getWindow());
    }
}
 
Example 20
Source File: CaptureSaveController.java    From logbook-kai with MIT License 4 votes vote down vote up
@FXML
void save(ActionEvent event) {
    List<ImageData> selections = this.list.getCheckModel().getCheckedItems();

    if (!selections.isEmpty()) {
        DirectoryChooser dc = new DirectoryChooser();
        dc.setTitle("キャプチャの保存先");
        // 覚えた保存先をセット
        File initDir = Optional.ofNullable(AppConfig.get().getCaptureDir())
                .map(File::new)
                .filter(File::isDirectory)
                .orElse(null);
        if (initDir != null) {
            dc.setInitialDirectory(initDir);
        }
        File file = dc.showDialog(this.getWindow());
        if (file != null) {
            // 保存先を覚える
            AppConfig.get().setCaptureDir(file.getAbsolutePath());

            Path path = file.toPath();

            Task<Void> task = new Task<Void>() {
                @Override
                protected Void call() throws Exception {
                    CaptureSaveController.this.saveJpeg(selections, path);
                    return null;
                }

                @Override
                protected void succeeded() {
                    super.succeeded();

                    Tools.Conrtols.alert(AlertType.INFORMATION,
                            "キャプチャが保存されました",
                            "キャプチャが保存されました",
                            CaptureSaveController.this.getWindow());
                }

                @Override
                protected void failed() {
                    super.failed();
                    Throwable t = this.getException();

                    Tools.Conrtols.alert(AlertType.ERROR,
                            "キャプチャの保存先に失敗しました",
                            "キャプチャの保存先に失敗しました",
                            t,
                            CaptureSaveController.this.getWindow());
                }
            };
            ThreadManager.getExecutorService().execute(task);
        }
    }
}