소스 검색

add indicator when passwords match

Armin Schrenk 6 년 전
부모
커밋
dcf44aa134

+ 18 - 7
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java

@@ -2,6 +2,7 @@ package org.cryptomator.ui.addvaultwizard;
 
 import dagger.Lazy;
 import javafx.beans.binding.Bindings;
+import javafx.beans.binding.BooleanBinding;
 import javafx.beans.property.IntegerProperty;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleIntegerProperty;
@@ -11,7 +12,9 @@ import javafx.fxml.FXML;
 import javafx.scene.Scene;
 import javafx.scene.control.Button;
 import javafx.scene.control.Label;
+import javafx.scene.layout.HBox;
 import javafx.scene.layout.Region;
+import javafx.scene.shape.Rectangle;
 import javafx.stage.Stage;
 import org.cryptomator.common.settings.VaultSettings;
 import org.cryptomator.common.vaults.Vault;
@@ -51,6 +54,10 @@ public class CreateNewVaultPasswordController implements FxController {
 	public Region passwordStrengthLevel3;
 	public Region passwordStrengthLevel4;
 	public Label passwordStrengthLabel;
+	public HBox passwordMatchBox;
+	public Rectangle checkmark;
+	public Rectangle cross;
+	public Label passwordMatchLabel;
 
 	@Inject
 	CreateNewVaultPasswordController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy<Scene> previousScene, StringProperty vaultName, ObjectProperty<Path> vaultPath, ObservableList<Vault> vaults, VaultFactory vaultFactory, ResourceBundle resourceBundle, PasswordStrengthUtil strengthRater) {
@@ -68,14 +75,18 @@ public class CreateNewVaultPasswordController implements FxController {
 	@FXML
 	public void initialize() {
 		//binds the actual strength value to the rating of the password util
-		passwordStrength.bind(
-				Bindings.createIntegerBinding(() -> strengthRater.computeRate(passwordField.getCharacters().toString()), passwordField.textProperty())
-		);
+		passwordStrength.bind(Bindings.createIntegerBinding(() -> strengthRater.computeRate(passwordField.getCharacters().toString()), passwordField.textProperty()));
+		//binding indicating if the passwords not match
+		BooleanBinding passwordsMatch = Bindings.createBooleanBinding(() -> CharSequence.compare(passwordField.getCharacters(), retypeField.getCharacters()) == 0, passwordField.textProperty(), retypeField.textProperty());
+		BooleanBinding retypteFieldNotEmpty = retypeField.textProperty().isNotEmpty();
 		//disable the finish button when passwords do not match or one is empty
-		finishButton.disableProperty().bind(
-				passwordField.textProperty().isEmpty()
-						.or(Bindings.createBooleanBinding(() -> CharSequence.compare(passwordField.getCharacters(),retypeField.getCharacters()) != 0,passwordField.textProperty(), retypeField.textProperty()))
-		);
+		finishButton.disableProperty().bind(retypteFieldNotEmpty.not().or(passwordsMatch.not()));
+		//make match indicator invisible when passwords do not match or one is empty
+		passwordMatchBox.visibleProperty().bind(retypteFieldNotEmpty);
+		checkmark.visibleProperty().bind(passwordsMatch.and(retypteFieldNotEmpty));
+		cross.visibleProperty().bind(passwordsMatch.not().and(retypteFieldNotEmpty));
+		passwordMatchLabel.textProperty().bind(Bindings.when(passwordsMatch.and(retypteFieldNotEmpty)).then(resourceBundle.getString("addvaultwizard.new.passwordsMatch")).otherwise(resourceBundle.getString("addvaultwizard.new.passwordsDoNotMatch")));
+
 		//bindsings for the password strength indicator
 		passwordStrengthLevel0.backgroundProperty().bind(EasyBind.combine(passwordStrength, new SimpleIntegerProperty(0), strengthRater::getBackgroundWithStrengthColor));
 		passwordStrengthLevel1.backgroundProperty().bind(EasyBind.combine(passwordStrength, new SimpleIntegerProperty(1), strengthRater::getBackgroundWithStrengthColor));

+ 11 - 0
main/ui/src/main/resources/fxml/addvault_new_password.fxml

@@ -8,6 +8,8 @@
 <?import javafx.scene.layout.VBox?>
 <?import org.cryptomator.ui.controls.SecPasswordField?>
 <?import javafx.scene.layout.HBox?>
+<?import javafx.scene.image.ImageView?>
+<?import javafx.scene.shape.Rectangle?>
 <VBox xmlns="http://javafx.com/javafx"
 	  xmlns:fx="http://javafx.com/fxml"
 	  fx:controller="org.cryptomator.ui.addvaultwizard.CreateNewVaultPasswordController"
@@ -31,6 +33,15 @@
 		<Region VBox.vgrow="ALWAYS"/>
 		<Label text="%addvaultwizard.new.reenterPassword"/>
 		<SecPasswordField fx:id="retypeField"/>
+		<HBox fx:id="passwordMatchBox" spacing="12.0" alignment="BASELINE_RIGHT" >
+			<!-- TODO
+			<ImageView fx:id="checkmark" image="/path/to/checkmark" fitWidth="10" fitHeight="10" />
+			<ImageView fx:id="cross" image="/path/to/cross" fitWidth="10" fitHeight="10" />
+			-->
+			<Rectangle fx:id="checkmark" width="10" height="10" fill="green"/>
+			<Rectangle fx:id="cross" width="10" height="10" fill="red"/>
+			<Label fx:id="passwordMatchLabel" />
+		</HBox>
 		<Region VBox.vgrow="ALWAYS"/>
 		<ButtonBar buttonMinWidth="120" buttonOrder="B+I">
 			<buttons>

+ 2 - 0
main/ui/src/main/resources/i18n/strings.properties

@@ -25,6 +25,8 @@ addvaultwizard.new.directoryPickerButton=TODO DirPicker
 addvaultwizard.new.directoryPickerTitle=Select Directory
 addvaultwizard.new.enterPassword=Please enter a Password for your vault:
 addvaultwizard.new.reenterPassword=Please retype the password:
+addvaultwizard.new.passwordsMatch=Passwords match!
+addvaultwizard.new.passwordsDoNotMatch=Passwords do not match.
 
 #Unlock
 unlock.title=Unlock Vault