Example usage for javafx.stage FileChooser showOpenDialog

List of usage examples for javafx.stage FileChooser showOpenDialog

Introduction

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

Prototype

public File showOpenDialog(final Window ownerWindow) 

Source Link

Document

Shows a new file open dialog.

Usage

From source file:open.dolphin.client.MainWindowController.java

@FXML
protected void fileChoose() {
    FileChooser fc = new FileChooser();
    fc.setTitle("select file");
    fc.setInitialDirectory(new File(System.getProperty("user.home")));
    fc.getExtensionFilters().add(new ExtensionFilter("????", "*.*"));

    File f = fc.showOpenDialog(null);
    if (f != null) {
        try {/*  ww  w  . j a  va2s .  c o  m*/
            Path path = f.toPath();
            choiceFile.setText(path.getFileName().toString());
            for (String s : Files.readAllLines(path, Charset.forName("SJIS"))) {
                System.out.println(s);
            }
        } catch (IOException ex) {
            Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ch.unibas.charmmtools.gui.step1.mdAssistant.CHARMM_GUI_InputAssistant.java

/**
 * Handles the event when one of the 3 button_open_XXX is pressed button_generate is enabled only when the 3 files
 * have been loaded/*from  ww w.  ja va 2 s  . c o m*/
 *
 * @param event
 */
@FXML
protected void OpenButtonPressed(ActionEvent event) {

    Window myParent = button_generate.getScene().getWindow();
    FileChooser chooser = new FileChooser();
    chooser.setInitialDirectory(new File("."));
    File selectedFile = null;

    chooser.setTitle("Open File");

    if (event.getSource().equals(button_open_PAR)) {
        chooser.getExtensionFilters().add(
                new FileChooser.ExtensionFilter("CHARMM FF parameters file (*.par,*.prm)", "*.par", "*.prm"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_PAR.setText(selectedFile.getAbsolutePath());
            PAR_selected = true;
        }
    } else if (event.getSource().equals(button_open_RTF)) {
        chooser.getExtensionFilters().add(
                new FileChooser.ExtensionFilter("CHARMM FF topology file (*.top,*.rtf)", "*.top", "*.rtf"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_RTF.setText(selectedFile.getAbsolutePath());
            RTF_selected = true;
        }
    } else if (event.getSource().equals(button_open_COR_gas)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_COR_gas.setText(selectedFile.getAbsolutePath());
            COR_selected_gas = true;
        }
    } else if (event.getSource().equals(button_open_COR_liquid)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_COR_liquid.setText(selectedFile.getAbsolutePath());
            COR_selected_liquid = true;
        }
    } else if (event.getSource().equals(button_open_COR_solv)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_COR_solv.setText(selectedFile.getAbsolutePath());
            COR_selected_solv = true;
        }
    } else if (event.getSource().equals(button_open_LPUN)) {
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("LPUN file", "*.lpun"));
        selectedFile = chooser.showOpenDialog(myParent);
        if (selectedFile != null) {
            textfield_LPUN.setText(selectedFile.getAbsolutePath());
            LPUN_selected = true;
        }
    } else {
        throw new UnknownError("Unknown Event in OpenButtonPressed(ActionEvent event)");
    }

    this.validateButtonGenerate();

}

From source file:ninja.javafx.smartcsv.fx.SmartCSVController.java

private void loadFile(String filterText, String filter, String title, FileStorage storageFile) {
    final FileChooser fileChooser = new FileChooser();

    //Set extension filter
    final FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(filterText, filter);
    fileChooser.getExtensionFilters().add(extFilter);
    fileChooser.setTitle(title);/*w  w  w .  j  a  v a 2s  .com*/

    if (storageFile.getFile() != null) {
        fileChooser.setInitialDirectory(storageFile.getFile().getParentFile());
    }

    //Show open file dialog
    File file = fileChooser.showOpenDialog(applicationPane.getScene().getWindow());
    if (file != null) {
        storageFile.setFile(file);
        useLoadFileService(storageFile, t -> resetContent());
    }
}

From source file:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

/**
 * Load an ini file, add it to the list of recently used ini files.
 * TODO Store this info somewhere!//from w  ww  .  ja va2s.c  om
 *
 * @param actionEvent
 */
public void loadApplicationIniFile(ActionEvent actionEvent) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open Resource File");
    File iniFile = fileChooser.showOpenDialog(App.instance.primaryStage);
    if (iniFile != null && iniFile.exists()) {
        comboBoxApplicationIniFiles.getItems().add(iniFile);
        selectedApplicationIniChanged(iniFile.getAbsolutePath());
    }
}

From source file:acmi.l2.clientmod.xdat.Controller.java

@FXML
private void open() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open interface.xdat");
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("XDAT (*.xdat)", "*.xdat"),
            new FileChooser.ExtensionFilter("All files", "*.*"));

    if (initialDirectory.getValue() != null && initialDirectory.getValue().exists()
            && initialDirectory.getValue().isDirectory())
        fileChooser.setInitialDirectory(initialDirectory.getValue());

    File selected = fileChooser.showOpenDialog(editor.getStage());
    if (selected == null)
        return;/*from   www .j a  v  a  2s.c  o  m*/

    xdatFile.setValue(selected);
    initialDirectory.setValue(selected.getParentFile());

    try {
        IOEntity xdat = editor.getXdatClass().getConstructor().newInstance();

        editor.execute(() -> {
            CountingInputStream cis = new CountingInputStream(
                    new BufferedInputStream(new FileInputStream(selected)));
            try (InputStream is = cis) {
                xdat.read(is);

                Platform.runLater(() -> editor.setXdatObject(xdat));
            } catch (Exception e) {
                log.log(Level.WARNING, String.format("Read error before offset 0x%x", cis.getCount()), e);
                throw e;
            }
            return null;
        }, e -> Platform.runLater(() -> Dialogs.show(Alert.AlertType.ERROR, "Read error", null,
                "Try to choose another version")));
    } catch (ReflectiveOperationException e) {
        log.log(Level.WARNING, "XDAT class should have empty public constructor", e);
        Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null,
                "XDAT class should have empty public constructor");
    }
}

From source file:cz.lbenda.dataman.db.frm.DbConfigFrmController.java

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
    lvLibraries.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    btnAddLibrary.setOnAction(event -> {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(msgLibraryChooseTitle);
        fileChooser.getExtensionFilters().addAll(Constants.librariesFilter);
        List<File> files = fileChooser.showOpenMultipleDialog(btnAddLibrary.getScene().getWindow());
        if (files != null) {
            files.forEach(file -> lvLibraries.getItems().add(file.getAbsolutePath()));
        }/*from ww  w  .ja v  a 2 s. c  o m*/
    });
    btnRemoveLibrary.setOnAction(
            event -> lvLibraries.getItems().removeAll(lvLibraries.getSelectionModel().getSelectedItems()));
    btnExtendConfigFindPath.setOnAction(event -> {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(msgExtendConfigChooseTitle);
        fileChooser.getExtensionFilters().addAll(Constants.configFileFilter);
        if (StringUtils.isEmpty(tfExtendConfigPath.getText())) {
            fileChooser.setInitialFileName(tfExtendConfigPath.getText());
        }
        File file = fileChooser.showOpenDialog(btnExtendConfigFindPath.getScene().getWindow());
        if (file != null) {
            tfExtendConfigPath.setText(file.getAbsolutePath());
        }
    });
    lvLibraries.getItems().addListener((ListChangeListener<String>) change -> {
        while (change.next()) {
            if (change.wasAdded() || change.wasRemoved()) {
                findDriverClasses();
            }
        }
    });
}

From source file:condorclient.CreateJobDialogController.java

/**
 * Initializes the controller class./*from w  w  w. ja v a  2 s.  c  om*/
 */
@FXML
private void infoFileChooserFired(ActionEvent event) {
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("??");
    fileChooser.setInitialDirectory(new File(infoFileInitialDir));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("IXL", "*.ixl"));

    File file = fileChooser.showOpenDialog(this.stage);

    if (file != null) {
        infoFileText.setText(file.getAbsolutePath());
        infoFileInitialDir = file.getParent();

        System.out.println("infoFileInitialDir:" + infoFileInitialDir);
        // System.out.println(file.getName());

        // openFile(file);
    }
    infoOk = true;
    enableButton();
}

From source file:condorclient.CreateJobDialogController.java

@FXML
private void expFileChooserFired(ActionEvent event) {
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("");

    fileChooser.setInitialDirectory(new File(expFileInitialDir));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("EXL", "*.exl"));

    File file = fileChooser.showOpenDialog(this.stage);
    String s = "";
    if (file != null) {
        expFileText.setText(file.getAbsolutePath());
        expFileInitialDir = file.getParent();
        XMLHandler handler = new XMLHandler();
        s = handler.getNRun(file.getAbsolutePath());
    }//from   ww w  .j a  v  a 2  s  .com

    sampleNumText.setText(s);
    sampleNumText.setDisable(true);
    //?
    expOk = true;
    enableButton();
}

From source file:acmi.l2.clientmod.l2smr.Controller.java

@FXML
private void importSM() {
    if (this.unrChooser.getSelectionModel().getSelectedItem() == null)
        return;//from ww w.  ja v  a 2  s.  c o  m

    FileChooser fileChooser = new FileChooser();
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
    fileChooser.setTitle("Open");
    File file = fileChooser.showOpenDialog(getStage());
    if (file == null)
        return;

    int xy = 18 | (20 << 8);
    try {
        xy = getXY(getMapsDir(), this.unrChooser.getSelectionModel().getSelectedItem());
    } catch (IOException e) {
        showAlert(Alert.AlertType.WARNING, "Import", null, "Couldn't read map coords, using default 18_20");
    }

    ImportExportDialog dlg = new ImportExportDialog(xy & 0xff, (xy >> 8) & 0xff);
    ButtonType response = dlg.showAndWait().orElse(null);
    if (response != ButtonType.OK)
        return;

    AffineTransform transform = AffineTransform.getRotateInstance(Math.PI * dlg.getAngle() / 180);

    ObjectMapper objectMapper = new ObjectMapper();
    try {
        L2Map map = objectMapper.readValue(file, L2Map.class);

        if (map.getStaticMeshes().isEmpty())
            return;

        longTask(progress -> {
            try (UnrealPackage up = new UnrealPackage(
                    new File(getMapsDir(), unrChooser.getSelectionModel().getSelectedItem()), false)) {
                up.addImportEntries(map.getStaticMeshes().stream().collect(
                        Collectors.toMap(Actor::getStaticMesh, a -> "Engine.StaticMesh", (o1, o2) -> o1)));

                for (int i = 0; i < map.getStaticMeshes().size(); i++) {
                    Actor actor = map.getStaticMeshes().get(i);

                    int newActorInd = StaticMeshActorUtil.addStaticMeshActor(up,
                            up.objectReferenceByName(actor.getStaticMesh(), c -> true), actor.getActorClass(),
                            true, true, oldFormat.isSelected());
                    UnrealPackage.ExportEntry newActor = (UnrealPackage.ExportEntry) up
                            .objectReference(newActorInd);

                    actor.setActorName(newActor.getObjectInnerFullName());
                    actor.setStaticMeshRef(up.objectReferenceByName(actor.getStaticMesh(), c -> true));

                    byte[] bytes = newActor.getObjectRawData();
                    Offsets offsets = StaticMeshActorUtil.getOffsets(bytes, up);

                    Point2D.Float point = new Point2D.Float(actor.getX(), actor.getY());
                    transform.transform(point, point);

                    actor.setX(dlg.getX() + point.x);
                    actor.setY(dlg.getY() + point.y);
                    actor.setZ(dlg.getZ() + actor.getZ());

                    actor.setYaw((actor.getYaw() + (int) (0xFFFF * dlg.getAngle() / 360)) & 0xFFFF);

                    StaticMeshActorUtil.setLocation(bytes, offsets, actor.getX(), actor.getY(), actor.getZ());
                    StaticMeshActorUtil.setRotation(bytes, offsets, actor.getPitch(), actor.getYaw(),
                            actor.getRoll());
                    if (actor.getScale3D() != null)
                        StaticMeshActorUtil.setDrawScale3D(bytes, offsets, actor.getScaleX(), actor.getScaleY(),
                                actor.getScaleZ());
                    if (actor.getScale() != null)
                        StaticMeshActorUtil.setDrawScale(bytes, offsets, actor.getScale());
                    if (actor.getRotationRate() != null)
                        StaticMeshActorUtil.setRotationRate(bytes, offsets, actor.getPitchRate(),
                                actor.getYawRate(), actor.getRollRate());
                    if (actor.getZoneRenderState() != null)
                        bytes = StaticMeshActorUtil.setZoneRenderState(bytes, offsets,
                                actor.getZoneRenderState());

                    newActor.setObjectRawData(bytes);

                    progress.accept((double) i / map.getStaticMeshes().size());
                }
            }

            Platform.runLater(() -> {
                String unr = unrChooser.getSelectionModel().getSelectedItem();
                Actor act = map.getStaticMeshes().get(map.getStaticMeshes().size() - 1);

                unrChooser.getSelectionModel().clearSelection();
                unrChooser.getSelectionModel().select(unr);

                table.getSelectionModel().select(act);
                table.scrollTo(act);
            });
        }, e -> onException("Import failed", e));
    } catch (IOException e) {
        onException("Import failed", e);
    }
}

From source file:dsfixgui.view.DSPWPane.java

private void initializeEventHandlers() {

    applySettingsButton.setOnAction(e -> {
        ui.applyDSPWConfig();/*  w  ww  .j  a va2s.  c o  m*/
    });

    restoreDefaultsButton.setOnAction(e -> {
        ContinueDialog cD = new ContinueDialog(300.0, 80.0, DIALOG_TITLE_RESET, DIALOG_MSG_RESTORE_SETTINGS,
                DIALOG_BUTTON_TEXTS[2], DIALOG_BUTTON_TEXTS[1]);
        if (cD.show()) {
            config.restoreDefaults();
            ui.refreshUI();
        }
    });

    versionBannerOn.setOnAction(e -> {
        config.ShowVersionBanner.replace(0, config.ShowVersionBanner.length(), TRUE_FALSE[0]);
    });

    versionBannerOff.setOnAction(e -> {
        config.ShowVersionBanner.replace(0, config.ShowVersionBanner.length(), TRUE_FALSE[1]);
    });

    overlayOn.setOnAction(e -> {
        config.ShowOverlay.replace(0, config.ShowOverlay.length(), TRUE_FALSE[0]);
    });

    overlayOff.setOnAction(e -> {
        config.ShowOverlay.replace(0, config.ShowOverlay.length(), TRUE_FALSE[1]);
    });

    invasionNotifOn.setOnAction(e -> {
        config.InvasionSoundNotification.replace(0, config.InvasionSoundNotification.length(), TRUE_FALSE[0]);
    });

    invasionNotifOff.setOnAction(e -> {
        config.InvasionSoundNotification.replace(0, config.InvasionSoundNotification.length(), TRUE_FALSE[1]);
    });

    cheaterNotifOn.setOnAction(e -> {
        config.CheaterSoundNotification.replace(0, config.CheaterSoundNotification.length(), TRUE_FALSE[0]);
    });

    cheaterNotifOff.setOnAction(e -> {
        config.CheaterSoundNotification.replace(0, config.CheaterSoundNotification.length(), TRUE_FALSE[1]);
    });

    blockArenaFreezeOn.setOnAction(e -> {
        config.BlockArenaFreeze.replace(0, config.BlockArenaFreeze.length(), TRUE_FALSE[0]);
    });

    blockArenaFreezeOff.setOnAction(e -> {
        config.BlockArenaFreeze.replace(0, config.BlockArenaFreeze.length(), TRUE_FALSE[1]);
    });

    nodeCountOn.setOnAction(e -> {
        config.ShowNodeDbCount.replace(0, config.ShowNodeDbCount.length(), TRUE_FALSE[0]);
    });

    nodeCountOff.setOnAction(e -> {
        config.ShowNodeDbCount.replace(0, config.ShowNodeDbCount.length(), TRUE_FALSE[1]);
    });

    increaseNodesOn.setOnAction(e -> {
        config.IncreaseNodeDbLimit.replace(0, config.IncreaseNodeDbLimit.length(), TRUE_FALSE[0]);
    });

    increaseNodesOff.setOnAction(e -> {
        config.IncreaseNodeDbLimit.replace(0, config.IncreaseNodeDbLimit.length(), TRUE_FALSE[1]);
    });

    dateOn.setOnAction(e -> {
        config.DisplayDate.replace(0, config.DisplayDate.length(), TRUE_FALSE[0]);
    });

    dateOff.setOnAction(e -> {
        config.DisplayDate.replace(0, config.DisplayDate.length(), TRUE_FALSE[1]);
    });

    timeOn.setOnAction(e -> {
        config.DisplayClock.replace(0, config.DisplayClock.length(), TRUE_FALSE[0]);
    });

    timeOff.setOnAction(e -> {
        config.DisplayClock.replace(0, config.DisplayClock.length(), TRUE_FALSE[1]);
    });

    updateOn.setOnAction(e -> {
        config.CheckForUpdates.replace(0, config.CheckForUpdates.length(), TRUE_FALSE[0]);
    });

    updateOff.setOnAction(e -> {
        config.CheckForUpdates.replace(0, config.CheckForUpdates.length(), TRUE_FALSE[1]);
    });

    textAlignmentLeft.setOnAction(e -> {
        config.TextAlignment.replace(0, config.TextAlignment.length(), DSPW_TEXT_ALIGNMENT_OPTIONS[0]);
    });

    textAlignmentCenter.setOnAction(e -> {
        config.TextAlignment.replace(0, config.TextAlignment.length(), DSPW_TEXT_ALIGNMENT_OPTIONS[1]);
    });

    textAlignmentRight.setOnAction(e -> {
        config.TextAlignment.replace(0, config.TextAlignment.length(), DSPW_TEXT_ALIGNMENT_OPTIONS[2]);
    });

    fontSizeField.textProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldText, String newText) {
            try {
                if (!NumberUtils.isParsable(newText) || Integer.parseInt(newText) > 72
                        || Integer.parseInt(newText) < 15) {
                    fontSizeField.pseudoClassStateChanged(INVALID_INPUT, true);
                } else {
                    fontSizeField.pseudoClassStateChanged(INVALID_INPUT, false);
                    config.FontSize.replace(0, config.FontSize.length(), "" + Integer.parseInt(newText));
                }
            } catch (NumberFormatException nFE) {
                ui.printConsole(INPUT_TOO_LARGE);
                fontSizeField.setText("");
            }
        }
    });

    dllChainButton.setOnAction(e -> {
        FileChooser dllChooser = new FileChooser();
        dllChooser.setTitle(DIALOG_TITLE_DLL);
        if (ui.getDataFolder() != null) {
            dllChooser.setInitialDirectory(ui.getDataFolder());
        }
        ExtensionFilter dllFilter = new ExtensionFilter(DLL_EXT_FILTER[0], DLL_EXT_FILTER[1]);
        dllChooser.getExtensionFilters().add(dllFilter);

        File dll = dllChooser.showOpenDialog(ui.getStage());

        if (dll != null && ui.getDataFolder() != null) {
            File checkDLL = new File(ui.getDataFolder() + "\\" + dll.getName());
            if (!checkDLL.exists()) {
                AlertDialog aD = new AlertDialog(300.0, 80.0, DIALOG_TITLE_WRONG_FOLDER, DLL_MUST_BE_IN_DATA,
                        DIALOG_BUTTON_TEXTS[0]);
            } else {
                if (dll.getName().equals(DSM_FILES[0])) {
                    AlertDialog aD = new AlertDialog(300.0, 80.0, INVALID_DLL, CANT_CHAIN_DLL_WITH_DSM,
                            DIALOG_BUTTON_TEXTS[0]);
                } else if (dll.getName().equals(DSF_FILES[0])) {
                    AlertDialog aD = new AlertDialog(300.0, 80.0, INVALID_DLL, CANT_CHAIN_DLL_WITH_DSF,
                            DIALOG_BUTTON_TEXTS[0]);
                } else if (dll.getName().equals(DS_DEFAULT_DLLS[0]) || dll.getName().equals(DS_DEFAULT_DLLS[1])
                        || dll.getName().equals(DS_DEFAULT_DLLS[2])) {
                    AlertDialog aD = new AlertDialog(300.0, 80.0, INVALID_DLL, CANT_CHAIN_DLL_WITH_DEFAULT,
                            DIALOG_BUTTON_TEXTS[0]);
                } else if (dll.getName().equals(DSPW_FILES[1]) || dll.getName().equals(DSPW_FILES[4])
                        || dll.getName().equals(DSPW_FILES[5])) {
                    AlertDialog aD = new AlertDialog(300.0, 80.0, INVALID_DLL, CANT_CHAIN_DSPW_WITH_DSPW,
                            DIALOG_BUTTON_TEXTS[0]);
                } else {
                    config.d3d9dllWrapper.replace(0, config.d3d9dllWrapper.length(), dll.getName());
                    dllChainField.setText(dll.getName());
                    dllChainField.setStyle("-fx-text-fill: black;");
                    noChainButton.setDisable(false);
                }
            }
        }
    });

    noChainButton.setOnAction(e -> {
        dllChainField.setText(NONE);
        noChainButton.setDisable(true);
        dllChainField.setStyle("-fx-text-fill: gray;");
        config.d3d9dllWrapper.replace(0, config.d3d9dllWrapper.length(), NONE);
    });

    banPicker.setOnAction(e -> {
        config.key_BanPhantom.replace(0, config.key_BanPhantom.length(),
                keybindsHex.get(keybinds.indexOf(banPicker.getValue())));
    });

    ignorePicker.setOnAction(e -> {
        config.key_IgnorePhantom.replace(0, config.key_IgnorePhantom.length(),
                keybindsHex.get(keybinds.indexOf(ignorePicker.getValue())));
    });

    toggleOverlayPicker.setOnAction(e -> {
        config.key_HideOverlay.replace(0, config.key_HideOverlay.length(),
                keybindsHex.get(keybinds.indexOf(toggleOverlayPicker.getValue())));
    });

    aboutPicker.setOnAction(e -> {
        config.key_AboutDSPW.replace(0, config.key_AboutDSPW.length(),
                keybindsHex.get(keybinds.indexOf(aboutPicker.getValue())));
    });

}