67 lines
2.3 KiB
Java
67 lines
2.3 KiB
Java
package envoy.client.ui.settings;
|
|
|
|
import javafx.geometry.Insets;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.CheckBox;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.layout.HBox;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.stage.DirectoryChooser;
|
|
|
|
import envoy.client.ui.SceneContext;
|
|
|
|
/**
|
|
* Displays options for downloading {@link envoy.data.Attachment}s.
|
|
* <p>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>DownloadSettingsPane.java</strong><br>
|
|
* Created: <strong>27.07.2020</strong><br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Client v0.2-beta
|
|
*/
|
|
public 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");
|
|
final var vbox = new VBox(15);
|
|
vbox.setPadding(new Insets(15));
|
|
// checkbox to disable asking
|
|
final var checkBox = new CheckBox(settings.getItems().get("autoSaveDownloads").getUserFriendlyName());
|
|
checkBox.setSelected(settings.isDownloadSavedWithoutAsking());
|
|
checkBox.setOnAction(e -> settings.setDownloadSavedWithoutAsking(checkBox.isSelected()));
|
|
vbox.getChildren().add(checkBox);
|
|
|
|
// Displaying the default path to save to
|
|
vbox.getChildren().add(new Label(settings.getItems().get("downloadLocation").getDescription() + ":"));
|
|
final var hbox = new HBox(20);
|
|
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);
|
|
vbox.getChildren().add(hbox);
|
|
getChildren().add(vbox);
|
|
}
|
|
|
|
}
|