From adf0e3720dcb15ada23677bdc1c5e19d90049a1a Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 17 Feb 2020 20:34:20 +0100 Subject: [PATCH] dedup --- .../org/cryptomator/ui/common/Animations.java | 36 +++++++++++++++++++ .../ui/migration/MigrationRunController.java | 30 ++-------------- .../RecoveryKeyCreationController.java | 30 ++-------------- .../ui/unlock/UnlockController.java | 30 ++-------------- 4 files changed, 42 insertions(+), 84 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/common/Animations.java diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/Animations.java b/main/ui/src/main/java/org/cryptomator/ui/common/Animations.java new file mode 100644 index 000000000..d9c1ed19f --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/common/Animations.java @@ -0,0 +1,36 @@ +package org.cryptomator.ui.common; + +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.Timeline; +import javafx.beans.value.WritableValue; +import javafx.stage.Window; +import javafx.util.Duration; + +public class Animations { + + public static Timeline createShakeWindowAnimation(Window window) { + WritableValue writableWindowX = new WritableValue<>() { + @Override + public Double getValue() { + return window.getX(); + } + + @Override + public void setValue(Double value) { + window.setX(value); + } + }; + return new Timeline( // + new KeyFrame(Duration.ZERO, new KeyValue(writableWindowX, window.getX())), // + new KeyFrame(new Duration(100), new KeyValue(writableWindowX, window.getX() - 22.0)), // + new KeyFrame(new Duration(200), new KeyValue(writableWindowX, window.getX() + 18.0)), // + new KeyFrame(new Duration(300), new KeyValue(writableWindowX, window.getX() - 14.0)), // + new KeyFrame(new Duration(400), new KeyValue(writableWindowX, window.getX() + 10.0)), // + new KeyFrame(new Duration(500), new KeyValue(writableWindowX, window.getX() - 6.0)), // + new KeyFrame(new Duration(600), new KeyValue(writableWindowX, window.getX() + 2.0)), // + new KeyFrame(new Duration(700), new KeyValue(writableWindowX, window.getX())) // + ); + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/migration/MigrationRunController.java b/main/ui/src/main/java/org/cryptomator/ui/migration/MigrationRunController.java index 18be66c5d..19cdea0fe 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/migration/MigrationRunController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/migration/MigrationRunController.java @@ -30,6 +30,7 @@ import org.cryptomator.cryptofs.migration.api.NoApplicableMigratorException; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.keychain.KeychainAccess; import org.cryptomator.keychain.KeychainAccessException; +import org.cryptomator.ui.common.Animations; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; @@ -123,7 +124,7 @@ public class MigrationRunController implements FxController { window.setScene(successScene.get()); } }).onError(InvalidPassphraseException.class, e -> { - shakeWindow(); + Animations.createShakeWindowAnimation(window).play(); passwordField.selectAll(); passwordField.requestFocus(); vault.setState(VaultState.NEEDS_MIGRATION); @@ -176,33 +177,6 @@ public class MigrationRunController implements FxController { } } - /* Animations */ - - private void shakeWindow() { - WritableValue writableWindowX = new WritableValue<>() { - @Override - public Double getValue() { - return window.getX(); - } - - @Override - public void setValue(Double value) { - window.setX(value); - } - }; - Timeline timeline = new Timeline( // - new KeyFrame(Duration.ZERO, new KeyValue(writableWindowX, window.getX())), // - new KeyFrame(new Duration(100), new KeyValue(writableWindowX, window.getX() - 22.0)), // - new KeyFrame(new Duration(200), new KeyValue(writableWindowX, window.getX() + 18.0)), // - new KeyFrame(new Duration(300), new KeyValue(writableWindowX, window.getX() - 14.0)), // - new KeyFrame(new Duration(400), new KeyValue(writableWindowX, window.getX() + 10.0)), // - new KeyFrame(new Duration(500), new KeyValue(writableWindowX, window.getX() - 6.0)), // - new KeyFrame(new Duration(600), new KeyValue(writableWindowX, window.getX() + 2.0)), // - new KeyFrame(new Duration(700), new KeyValue(writableWindowX, window.getX())) // - ); - timeline.play(); - } - /* Getter/Setter */ public Vault getVault() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java index 945256f9e..9c9a173c6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyCreationController.java @@ -13,6 +13,7 @@ import javafx.stage.Stage; import javafx.util.Duration; import org.cryptomator.common.vaults.Vault; import org.cryptomator.cryptolib.api.InvalidPassphraseException; +import org.cryptomator.ui.common.Animations; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; @@ -59,7 +60,7 @@ public class RecoveryKeyCreationController implements FxController { }).onError(IOException.class, e -> { LOG.error("Creation of recovery key failed.", e); }).onError(InvalidPassphraseException.class, e -> { - shakeWindow(); + Animations.createShakeWindowAnimation(window).play(); }).runOnce(executor); } @@ -68,33 +69,6 @@ public class RecoveryKeyCreationController implements FxController { window.close(); } - /* Animations */ - - private void shakeWindow() { - WritableValue writableWindowX = new WritableValue<>() { - @Override - public Double getValue() { - return window.getX(); - } - - @Override - public void setValue(Double value) { - window.setX(value); - } - }; - Timeline timeline = new Timeline( // - new KeyFrame(Duration.ZERO, new KeyValue(writableWindowX, window.getX())), // - new KeyFrame(new Duration(100), new KeyValue(writableWindowX, window.getX() - 22.0)), // - new KeyFrame(new Duration(200), new KeyValue(writableWindowX, window.getX() + 18.0)), // - new KeyFrame(new Duration(300), new KeyValue(writableWindowX, window.getX() - 14.0)), // - new KeyFrame(new Duration(400), new KeyValue(writableWindowX, window.getX() + 10.0)), // - new KeyFrame(new Duration(500), new KeyValue(writableWindowX, window.getX() - 6.0)), // - new KeyFrame(new Duration(600), new KeyValue(writableWindowX, window.getX() + 2.0)), // - new KeyFrame(new Duration(700), new KeyValue(writableWindowX, window.getX())) // - ); - timeline.play(); - } - /* Getter/Setter */ public Vault getVault() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java index ec9013d51..30acd2486 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockController.java @@ -24,6 +24,7 @@ import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.cryptolib.api.UnsupportedVaultFormatException; import org.cryptomator.keychain.KeychainAccess; import org.cryptomator.keychain.KeychainAccessException; +import org.cryptomator.ui.common.Animations; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; @@ -113,7 +114,7 @@ public class UnlockController implements FxController { }); task.setOnFailed(event -> { if (task.getException() instanceof InvalidPassphraseException) { - shakeWindow(); + Animations.createShakeWindowAnimation(window).play(); passwordField.selectAll(); passwordField.requestFocus(); } else if (task.getException() instanceof NotDirectoryException @@ -171,33 +172,6 @@ public class UnlockController implements FxController { } } - /* Animations */ - - private void shakeWindow() { - WritableValue writableWindowX = new WritableValue<>() { - @Override - public Double getValue() { - return window.getX(); - } - - @Override - public void setValue(Double value) { - window.setX(value); - } - }; - Timeline timeline = new Timeline( // - new KeyFrame(Duration.ZERO, new KeyValue(writableWindowX, window.getX())), // - new KeyFrame(new Duration(100), new KeyValue(writableWindowX, window.getX() - 22.0)), // - new KeyFrame(new Duration(200), new KeyValue(writableWindowX, window.getX() + 18.0)), // - new KeyFrame(new Duration(300), new KeyValue(writableWindowX, window.getX() - 14.0)), // - new KeyFrame(new Duration(400), new KeyValue(writableWindowX, window.getX() + 10.0)), // - new KeyFrame(new Duration(500), new KeyValue(writableWindowX, window.getX() - 6.0)), // - new KeyFrame(new Duration(600), new KeyValue(writableWindowX, window.getX() + 2.0)), // - new KeyFrame(new Duration(700), new KeyValue(writableWindowX, window.getX())) // - ); - timeline.play(); - } - /* Getter/Setter */ public Vault getVault() {