From 2f9818aadec270b3ac0df9a5a1204e100e40226f Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 29 Nov 2022 17:07:43 +0100 Subject: [PATCH] use new JavaFX 19 API --- .../ChooseExistingVaultController.java | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java index 0a0dc3d2e..fe4ac3bd1 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java @@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.Scene; @@ -25,6 +24,7 @@ import javafx.stage.Stage; import java.io.File; import java.io.IOException; import java.nio.file.Path; +import java.util.Objects; import java.util.ResourceBundle; import static org.cryptomator.common.Constants.CRYPTOMATOR_FILENAME_GLOB; @@ -42,9 +42,7 @@ public class ChooseExistingVaultController implements FxController { private final ObjectProperty vault; private final VaultListManager vaultListManager; private final ResourceBundle resourceBundle; - private final FxApplicationStyle applicationStyle; - - private final ObjectProperty screenshot = new SimpleObjectProperty<>(); + private final ObservableValue screenshot; @Inject ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, FxApplicationWindows appWindows, ObjectProperty vaultPath, @AddVaultWizardWindow ObjectProperty vault, VaultListManager vaultListManager, ResourceBundle resourceBundle, FxApplicationStyle applicationStyle) { @@ -56,28 +54,20 @@ public class ChooseExistingVaultController implements FxController { this.vault = vault; this.vaultListManager = vaultListManager; this.resourceBundle = resourceBundle; - this.applicationStyle = applicationStyle; + this.screenshot = applicationStyle.appliedThemeProperty().map(this::selectScreenshot); } - @FXML - public void initialize() { + private Image selectScreenshot(Theme theme) { + String imageResourcePath; if (SystemUtils.IS_OS_MAC) { - applicationStyle.appliedThemeProperty().addListener(this::appliedThemeChanged); - setMacScreenshot(applicationStyle.appliedThemeProperty().get()); + imageResourcePath = switch (theme) { + case LIGHT -> "/img/select-masterkey-mac.png"; + case DARK -> "/img/select-masterkey-mac-dark.png"; + }; } else { - this.screenshot.set(new Image(getClass().getResource("/img/select-masterkey-win.png").toString())); - } - } - - private void appliedThemeChanged(@SuppressWarnings("unused") ObservableValue observable, @SuppressWarnings("unused") Theme oldValue, Theme newValue) { - setMacScreenshot(newValue); - } - - private void setMacScreenshot(Theme theme) { - switch (theme) { - case LIGHT -> this.screenshot.set(new Image(getClass().getResource("/img/select-masterkey-mac.png").toString())); - case DARK -> this.screenshot.set(new Image(getClass().getResource("/img/select-masterkey-mac-dark.png").toString())); + imageResourcePath = "/img/select-masterkey-win.png"; } + return new Image((Objects.requireNonNull(getClass().getResource(imageResourcePath)).toString())); } @FXML @@ -106,12 +96,12 @@ public class ChooseExistingVaultController implements FxController { /* Getter */ - public ObjectProperty screenshotProperty() { + public ObservableValue screenshotProperty() { return screenshot; } public Image getScreenshot() { - return screenshot.get(); + return screenshot.getValue(); }