Merge branch 'feature/client_navigation' into 'main'

Feature/client navigation

See merge request cse1105/2025-2026/teams/csep-team-76!15
This commit is contained in:
Zhongheng Liu 2025-12-17 13:17:07 +01:00
commit ca1d7ab872

View file

@ -0,0 +1,41 @@
package client.utils;
import client.MyFXML;
import javafx.scene.Parent;
import javafx.scene.layout.Pane;
public class Navigation {
private final MyFXML myFXML;
private Pane screen;
/**
* Constructs a Navigation Object that uses a fxml object and Pane that will allow to switch UI screens
* @param x - a MyFXML Object
* @param y - a Pane Object
*/
public Navigation(MyFXML x, Pane y){
this.myFXML = x;
this.screen = y;
}
/**
* The show function takes in an FxmlPath and changes the current pane to the value given by the path
* using the load function of the myFXML object
* @param fxmlpath - FXML path provided to show the next pane
*/
public void show(String fxmlpath){
try{
var result = myFXML.load(Object.class, fxmlpath); //stores the result of the load method in result
Parent uiRoot = result.getValue();
screen.getChildren().setAll(uiRoot);
}
catch(Exception e) { //catches any failures thrown by the load method
System.err.println("Failed to load FXML file: " + fxmlpath);
throw new IllegalArgumentException("Cannot load FXML file: " + fxmlpath, e);
}
}
}