From ea654441eccce400185ad4a54306b85daa4c363f Mon Sep 17 00:00:00 2001 From: itorod Date: Sat, 23 Mar 2024 00:50:12 +0000 Subject: [PATCH 1/9] changed helpLabel code to errorLabel code for error validation --- .../controls/MaterialTextField.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index 23ff2a8f0c..fe24b965cb 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -56,6 +56,10 @@ public class MaterialTextField extends Pane { protected final TextInputControl textInputControl; @Getter protected final Label helpLabel = new Label(); + + @Getter + protected final Label errorLabel = new Label(); + @Getter private final BisqIconButton iconButton = new BisqIconButton(); private ChangeListener iconButtonHeightListener; @@ -118,7 +122,14 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, helpLabel.setText(help); } - getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel); + errorLabel.setLayoutX(16); + errorLabel.getStyleClass().add("material-text-field-help"); + errorLabel.setMouseTransparent(true); + if (StringUtils.isNotEmpty(help)) { + errorLabel.setText(help); + } + + getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel,errorLabel); widthProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> onWidthChanged((double) newValue)).get()); @@ -181,12 +192,12 @@ public boolean validate() { selectionLine.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, !isValid.get()); descriptionLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, !isValid.get()); getActiveValidator().ifPresentOrElse(validator -> { - helpLabel.setText(validator.getMessage()); - helpLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, true); + errorLabel.setText(validator.getMessage()); + errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, true); }, () -> { - helpLabel.setText(""); - helpLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); + errorLabel.setText(""); + errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); }); return isValid.get(); } @@ -196,8 +207,8 @@ public void resetValidation() { isValid.set(false); selectionLine.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); descriptionLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); - helpLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); - helpLabel.setText(""); + errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); + errorLabel.setText(""); } private final BooleanProperty isValid = new SimpleBooleanProperty(); @@ -432,6 +443,7 @@ protected void doLayout() { selectionLine.setLayoutY(getBgHeight() - 2); textInputControl.setLayoutY(getFieldLayoutY()); helpLabel.setLayoutY(getBgHeight() + 3.5); + errorLabel.setLayoutY(getBgHeight() + 3.5); } private void layoutIconButton() { @@ -465,6 +477,7 @@ void update() { Transitions.animateLayoutY(descriptionLabel, 16.5, Transitions.DEFAULT_DURATION / 6d, null); } } + helpLabel.setVisible(StringUtils.isNotEmpty(helpProperty().get())); helpLabel.setManaged(StringUtils.isNotEmpty(helpProperty().get())); From a79e8e0cfeb01c3b6f4f3e9b80d41a1c36ab1bca Mon Sep 17 00:00:00 2001 From: itorod Date: Sat, 23 Mar 2024 09:46:56 +0000 Subject: [PATCH 2/9] made helplabel invisible when error label shows --- .../components/controls/MaterialTextField.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index fe24b965cb..a598f55906 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -125,9 +125,9 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, errorLabel.setLayoutX(16); errorLabel.getStyleClass().add("material-text-field-help"); errorLabel.setMouseTransparent(true); - if (StringUtils.isNotEmpty(help)) { - errorLabel.setText(help); - } +// if (StringUtils.isNotEmpty(help)) { +// errorLabel.setText(help); +// } getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel,errorLabel); @@ -186,7 +186,7 @@ public void setValidators(ValidatorBase... validators) { validationControl.setValidators(validators); } - // TODO add custom errorLabel and not reuse helpLabel as it would cause an exception when binding at the helpLabel is used + public boolean validate() { isValid.set(validationControl.validate()); selectionLine.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, !isValid.get()); @@ -194,10 +194,14 @@ public boolean validate() { getActiveValidator().ifPresentOrElse(validator -> { errorLabel.setText(validator.getMessage()); errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, true); + helpLabel.setOpacity(0); + helpLabel.setDisable(true); }, () -> { errorLabel.setText(""); errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); + helpLabel.setOpacity(1); + helpLabel.setDisable(false); }); return isValid.get(); } @@ -417,6 +421,7 @@ protected void onWidthChanged(double width) { double iconWidth = iconButton.isVisible() ? 25 : 0; textInputControl.setPrefWidth(width - 2 * textInputControl.getLayoutX() - iconWidth); helpLabel.setPrefWidth(width - 2 * helpLabel.getLayoutX()); + errorLabel.setPrefWidth(width - 2 * errorLabel.getLayoutX()); } } From 7788f318e3871fac3daf415c93b31619ad61e42a Mon Sep 17 00:00:00 2001 From: itorod Date: Sat, 23 Mar 2024 09:56:43 +0000 Subject: [PATCH 3/9] removed commented code. Setting errorlabel to help is unecessary --- .../bisq/desktop/components/controls/MaterialTextField.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index a598f55906..83ad9e17ce 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -56,10 +56,8 @@ public class MaterialTextField extends Pane { protected final TextInputControl textInputControl; @Getter protected final Label helpLabel = new Label(); - @Getter protected final Label errorLabel = new Label(); - @Getter private final BisqIconButton iconButton = new BisqIconButton(); private ChangeListener iconButtonHeightListener; @@ -125,9 +123,6 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, errorLabel.setLayoutX(16); errorLabel.getStyleClass().add("material-text-field-help"); errorLabel.setMouseTransparent(true); -// if (StringUtils.isNotEmpty(help)) { -// errorLabel.setText(help); -// } getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel,errorLabel); @@ -186,7 +181,6 @@ public void setValidators(ValidatorBase... validators) { validationControl.setValidators(validators); } - public boolean validate() { isValid.set(validationControl.validate()); selectionLine.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, !isValid.get()); From d4c4d368266f16fbddc2dda49ea997d3404fab4a Mon Sep 17 00:00:00 2001 From: itorod Date: Sun, 24 Mar 2024 13:25:18 +0000 Subject: [PATCH 4/9] changed spacing of vbox to accomodate error message --- .../main/content/settings/preferences/PreferencesView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java index faf484e889..aa0ebaecd6 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java @@ -206,7 +206,7 @@ public String fromString(String string) { difficultyAdjustmentFactor.setValidators(DIFFICULTY_ADJUSTMENT_FACTOR_VALIDATOR); ignoreDiffAdjustFromSecManagerSwitch = new Switch(Res.get("settings.preferences.network.ignoreDifficultyAdjustmentFactorFromSecManager")); - VBox networkVBox = new VBox(10, difficultyAdjustmentFactor, ignoreDiffAdjustFromSecManagerSwitch); + VBox networkVBox = new VBox(20, difficultyAdjustmentFactor, ignoreDiffAdjustFromSecManagerSwitch); Insets insets = new Insets(0, 5, 0, 5); From 5b08aa294ec7c2d4c64183fce13407c134ee719f Mon Sep 17 00:00:00 2001 From: itorod Date: Fri, 29 Mar 2024 16:02:38 +0000 Subject: [PATCH 5/9] removed setopacity and used setmanage instead. Made height to be calculated automatically for error text --- .../controls/MaterialTextField.java | 35 ++++++++++++++++--- .../settings/preferences/PreferencesView.java | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index 83ad9e17ce..02ec92ac61 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -62,6 +62,8 @@ public class MaterialTextField extends Pane { private final BisqIconButton iconButton = new BisqIconButton(); private ChangeListener iconButtonHeightListener; + private String globalHelpText = ""; + public MaterialTextField() { this(null, null, null); } @@ -118,6 +120,7 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, helpLabel.setMouseTransparent(true); if (StringUtils.isNotEmpty(help)) { helpLabel.setText(help); + globalHelpText = help; } errorLabel.setLayoutX(16); @@ -134,6 +137,8 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, descriptionLabel.textProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> update()).get()); +// errorProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> +// update()).get()); promptTextProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> update()).get()); helpProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> @@ -188,14 +193,16 @@ public boolean validate() { getActiveValidator().ifPresentOrElse(validator -> { errorLabel.setText(validator.getMessage()); errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, true); - helpLabel.setOpacity(0); - helpLabel.setDisable(true); + helpLabel.setManaged(false); + helpLabel.setVisible(false); + helpLabel.setText(""); }, () -> { errorLabel.setText(""); errorLabel.pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false); - helpLabel.setOpacity(1); - helpLabel.setDisable(false); + helpLabel.setManaged(true); + helpLabel.setVisible(true); + helpLabel.setText(globalHelpText); }); return isValid.get(); } @@ -303,6 +310,22 @@ public final StringProperty helpProperty() { return helpLabel.textProperty(); } + /////////////////////////////////////////////////////////////////////////////////////////////////// + // Error + /////////////////////////////////////////////////////////////////////////////////////////////////// + + public String getErrorText() { + return errorLabel.getText(); + } + + public void setErrorText(String value) { + errorLabel.setText(value); + } + + public final StringProperty errorProperty() { + return errorLabel.textProperty(); + } + /////////////////////////////////////////////////////////////////////////////////////////////////// // Icon @@ -541,7 +564,9 @@ protected double getFieldLayoutY() { protected double computeMinHeight(double width) { if (helpLabel.isManaged()) { return helpLabel.getLayoutY() + helpLabel.getHeight(); - } else { + } else if(errorLabel.isManaged()){ + return errorLabel.getLayoutY() + errorLabel.getHeight(); + }else{ return getBgHeight(); } } diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java index aa0ebaecd6..faf484e889 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/main/content/settings/preferences/PreferencesView.java @@ -206,7 +206,7 @@ public String fromString(String string) { difficultyAdjustmentFactor.setValidators(DIFFICULTY_ADJUSTMENT_FACTOR_VALIDATOR); ignoreDiffAdjustFromSecManagerSwitch = new Switch(Res.get("settings.preferences.network.ignoreDifficultyAdjustmentFactorFromSecManager")); - VBox networkVBox = new VBox(20, difficultyAdjustmentFactor, ignoreDiffAdjustFromSecManagerSwitch); + VBox networkVBox = new VBox(10, difficultyAdjustmentFactor, ignoreDiffAdjustFromSecManagerSwitch); Insets insets = new Insets(0, 5, 0, 5); From 0976cf07f09194b595dcf0e97e1477b314964c0a Mon Sep 17 00:00:00 2001 From: itorod Date: Fri, 29 Mar 2024 16:05:38 +0000 Subject: [PATCH 6/9] removed unecessary commented code --- .../bisq/desktop/components/controls/MaterialTextField.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index 02ec92ac61..65a8fce0d2 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -61,7 +61,6 @@ public class MaterialTextField extends Pane { @Getter private final BisqIconButton iconButton = new BisqIconButton(); private ChangeListener iconButtonHeightListener; - private String globalHelpText = ""; public MaterialTextField() { @@ -136,9 +135,6 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, onInputTextFieldFocus(newValue)).get()); descriptionLabel.textProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> update()).get()); - -// errorProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> -// update()).get()); promptTextProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> update()).get()); helpProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> From 9a3a3d68fc0a4a53b1788875f433754298ddd13c Mon Sep 17 00:00:00 2001 From: itorod Date: Sat, 30 Mar 2024 09:04:31 +0000 Subject: [PATCH 7/9] enabled reformat code --- .../bisq/desktop/components/controls/MaterialTextField.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index 65a8fce0d2..1831784465 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -126,7 +126,7 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, errorLabel.getStyleClass().add("material-text-field-help"); errorLabel.setMouseTransparent(true); - getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel,errorLabel); + getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel, errorLabel); widthProperty().addListener(new WeakReference>((observable, oldValue, newValue) -> onWidthChanged((double) newValue)).get()); @@ -560,9 +560,9 @@ protected double getFieldLayoutY() { protected double computeMinHeight(double width) { if (helpLabel.isManaged()) { return helpLabel.getLayoutY() + helpLabel.getHeight(); - } else if(errorLabel.isManaged()){ + } else if (errorLabel.isManaged()) { return errorLabel.getLayoutY() + errorLabel.getHeight(); - }else{ + } else { return getBgHeight(); } } From ce6d33e86232222ca30f25dc54be14f61ddecba9 Mon Sep 17 00:00:00 2001 From: itorod Date: Mon, 1 Apr 2024 11:10:48 +0000 Subject: [PATCH 8/9] added code to make height go back to original position after resize --- .../components/controls/MaterialTextField.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index 1831784465..76f781b345 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -123,7 +123,6 @@ public MaterialTextField(@Nullable String description, @Nullable String prompt, } errorLabel.setLayoutX(16); - errorLabel.getStyleClass().add("material-text-field-help"); errorLabel.setMouseTransparent(true); getChildren().addAll(bg, line, selectionLine, descriptionLabel, textInputControl, iconButton, helpLabel, errorLabel); @@ -508,6 +507,15 @@ void update() { descriptionLabel.getStyleClass().remove("material-text-field-description-deselected"); descriptionLabel.getStyleClass().remove("material-text-field-description-read-only"); + if (showErrorLabel()) { + errorLabel.getStyleClass().add("material-text-field-help"); + errorLabel.setVisible(true); + errorLabel.setManaged(true); + } else { + errorLabel.setVisible(false); + errorLabel.setManaged(false); + } + if (showInputTextField()) { descriptionLabel.getStyleClass().add("material-text-field-description-small"); } else { @@ -548,6 +556,10 @@ protected boolean showInputTextField() { textInputControl.isFocused(); } + protected boolean showErrorLabel() { + return StringUtils.isNotEmpty(errorProperty().get()); + } + protected double getBgHeight() { return 56; } From 04951f885a58d48ab65a9ab438b94525914273bf Mon Sep 17 00:00:00 2001 From: itorod Date: Mon, 1 Apr 2024 19:29:51 +0000 Subject: [PATCH 9/9] Check that error style does not exist before you set error style --- .../bisq/desktop/components/controls/MaterialTextField.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java index 76f781b345..0844691879 100644 --- a/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java +++ b/apps/desktop/desktop/src/main/java/bisq/desktop/components/controls/MaterialTextField.java @@ -508,7 +508,8 @@ void update() { descriptionLabel.getStyleClass().remove("material-text-field-description-read-only"); if (showErrorLabel()) { - errorLabel.getStyleClass().add("material-text-field-help"); + if (!errorLabel.getStyleClass().contains("material-text-field-help")) + errorLabel.getStyleClass().add("material-text-field-help"); errorLabel.setVisible(true); errorLabel.setManaged(true); } else {