diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java new file mode 100644 index 0000000000..8473c6e7e3 --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/JFXCheckBoxTableCell.java @@ -0,0 +1,68 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2025 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.construct; + +import com.jfoenix.controls.JFXCheckBox; +import javafx.beans.binding.Bindings; +import javafx.beans.property.BooleanProperty; +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.util.Callback; + +/// @author Glavo +public final class JFXCheckBoxTableCell extends TableCell { + public static Callback, TableCell> forTableColumn( + final TableColumn column) { + return list -> new JFXCheckBoxTableCell<>(); + } + + private final JFXCheckBox checkBox = new JFXCheckBox(); + private BooleanProperty booleanProperty; + + public JFXCheckBoxTableCell() { + this.getStyleClass().add("jfx-checkbox-table-cell"); + } + + @Override + protected void updateItem(T item, boolean empty) { + super.updateItem(item, empty); + + if (empty) { + setText(null); + setGraphic(null); + checkBox.disableProperty().unbind(); + } else { + setGraphic(checkBox); + + if (booleanProperty != null) { + checkBox.selectedProperty().unbindBidirectional(booleanProperty); + } + if (getTableColumn().getCellObservableValue(getIndex()) instanceof BooleanProperty obsValue) { + booleanProperty = obsValue; + checkBox.selectedProperty().bindBidirectional(booleanProperty); + } + + checkBox.disableProperty().bind(Bindings.not( + getTableView().editableProperty().and( + getTableColumn().editableProperty()).and( + editableProperty()) + )); + } + } + +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java index e3f253e169..00be5bf699 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java @@ -18,16 +18,15 @@ package org.jackhuang.hmcl.ui.versions; import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXCheckBox; import javafx.beans.property.*; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; -import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; -import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import org.jackhuang.hmcl.mod.LocalModFile; @@ -38,6 +37,7 @@ import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.construct.JFXCheckBoxTableCell; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.PageCloseEvent; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; @@ -72,9 +72,10 @@ public ModUpdatesPage(ModManager modManager, List update getStyleClass().add("gray-background"); TableColumn enabledColumn = new TableColumn<>(); - CheckBox allEnabledBox = new CheckBox(); + var allEnabledBox = new JFXCheckBox(); + enabledColumn.setStyle("-fx-alignment: CENTER;"); enabledColumn.setGraphic(allEnabledBox); - enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn)); + enabledColumn.setCellFactory(JFXCheckBoxTableCell.forTableColumn(enabledColumn)); setupCellValueFactory(enabledColumn, ModUpdateObject::enabledProperty); enabledColumn.setEditable(true); enabledColumn.setMaxWidth(40); diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index 7d7c06e7d1..2bb6cf1731 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -813,6 +813,10 @@ -jfx-unchecked-color: transparent; } +.table-view .jfx-check-box .jfx-rippler { + -jfx-rippler-disabled: true; +} + /******************************************************************************* * * * JFX Progress Bar *