package envoy.client.ui.settings; import javafx.geometry.Insets; import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.stage.DirectoryChooser; import envoy.client.ui.SceneContext; /** * Displays options for downloading {@link envoy.data.Attachment}s. *
* Project: envoy-client
* File: DownloadSettingsPane.java
* Created: 27.07.2020
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public final class DownloadSettingsPane extends SettingsPane {
/**
* Constructs a new {@code DownloadSettingsPane}.
*
* @param sceneContext the {@code SceneContext} used to block input to the
* {@link javafx.stage.Stage} used in Envoy
* @since Envoy Client v0.2-beta
*/
public DownloadSettingsPane(SceneContext sceneContext) {
super("Download");
setSpacing(15);
setPadding(new Insets(15));
// checkbox to disable asking
final var checkBox = new CheckBox(settings.getItems().get("autoSaveDownloads").getUserFriendlyName());
checkBox.setSelected(settings.isDownloadSavedWithoutAsking());
checkBox.setTooltip(new Tooltip("Determines whether a \"Select save location\" - dialogue will be shown when saving attachments."));
checkBox.setOnAction(e -> settings.setDownloadSavedWithoutAsking(checkBox.isSelected()));
getChildren().add(checkBox);
// Displaying the default path to save to
final var pathLabel = new Label(settings.getItems().get("downloadLocation").getDescription() + ":");
pathLabel.setWrapText(true);
getChildren().add(pathLabel);
final var hbox = new HBox(20);
Tooltip.install(hbox, new Tooltip("Determines the location where attachments will be saved to."));
final var currentPath = new Label(settings.getDownloadLocation().getAbsolutePath());
hbox.getChildren().add(currentPath);
// Setting the default path
final var button = new Button("Select");
button.setOnAction(e -> {
final var directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select the directory where attachments should be saved to");
directoryChooser.setInitialDirectory(settings.getDownloadLocation());
final var selectedDirectory = directoryChooser.showDialog(sceneContext.getStage());
if (selectedDirectory != null) {
currentPath.setText(selectedDirectory.getAbsolutePath());
settings.setDownloadLocation(selectedDirectory);
}
});
hbox.getChildren().add(button);
getChildren().add(hbox);
}
}