InstallLocation.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:OneClient 作者:
public static void getInstallDir(Predicate<File> predicate) throws IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL fxmlUrl = classLoader.getResource("gui/install_location.fxml");
    if (fxmlUrl == null) {
        OneClientLogging.logger.error("An error has occurred loading the fxml!");
    }
    FXMLLoader fxmlLoader = new FXMLLoader();
    fxmlLoader.setLocation(fxmlUrl);
    fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
    Parent root = fxmlLoader.load(fxmlUrl.openStream());
    Stage stage = new Stage();
    stage.setTitle("Select Install Location");
    stage.getIcons().add(new Image("images/icon.png"));
    stage.setResizable(false);
    stage.initOwner(Main.stage);
    stage.initModality(Modality.WINDOW_MODAL);
    Scene scene = new Scene(root, 500, 150);
    scene.getStylesheets().add("gui/css/theme.css");
    stage.setScene(scene);
    stage.show();
    InstallLocation controller = fxmlLoader.getController();
    controller.okButton.setOnAction(event -> {
        predicate.test(new File(controller.locationField.getText()));
        stage.close();
    });
    controller.browseButton.setOnAction(event -> {
        DirectoryChooser directoryChooser = new DirectoryChooser();
        File dir = new File(controller.locationField.getText());
        if (dir.exists())
            directoryChooser.setInitialDirectory(dir);
        File selectedDirectory = directoryChooser.showDialog(stage);
        if (selectedDirectory != null) {
            controller.locationField.setText(selectedDirectory.getAbsolutePath());
        }
    });
    controller.locationField.setText(Constants.getDefaultDir().getAbsolutePath());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号