From e4800d4d2c2d6309119bda791b736b5dd51a518a Mon Sep 17 00:00:00 2001 From: LeStegii Date: Tue, 27 Feb 2024 10:38:25 +0100 Subject: [PATCH] feat(framework): Make titles accessible through app --- .../main/java/org/fulib/fx/FulibFxApp.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/framework/src/main/java/org/fulib/fx/FulibFxApp.java b/framework/src/main/java/org/fulib/fx/FulibFxApp.java index 7fbb5a52..c3cfd657 100644 --- a/framework/src/main/java/org/fulib/fx/FulibFxApp.java +++ b/framework/src/main/java/org/fulib/fx/FulibFxApp.java @@ -28,6 +28,7 @@ import java.util.ResourceBundle; import java.util.function.Function; import java.util.logging.Logger; + import static org.fulib.fx.util.FrameworkUtil.error; public abstract class FulibFxApp extends Application { @@ -208,7 +209,7 @@ public void stop() { this.currentMainController = controller; onShow(Optional.empty(), controller, renderedParent, params); display(renderedParent); - this.component.controllerManager().getTitle(controller).ifPresent(title -> stage.setTitle(title(title))); + getTitle(controller).ifPresent(title -> stage.setTitle(formatTitle(title))); return renderedParent; } @@ -224,7 +225,7 @@ public void stop() { Pair rendered = this.component.router().renderRoute(route, params); this.currentMainController = rendered.getKey(); display(rendered.getValue()); - this.component.controllerManager().getTitle(currentMainController).ifPresent(title -> stage.setTitle(title(title))); + getTitle(currentMainController).ifPresent(title -> stage.setTitle(formatTitle(title))); onShow(Optional.of(route), rendered.getKey(), rendered.getValue(), params); return rendered.getValue(); } @@ -367,8 +368,24 @@ public void setTitlePattern(String titlePattern) { this.titlePattern = titlePattern::formatted; } - private String title(String title) { + /** + * Formats the title of a controller using the title pattern. + * + * @param title The title of the controller + * @return The formatted title + */ + public String formatTitle(String title) { return this.titlePattern.apply(title); } + /** + * Returns the title of the given controller. + * + * @param controller The controller instance + * @return The title of the controller + */ + public Optional getTitle(Object controller) { + return this.component.controllerManager().getTitle(controller); + } + }