Skip to content

Commit

Permalink
test(ludo): Prepare for more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStegii committed Feb 27, 2024
1 parent ef13de8 commit e0c0a03
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
37 changes: 21 additions & 16 deletions framework/src/main/java/org/fulib/fx/FulibFxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class FulibFxApp extends Application {
private static Path resourcesPath = Path.of("src/main/resources");

// The component holding the required dependencies like router, controller manager, etc.
private FrameworkComponent component;
private FrameworkComponent frameworkComponent;

// The stage of the application
private Stage stage;
Expand Down Expand Up @@ -129,7 +129,7 @@ public static void setResourcesPath(@NotNull Path path) {
if (!ControllerUtil.isComponent(component))
throw new IllegalArgumentException(error(1000).formatted(component.getClass().getName()));

Disposable disposable = this.component.controllerManager().init(component, params, false);
Disposable disposable = this.frameworkComponent.controllerManager().init(component, params, false);
if (onDestroy != null) {
onDestroy.add(disposable);
}
Expand Down Expand Up @@ -157,7 +157,9 @@ public static void setResourcesPath(@NotNull Path path) {
public void start(Stage primaryStage) {
this.stage = primaryStage;

this.component = DaggerFrameworkComponent.builder().framework(this).build();
this.frameworkComponent = DaggerFrameworkComponent.builder().framework(this).build();
System.out.println(this);
System.out.println(frameworkComponent);

Scene scene = new Scene(new Pane()); // Show default scene

Expand Down Expand Up @@ -208,7 +210,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)));
this.frameworkComponent.controllerManager().getTitle(controller).ifPresent(title -> stage.setTitle(title(title)));
return renderedParent;
}

Expand All @@ -221,10 +223,10 @@ public void stop() {
*/
public @NotNull Parent show(@NotNull String route, @NotNull Map<@NotNull String, @Nullable Object> params) {
cleanup();
Pair<Object, Parent> rendered = this.component.router().renderRoute(route, params);
Pair<Object, Parent> rendered = this.frameworkComponent.router().renderRoute(route, params);
this.currentMainController = rendered.getKey();
display(rendered.getValue());
this.component.controllerManager().getTitle(currentMainController).ifPresent(title -> stage.setTitle(title(title)));
this.frameworkComponent.controllerManager().getTitle(currentMainController).ifPresent(title -> stage.setTitle(title(title)));
onShow(Optional.of(route), rendered.getKey(), rendered.getValue(), params);
return rendered.getValue();
}
Expand All @@ -241,7 +243,10 @@ protected void display(@NotNull Parent parent) {

// Internal helper method
protected void cleanup() {
this.component.controllerManager().cleanup();
System.out.println("cleanup");
System.out.println(this);
System.out.println(frameworkComponent);
this.frameworkComponent.controllerManager().cleanup();
}

/**
Expand Down Expand Up @@ -276,7 +281,7 @@ public Stage stage() {
*/
@ApiStatus.Internal
public FrameworkComponent frameworkComponent() {
return this.component;
return this.frameworkComponent;
}

/**
Expand All @@ -285,29 +290,29 @@ public FrameworkComponent frameworkComponent() {
* @param routes The class to register the routes from
*/
public void registerRoutes(Object routes) {
this.component.router().registerRoutes(routes);
this.frameworkComponent.router().registerRoutes(routes);
}

/**
* Sets the default resource bundle to use for FXML files if no resource bundle is provided in the controller/component.
*/
public void setDefaultResourceBundle(ResourceBundle resourceBundle) {
this.component.controllerManager().setDefaultResourceBundle(resourceBundle);
this.frameworkComponent.controllerManager().setDefaultResourceBundle(resourceBundle);
}

/**
* Returns auto refresher of the application.
*/
public AutoRefresher autoRefresher() {
return this.component.autoRefresher();
return this.frameworkComponent.autoRefresher();
}

/**
* Returns to the previous controller in the history if possible.
*/
public void back() {
cleanup();
Parent parent = this.component.router().back();
Parent parent = this.frameworkComponent.router().back();
if (parent != null)
display(parent);
}
Expand All @@ -317,7 +322,7 @@ public void back() {
*/
public void forward() {
cleanup();
Parent parent = this.component.router().forward();
Parent parent = this.frameworkComponent.router().forward();
if (parent != null)
display(parent);
}
Expand All @@ -330,9 +335,9 @@ public void forward() {
*/
public void refresh() {
cleanup();
Map<String, Object> params = this.component.router().current().getValue(); // Use the same parameters as before
this.component.controllerManager().init(currentMainController, params, true); // Re-initialize the controller
Parent parent = this.component.controllerManager().render(currentMainController, params); // Re-render the controller
Map<String, Object> params = this.frameworkComponent.router().current().getValue(); // Use the same parameters as before
this.frameworkComponent.controllerManager().init(currentMainController, params, true); // Re-initialize the controller
Parent parent = this.frameworkComponent.controllerManager().render(currentMainController, params); // Re-render the controller
ReflectionUtil.resetMouseHandler(stage());
display(parent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.uniks.ludo.App;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Slider;
import org.fulib.fx.annotation.controller.Controller;
import org.fulib.fx.annotation.controller.Resource;
Expand All @@ -15,6 +16,8 @@
@Controller
public class SetupController {

@FXML
public Button startButton;
@FXML
private Slider playerAmountSlider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
<Insets />
</VBox.margin>
</Slider>
<Button defaultButton="true" mnemonicParsing="false" onAction="#onPlayClick" text="%setup.start.game" />
<Button fx:id="startButton" defaultButton="true" mnemonicParsing="false" onAction="#onPlayClick" text="%setup.start.game" />
</VBox>
7 changes: 0 additions & 7 deletions ludo/src/test/java/de/uniks/ludo/TestComponent.java

This file was deleted.

0 comments on commit e0c0a03

Please sign in to comment.