Attempt to solve #481

This commit is contained in:
huanghongxun
2018-10-23 13:32:25 +08:00
parent 66a4566dc5
commit aafcd57c82
2 changed files with 13 additions and 7 deletions

View File

@@ -17,9 +17,7 @@
*/ */
package org.jackhuang.hmcl.ui.construct; package org.jackhuang.hmcl.ui.construct;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.event.Event; import javafx.event.Event;
import javafx.event.EventHandler; import javafx.event.EventHandler;
@@ -40,19 +38,23 @@ public class Navigator extends StackPane {
private final Stack<Node> stack = new Stack<>(); private final Stack<Node> stack = new Stack<>();
private final TransitionHandler animationHandler = new TransitionHandler(this); private final TransitionHandler animationHandler = new TransitionHandler(this);
private final ReadOnlyBooleanWrapper canGoBack = new ReadOnlyBooleanWrapper(); private boolean initialized = false;
public Navigator(Node init) { public void init(Node init) {
stack.push(init); stack.push(init);
getChildren().setAll(init); getChildren().setAll(init);
Platform.runLater(() -> fireEvent(new NavigationEvent(this, init, NavigationEvent.NAVIGATED));
fireEvent(new NavigationEvent(this, init, NavigationEvent.NAVIGATED)));
initialized = true;
} }
public void navigate(Node node) { public void navigate(Node node) {
FXUtils.checkFxUserThread(); FXUtils.checkFxUserThread();
if (!initialized)
throw new IllegalStateException("Navigator must have a root page");
Node from = stack.peek(); Node from = stack.peek();
if (from == node) if (from == node)
return; return;
@@ -89,6 +91,9 @@ public class Navigator extends StackPane {
public void close(Node from) { public void close(Node from) {
FXUtils.checkFxUserThread(); FXUtils.checkFxUserThread();
if (!initialized)
throw new IllegalStateException("Navigator must have a root page");
Logging.LOG.info("Closed page " + from); Logging.LOG.info("Closed page " + from);
if (stack.peek() != from) if (stack.peek() != from)

View File

@@ -84,9 +84,10 @@ public class DecoratorController {
decorator.titleProperty().set(Metadata.TITLE); decorator.titleProperty().set(Metadata.TITLE);
decorator.setOnCloseButtonAction(Launcher::stopApplication); decorator.setOnCloseButtonAction(Launcher::stopApplication);
navigator = new Navigator(mainPage); navigator = new Navigator();
navigator.setOnNavigating(this::onNavigating); navigator.setOnNavigating(this::onNavigating);
navigator.setOnNavigated(this::onNavigated); navigator.setOnNavigated(this::onNavigated);
navigator.init(mainPage);
decorator.getContent().setAll(navigator); decorator.getContent().setAll(navigator);
decorator.onCloseNavButtonActionProperty().set(e -> close()); decorator.onCloseNavButtonActionProperty().set(e -> close());