private Stage createStage(Stage mainStage) { FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("event-log.fxml")); loader.setController(this); final Stage dialog = new Stage(); dialog.initOwner(mainStage.getScene().getWindow()); dialog.initModality(Modality.NONE); Parent root; try { root = loader.load(); } catch (IOException e) { throw new IllegalStateException(e); } Scene scene = new Scene(root); dialog.setScene(scene); return dialog; }
@Override public Node load(String name) { final FXMLLoader loader = fxmlLoader(); final String filename = FXML_PREFIX + name + FXML_SUFFIX; loader.setLocation(InjectionLoaderImpl.class.getResource(filename)); try { return loader.load(); } catch (final IOException ex) { throw new SpeedmentToolException( "Error! Could not find FXML-file: " + filename + ".", ex ); } }
FXMLLoader fxmlLoader = new FXMLLoader(DesignerUtil.getFxml("auxclasspath-setup-popup.fxml")); fxmlLoader.setControllerFactory(type -> { if (type == AuxclasspathSetupController.class) { return this; stage.setScene(new Scene(fxmlLoader.load())); } catch (IOException e) { e.printStackTrace();
public FXMLLoader fxmlLoader() { final FXMLLoader loader = new FXMLLoader(StandardCharsets.UTF_8); loader.setControllerFactory(clazz -> MapStream.of(constructors) .filterKey(clazz::isAssignableFrom) .values() .findFirst() .map(Supplier::get) .map(injector::inject) .orElseThrow(() -> new SpeedmentToolException( "FXML Controller '" + clazz.getName() + "' have not been installed in " + getClass().getSimpleName() + "." ))); return loader; }
/** * Load a content from an FXML definition */ protected Node loadFXML(URL fxmlLocation) { try { if (fxmlLocation != null) { final FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setLocation(fxmlLocation); fxmlLoader.setController(this); fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory()); return fxmlLoader.load(); } } catch (final IOException e) { e.printStackTrace(); } return null; }
public void run() { // Parent root; try { // root = FXMLLoader.load(getClass().getResource("/eu/agrosense/client/grid/impl/GridPropertiesElement.fxml")); // Scene scene = new Scene(root); // fxPanel.setScene(scene); String fxml = "GridPropertiesElement.fxml"; FXMLLoader loader = new FXMLLoader(); InputStream in = GridPropertiesElement.class.getResourceAsStream(fxml); loader.setBuilderFactory(new JavaFXBuilderFactory()); loader.setLocation(GridPropertiesElement.class.getResource(fxml)); AnchorPane page; try { page = (AnchorPane) loader.load(in); } finally { in.close(); } Scene scene = new Scene(page, 800, 600); fxPanel.setScene(scene); controller = loader.getController(); controller.setGrid(gridDataObject.getLookup().lookup(Grid.class)); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } });
@Override public void start(Stage stage) throws Exception { FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Scene.fxml")); Parent root = loader.load(); Scene scene = new Scene(root); scene.getStylesheets().add("/styles/Styles.css"); stage.setTitle("Pose List 3D Plot"); stage.setScene(scene); FXMLController controller = loader.getController(); controller.setStage(stage); stage.show(); }
/** * Loads and parses a fxml document. * * @param fxml * the stream containing the document * @param closeStream * close the stream after processing */ public void load(InputStream fxml, boolean closeStream) throws Exception { FXMLLoader loader = new FXMLLoader(); fxmlRoot = loader.load(fxml); if (closeStream) fxml.close(); }
/** * init fxml when loaded. */ @PostConstruct public void init() { try { popup = new JFXPopup(FXMLLoader.load(getClass().getResource("/fxml/ui/popup/DemoPopup.fxml"))); } catch (IOException ioExc) { ioExc.printStackTrace(); } burger1.setOnMouseClicked((e) -> popup.show(rippler1, PopupVPosition.TOP, PopupHPosition.LEFT)); burger2.setOnMouseClicked((e) -> popup.show(rippler2, PopupVPosition.TOP, PopupHPosition.RIGHT)); burger3.setOnMouseClicked((e) -> popup.show(rippler3, PopupVPosition.BOTTOM, PopupHPosition.LEFT)); burger4.setOnMouseClicked((e) -> popup.show(rippler4, PopupVPosition.BOTTOM, PopupHPosition.RIGHT)); } }
public WorldPane() { log.finest("constructing world pane"); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("WorldPane.fxml")); fxmlLoader.setRoot(this); fxmlLoader.setController(this); try { fxmlLoader.load(); } catch (IOException exception) { throw new RuntimeException(exception); } }
public static <O, C> FXMLData<O, C> loadWithController(@NonNull final ClassLoader classloader, @Nullable URL url, @Nullable InputStream stream, @Nullable ResourceBundle resourceBundle, @Nullable final BuilderFactory builderFactory, @Nullable Callback<Class<?>, Object> controllerFactory) throws IOException { FXMLLoader loader = new FXMLLoader(); loader.setLocation(url); loader.setClassLoader(classloader); loader.setResources(resourceBundle); if (builderFactory == null) { loader.setBuilderFactory(new JavaFXBuilderFactory(classloader)); } else { loader.setBuilderFactory(new BuilderFactory() { private JavaFXBuilderFactory orgBuilder = new JavaFXBuilderFactory(classloader); loader.setControllerFactory(controllerFactory); O value = loader.load(stream); if (value != null) { return new FXMLData<O, C>(value, (C) loader.getController()); O value = loader.load(in); if (value != null) { return new FXMLData<O, C>(value, (C) loader.getController());
final FXMLLoader loader = new FXMLLoader(); loader.setLocation(url); if (resources != null) { loader.setResources(resources); loader.setBuilderFactory(injector.getInstance(FXMLComponentBuilderFactory.class)); loader.setControllerFactory(new Callback<Class<?>, Object>() { @Override public Object call(final Class<?> param) { final Node root = (Node) loader.load(url.openStream()); result.location.set(loader.getLocation()); result.resources.set(loader.getResources()); result.controller.set(loader.getController()); result.root.set(root); result.charset.set(loader.getCharset());
final FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setLocation(location); final String resourcesString = annotation.resources(); if (!resourcesString.isEmpty()) { fxmlLoader.setResources(ResourceBundle.getBundle(resourcesString)); fxmlLoader.setCharset(Charset.forName(annotation.charset())); fxmlLoader.setController(instance); fxmlLoader.setRoot(instance); final Object loaded = fxmlLoader.load(); if (loaded != instance) { throw new IllegalStateException("Loading of FXML component went terribly wrong! :-(");
public static <M extends Model> FXMLComponentBase loadFXML(final M model, final String fxmlPath, final String bundlePath) { final FXMLLoader fxmlLoader = new FXMLLoader(); fxmlLoader.setControllerFactory(fxmlControllerFactory); fxmlLoader.setLocation(convertFxmlUrl(model, fxmlPath)); fxmlLoader.setResources(ResourceBundle.getBundle(bundlePath)); boolean error = false; try { error = fxmlLoader.getLocation() == null; if (error) { node = TextBuilder.create().text(FXML_ERROR_NODE_LABEL.getText(fxmlPath)).build(); } else { node = (Node) fxmlLoader.load(fxmlLoader.getLocation().openStream()); final FXMLController<M, ?> fxmlController = (FXMLController<M, ?>) fxmlLoader.getController(); if (!error && !(fxmlLoader.getController() instanceof AbstractFXMLController)) { throw new CoreRuntimeException(BAD_FXML_CONTROLLER_ANCESTOR.getText(fxmlLoader.getController().getClass().getCanonicalName()));
private FXMLLoader createLoader(final Object controller, String fxmlName, ViewConfiguration viewConfiguration) throws FxmlLoadException { Class<?> controllerClass = controller.getClass(); String foundFxmlName = getFxmlName(controllerClass); if (fxmlName != null) { foundFxmlName = fxmlName; } if (foundFxmlName == null) { throw new FxmlLoadException("No FXML File specified!"); } FXMLLoader fxmlLoader = new FXMLLoader( controllerClass.getResource(foundFxmlName)); fxmlLoader.setBuilderFactory(viewConfiguration.getBuilderFactory()); fxmlLoader.setCharset(viewConfiguration.getCharset()); fxmlLoader.setResources(viewConfiguration.getResources()); fxmlLoader.setController(controller); fxmlLoader.setControllerFactory(c -> controller); return fxmlLoader; }
@SuppressWarnings("null") @Override public Node getGraphicNode(URI uri) throws IOException { if( uri.isPlatformPlugin() ) { Bundle b = org.eclipse.core.runtime.Platform.getBundle(uri.segment(1)); if( b != null ) { StringBuilder sb = new StringBuilder(); for (int i = 2; i < uri.segmentCount(); i++) { if (sb.length() != 0) { sb.append("/"); //$NON-NLS-1$ } sb.append(uri.segment(i)); } FXMLLoader loader = new FXMLLoader(); loader.setClassLoader(b.adapt(BundleWiring.class).getClassLoader()); URL url = b.getResource(sb.toString()); loader.setLocation(url); return loader.load(); } else { throw new IOException("Unknown bundle '"+uri.segment(1)+"'"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { return FXMLLoader.load(new URL(uri.toString())); } } }
try { Stage popup = new Stage(); FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("generate-xpath-from-stack-trace.fxml")); Parent root = loader.load(); Button button = (Button) loader.getNamespace().get("generateButton"); TextArea area = (TextArea) loader.getNamespace().get("stackTraceArea");
public void openNetworkSettings() { final FXMLLoader settings = FXUtil.load(SettingsController.class); try { final Node node = settings.load(); final SettingsController controller = settings.getController(); final Stage stage = new Stage(); final Scene scene = new Scene(new Group(node)); stage.setTitle("Network Settings"); stage.setScene(scene); stage.initModality(Modality.APPLICATION_MODAL); controller.setOnClose(e -> stage.close()); stage.show(); } catch (IOException ex) { Logger.getLogger(BrowserFXController.class.getName()).log(Level.SEVERE, "Unable to open settings", ex); } }
@Nonnull protected FXMLLoader createFxmlLoader(@Nonnull URL viewResource) { return new FXMLLoader(viewResource); }
/** * Creates a new {@link FXMLLoader}. <br/> <br/> * Sets: * <ul> * <li>the {@link ClassLoader} to the ClassLoader of the specified type</li> * <li>the {@link ResourceBundle} by looking for a {@code Bundle.properties} file in the package of the specified type (or a locale specific derivation) using the default {@link Locale}</li> * </ul> * @param type the type specifing the {@link ClassLoader} and the package of the {@code Bundle.properties} file * @return a {@link FXMLLoader} */ public static FXMLLoader createFXMLLoader(Class<?> type) { FXMLLoader loader = new FXMLLoader(); loader.setClassLoader(type.getClassLoader()); loader.setResources(Resources.getResourceBundle(type)); return loader; } /**