use of se.light.assembly64.fx.NullWindowOwner 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);
}
}
Aggregations