Search in sources :

Example 51 with FileChooser

use of javafx.stage.FileChooser in project jabref by JabRef.

the class FXDialogService method getConfiguredFileChooser.

@Override
public FileChooser getConfiguredFileChooser(FileDialogConfiguration fileDialogConfiguration) {
    FileChooser chooser = new FileChooser();
    chooser.getExtensionFilters().addAll(fileDialogConfiguration.getExtensionFilters());
    chooser.setSelectedExtensionFilter(fileDialogConfiguration.getDefaultExtension());
    chooser.setInitialFileName(fileDialogConfiguration.getInitialFileName());
    fileDialogConfiguration.getInitialDirectory().map(Path::toFile).ifPresent(chooser::setInitialDirectory);
    return chooser;
}
Also used : FileChooser(javafx.stage.FileChooser)

Example 52 with FileChooser

use of javafx.stage.FileChooser in project intellij-plugins by StepicOrg.

the class FormListener method getDataFromFile.

@Nullable
private static String getDataFromFile(@NotNull StepNode stepNode, @NotNull Project project) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open file");
    VirtualFile srcDirectory = getOrCreateSrcDirectory(project, stepNode, true);
    if (srcDirectory != null) {
        File initialDir = new File(srcDirectory.getPath());
        fileChooser.setInitialDirectory(initialDir);
    }
    File file = fileChooser.showOpenDialog(null);
    if (file != null) {
        try {
            List<String> lines = Files.readAllLines(file.toPath());
            return lines.stream().collect(Collectors.joining("\n"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooser(javafx.stage.FileChooser) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 53 with FileChooser

use of javafx.stage.FileChooser in project Smartcity-Smarthouse by TechnionYP5777.

the class ApplicationsInstallerViewController method initBrowseBtn.

private void initBrowseBtn() {
    browseBtn.setOnAction(e -> {
        final Stage stage = new Stage();
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Open Resource File");
        Optional.ofNullable(fileChooser.showOpenDialog(stage)).ifPresent(a -> browseText.setText(a.getAbsolutePath()));
    });
}
Also used : FileChooser(javafx.stage.FileChooser) Stage(javafx.stage.Stage)

Example 54 with FileChooser

use of javafx.stage.FileChooser in project Media-Library by The-Rain-Goddess.

the class ApplicationWindow method getWindowComponents.

private List<Control> getWindowComponents(Stage parent) {
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Media Selection.");
    //Defining path text field
    final TextField songPath = new TextField();
    songPath.setPromptText("C:\\... *");
    songPath.setPrefColumnCount(30);
    songPath.setEditable(false);
    songPath.setFocusTraversable(false);
    GridPane.setConstraints(songPath, 1, 0);
    final Label songPathLabel = new Label("Path: ");
    GridPane.setConstraints(songPathLabel, 0, 0);
    //Defining the Name text field
    final TextField songName = new TextField();
    songName.setPromptText("Enter the song's name. *");
    songName.setPrefColumnCount(20);
    GridPane.setConstraints(songName, 1, 2);
    final Label songNameLabel = new Label("Name: ");
    GridPane.setConstraints(songNameLabel, 0, 2);
    //Defining the Last Name text field
    final TextField artistNames = new TextField();
    artistNames.setPromptText("Enter the artist name(s). *");
    GridPane.setConstraints(artistNames, 1, 3);
    final Label songArtistLabel = new Label("Artist(s): ");
    GridPane.setConstraints(songArtistLabel, 0, 3);
    //Defining the Comment text field
    final TextField albumName = new TextField();
    albumName.setPrefColumnCount(15);
    albumName.setPromptText("Enter the album name. *");
    GridPane.setConstraints(albumName, 1, 4);
    final Label songAlbumLabel = new Label("Album: ");
    GridPane.setConstraints(songAlbumLabel, 0, 4);
    //album number
    final TextField albumNumber = new TextField();
    albumNumber.setPrefColumnCount(20);
    albumNumber.setPromptText("Enter the song's album number.");
    albumNumber.textProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            if (!newValue.matches("\\d*")) {
                albumNumber.setText(newValue.replaceAll("[^\\d]", ""));
            }
        }
    });
    GridPane.setConstraints(albumNumber, 1, 5);
    final Label songNumberLabel = new Label("Number: ");
    GridPane.setConstraints(songNumberLabel, 0, 5);
    //genre
    final TextField genre = new TextField();
    genre.setPrefColumnCount(20);
    genre.setPromptText("Enter the song's genre.");
    GridPane.setConstraints(genre, 1, 6);
    final Label songGenreLabel = new Label("Genre: ");
    GridPane.setConstraints(songGenreLabel, 0, 6);
    //required label
    final Label requiredLabel = new Label("* Required");
    GridPane.setConstraints(requiredLabel, 1, 7);
    //Defining the Submit button
    Button submit = new Button("Submit");
    GridPane.setConstraints(submit, 2, 3);
    submit.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            if (songName.textProperty() != null && albumName.textProperty() != null && artistNames.textProperty() != null && !songName.textProperty().getValue().equals("") && !albumName.textProperty().getValue().equals("") && !artistNames.textProperty().getValue().equals("") && !songPath.textProperty().getValue().equals("") && songPath.textProperty() != null) {
                MediaFile newFile = new MediaFile();
                String number = (albumNumber.textProperty().getValue().equals("")) ? "0" : albumNumber.textProperty().getValue();
                MediaFileAttribute mfa = new MediaFileAttribute().setAlbum(albumName.textProperty()).setName(songName.textProperty()).setArtists(artistNames.textProperty()).setGenre(genre.textProperty()).setDateCreated(new Date().toString()).setNumber(Integer.parseInt(number)).setPath(songPath.textProperty().getValue()).setPlays(0);
                try {
                    mfa.setLength(AudioFileIO.read(new File(songPath.textProperty().getValue())).getAudioHeader().getTrackLength());
                } catch (IOException | NumberFormatException | CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
                    e.printStackTrace();
                    mfa.setLength(Double.NaN);
                }
                newFile = new MediaFile(mfa, Main.getNextUUID());
                System.out.println("Successfuly Added:");
                System.out.println(newFile);
                String[] attrs = newFile.getFilePath().split("\\.");
                newFile.setLibraryFilePath("C:\\Music\\" + newFile.getArtistName() + "\\" + newFile.getAlbumName() + "\\" + newFile.getSongName() + "." + attrs[attrs.length - 1]);
                try {
                    newFile.writeToDisk();
                    Files.copy(Paths.get(songPath.textProperty().getValue()), Paths.get(newFile.getLibraryFilePath()), StandardCopyOption.COPY_ATTRIBUTES);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Main.getMasterData().put(newFile.getUUID(), newFile);
                ((Stage) ((Button) t.getSource()).getScene().getWindow()).close();
                updateDataTable();
                updateFileSystem();
            }
        }
    });
    //Defining the Clear button
    Button clear = new Button("Clear");
    clear.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            List<TextField> fields = Arrays.asList(songPath, songName, artistNames, albumName, albumNumber, genre);
            for (TextField s : fields) s.textProperty().set("");
        }
    });
    GridPane.setConstraints(clear, 2, 4);
    //Open file button
    final Button openFile = new Button("Add media files...");
    openFile.setOnAction(new EventHandler<ActionEvent>() {

        final TextField path = songPath;

        @Override
        public void handle(final ActionEvent e) {
            List<File> list = fileChooser.showOpenMultipleDialog(parent);
            if (list != null) {
                for (File file : list) {
                    path.appendText(file.getAbsolutePath().toString());
                }
            }
        }
    });
    GridPane.setConstraints(openFile, 2, 0);
    return Arrays.asList(songPathLabel, songNameLabel, songArtistLabel, songAlbumLabel, songNumberLabel, songGenreLabel, requiredLabel, songPath, songName, artistNames, albumName, albumNumber, genre, openFile, submit, clear);
}
Also used : MediaFile(com.negativevr.media_library.files.MediaFile) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) IOException(java.io.IOException) Date(java.util.Date) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) FileChooser(javafx.stage.FileChooser) TextField(javafx.scene.control.TextField) SortedList(javafx.collections.transformation.SortedList) FilteredList(javafx.collections.transformation.FilteredList) List(java.util.List) ArrayList(java.util.ArrayList) MediaFileAttribute(com.negativevr.media_library.files.MediaFileAttribute) MediaFile(com.negativevr.media_library.files.MediaFile) File(java.io.File)

Example 55 with FileChooser

use of javafx.stage.FileChooser in project fxexperience2 by EricCanull.

the class MainController method saveButtonAction.

@FXML
private void saveButtonAction(ActionEvent event) {
    if (stylerToggle.isSelected()) {
        FileChooser fileChooser = new FileChooser();
        File file = fileChooser.showSaveDialog(rootContainer.getScene().getWindow());
        if (file != null && !file.exists() && file.getParentFile().isDirectory()) {
            try (FileWriter writer = new FileWriter(file)) {
                writer.write(stylerController.getCodeOutput());
                writer.flush();
            } catch (IOException ex) {
                Logger.getLogger(StylerController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        Alert alert = new Alert(Alert.AlertType.INFORMATION, "Code has been saved.", ButtonType.OK);
        alert.getDialogPane().setId("Code-dialog");
        alert.setHeaderText(null);
        alert.getDialogPane().getStylesheets().add(AppPaths.STYLE_PATH + "dialog.css");
        alert.showAndWait();
        event.consume();
    }
}
Also used : FileWriter(java.io.FileWriter) FileChooser(javafx.stage.FileChooser) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) File(java.io.File) FXML(javafx.fxml.FXML)

Aggregations

FileChooser (javafx.stage.FileChooser)65 File (java.io.File)60 Preferences (java.util.prefs.Preferences)21 IOException (java.io.IOException)17 ResourceBundle (java.util.ResourceBundle)11 FXML (javafx.fxml.FXML)11 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 Alert (javafx.scene.control.Alert)5 Button (javafx.scene.control.Button)5 Popup (io.bitsquare.gui.main.overlays.popups.Popup)3 List (java.util.List)3 GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)2 Palette (fractal.Palette)2 Path (java.nio.file.Path)2 ObservableList (javafx.collections.ObservableList)2 FilteredList (javafx.collections.transformation.FilteredList)2 SortedList (javafx.collections.transformation.SortedList)2 Task (javafx.concurrent.Task)2 Insets (javafx.geometry.Insets)2