Craig Raw
5 years ago
11 changed files with 405 additions and 37 deletions
@ -1 +1 @@ |
|||
Subproject commit 813781902b8914fbac20c5a36ef230a44639ecbc |
|||
Subproject commit 282628e4558b04dfa17c3f85247378204f8c82ff |
@ -0,0 +1,65 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import com.sparrowwallet.sparrow.AppController; |
|||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; |
|||
import com.sparrowwallet.sparrow.storage.Storage; |
|||
import javafx.application.Platform; |
|||
import javafx.beans.binding.Bindings; |
|||
import javafx.beans.binding.BooleanBinding; |
|||
import javafx.scene.control.*; |
|||
import javafx.scene.layout.VBox; |
|||
import javafx.scene.text.Font; |
|||
import org.controlsfx.control.textfield.CustomTextField; |
|||
import org.controlsfx.control.textfield.TextFields; |
|||
import org.controlsfx.glyphfont.FontAwesome; |
|||
import org.controlsfx.glyphfont.Glyph; |
|||
import org.controlsfx.glyphfont.GlyphFont; |
|||
import org.controlsfx.glyphfont.GlyphFontRegistry; |
|||
import org.controlsfx.validation.ValidationResult; |
|||
import org.controlsfx.validation.ValidationSupport; |
|||
import org.controlsfx.validation.Validator; |
|||
import org.controlsfx.validation.decoration.StyleClassValidationDecoration; |
|||
|
|||
public class WalletNameDialog extends Dialog<String> { |
|||
private final CustomTextField name; |
|||
|
|||
public WalletNameDialog() { |
|||
this.name = (CustomTextField)TextFields.createClearableTextField(); |
|||
final DialogPane dialogPane = getDialogPane(); |
|||
|
|||
setTitle("Wallet Password"); |
|||
dialogPane.setHeaderText("Enter a name for this wallet:"); |
|||
dialogPane.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm()); |
|||
dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); |
|||
dialogPane.setPrefWidth(380); |
|||
dialogPane.setPrefHeight(200); |
|||
|
|||
Glyph wallet = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.WALLET); |
|||
wallet.setFontSize(50); |
|||
dialogPane.setGraphic(wallet); |
|||
|
|||
final VBox content = new VBox(10); |
|||
content.getChildren().add(name); |
|||
|
|||
dialogPane.setContent(content); |
|||
|
|||
ValidationSupport validationSupport = new ValidationSupport(); |
|||
Platform.runLater( () -> { |
|||
validationSupport.registerValidator(name, Validator.combine( |
|||
Validator.createEmptyValidator("Wallet name is required"), |
|||
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Wallet name is not unique", Storage.getStorage().getWalletFile(newValue).exists()) |
|||
)); |
|||
validationSupport.setValidationDecorator(new StyleClassValidationDecoration()); |
|||
}); |
|||
|
|||
final ButtonType okButtonType = new javafx.scene.control.ButtonType("New Wallet", ButtonBar.ButtonData.OK_DONE); |
|||
dialogPane.getButtonTypes().addAll(okButtonType); |
|||
Button okButton = (Button) dialogPane.lookupButton(okButtonType); |
|||
BooleanBinding isInvalid = Bindings.createBooleanBinding(() -> |
|||
name.getText().length() == 0 || Storage.getStorage().getWalletFile(name.getText()).exists(), name.textProperty()); |
|||
okButton.disableProperty().bind(isInvalid); |
|||
|
|||
name.setPromptText("Wallet Name"); |
|||
setResultConverter(dialogButton -> dialogButton == okButtonType ? name.getText() : null); |
|||
} |
|||
} |
@ -0,0 +1,99 @@ |
|||
package com.sparrowwallet.sparrow.control; |
|||
|
|||
import com.sparrowwallet.sparrow.AppController; |
|||
import javafx.application.Platform; |
|||
import javafx.beans.binding.Bindings; |
|||
import javafx.beans.binding.BooleanBinding; |
|||
import javafx.scene.control.*; |
|||
import javafx.scene.layout.VBox; |
|||
import org.controlsfx.control.textfield.CustomPasswordField; |
|||
import org.controlsfx.control.textfield.TextFields; |
|||
import org.controlsfx.glyphfont.FontAwesome; |
|||
import org.controlsfx.glyphfont.Glyph; |
|||
import org.controlsfx.validation.ValidationResult; |
|||
import org.controlsfx.validation.ValidationSupport; |
|||
import org.controlsfx.validation.decoration.StyleClassValidationDecoration; |
|||
|
|||
public class WalletPasswordDialog extends Dialog<String> { |
|||
private final ButtonType okButtonType; |
|||
private final PasswordRequirement requirement; |
|||
private final CustomPasswordField password; |
|||
private final CustomPasswordField passwordConfirm; |
|||
|
|||
public WalletPasswordDialog(PasswordRequirement requirement) { |
|||
this.requirement = requirement; |
|||
this.password = (CustomPasswordField)TextFields.createClearablePasswordField(); |
|||
this.passwordConfirm = (CustomPasswordField)TextFields.createClearablePasswordField(); |
|||
|
|||
final DialogPane dialogPane = getDialogPane(); |
|||
setTitle("Wallet Password"); |
|||
dialogPane.setHeaderText(requirement.description); |
|||
dialogPane.getStylesheets().add(AppController.class.getResource("general.css").toExternalForm()); |
|||
dialogPane.getButtonTypes().addAll(ButtonType.CANCEL); |
|||
dialogPane.setPrefWidth(380); |
|||
dialogPane.setPrefHeight(250); |
|||
|
|||
Glyph lock = new Glyph("FontAwesome", FontAwesome.Glyph.LOCK); |
|||
lock.setFontSize(50); |
|||
dialogPane.setGraphic(lock); |
|||
|
|||
final VBox content = new VBox(10); |
|||
content.setPrefHeight(100); |
|||
content.getChildren().add(password); |
|||
content.getChildren().add(passwordConfirm); |
|||
|
|||
dialogPane.setContent(content); |
|||
|
|||
ValidationSupport validationSupport = new ValidationSupport(); |
|||
Platform.runLater( () -> { |
|||
validationSupport.registerValidator(passwordConfirm, (Control c, String newValue) -> ValidationResult.fromErrorIf(c, "Password confirmation does not match", !passwordConfirm.getText().equals(password.getText()))); |
|||
validationSupport.setValidationDecorator(new StyleClassValidationDecoration()); |
|||
}); |
|||
|
|||
okButtonType = new javafx.scene.control.ButtonType(requirement.okButtonText, ButtonBar.ButtonData.OK_DONE); |
|||
dialogPane.getButtonTypes().addAll(okButtonType); |
|||
Button okButton = (Button) dialogPane.lookupButton(okButtonType); |
|||
okButton.setPrefWidth(130); |
|||
BooleanBinding isInvalid = Bindings.createBooleanBinding(() -> passwordConfirm.isVisible() && !password.getText().equals(passwordConfirm.getText()), password.textProperty(), passwordConfirm.textProperty()); |
|||
okButton.disableProperty().bind(isInvalid); |
|||
|
|||
if(requirement != PasswordRequirement.UPDATE_NEW) { |
|||
passwordConfirm.setVisible(false); |
|||
passwordConfirm.setManaged(false); |
|||
} |
|||
|
|||
if(requirement == PasswordRequirement.UPDATE_NEW || requirement == PasswordRequirement.UPDATE_EMPTY) { |
|||
password.textProperty().addListener((observable, oldValue, newValue) -> { |
|||
if(newValue.isEmpty()) { |
|||
okButton.setText("No Password"); |
|||
passwordConfirm.setVisible(false); |
|||
passwordConfirm.setManaged(false); |
|||
} else { |
|||
okButton.setText("Set Password"); |
|||
passwordConfirm.setVisible(true); |
|||
passwordConfirm.setManaged(true); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
password.setPromptText("Password"); |
|||
passwordConfirm.setPromptText("Password Confirmation"); |
|||
|
|||
setResultConverter(dialogButton -> dialogButton == okButtonType ? password.getText() : null); |
|||
} |
|||
|
|||
public enum PasswordRequirement { |
|||
LOAD("Please enter the wallet password:", "Unlock"), |
|||
UPDATE_NEW("Add a password to the wallet?\nLeave empty for none:", "No Password"), |
|||
UPDATE_EMPTY("This wallet has no password.\nAdd a password to the wallet?\nLeave empty for none:", "No Password"), |
|||
UPDATE_SET("Please re-enter the wallet password:", "Verify Password"); |
|||
|
|||
private final String description; |
|||
private final String okButtonText; |
|||
|
|||
PasswordRequirement(String description, String okButtonText) { |
|||
this.description = description; |
|||
this.okButtonText = okButtonText; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,56 @@ |
|||
package com.sparrowwallet.sparrow.glyphfont; |
|||
|
|||
import org.controlsfx.glyphfont.FontAwesome; |
|||
import org.controlsfx.glyphfont.GlyphFont; |
|||
import org.controlsfx.glyphfont.GlyphFontRegistry; |
|||
import org.controlsfx.glyphfont.INamedCharacter; |
|||
|
|||
import java.io.InputStream; |
|||
import java.util.Arrays; |
|||
|
|||
public class FontAwesome5 extends GlyphFont { |
|||
public static String FONT_NAME = "Font Awesome 5 Free Solid"; |
|||
|
|||
/** |
|||
* The individual glyphs offered by the FontAwesome5 font. |
|||
*/ |
|||
public static enum Glyph implements INamedCharacter { |
|||
WALLET('\uf555'); |
|||
|
|||
private final char ch; |
|||
|
|||
/** |
|||
* Creates a named Glyph mapped to the given character |
|||
* @param ch |
|||
*/ |
|||
Glyph( char ch ) { |
|||
this.ch = ch; |
|||
} |
|||
|
|||
@Override |
|||
public char getChar() { |
|||
return ch; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Do not call this constructor directly - instead access the |
|||
* {@link FontAwesome5.Glyph} public static enumeration method to create the glyph nodes), or |
|||
* use the {@link GlyphFontRegistry} class to get access. |
|||
* |
|||
* Note: Do not remove this public constructor since it is used by the service loader! |
|||
*/ |
|||
public FontAwesome5() { |
|||
this(FontAwesome5.class.getResourceAsStream("/font/fa-solid-900.ttf")); |
|||
} |
|||
|
|||
/** |
|||
* Creates a new FontAwesome instance which uses the provided font source. |
|||
* @param is |
|||
*/ |
|||
public FontAwesome5(InputStream is){ |
|||
super(FONT_NAME, 14, is, true); |
|||
registerAll(Arrays.asList(FontAwesome.Glyph.values())); |
|||
registerAll(Arrays.asList(FontAwesome5.Glyph.values())); |
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue