From 828a2fdb620354bd0b3c6b3c3e296542214281ae Mon Sep 17 00:00:00 2001 From: octopus_yan Date: Sat, 21 Sep 2024 12:46:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8B=E6=8B=89=E6=A1=86=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E8=AF=AD=E8=A8=80=E5=88=87=E6=8D=A2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alistgui/controller/SetupController.java | 12 ++++++++++ .../octopusyan/alistgui/enums/ProxySetup.java | 7 +++++- .../alistgui/view/ProxySetupCell.java | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java diff --git a/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java b/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java index b2b58bc..5e2f529 100644 --- a/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java +++ b/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java @@ -6,6 +6,7 @@ import cn.octopusyan.alistgui.config.Context; import cn.octopusyan.alistgui.config.I18n; import cn.octopusyan.alistgui.enums.ProxySetup; import cn.octopusyan.alistgui.manager.ConfigManager; +import cn.octopusyan.alistgui.view.ProxySetupCell; import cn.octopusyan.alistgui.viewModel.SetupViewModel; import javafx.collections.FXCollections; import javafx.fxml.FXML; @@ -60,6 +61,9 @@ public class SetupController extends BaseController implements I themeComboBox.setItems(FXCollections.observableList(ConfigManager.THEME_LIST)); proxySetupComboBox.setItems(FXCollections.observableList(List.of(ProxySetup.values()))); + proxySetupComboBox.setCellFactory(_ -> new ProxySetupCell()); + proxySetupComboBox.setButtonCell(new ProxySetupCell()); + themeComboBox.setConverter(new StringConverter<>() { @Override public String toString(Theme object) { @@ -78,6 +82,14 @@ public class SetupController extends BaseController implements I proxySetupComboBox.getSelectionModel().selectedItemProperty().addListener((_, _, newValue) -> { proxySetupPane.setVisible(ProxySetup.MANUAL.equals(newValue)); proxyCheck.setVisible(!ProxySetup.NO_PROXY.equals(newValue)); + +// proxySetupComboBox.promptTextProperty().bind( +//// Bindings.createStringBinding( +//// () -> Context.getLanguageBinding(STR."proxy.setup.label.\{newValue.getName()}").get(), +//// Context.currentLocaleProperty() +//// ) +// Context.getLanguageBinding(STR."proxy.setup.label.\{newValue.getName()}") +// ); }); languageComboBox.getSelectionModel().select(ConfigManager.language()); diff --git a/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java b/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java index d0e119a..5ec896b 100644 --- a/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java +++ b/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java @@ -1,6 +1,7 @@ package cn.octopusyan.alistgui.enums; import cn.octopusyan.alistgui.config.Context; +import javafx.beans.binding.StringBinding; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -20,6 +21,10 @@ public enum ProxySetup { @Override public String toString() { - return Context.getLanguageBinding("proxy.setup.label." + getName()).getValue(); + return getBinding().get(); + } + + public StringBinding getBinding() { + return Context.getLanguageBinding(STR."proxy.setup.label.\{getName()}"); } } diff --git a/src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java b/src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java new file mode 100644 index 0000000..b15c26f --- /dev/null +++ b/src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java @@ -0,0 +1,23 @@ +package cn.octopusyan.alistgui.view; + +import cn.octopusyan.alistgui.enums.ProxySetup; +import javafx.scene.control.ListCell; + +/** + * ProxySetup I18n Cell + * + * @author octopus_yan + */ +public class ProxySetupCell extends ListCell { + + @Override + protected void updateItem(ProxySetup item, boolean empty) { + super.updateItem(item, empty); + textProperty().unbind(); + if (empty || item == null) { + setText(""); + } else { + textProperty().bind(item.getBinding()); + } + } +}