Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@
package org.jackhuang.hmcl.ui;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXListView;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ListCell;
import javafx.scene.control.SkinBase;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.ui.construct.ComponentList;
import org.jackhuang.hmcl.ui.construct.SpinnerPane;

import java.util.List;

public abstract class ToolbarListPageSkin<T extends ListPageBase<? extends Node>> extends SkinBase<T> {
public abstract class ToolbarListPageSkin<E, P extends ListPageBase<E>> extends SkinBase<P> {

public ToolbarListPageSkin(T skinnable) {
protected final JFXListView<E> listView;

public ToolbarListPageSkin(P skinnable) {
super(skinnable);

SpinnerPane spinnerPane = new SpinnerPane();
Expand All @@ -58,18 +60,12 @@ public ToolbarListPageSkin(T skinnable) {
}

{
ScrollPane scrollPane = new ScrollPane();
ComponentList.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.setFitToWidth(true);

VBox content = new VBox();

Bindings.bindContent(content.getChildren(), skinnable.itemsProperty());

scrollPane.setContent(content);
FXUtils.smoothScrolling(scrollPane);

root.getContent().add(scrollPane);
this.listView = new JFXListView<>();
this.listView.setPadding(Insets.EMPTY);
this.listView.setCellFactory(listView -> createListCell((JFXListView<E>) listView));
ComponentList.setVgrow(listView, Priority.ALWAYS);
Bindings.bindContent(this.listView.getItems(), skinnable.itemsProperty());
root.getContent().add(listView);
}

spinnerPane.setContent(root);
Expand Down Expand Up @@ -102,5 +98,21 @@ public static JFXButton createDecoratorButton(String tooltip, SVG svg, Runnable
return ret;
}

protected abstract List<Node> initializeToolbar(T skinnable);
protected abstract List<Node> initializeToolbar(P skinnable);

protected ListCell<E> createListCell(JFXListView<E> listView) {
Comment thread
Glavo marked this conversation as resolved.
return new ListCell<>() {
@Override
protected void updateItem(E item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item instanceof Node node) {
setGraphic(node);
setText(null);
} else {
setGraphic(null);
setText(null);
}
}
};
}
}
75 changes: 0 additions & 75 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin2.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private static final class JavaRuntimeItemSkin extends SkinBase<JavaItem> {
}
}

private static final class JavaPageSkin extends ToolbarListPageSkin<JavaManagementPage> {
private static final class JavaPageSkin extends ToolbarListPageSkin<JavaItem, JavaManagementPage> {

JavaPageSkin(JavaManagementPage skinnable) {
super(skinnable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private static final class DisabledJavaItemSkin extends SkinBase<DisabledJavaIte
}
}

private static final class JavaRestorePageSkin extends ToolbarListPageSkin<JavaRestorePage> {
private static final class JavaRestorePageSkin extends ToolbarListPageSkin<DisabledJavaItem, JavaRestorePage> {
JavaRestorePageSkin(JavaRestorePage skinnable) {
super(skinnable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
*/
package org.jackhuang.hmcl.ui.versions;

import com.jfoenix.controls.JFXListView;
import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.ListCell;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -154,17 +156,21 @@ protected GameListSkin createDefaultSkin() {
return new GameListSkin();
}

private class GameListSkin extends ToolbarListPageSkin2<GameListItem, GameList> {
private class GameListSkin extends ToolbarListPageSkin<GameListItem, GameList> {
Comment thread
Glavo marked this conversation as resolved.

public GameListSkin() {
super(GameList.this);
this.listView.setCellFactory(listView -> new GameListCell());
}

@Override
protected List<Node> initializeToolbar(GameList skinnable) {
return Collections.emptyList();
}

@Override
protected ListCell<GameListItem> createListCell(JFXListView<GameListItem> listView) {
return new GameListCell();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void onStop(boolean success, TaskExecutor executor) {
executor.start();
}

private class InstallerListPageSkin extends ToolbarListPageSkin<InstallerListPage> {
private class InstallerListPageSkin extends ToolbarListPageSkin<InstallerItem, InstallerListPage> {
Comment thread
Glavo marked this conversation as resolved.

InstallerListPageSkin() {
super(InstallerListPage.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public ItemSkin(Item item) {
}
}

private final class SchematicsPageSkin extends ToolbarListPageSkin<SchematicsPage> {
private final class SchematicsPageSkin extends ToolbarListPageSkin<Item, SchematicsPage> {
Comment thread
Glavo marked this conversation as resolved.
SchematicsPageSkin() {
super(SchematicsPage.this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void createBackup() {
}), i18n("world.backup"), null);
}

private final class WorldBackupsPageSkin extends ToolbarListPageSkin<WorldBackupsPage> {
private final class WorldBackupsPageSkin extends ToolbarListPageSkin<BackupInfo, WorldBackupsPage> {

WorldBackupsPageSkin() {
super(WorldBackupsPage.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.Node;
import javafx.scene.control.Skin;
import javafx.stage.FileChooser;
import org.jackhuang.hmcl.game.World;
import org.jackhuang.hmcl.setting.Profile;
Expand Down Expand Up @@ -67,7 +68,7 @@ public WorldListPage() {
}

@Override
protected ToolbarListPageSkin<WorldListPage> createDefaultSkin() {
protected Skin<WorldListPage> createDefaultSkin() {
return new WorldListPageSkin();
}

Expand Down Expand Up @@ -161,7 +162,7 @@ public void setShowAll(boolean showAll) {
this.showAll.set(showAll);
}

private final class WorldListPageSkin extends ToolbarListPageSkin<WorldListPage> {
private final class WorldListPageSkin extends ToolbarListPageSkin<WorldListItem, WorldListPage> {
Comment thread
Glavo marked this conversation as resolved.

WorldListPageSkin() {
super(WorldListPage.this);
Expand Down
Loading