List of usage examples for javafx.fxml FXMLLoader setControllerFactory
public void setControllerFactory(Callback<Class<?>, Object> controllerFactory)
From source file:com.ucu.seguridad.views.AbstractFxmlView.java
FXMLLoader loadSynchronously(URL resource, ResourceBundle bundle) throws IllegalStateException { FXMLLoader loader = new FXMLLoader(resource, bundle); loader.setControllerFactory(this::createControllerForType); try {/*w ww . j av a 2 s . com*/ loader.load(); } catch (IOException ex) { throw new IllegalStateException("Cannot load " + getConventionalName(), ex); } return loader; }
From source file:acmi.l2.clientmod.xdat.XdatEditor.java
@Override public void start(Stage primaryStage) throws Exception { this.stage = primaryStage; FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"), interfaceResources); loader.setClassLoader(getClass().getClassLoader()); loader.setControllerFactory(param -> new Controller(XdatEditor.this)); Parent root = loader.load();/*from w w w . java 2s . c om*/ controller = loader.getController(); primaryStage.setTitle("XDAT Editor"); primaryStage.setScene(new Scene(root)); primaryStage.show(); postShow(); }
From source file:com.rvantwisk.cnctools.controllers.TaskEditController.java
public void setTask(final Project project, final TaskRunnable taskRunnable) { currentTaskRunnable = taskRunnable;//from w w w.j a v a2s . com tasksController = (MillTaskController) applicationContext.getBean(taskRunnable.getClassName()); // Ensure we supply a non-null model to the operation if (taskRunnable.getMilltaskModel() == null) { TaskModel m = tasksController.createNewModel(); taskRunnable.setMilltaskModel(m); tasksController.setModel(m); } else { tasksController.setModel(taskRunnable.getMilltaskModel()); } tasksController.setProject(project); // get the resource path of the main class for this MillTask List<String> path = new ArrayList<>(Arrays.asList(taskRunnable.getClassName().split("\\."))); path.remove(path.size() - 1); // verify the fxml location final String tpackage = StringUtils.join(path, "/") + "/" + taskRunnable.getFxmlFileName(); if (tpackage.contains("../") || tpackage.contains("http:") || tpackage.contains("https:")) { throw new RuntimeException( "Resource for ApplicapableMillTask with name [" + taskRunnable.getName() + "] is invalid."); } try { FXMLLoader loader = new FXMLLoader( tasksController.getClass().getResource(taskRunnable.getFxmlFileName())); loader.setControllerFactory(new Callback<Class<?>, Object>() { @Override public Object call(Class<?> aClass) { return tasksController; } }); lbHeader.setText(taskRunnable.getName()); AnchorPane aPane = (AnchorPane) loader.load(); taskPane.getChildren().add(aPane); taskPane.setBottomAnchor(aPane, 0.0); taskPane.setTopAnchor(aPane, 0.0); taskPane.setRightAnchor(aPane, 0.0); taskPane.setLeftAnchor(aPane, 0.0); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:ca.wumbo.doommanager.client.controller.CoreController.java
/** * The starting point of the application. The Core should pass the first * stage (what should be the primary stage) to this method, which will in * turn cascade and create all the //from w w w . j ava2 s . c o m * * @param primaryStage * The stage created by the main JavaFX thread at the beginning. * * @throws IOException * If there is an error loading the FXML file. * * @throws NullPointerException * If the argument is null. */ public void start(Stage primaryStage) throws IOException { if (primaryStage == null) throw new NullPointerException("Passed a null stage to start."); // Load the required data into ourselves. FXMLLoader loader = new FXMLLoader(Client.class.getResource(fxmlPath)); loader.setControllerFactory((cls) -> { return this; }); loader.load(); // Add the loaded tab panes into their respective tabs. mainTab.setContent(startController.getRootPane()); fileEditorTab.setContent(fileEditorController.getRootPane()); mapEditorTab.setContent(mapEditorController.getRootPane()); textureDatabaseTab.setContent(textureDatabaseController.getRootPane()); serverBrowserTab.setContent(serverBrowserController.getRootPane()); ircTab.setContent(ircController.getRootPane()); optionsTab.setContent(optionsController.getRootPane()); consoleTab.setContent(consoleController.getRootPane()); // Set up the scene and stage and display it. ClientConfig clientConfig = config.getClientConfig(); Scene primaryScene = new Scene(rootBorderPane, clientConfig.getStartingWidth(), clientConfig.getStartingHeight()); scene = primaryScene; scene.getStylesheets().add(cssPath); stage = primaryStage; stage.setTitle(applicationTitle + " v" + applicationVersion); stage.setMaximized(clientConfig.isStartMaximized()); stage.setScene(scene); stage.show(); // Start the ticker now that everything is ready to go. ticker = new JavaFXTicker((int) (TICRATE_NANO / MS_PER_NANO), event -> tick()); ticker.start(); // Set up the network connections by starting the selector. if (clientSelector.errorOccured()) { Alert alert = new Alert(Alert.AlertType.WARNING, "Unable to request network channels from OS."); // TODO - make less cryptic. alert.show(); } else if (!clientSelector.selectorIsOpen()) { Alert alert = new Alert(Alert.AlertType.WARNING, "Unable to open network channels."); // TODO - make less cryptic. alert.show(); } // Set up the stage exit handling. stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> ticker.stop()); log.info("Welcome to " + applicationTitle + " v" + applicationVersion + "!"); }
From source file:acmi.l2.clientmod.xdat.Controller.java
private Node loadScriptTabContent() { try {/*from ww w . ja v a 2 s. c o m*/ FXMLLoader loader = new FXMLLoader(getClass().getResource("scripting/main.fxml")); loader.setClassLoader(getClass().getClassLoader()); loader.setControllerFactory(param -> new acmi.l2.clientmod.xdat.scripting.Controller(editor)); return wrap(loader.load()); } catch (IOException e) { log.log(Level.WARNING, "Couldn't load script console", e); } return null; }
From source file:ubicrypt.ui.StackNavigator.java
public <R> Parent loadFrom(final Optional<R> data) { log.debug("fxml:{}", levels.peek()); final FXMLLoader loader = new FXMLLoader( StackNavigator.class.getResource(format("/fxml/%s.fxml", levels.peek())), bundle); loader.setControllerFactory(controllerFactory); try {//from w w w. j a va2s . c om Parent parent; if (root != null) { root.getChildren().setAll((Node) loader.load()); parent = (Parent) root.getChildren().get(0); } else { parent = loader.load(); } Object controller = loader.getController(); stream(getAllFields(controller.getClass())).filter(field -> field.getType() == StackNavigator.class) .forEach(field -> { try { writeField(field, controller, this, true); } catch (IllegalAccessException e) { log.error("error setting field:{} in:{}", field, controller); Throwables.propagate(e); } log.debug("{} inject stack navigator", controller.getClass().getSimpleName()); }); if (Consumer.class.isAssignableFrom(controller.getClass())) { data.ifPresent(((Consumer<R>) controller)::accept); } return parent; } catch (final IOException e) { Throwables.propagate(e); } return null; }