From 9766e1ddee335d3ccd300b86ba88476990cafd68 Mon Sep 17 00:00:00 2001
From: andrewlalis
Date: Sat, 23 Dec 2023 08:20:55 -0500
Subject: [PATCH] Added some javadoc, improved the readme.
---
README.md | 70 +++++++++++++++++++
pom.xml | 2 +-
.../javafx_scene_router/SceneRouter.java | 5 ++
3 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e86f2d3..ad53de0 100644
--- a/README.md
+++ b/README.md
@@ -13,3 +13,73 @@ However, sometimes you'll want a web-like experience with your desktop app, and
for that purpose, I've created javafx-scene-router. It allows you to initialize
a router that controls the content of a Pane or similar, and depending on what
route is selected, different content will be shown in that pane.
+
+# Usage
+
+Add the following dependency to your `pom.xml`:
+```xml
+
+ com.andrewlalis
+ javafx-scene-router
+ LATEST_VERSION
+
+```
+> Replace `LATEST_VERSION` with the most recent version found on [maven central](https://central.sonatype.com/artifact/com.andrewlalis/javafx-scene-router).
+
+Then, most often you'll create a singleton instance of `SceneRouter`, probably
+in your app's main class like so:
+
+```java
+import com.andrewlalis.javafx_scene_router.SceneRouter;
+
+public class MyJavaFXApp extends Application {
+ public static final SceneRouter router = new SceneRouter();
+
+ public static void main(String[] args) {
+ // Setup the router's routes before starting the app:
+ router.map("accounts", MyJavaFXApp.class.getResource("/accounts-view.fxml"));
+ router.map("account", MyJavaFXApp.class.getResource("/account.fxml"));
+ router.map("settings", MyJavaFXApp.class.getResource("/settings.fxml"));
+
+ launch(args);
+ }
+}
+```
+
+From here, it's just a matter of attaching the router's view pane to one of
+your scene's nodes, and mapping string route names to other nodes or FXML
+files.
+
+For example, suppose my app has a main scene with a `MainController` class.
+We'd hook up the router's view pane to that scene's center view:
+```java
+public class MainController {
+ @FXML
+ public BorderPane borderPane;
+
+ @FXML
+ public void initialize() {
+ borderPane.setCenter(MyJavaFXApp.router.getViewPane());
+ }
+}
+```
+
+Finally, we can use the router from anywhere in our app to control which "page"
+is being displayed:
+
+```java
+public class MainController {
+ // Rest of the class omitted.
+
+ @FXML
+ public void onBackButton() {
+ MyJavaFXApp.router.navigateBack();
+ }
+
+ @FXML
+ public void onAccountClicked() {
+ Account acc = getClickedAccount();
+ MyJavaFXApp.router.navigate("account", acc);
+ }
+}
+```
diff --git a/pom.xml b/pom.xml
index 802b746..8c7be89 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.andrewlalis
javafx-scene-router
- 1.1.0
+ 1.1.1
JavaFX Scene Router
A library that provides a router implementation for JavaFX, for browser-like navigation between pages.
https://github.com/andrewlalis/javafx-scene-router
diff --git a/src/main/java/com/andrewlalis/javafx_scene_router/SceneRouter.java b/src/main/java/com/andrewlalis/javafx_scene_router/SceneRouter.java
index fc7bb9b..5852f9a 100644
--- a/src/main/java/com/andrewlalis/javafx_scene_router/SceneRouter.java
+++ b/src/main/java/com/andrewlalis/javafx_scene_router/SceneRouter.java
@@ -24,6 +24,11 @@ import java.util.function.Consumer;
* The router maintains a {@link RouteHistory} so that it's possible to
* navigate backward and forward, much like a web browser would.
*
+ *
+ * Note that this router is intended to be used by a single JavaFX
+ * application, and is not threadsafe! Use a separate
+ * router for each separate JavaFX application you create.
+ *
*/
public class SceneRouter {
private final Pane viewPane = new Pane();