Example usage for javafx.stage FileChooser FileChooser

List of usage examples for javafx.stage FileChooser FileChooser

Introduction

In this page you can find the example usage for javafx.stage FileChooser FileChooser.

Prototype

FileChooser

Source Link

Usage

From source file:org.beryx.vbundle.chart.html.HtmlChartContentPane.java

public void chooseFile() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("HTML file");
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("HTML files", "*.html", "*.htm"),
            new FileChooser.ExtensionFilter("All files", "*.*"));

    String initialDirPath = System.getProperty("user.dir");
    File initialDir = new File(initialDirPath);
    fileChooser.setInitialDirectory(initialDir);

    File htmlFile = fileChooser.showOpenDialog(getScene().getWindow());
    if (htmlFile != null) {
        txtFile.setText(htmlFile.getAbsolutePath());
    }/*from w  ww  . j  av a 2s  .  c o  m*/
}

From source file:context.ui.misc.FileHandler.java

/**
 *
 * @param message//from  w  w  w.  ja  v  a  2 s.  com
 * @return
 */
public static FileData openFileChooser(String message) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(message);

    fileChooser.setInitialDirectory(new File(getLastFileLocation()));
    final File selectedFile = fileChooser.showOpenDialog(ContextFXController.getStage());
    if (selectedFile != null) {
        selectedFile.getAbsolutePath();
        FileData file = new FileData(new SimpleStringProperty(selectedFile.getName()), selectedFile);
        setLastFileLocation(selectedFile.getParent());
        return file;
    } else {
        System.out.println("Selected File is Null");
        return null;
    }
}

From source file:org.dataconservancy.packaging.gui.presenter.impl.OpenExistingPackagePresenterImpl.java

public OpenExistingPackagePresenterImpl(OpenExistingPackageView view) {
    super(view);//from  w w  w.  j a  va 2  s .  c o m
    this.view = view;
    this.directoryChooser = new DirectoryChooser();
    this.fileChooser = new FileChooser();

    view.setPresenter(this);
    bind();

    // Staging directory is working directory by default.
    stagingDir = new File(System.getProperty("user.dir"));

    //If we can't write to the current working directory switch to the java temp dir which we should have write access to
    if (!Files.isWritable(FileSystems.getDefault().getPath(stagingDir.getPath()))) {
        stagingDir = new File(System.getProperty("java.io.tmpdir"));
    }
}

From source file:cz.lbenda.gui.controls.FileField.java

protected EventHandler<ActionEvent> buttonEventHandler() {
    return event -> {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(CHOOSE_FILE_WINDOW_TITLE);
        fileChooser.getExtensionFilters().addAll(Constants.allFilesFilter);
        if (!StringUtils.isBlank(getText())) {
            fileChooser.setInitialFileName(getText());
            File file = new File(getText());
            if (file.isDirectory()) {
                fileChooser.setInitialDirectory(file);
            } else {
                fileChooser.setInitialDirectory(file.getParentFile());
            }//from w w  w  .  jav  a 2s . c o  m
        }
        File file;
        if (isSave()) {
            file = fileChooser.showSaveDialog(((Node) event.getSource()).getScene().getWindow());
        } else {
            file = fileChooser.showOpenDialog(((Node) event.getSource()).getScene().getWindow());
        }
        if (file != null) {
            setText(file.getAbsolutePath());
        }
    };
}

From source file:org.apache.cayenne.modeler.layout.SplashLayout.java

public void onOpenClicked() {
    try {/*from   w  ww  .  ja va 2  s . co m*/
        final FileChooser fileChooser = new FileChooser();

        fileChooser.setTitle("Open Cayenne Model");
        fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));

        fileChooser.getExtensionFilters().addAll(
                new FileChooser.ExtensionFilter("Cayenne Projects", "cayenne*.xml"),
                new FileChooser.ExtensionFilter("All Files", "*.*"));

        final File file = fileChooser.showOpenDialog(getStage());

        if (file != null) {
            CayenneModeler.openProject(file.getAbsolutePath());
            hide();
        } else {
            LOGGER.info("Open canceled");
        }
    } catch (final Exception exception) {
        // TODO Auto-generated catch block
        LOGGER.error("Could not load Cayenne model", exception);
    }
}

From source file:com.epitech.oliver_f.astextexls.MainClass.java

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("Hello World!");
    DirectoryChooser dChooser = new DirectoryChooser();
    dChooser.setTitle("Choose the directory of the excel files");
    File defaultDirectory = new File("c:/");
    dChooser.setInitialDirectory(defaultDirectory);
    File selectedDirectory = dChooser.showDialog(primaryStage);
    StackPane root = new StackPane();
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open excel 'ALL' File");
    File choosenFile = fileChooser.showOpenDialog(primaryStage);
    launchWriteAndRead(selectedDirectory.getAbsolutePath(), choosenFile.getAbsolutePath());
    //root.getChildren().add(btn);
    //primaryStage.setScene(new Scene(root, 300, 250));
    //primaryStage.show();
    Platform.exit();/*from   w  ww. j a v  a 2 s.c  om*/

}

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();// w  w w  .j  av a2s  . com
    }
    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:jp.toastkid.script.Controller.java

/**
 * Open script file.//from   ww w.  ja  v a  2 s .c  om
 * @see <a href="http://javafx-trick.appspot.com/article/110010/80074/70110.html">
 * ?(showOpenDialog)??</a>
 */
@FXML
private void openScript() {
    final FileChooser fc = new FileChooser();
    fc.setInitialDirectory(new File("."));
    final File result = fc.showOpenDialog(stage.getScene().getWindow());
    loadScript(result);
}

From source file:by.zuyeu.deyestracker.reader.ui.readpane.ReadPaneController.java

public void openFileButtonAction(ActionEvent event) {
    LOG.info("openFileButtonAction() - start;");

    FileChooser fileChooser = new FileChooser();
    //TODO extract text to bundle
    fileChooser.setTitle("Open Text File");
    fileChooser.getExtensionFilters().addAll(new ExtensionFilter("Text Files", "*.txt"));
    File selectedFile = fileChooser.showOpenDialog(application.getStage());
    if (selectedFile != null) {
        try {/*from w w w . j  ava2  s  . c om*/
            final String text = FileUtils.readFileToString(selectedFile);
            textFlow.getChildren().clear();
            textFlow.getChildren().add(new Text(text));
            addScrollTracker();
        } catch (IOException ex) {
            LOG.warn("openFileButtonAction", ex);
            DialogsFrame.showOKDialog(application.getStage(), bundle.getString(ERROR_READ_FILE));
        } catch (DEyesTrackerException ex) {
            LOG.warn("openFileButtonAction", ex);
            DialogsFrame.showOKDialog(application.getStage(), "Unable to run tracker");
        }
    }
    LOG.info("openFileButtonAction() - end;");
}

From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java

public PerformUpdateDialog(RemoteVersionResult newVersion) {
    this.chosen = new SimpleObjectProperty<>(
            Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile());

    this.setHeaderText("Updating to " + newVersion.getVersion());
    this.setTitle("Skadi Updater");
    this.getDialogPane().getStyleClass().add("alert");
    this.getDialogPane().getStyleClass().add("information");

    final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE);
    this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL);

    Node btn = this.getDialogPane().lookupButton(restartButtonType);
    btn.setDisable(true);/*from w  w w. j  a v  a2 s .  c  o  m*/

    Label lbPath = new Label("Save as");
    TextField tfPath = new TextField();
    tfPath.textProperty()
            .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen));
    tfPath.setPrefColumnCount(40);
    tfPath.setEditable(false);

    Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse...");
    btChangePath.setOnAction(event -> {
        FileChooser fc = new FileChooser();
        fc.setTitle("Save downloaded jar..");
        fc.setInitialFileName(this.chosen.getValue().getName());
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar"));
        fc.setInitialDirectory(this.chosen.getValue().getParentFile());
        File selected = fc.showSaveDialog(this.getOwner());
        if (selected != null) {
            this.chosen.set(selected);
        }
    });

    ProgressBar pbDownload = new ProgressBar(0);
    pbDownload.setDisable(true);
    pbDownload.setMaxWidth(Double.MAX_VALUE);
    Label lbDownload = new Label("Download");
    Label lbDownloadValue = new Label();
    Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start");
    btDownload.setMaxWidth(Double.MAX_VALUE);
    btDownload.setOnAction(event -> {
        btChangePath.setDisable(true);
        btDownload.setDisable(true);

        this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue());

        lbDownloadValue.textProperty().bind(this.downloadService.messageProperty());
        pbDownload.progressProperty().bind(this.downloadService.progressProperty());

        this.downloadService.setOnSucceeded(dlEvent -> {
            btn.setDisable(false);
        });
        this.downloadService.setOnFailed(dlFailed -> {
            LOGGER.error("new version download failed", dlFailed.getSource().getException());
            lbDownloadValue.textProperty().unbind();
            lbDownloadValue.setText("Download failed, check log file for details.");
        });

        this.downloadService.start();
    });

    final GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);

    grid.add(lbPath, 0, 0);
    grid.add(tfPath, 1, 0);
    grid.add(btChangePath, 2, 0);
    grid.add(new Separator(), 0, 1, 3, 1);
    grid.add(lbDownload, 0, 2);
    grid.add(pbDownload, 1, 2);
    grid.add(btDownload, 2, 2);
    grid.add(lbDownloadValue, 1, 3);

    this.getDialogPane().setContent(grid);

    this.setResultConverter(btnType -> {
        if (btnType == restartButtonType) {
            return this.chosen.getValue();
        }

        if (btnType == ButtonType.CANCEL) {
            if (this.downloadService.isRunning()) {
                this.downloadService.cancel();
            }
        }

        return null;
    });

}