diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java index c2ffbc4c8..4ef9ea2ef 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsView.java @@ -109,9 +109,9 @@ public abstract class SettingsView extends StackPane { content.getChildren().setAll(chkUpdateStable, chkUpdateDev, noteWrapper); - updatePane.addChildren(content); + updatePane.getContent().add(content); } - settingsPane.addChildren(updatePane); + settingsPane.getContent().add(updatePane); } { @@ -122,7 +122,7 @@ public abstract class SettingsView extends StackPane { fileCommonLocation.setHasSubtitle(true); fileCommonLocation.setCustomText("settings.custom"); - settingsPane.addChildren(fileCommonLocation); + settingsPane.getContent().add(fileCommonLocation); } { @@ -132,7 +132,7 @@ public abstract class SettingsView extends StackPane { backgroundItem.setHasSubtitle(true); backgroundItem.setCustomText(I18n.i18n("settings.custom")); - settingsPane.addChildren(backgroundItem); + settingsPane.getContent().add(backgroundItem); } { @@ -169,7 +169,7 @@ public abstract class SettingsView extends StackPane { ); downloadSourcePane.setRight(cboDownloadSource); } - settingsPane.addChildren(downloadSourcePane); + settingsPane.getContent().add(downloadSourcePane); } { @@ -183,7 +183,7 @@ public abstract class SettingsView extends StackPane { FXUtils.setLimitWidth(cboLanguage, 400); languagePane.setRight(cboLanguage); - settingsPane.addChildren(languagePane); + settingsPane.getContent().add(languagePane); } { @@ -309,8 +309,8 @@ public abstract class SettingsView extends StackPane { } proxyWrapper.getChildren().add(proxyPane); } - proxyList.addChildren(proxyWrapper); - settingsPane.addChildren(proxyList); + proxyList.getContent().add(proxyWrapper); + settingsPane.getContent().add(proxyList); } { @@ -324,13 +324,13 @@ public abstract class SettingsView extends StackPane { themeColorPickerContainer.setMinHeight(30); themePane.setRight(themeColorPickerContainer); - settingsPane.addChildren(themePane); + settingsPane.getContent().add(themePane); } { VBox fontPane = new VBox(); fontPane.setSpacing(5); - settingsPane.addChildren(fontPane); + settingsPane.getContent().add(fontPane); { BorderPane borderPane = new BorderPane(); @@ -462,7 +462,7 @@ public abstract class SettingsView extends StackPane { gridPane.getChildren().add(label); } aboutPane.getChildren().setAll(gridPane); - settingsPane.addChildren(aboutPane); + settingsPane.getContent().add(aboutPane); } rootPane.getChildren().add(settingsPane); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java index ffe131359..382a58116 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentList.java @@ -18,6 +18,7 @@ package org.jackhuang.hmcl.ui.construct; import javafx.beans.DefaultProperty; +import javafx.beans.binding.Bindings; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; @@ -26,12 +27,15 @@ import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.scene.Node; +import javafx.scene.control.Control; +import javafx.scene.control.Skin; +import javafx.scene.control.SkinBase; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +import org.jackhuang.hmcl.util.MappedObservableList; @DefaultProperty("content") -public class ComponentList extends StackPane { - private final VBox vbox = new VBox(); +public class ComponentList extends Control { private final StringProperty title = new SimpleStringProperty(this, "title", "Group"); private final StringProperty subtitle = new SimpleStringProperty(this, "subtitle", ""); private final IntegerProperty depth = new SimpleIntegerProperty(this, "depth", 0); @@ -39,31 +43,9 @@ public class ComponentList extends StackPane { public final ObservableList content = FXCollections.observableArrayList(); public ComponentList() { - getChildren().setAll(vbox); - content.addListener((ListChangeListener) change -> { - while (change.next()) { - for (int i = change.getFrom(); i < change.getTo(); ++i) - addChildren(change.getList().get(i)); - } - }); getStyleClass().add("options-list"); } - public void addChildren(Node node) { - StackPane child = new StackPane(); - child.getChildren().add(new ComponentListCell(node)); - if (vbox.getChildren().isEmpty()) - child.getStyleClass().add("options-list-item-ahead"); - else - child.getStyleClass().add("options-list-item"); - child.getProperties().put("node", node); - vbox.getChildren().add(child); - } - - public void removeChild(Node node) { - vbox.getChildren().removeIf(node1 -> node1.getProperties().get("node") == node); - } - public String getTitle() { return title.get(); } @@ -111,4 +93,28 @@ public class ComponentList extends StackPane { public ObservableList getContent() { return content; } + + @Override + protected javafx.scene.control.Skin createDefaultSkin() { + return new Skin(this); + } + + protected static class Skin extends SkinBase { + + protected Skin(ComponentList control) { + super(control); + + VBox vbox = new VBox(); + Bindings.bindContent(vbox.getChildren(), + MappedObservableList.create(control.getContent(), this::mapper)); + getChildren().setAll(vbox); + } + + private Node mapper(Node node) { + StackPane child = new StackPane(); + child.getChildren().add(new ComponentListCell(node)); + child.getStyleClass().add("options-list-item"); + return child; + } + } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java index 7b80abf61..2ae9b3dc3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/ComponentListCell.java @@ -40,13 +40,13 @@ import org.jackhuang.hmcl.ui.SVG; /** * @author huangyuhui */ -public class ComponentListCell extends StackPane { +class ComponentListCell extends StackPane { private final Node content; private Animation expandAnimation; private Rectangle clipRect; private final BooleanProperty expanded = new SimpleBooleanProperty(this, "expanded", false); - public ComponentListCell(Node content) { + ComponentListCell(Node content) { this.content = content; updateLayout(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiColorItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiColorItem.java index 4cb7ef2ba..6fd823ebb 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiColorItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiColorItem.java @@ -57,7 +57,7 @@ public class MultiColorItem extends ComponentList { if (hasCustom) pane.getChildren().add(custom); - addChildren(pane); + getContent().add(pane); group.selectedToggleProperty().addListener((a, b, newValue) -> { if (toggleSelectedListener != null) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiFileItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiFileItem.java index c8fcc6ca6..3e676a03a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiFileItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MultiFileItem.java @@ -106,7 +106,7 @@ public class MultiFileItem extends ComponentList { if (hasCustom) pane.getChildren().add(custom); - addChildren(pane); + getContent().add(pane); group.selectedToggleProperty().addListener((a, b, newValue) -> { if (toggleSelectedListener != null) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java index a2edfefe1..1bcb87047 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java @@ -152,7 +152,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag this.versionId = versionId; if (versionId == null) { - componentList.removeChild(iconPickerItem); + componentList.getContent().remove(iconPickerItem); rootPane.getChildren().remove(settingsTypePane); chkEnableSpecificSettings.setSelected(true); }