From c13b5e15d40ff87a4c604b4918a2373dde0457ec Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 24 Dec 2025 00:41:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20JFXListViewSkin=20?= =?UTF-8?q?=E5=A4=A7=E9=87=8F=E8=A7=A6=E5=8F=91=20ListCell#updateItem=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#5056)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jfoenix/skins/JFXListViewSkin.java | 44 ------------------- .../java/org/jackhuang/hmcl/ui/FXUtils.java | 6 --- .../java/org/jackhuang/hmcl/ui/LogWindow.java | 9 +--- .../hmcl/ui/construct/MDListCell.java | 12 +---- .../hmcl/ui/construct/TaskListPane.java | 7 --- .../hmcl/ui/download/VersionsPage.java | 14 +----- .../jackhuang/hmcl/ui/nbt/NBTTreeView.java | 7 --- .../ui/versions/DatapackListPageSkin.java | 8 ++-- .../hmcl/ui/versions/ModListPageSkin.java | 7 ++- .../ui/versions/ResourcepackListPage.java | 8 ++-- 10 files changed, 13 insertions(+), 109 deletions(-) diff --git a/HMCL/src/main/java/com/jfoenix/skins/JFXListViewSkin.java b/HMCL/src/main/java/com/jfoenix/skins/JFXListViewSkin.java index c6523a133..db317fe62 100644 --- a/HMCL/src/main/java/com/jfoenix/skins/JFXListViewSkin.java +++ b/HMCL/src/main/java/com/jfoenix/skins/JFXListViewSkin.java @@ -25,7 +25,6 @@ import com.jfoenix.controls.JFXListView; import com.jfoenix.effects.JFXDepthManager; import javafx.scene.control.ListCell; import javafx.scene.control.skin.VirtualFlow; -import javafx.scene.layout.Region; import org.jackhuang.hmcl.ui.FXUtils; // https://github.com/HMCL-dev/HMCL/issues/4720 @@ -50,47 +49,4 @@ public class JFXListViewSkin extends ListViewSkin { return 200; } - @Override - protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { - final int itemsCount = getSkinnable().getItems().size(); - if (getSkinnable().maxHeightProperty().isBound() || itemsCount <= 0) { - return super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); - } - - final double fixedCellSize = getSkinnable().getFixedCellSize(); - double computedHeight = fixedCellSize != Region.USE_COMPUTED_SIZE ? - fixedCellSize * itemsCount + snapVerticalInsets() : estimateHeight(); - double height = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset); - if (height > computedHeight) { - height = computedHeight; - } - - if (getSkinnable().getMaxHeight() > 0 && computedHeight > getSkinnable().getMaxHeight()) { - return getSkinnable().getMaxHeight(); - } - - return height; - } - - private double estimateHeight() { - // compute the border/padding for the list - double borderWidth = snapVerticalInsets(); - // compute the gap between list cells - - JFXListView listview = (JFXListView) getSkinnable(); - double gap = listview.isExpanded() ? ((JFXListView) getSkinnable()).getVerticalGap() * (getSkinnable().getItems() - .size()) : 0; - // compute the height of each list cell - double cellsHeight = 0; - for (int i = 0; i < flow.getCellCount(); i++) { - ListCell cell = flow.getCell(i); - cellsHeight += cell.getHeight(); - } - return cellsHeight + gap + borderWidth; - } - - private double snapVerticalInsets() { - return getSkinnable().snappedBottomInset() + getSkinnable().snappedTopInset(); - } - } 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 c7621d137..84e667ce9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -1309,17 +1309,11 @@ public final class FXUtils { } public static Callback, ListCell> jfxListCellFactory(Function graphicBuilder) { - Holder lastCell = new Holder<>(); return view -> new JFXListCell() { @Override public void updateItem(T item, boolean empty) { super.updateItem(item, empty); - // https://mail.openjdk.org/pipermail/openjfx-dev/2022-July/034764.html - if (this == lastCell.value && !isVisible()) - return; - lastCell.value = this; - if (!empty) { setContentDisplay(ContentDisplay.GRAPHIC_ONLY); setGraphic(graphicBuilder.apply(item)); 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 275d5d7de..f5c71de7a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java @@ -46,7 +46,6 @@ import org.jackhuang.hmcl.setting.StyleSheets; import org.jackhuang.hmcl.theme.Themes; import org.jackhuang.hmcl.ui.construct.NoneMultipleSelectionModel; import org.jackhuang.hmcl.ui.construct.SpinnerPane; -import org.jackhuang.hmcl.util.Holder; import org.jackhuang.hmcl.util.CircularArrayList; import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.Log4jLevel; @@ -344,8 +343,7 @@ public final class LogWindow extends Stage { listView.setStyle("-fx-font-family: \"" + Lang.requireNonNullElse(config().getFontFamily(), FXUtils.DEFAULT_MONOSPACE_FONT) + "\"; -fx-font-size: " + config().getFontSize() + "px;"); - Holder lastCell = new Holder<>(); - listView.setCellFactory(x -> new ListCell() { + listView.setCellFactory(x -> new ListCell<>() { { x.setSelectionModel(new NoneMultipleSelectionModel<>()); getStyleClass().add("log-window-list-cell"); @@ -389,11 +387,6 @@ public final class LogWindow extends Stage { protected void updateItem(Log item, boolean empty) { super.updateItem(item, empty); - // https://mail.openjdk.org/pipermail/openjfx-dev/2022-July/034764.html - if (this == lastCell.value && !isVisible()) - return; - lastCell.value = this; - pseudoClassStateChanged(EMPTY, empty); pseudoClassStateChanged(FATAL, !empty && item.getLevel() == Log4jLevel.FATAL); pseudoClassStateChanged(ERROR, !empty && item.getLevel() == Log4jLevel.ERROR); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MDListCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MDListCell.java index 156e62d12..62fbf277a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MDListCell.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MDListCell.java @@ -24,17 +24,14 @@ import javafx.scene.control.ListCell; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import org.jackhuang.hmcl.ui.FXUtils; -import org.jackhuang.hmcl.util.Holder; public abstract class MDListCell extends ListCell { private final PseudoClass SELECTED = PseudoClass.getPseudoClass("selected"); private final StackPane container = new StackPane(); private final StackPane root = new StackPane(); - private final Holder lastCell; - public MDListCell(JFXListView listView, Holder lastCell) { - this.lastCell = lastCell; + public MDListCell(JFXListView listView) { setText(null); setGraphic(null); @@ -58,13 +55,6 @@ public abstract class MDListCell extends ListCell { protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); - // https://mail.openjdk.org/pipermail/openjfx-dev/2022-July/034764.html - if (lastCell != null) { - if (this == lastCell.value && !isVisible()) - return; - lastCell.value = this; - } - updateControl(item, empty); if (empty) { setGraphic(null); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java index 7b05008e4..06153282b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java @@ -92,8 +92,6 @@ public final class TaskListPane extends StackPane { private final ObjectProperty progressNodePadding = new SimpleObjectProperty<>(Insets.EMPTY); private final DoubleProperty cellWidth = new SimpleDoubleProperty(); - private Cell lastCell; - public TaskListPane() { listView.setPadding(new Insets(12, 0, 0, 0)); listView.setCellFactory(l -> new Cell()); @@ -316,11 +314,6 @@ public final class TaskListPane extends StackPane { protected void updateItem(Node item, boolean empty) { super.updateItem(item, empty); - // https://mail.openjdk.org/pipermail/openjfx-dev/2022-July/034764.html - if (this == lastCell && !isVisible()) - return; - lastCell = this; - pane.paddingProperty().unbind(); title.textProperty().unbind(); message.textProperty().unbind(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java index 7ffc699a5..daa341ee8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java @@ -57,7 +57,6 @@ import org.jackhuang.hmcl.ui.construct.TwoLineListItem; import org.jackhuang.hmcl.ui.wizard.Navigation; import org.jackhuang.hmcl.ui.wizard.Refreshable; import org.jackhuang.hmcl.ui.wizard.WizardPage; -import org.jackhuang.hmcl.util.Holder; import org.jackhuang.hmcl.util.NativePatcher; import org.jackhuang.hmcl.util.SettingsMap; import org.jackhuang.hmcl.util.StringUtils; @@ -164,10 +163,7 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab private final ImageView imageView = new ImageView(); private final StackPane pane = new StackPane(); - private final Holder lastCell; - - RemoteVersionListCell(Holder lastCell, VersionsPage control) { - this.lastCell = lastCell; + RemoteVersionListCell(VersionsPage control) { this.control = control; HBox hbox = new HBox(16); @@ -222,11 +218,6 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab public void updateItem(RemoteVersion remoteVersion, boolean empty) { super.updateItem(remoteVersion, empty); - // https://mail.openjdk.org/pipermail/openjfx-dev/2022-July/034764.html - if (this == lastCell.value && !isVisible()) - return; - lastCell.value = this; - if (empty) { setGraphic(null); return; @@ -398,8 +389,7 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab control.versions.addListener((InvalidationListener) o -> updateList()); - Holder lastCell = new Holder<>(); - list.setCellFactory(listView -> new RemoteVersionListCell(lastCell, control)); + list.setCellFactory(listView -> new RemoteVersionListCell(control)); ComponentList.setVgrow(list, Priority.ALWAYS); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeView.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeView.java index 650d02cbd..b8c258791 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeView.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeView.java @@ -27,7 +27,6 @@ import javafx.scene.control.TreeView; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.util.Callback; -import org.jackhuang.hmcl.util.Holder; import java.lang.reflect.Array; import java.util.EnumMap; @@ -45,7 +44,6 @@ public final class NBTTreeView extends JFXTreeView { } private static Callback, TreeCell> cellFactory() { - Holder lastCell = new Holder<>(); EnumMap icons = new EnumMap<>(NBTTagType.class); return view -> new TreeCell<>() { @@ -69,11 +67,6 @@ public final class NBTTreeView extends JFXTreeView { public void updateItem(Tag item, boolean empty) { super.updateItem(item, empty); - // https://mail.openjdk.org/pipermail/openjfx-dev/2022-July/034764.html - if (this == lastCell.value && !isVisible()) - return; - lastCell.value = this; - ImageView imageView = (ImageView) this.getGraphic(); if (imageView == null) { imageView = new ImageView(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java index 81394bf70..a6698bc2e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPageSkin.java @@ -54,7 +54,6 @@ import org.jackhuang.hmcl.ui.construct.ComponentList; import org.jackhuang.hmcl.ui.construct.MDListCell; import org.jackhuang.hmcl.ui.construct.SpinnerPane; import org.jackhuang.hmcl.ui.construct.TwoLineListItem; -import org.jackhuang.hmcl.util.Holder; import org.jackhuang.hmcl.util.io.CompressingUtils; import org.jetbrains.annotations.Nullable; @@ -180,8 +179,7 @@ final class DatapackListPageSkin extends SkinBase { center.getStyleClass().add("large-spinner-pane"); center.loadingProperty().bind(skinnable.loadingProperty()); - Holder lastCell = new Holder<>(); - listView.setCellFactory(x -> new DatapackInfoListCell(listView, lastCell)); + listView.setCellFactory(x -> new DatapackInfoListCell(listView)); listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); this.listView.setItems(filteredList); @@ -304,8 +302,8 @@ final class DatapackListPageSkin extends SkinBase { final TwoLineListItem content = new TwoLineListItem(); BooleanProperty booleanProperty; - DatapackInfoListCell(JFXListView listView, Holder lastCell) { - super(listView, lastCell); + DatapackInfoListCell(JFXListView listView) { + super(listView); HBox container = new HBox(8); container.setPickOnBounds(false); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java index 9dd1b6df3..dd60f0130 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java @@ -189,8 +189,7 @@ final class ModListPageSkin extends SkinBase { center.getStyleClass().add("large-spinner-pane"); center.loadingProperty().bind(skinnable.loadingProperty()); - Holder lastCell = new Holder<>(); - listView.setCellFactory(x -> new ModInfoListCell(listView, lastCell)); + listView.setCellFactory(x -> new ModInfoListCell(listView)); listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); Bindings.bindContent(listView.getItems(), skinnable.getItems()); skinnable.getItems().addListener((ListChangeListener) c -> { @@ -562,8 +561,8 @@ final class ModListPageSkin extends SkinBase { Tooltip warningTooltip; - ModInfoListCell(JFXListView listView, Holder lastCell) { - super(listView, lastCell); + ModInfoListCell(JFXListView listView) { + super(listView); this.getStyleClass().add("mod-info-list-cell"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ResourcepackListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ResourcepackListPage.java index acd07b1d5..bd2b1da00 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ResourcepackListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ResourcepackListPage.java @@ -24,7 +24,6 @@ import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.ListPageBase; import org.jackhuang.hmcl.ui.SVG; import org.jackhuang.hmcl.ui.construct.*; -import org.jackhuang.hmcl.util.Holder; import org.jackhuang.hmcl.util.io.FileUtils; import java.io.ByteArrayInputStream; @@ -156,8 +155,7 @@ public final class ResourcepackListPage extends ListPageBase lastCell = new Holder<>(); - listView.setCellFactory(x -> new ResourcepackListCell(listView, lastCell, control)); + listView.setCellFactory(x -> new ResourcepackListCell(listView, control)); Bindings.bindContent(listView.getItems(), control.getItems()); center.setContent(listView); @@ -210,8 +208,8 @@ public final class ResourcepackListPage extends ListPageBase listView, Holder lastCell, ResourcepackListPage page) { - super(listView, lastCell); + public ResourcepackListCell(JFXListView listView, ResourcepackListPage page) { + super(listView); this.page = page;