From 30c2d88f62f473d28970608d67c2cbd9acc2321a Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Fri, 11 Jan 2019 21:18:26 +0800 Subject: [PATCH] Use spinnerPane in ModListPage --- .../org/jackhuang/hmcl/ui/ListPageSkin.java | 23 ++++++--------- .../hmcl/ui/construct/SpinnerPane.java | 28 +++++++++++++++++-- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageSkin.java index e5ad4ae99..1e8cc6897 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ListPageSkin.java @@ -19,7 +19,7 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXScrollPane; -import com.jfoenix.controls.JFXSpinner; + import javafx.beans.binding.Bindings; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -28,17 +28,14 @@ import javafx.scene.control.SkinBase; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.setting.Theme; +import org.jackhuang.hmcl.ui.construct.SpinnerPane; -public class ListPageSkin extends SkinBase { +public class ListPageSkin extends SkinBase> { public ListPageSkin(ListPage skinnable) { super(skinnable); - StackPane rootPane = new StackPane(); - - JFXSpinner spinner = new JFXSpinner(); - spinner.setRadius(16); - spinner.getStyleClass().setAll("materialDesign-purple", "first-spinner"); + SpinnerPane spinnerPane = new SpinnerPane(); StackPane contentPane = new StackPane(); { @@ -56,7 +53,7 @@ public class ListPageSkin extends SkinBase { scrollPane.setContent(list); JFXScrollPane.smoothScrolling(scrollPane); } - + VBox vBox = new VBox(); { vBox.setAlignment(Pos.BOTTOM_RIGHT); @@ -92,13 +89,9 @@ public class ListPageSkin extends SkinBase { contentPane.getChildren().setAll(scrollPane, vBox); } - rootPane.getChildren().setAll(contentPane); + spinnerPane.loadingProperty().bind(skinnable.loadingProperty()); + spinnerPane.setContent(contentPane); - skinnable.loadingProperty().addListener((a, b, newValue) -> { - if (newValue) rootPane.getChildren().setAll(spinner); - else rootPane.getChildren().setAll(contentPane); - }); - - getChildren().setAll(rootPane); + getChildren().setAll(spinnerPane); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java index 995287691..66cf182f3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/SpinnerPane.java @@ -19,7 +19,9 @@ package org.jackhuang.hmcl.ui.construct; import com.jfoenix.controls.JFXSpinner; import javafx.beans.DefaultProperty; +import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Node; import javafx.scene.layout.StackPane; @@ -32,19 +34,29 @@ public class SpinnerPane extends StackPane { private final JFXSpinner spinner = new JFXSpinner(); private final StackPane contentPane = new StackPane(); private final ObjectProperty content = new SimpleObjectProperty<>(this, "content"); + private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading") { + protected void invalidated() { + if (get()) + transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer()); + else + transitionHandler.setContent(contentPane, ContainerAnimations.FADE.getAnimationProducer()); + } + }; public SpinnerPane() { + getStyleClass().add("spinner-pane"); + getChildren().setAll(contentPane); content.addListener((a, b, newValue) -> contentPane.getChildren().setAll(newValue)); } public void showSpinner() { - transitionHandler.setContent(spinner, ContainerAnimations.FADE.getAnimationProducer()); + setLoading(true); } public void hideSpinner() { - transitionHandler.setContent(contentPane, ContainerAnimations.FADE.getAnimationProducer()); + setLoading(false); } public Node getContent() { @@ -58,4 +70,16 @@ public class SpinnerPane extends StackPane { public void setContent(Node content) { this.content.set(content); } + + public boolean isLoading() { + return loading.get(); + } + + public BooleanProperty loadingProperty() { + return loading; + } + + public void setLoading(boolean loading) { + this.loading.set(loading); + } }