diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index 85a454c37..f555d7f83 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -48,6 +48,7 @@ import org.jackhuang.hmcl.util.*; import org.jackhuang.hmcl.util.i18n.I18n; import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.javafx.ExtendedProperties; +import org.jackhuang.hmcl.util.javafx.SafeStringConverter; import org.jackhuang.hmcl.util.platform.OperatingSystem; import java.io.File; @@ -331,7 +332,7 @@ public final class FXUtils { } public static void bindInt(JFXTextField textField, Property property) { - textField.textProperty().bindBidirectional(property, SafeIntStringConverter.INSTANCE); + textField.textProperty().bindBidirectional(property, SafeStringConverter.fromInteger()); } public static void unbindInt(JFXTextField textField, Property property) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SafeIntStringConverter.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SafeIntStringConverter.java deleted file mode 100644 index dfe9af4d6..000000000 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SafeIntStringConverter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2019 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.ui; - -import javafx.util.StringConverter; -import org.jackhuang.hmcl.util.Lang; - -import java.util.Optional; - -/** - * @author huangyuhui - */ -public final class SafeIntStringConverter extends StringConverter { - public static final SafeIntStringConverter INSTANCE = new SafeIntStringConverter(); - - private SafeIntStringConverter() { - } - - @Override - public Number fromString(String string) { - return Optional.ofNullable(string).map(Lang::toIntOrNull).orElse(null); - } - - @Override - public String toString(Number object) { - return Optional.ofNullable(object).map(Object::toString).orElse(""); - } -}