Updated to 1.2.0, added breadcrumb list property.
This commit is contained in:
parent
9766e1ddee
commit
5bb0b5410e
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>com.andrewlalis</groupId>
|
||||
<artifactId>javafx-scene-router</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.2.0</version>
|
||||
<name>JavaFX Scene Router</name>
|
||||
<description>A library that provides a router implementation for JavaFX, for browser-like navigation between pages.</description>
|
||||
<url>https://github.com/andrewlalis/javafx-scene-router</url>
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.andrewlalis.javafx_scene_router;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
@ -34,6 +37,7 @@ public class SceneRouter {
|
|||
private final Pane viewPane = new Pane();
|
||||
private final Map<String, Parent> routeMap = new HashMap<>();
|
||||
private final RouteHistory history = new RouteHistory();
|
||||
private final ListProperty<BreadCrumb> breadCrumbs = new SimpleListProperty<>();
|
||||
|
||||
/**
|
||||
* Constructs the router.
|
||||
|
@ -139,14 +143,29 @@ public class SceneRouter {
|
|||
return viewPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an observable list of {@link BreadCrumb} that is updated each time
|
||||
* the router's navigation history is updated.
|
||||
* @return The list of breadcrumbs.
|
||||
*/
|
||||
public ObservableList<BreadCrumb> getBreadCrumbs() {
|
||||
return breadCrumbs;
|
||||
}
|
||||
|
||||
private Parent getMappedNode(String route) {
|
||||
Parent node = routeMap.get(route);
|
||||
if (node == null) throw new IllegalArgumentException("Route " + route + " is not mapped to any node.");
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to actually set this router's view pane to a particular
|
||||
* node. This is called any time a route changes.
|
||||
* @param node The node to set.
|
||||
*/
|
||||
private void setCurrentNode(Parent node) {
|
||||
viewPane.getChildren().setAll(node);
|
||||
breadCrumbs.setAll(history.getBreadCrumbs());
|
||||
}
|
||||
|
||||
private <T> Parent loadNode(URL resource, Consumer<T> controllerCustomizer) {
|
||||
|
|
Loading…
Reference in New Issue