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
23 changes: 14 additions & 9 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/ToolbarListPageSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ public abstract class ToolbarListPageSkin<E, P extends ListPageBase<E>> extends
public ToolbarListPageSkin(P skinnable) {
super(skinnable);

SpinnerPane spinnerPane = new SpinnerPane();
spinnerPane.loadingProperty().bind(skinnable.loadingProperty());
spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty());
spinnerPane.onFailedActionProperty().bind(skinnable.onFailedActionProperty());

ComponentList root = new ComponentList();
root.getStyleClass().add("no-padding");

StackPane container = new StackPane();
container.getChildren().add(root);
StackPane.setMargin(root, new Insets(10));

List<Node> toolbarButtons = initializeToolbar(skinnable);
Expand All @@ -60,19 +58,26 @@ public ToolbarListPageSkin(P skinnable) {
root.getContent().add(toolbar);
}

SpinnerPane spinnerPane = new SpinnerPane();
spinnerPane.loadingProperty().bind(skinnable.loadingProperty());
spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty());
spinnerPane.onFailedActionProperty().bind(skinnable.onFailedActionProperty());

ComponentList.setVgrow(spinnerPane, Priority.ALWAYS);

{
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());
FXUtils.ignoreEvent(listView, KeyEvent.KEY_PRESSED, e -> e.getCode() == KeyCode.ESCAPE);
root.getContent().add(listView);

spinnerPane.setContent(listView);
}

spinnerPane.setContent(root);
root.getContent().add(spinnerPane);

getChildren().setAll(spinnerPane);
getChildren().setAll(container);
}

public static Node wrap(Node node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@

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.ListCell;
import javafx.scene.control.Skin;
import javafx.scene.control.SkinBase;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.stage.FileChooser;
import org.jackhuang.hmcl.mod.LocalModFile;
import org.jackhuang.hmcl.resourcepack.ResourcepackFile;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers;
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.ui.*;
import org.jackhuang.hmcl.ui.construct.MDListCell;
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
import org.jackhuang.hmcl.ui.construct.RipplerContainer;
import org.jackhuang.hmcl.ui.construct.TwoLineListItem;
import org.jackhuang.hmcl.util.io.FileUtils;

import java.io.ByteArrayInputStream;
Expand All @@ -38,7 +35,6 @@
import java.util.Objects;
import java.util.stream.Stream;

import static org.jackhuang.hmcl.ui.ToolbarListPageSkin.createToolbarButton2;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

Expand Down Expand Up @@ -128,44 +124,24 @@ private void onDownload() {
Controllers.navigate(Controllers.getDownloadPage());
}

private static final class ResourcepackListPageSkin extends SkinBase<ResourcepackListPage> {
private final JFXListView<ResourcepackInfoObject> listView;
private static final class ResourcepackListPageSkin extends ToolbarListPageSkin<ResourcepackInfoObject, ResourcepackListPage> {

private ResourcepackListPageSkin(ResourcepackListPage control) {
public ResourcepackListPageSkin(ResourcepackListPage control) {
super(control);
}

StackPane pane = new StackPane();
pane.setPadding(new Insets(10));
pane.getStyleClass().addAll("notice-pane");

ComponentList root = new ComponentList();
root.getStyleClass().add("no-padding");
listView = new JFXListView<>();

FXUtils.ignoreEvent(listView, KeyEvent.KEY_PRESSED, e -> e.getCode() == KeyCode.ESCAPE);

HBox toolbar = new HBox();
toolbar.setAlignment(Pos.CENTER_LEFT);
toolbar.setPickOnBounds(false);
toolbar.getChildren().setAll(
createToolbarButton2(i18n("button.refresh"), SVG.REFRESH, control::refresh),
createToolbarButton2(i18n("resourcepack.add"), SVG.ADD, control::onAddFiles),
createToolbarButton2(i18n("resourcepack.download"), SVG.DOWNLOAD, control::onDownload)
@Override
protected List<Node> initializeToolbar(ResourcepackListPage skinnable) {
return List.of(
createToolbarButton2(i18n("button.refresh"), SVG.REFRESH, skinnable::refresh),
createToolbarButton2(i18n("resourcepack.add"), SVG.ADD, skinnable::onAddFiles),
createToolbarButton2(i18n("resourcepack.download"), SVG.DOWNLOAD, skinnable::onDownload)
);
root.getContent().add(toolbar);

SpinnerPane center = new SpinnerPane();
ComponentList.setVgrow(center, Priority.ALWAYS);
center.loadingProperty().bind(control.loadingProperty());

listView.setCellFactory(x -> new ResourcepackListCell(listView, control));
Bindings.bindContent(listView.getItems(), control.getItems());

center.setContent(listView);
root.getContent().add(center);
}

pane.getChildren().setAll(root);
getChildren().setAll(pane);
@Override
protected ListCell<ResourcepackInfoObject> createListCell(JFXListView<ResourcepackInfoObject> listView) {
return new ResourcepackListCell(listView, getSkinnable());
}
}

Expand Down
Loading