From c17731e3dd1faa907a0c4c5d9fbaef80d1c11e48 Mon Sep 17 00:00:00 2001 From: leewyatt Date: Mon, 15 Apr 2024 21:22:56 +0900 Subject: [PATCH] updated maskText method --- .../skins/EnhancedPasswordFieldSkin.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java index 4bd032a0..32a8f500 100644 --- a/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java +++ b/gemsfx/src/main/java/com/dlsc/gemsfx/skins/EnhancedPasswordFieldSkin.java @@ -3,6 +3,7 @@ import com.dlsc.gemsfx.EnhancedPasswordField; import javafx.beans.binding.StringBinding; import javafx.scene.Node; +import javafx.scene.control.TextField; import javafx.scene.text.Text; import java.util.Optional; @@ -10,11 +11,8 @@ public abstract class EnhancedPasswordFieldSkin extends CustomTextFieldSkin { - private final EnhancedPasswordField control; - public EnhancedPasswordFieldSkin(EnhancedPasswordField control) { super(control); - this.control = control; // find the text nodes Set nodes = control.lookupAll(".text"); @@ -43,12 +41,23 @@ protected String computeValue() { @Override protected String maskText(String txt) { - if (control == null || !control.isShowPassword()) { - int n = txt.length(); - char echoChar = control != null ? control.getEchoCharSafe() : EnhancedPasswordField.DEFAULT_ECHO_CHAR; - return String.valueOf(echoChar).repeat(n); + TextField skinnable = getSkinnable(); + int len = txt.length(); + if (skinnable == null) { + return getDefaultMaskText(len); + } + + if (skinnable instanceof EnhancedPasswordField passwordField) { + if (passwordField.isShowPassword()) { + return txt; + } + return String.valueOf(passwordField.getEchoCharSafe()).repeat(len); } - return txt; + return getDefaultMaskText(len); + } + + private String getDefaultMaskText(int len) { + return String.valueOf(EnhancedPasswordField.DEFAULT_ECHO_CHAR).repeat(len); } } \ No newline at end of file