- loadScene method to load into current stage - loadPopupScene method to load into a new window - icon added to popup windows - load methods return Controller of the new scee - KeyBindingsController extends new Controller class and works correctly #story[1261]main
parent
1073113589
commit
4a0d04d7ab
@ -0,0 +1,62 @@
|
|||||||
|
package visualiser.Controllers2;
|
||||||
|
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import visualiser.app.App;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract controller class to give each subclass the functionality to load
|
||||||
|
* a new scene into the existing stage, or create a new popup window.
|
||||||
|
*/
|
||||||
|
public abstract class Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to load a new scene in the currently open stage.
|
||||||
|
* @param fxmlUrl the URL of the FXML file to be loaded
|
||||||
|
* @return the controller of the new scene
|
||||||
|
* @throws IOException if there is an issue with the fxmlUrl
|
||||||
|
*/
|
||||||
|
protected Controller loadScene(String fxmlUrl) throws IOException {
|
||||||
|
FXMLLoader loader = new FXMLLoader();
|
||||||
|
loader.setLocation(getClass().getResource(fxmlUrl));
|
||||||
|
Parent root = loader.load();
|
||||||
|
Stage stage = App.getStage();
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
|
||||||
|
return loader.getController();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to load a scene in a new separate popup stage.
|
||||||
|
* @param fxmlUrl the URL of the FXML file to be loaded
|
||||||
|
* @param title title for the new window
|
||||||
|
* @param modality modality settings for popup window
|
||||||
|
* @return the controller of the new scene
|
||||||
|
* @throws IOException if there is an issue with the fxmlUrl
|
||||||
|
*/
|
||||||
|
protected Controller loadPopupScene(String fxmlUrl, String title, Modality
|
||||||
|
modality) throws IOException {
|
||||||
|
FXMLLoader loader = new FXMLLoader();
|
||||||
|
loader.setLocation(getClass().getResource(fxmlUrl));
|
||||||
|
Parent root = loader.load();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.initModality(modality);
|
||||||
|
stage.setTitle(title);
|
||||||
|
stage.centerOnScreen();
|
||||||
|
stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("images/SailIcon.png")));
|
||||||
|
Scene scene = new Scene(root);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
|
||||||
|
return loader.getController();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue