From c1596443f5178a389e12649de0814019b3244700 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sun, 11 Apr 2021 22:50:09 +0800 Subject: [PATCH] fix: crash --- .../java/org/jackhuang/hmcl/ui/LogWindow.java | 2 +- .../hmcl/ui/construct/RequiredValidator.java | 29 +++++++++++++++++++ .../hmcl/ui/export/ModpackInfoPage.java | 19 ++++-------- .../resources/assets/fxml/account-add.fxml | 8 +++-- 4 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/RequiredValidator.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java index bbd362f2f..7b1c450bc 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java @@ -198,7 +198,7 @@ public final class LogWindow extends Stage { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(logFile.toFile()); - } catch (IOException ignored) { + } catch (IOException | IllegalArgumentException ignored) { } } }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/RequiredValidator.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/RequiredValidator.java new file mode 100644 index 000000000..f7f4642ec --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/RequiredValidator.java @@ -0,0 +1,29 @@ +package org.jackhuang.hmcl.ui.construct; + +import com.jfoenix.validation.base.ValidatorBase; +import javafx.beans.NamedArg; +import javafx.scene.control.TextInputControl; +import org.jackhuang.hmcl.util.StringUtils; + +public class RequiredValidator extends ValidatorBase { + + public RequiredValidator() { + } + + public RequiredValidator(@NamedArg("message") String message) { + super(message); + } + + @Override + protected void eval() { + if (srcControl.get() instanceof TextInputControl) { + evalTextInputField(); + } + } + + private void evalTextInputField() { + TextInputControl textField = ((TextInputControl) srcControl.get()); + + hasErrors.set(StringUtils.isBlank(textField.getText())); + } +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java index 5cc6de38d..08918d0fe 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java @@ -18,7 +18,6 @@ package org.jackhuang.hmcl.ui.export; import com.jfoenix.controls.*; -import com.jfoenix.validation.RequiredFieldValidator; import javafx.beans.binding.Bindings; import javafx.beans.property.*; import javafx.collections.ObservableList; @@ -44,10 +43,7 @@ import org.jackhuang.hmcl.setting.Accounts; import org.jackhuang.hmcl.setting.VersionSetting; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; -import org.jackhuang.hmcl.ui.construct.ComponentList; -import org.jackhuang.hmcl.ui.construct.NumberValidator; -import org.jackhuang.hmcl.ui.construct.TwoLineListItem; -import org.jackhuang.hmcl.ui.construct.Validator; +import org.jackhuang.hmcl.ui.construct.*; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardPage; import org.jackhuang.hmcl.util.StringUtils; @@ -218,9 +214,7 @@ public final class ModpackInfoPage extends Control implements WizardPage { txtModpackName.textProperty().bindBidirectional(skinnable.name); txtModpackName.setLabelFloat(true); txtModpackName.setPromptText(i18n("modpack.name")); - RequiredFieldValidator validator = new RequiredFieldValidator(); - validator.setMessage(i18n("modpack.not_a_valid_name")); - txtModpackName.getValidators().add(validator); + txtModpackName.getValidators().add(new RequiredValidator(i18n("modpack.not_a_valid_name"))); StackPane.setMargin(txtModpackName, insets); list.getContent().add(txtModpackName); @@ -234,8 +228,7 @@ public final class ModpackInfoPage extends Control implements WizardPage { txtModpackFileApi.setPromptText(i18n("modpack.file_api")); if (skinnable.options.isValidateFileApi()) { - RequiredFieldValidator validator = new RequiredFieldValidator(); - txtModpackFileApi.getValidators().add(validator); + txtModpackFileApi.getValidators().add(new RequiredValidator()); } txtModpackFileApi.getValidators().add(new Validator(s -> { @@ -260,8 +253,7 @@ public final class ModpackInfoPage extends Control implements WizardPage { txtModpackAuthor.textProperty().bindBidirectional(skinnable.author); txtModpackAuthor.setLabelFloat(true); txtModpackAuthor.setPromptText(i18n("archive.author")); - RequiredFieldValidator validator = new RequiredFieldValidator(); - txtModpackAuthor.getValidators().add(validator); + txtModpackAuthor.getValidators().add(new RequiredValidator()); StackPane.setMargin(txtModpackAuthor, insets); list.getContent().add(txtModpackAuthor); @@ -273,8 +265,7 @@ public final class ModpackInfoPage extends Control implements WizardPage { txtModpackVersion.textProperty().bindBidirectional(skinnable.version); txtModpackVersion.setLabelFloat(true); txtModpackVersion.setPromptText(i18n("archive.version")); - RequiredFieldValidator validator = new RequiredFieldValidator(); - txtModpackVersion.getValidators().add(validator); + txtModpackVersion.getValidators().add(new RequiredValidator()); StackPane.setMargin(txtModpackVersion, insets); list.getContent().add(txtModpackVersion); diff --git a/HMCL/src/main/resources/assets/fxml/account-add.fxml b/HMCL/src/main/resources/assets/fxml/account-add.fxml index c274631a3..39344564a 100644 --- a/HMCL/src/main/resources/assets/fxml/account-add.fxml +++ b/HMCL/src/main/resources/assets/fxml/account-add.fxml @@ -4,8 +4,10 @@ - + + + @@ -50,8 +52,8 @@ - - + +