From 76ddca0b471a51c8ec72d4ebcb04ce568c61c6dd Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 9 Mar 2020 16:10:52 +0100 Subject: [PATCH] Added hyperlink to downloads page in updates notification window --- .../ui/controls/FormattedString.java | 58 +++++++++++++++++++ .../UpdatesPreferencesController.java | 12 +++- .../resources/fxml/preferences_updates.fxml | 9 ++- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/controls/FormattedString.java diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/FormattedString.java b/main/ui/src/main/java/org/cryptomator/ui/controls/FormattedString.java new file mode 100644 index 000000000..d678a3d86 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/FormattedString.java @@ -0,0 +1,58 @@ +package org.cryptomator.ui.controls; + +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class FormattedString { + + private final StringProperty format = new SimpleStringProperty(""); + private final ObjectProperty arg1 = new SimpleObjectProperty<>(); + // add arg2, arg3, ... on demand + private final StringBinding value; + + public FormattedString() { + this.value = Bindings.createStringBinding(this::computeValue, format, arg1); + } + + protected String computeValue() { + return String.format(format.get(), arg1.get()); + } + + /* Observables */ + + public StringProperty formatProperty() { + return format; + } + + public String getFormat() { + return format.get(); + } + + public void setFormat(String format) { + this.format.set(format); + } + + public ObjectProperty arg1Property() { + return arg1; + } + + public Object getArg1() { + return arg1.get(); + } + + public void setArg1(Object arg1) { + this.arg1.set(arg1); + } + + public StringBinding valueProperty() { + return value; + } + + public String getValue() { + return value.get(); + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java index 6433d1ea7..60edc4f12 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/UpdatesPreferencesController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.preferences; +import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; import javafx.beans.binding.ObjectBinding; @@ -16,6 +17,9 @@ import javax.inject.Inject; @PreferencesScoped public class UpdatesPreferencesController implements FxController { + private static final String DOWNLOADS_URI = "https://cryptomator.org/downloads"; + + private final Application application; private final Settings settings; private final UpdateChecker updateChecker; private final ObjectBinding checkForUpdatesButtonState; @@ -25,7 +29,8 @@ public class UpdatesPreferencesController implements FxController { public CheckBox checkForUpdatesCheckbox; @Inject - UpdatesPreferencesController(Settings settings, UpdateChecker updateChecker) { + UpdatesPreferencesController(Application application, Settings settings, UpdateChecker updateChecker) { + this.application = application; this.settings = settings; this.updateChecker = updateChecker; this.checkForUpdatesButtonState = Bindings.when(updateChecker.checkingForUpdatesProperty()).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY); @@ -43,6 +48,11 @@ public class UpdatesPreferencesController implements FxController { updateChecker.checkForUpdatesNow(); } + @FXML + public void visitDownloadsPage() { + application.getHostServices().showDocument(DOWNLOADS_URI); + } + /* Observable Properties */ public ObjectBinding checkForUpdatesButtonStateProperty() { diff --git a/main/ui/src/main/resources/fxml/preferences_updates.fxml b/main/ui/src/main/resources/fxml/preferences_updates.fxml index 8ac357be0..1e7890a3c 100644 --- a/main/ui/src/main/resources/fxml/preferences_updates.fxml +++ b/main/ui/src/main/resources/fxml/preferences_updates.fxml @@ -3,13 +3,18 @@ + + + + + @@ -24,8 +29,8 @@ - - + +