Search in sources :

Example 1 with BaseGuiController

use of se.light.assembly64.model.BaseGuiController in project assembly64fx by freabemania.

the class GuiUtils method noShowDialog.

public static <T extends BaseGuiController> T noShowDialog(String fxmlName, Boolean modal, Boolean bare, String title, Window owner, Object... params) throws RuntimeException {
    try {
        Stage stage = new Stage();
        GuiUtils.attachIconToStage(stage);
        if (modal) {
            stage.initModality(Modality.WINDOW_MODAL);
        } else {
            stage.initModality(Modality.NONE);
        }
        if (bare) {
            stage.initStyle(StageStyle.UNDECORATED);
        }
        if (owner instanceof NullWindowOwner) {
            stage.initOwner(null);
        } else if (owner != null) {
            stage.initOwner(owner);
        } else {
            Scene rootScene = (Scene) GlobalRepoService.getInstance().get("rootscene");
            if (rootScene != null) {
                stage.initOwner(rootScene.getWindow());
            }
        }
        FXMLLoader loader = new FXMLLoader(Support.resolveMain().getClass().getResource(fxmlName));
        Parent root = (Parent) loader.load();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle(title);
        T controller = loader.getController();
        controller.setStage(stage);
        Optional<Method> m = Arrays.stream(controller.getClass().getMethods()).filter(method -> method.getName().equals("init")).findFirst();
        if (m.isPresent()) {
            m.get().invoke(controller, params);
        }
        return controller;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StageStyle(javafx.stage.StageStyle) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) Modality(javafx.stage.Modality) SystemUtils(org.apache.commons.lang3.SystemUtils) MouseEvent(javafx.scene.input.MouseEvent) Event(javafx.event.Event) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) Parent(javafx.scene.Parent) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) Support(se.light.assembly64.Support) Optional(java.util.Optional) Window(javafx.stage.Window) TableView(javafx.scene.control.TableView) Method(java.lang.reflect.Method) Image(javafx.scene.image.Image) BaseGuiController(se.light.assembly64.model.BaseGuiController) Parent(javafx.scene.Parent) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) Stage(javafx.stage.Stage) Method(java.lang.reflect.Method) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader)

Aggregations

Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 Event (javafx.event.Event)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Parent (javafx.scene.Parent)1 Scene (javafx.scene.Scene)1 TableView (javafx.scene.control.TableView)1 Image (javafx.scene.image.Image)1 MouseEvent (javafx.scene.input.MouseEvent)1 Modality (javafx.stage.Modality)1 Stage (javafx.stage.Stage)1 StageStyle (javafx.stage.StageStyle)1 Window (javafx.stage.Window)1 SystemUtils (org.apache.commons.lang3.SystemUtils)1 Support (se.light.assembly64.Support)1 NullWindowOwner (se.light.assembly64.fx.NullWindowOwner)1 BaseGuiController (se.light.assembly64.model.BaseGuiController)1 GlobalRepoService (se.light.assembly64.service.GlobalRepoService)1