Examples of FXMLLoader


Examples of javafx.fxml.FXMLLoader

                location = new URL(locationString);
            } catch (final MalformedURLException e) {
                throw new RuntimeException(String.format("Cannot construct URL from string '%s'.", locationString), e);
            }
        }
        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);

        // Invoke "fxmlLoader.setTemplate(true)" if we are using JavaFX 8.0 or
        // higher to improve performance on objects that are created multiple times.
        try {
            final Method setTemplateMethod = FXMLLoader.class.getMethod("setTemplate", boolean.class);
            setTemplateMethod.invoke(fxmlLoader, Boolean.TRUE);
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            // We simply ignore this exception. It means that we are using
            // a JavaFX runtime prior to JavaFX 8.0.
        }

        // Actual instantiation of the component has to happen on the JavaFX thread.
        // We simply delegate the loading.
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                try {
                    final Object loaded = fxmlLoader.load();
                    if (loaded != instance) {
                        throw new IllegalStateException("Loading of FXML component went terribly wrong! :-(");
                    }
                } catch (final IOException e) {
                    throw new RuntimeException(e);
View Full Code Here

Examples of javafx.fxml.FXMLLoader

     */
    public Result load(final URL url, final ResourceBundle resources) throws IOException  {

        fxmlLoadingScope.enter(this);

        final FXMLLoader loader = new FXMLLoader();
        loader.setLocation(url);
        if (resources != null) {
            loader.setResources(resources);
        }
        loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(final Class<?> param) {
                // Use our Guice injector to fetch an instance of the desired
                // controller class
                return param == null ? null : injector.getInstance(param);
            }
        });

        final Node root = (Node) loader.load(url.openStream());

        // Prepares the result that is being returned after loading the FXML hierarchy.
        final Result result = new Result();
        result.location.set(loader.getLocation());
        result.resources.set(loader.getResources());
        result.controller.set(loader.getController());
        result.root.set(root);
        result.charset.set(loader.getCharset());

        fxmlLoadingScope.exit();

        return result;

View Full Code Here

Examples of javafx.fxml.FXMLLoader

                location = new URL(locationString);
            } catch (final MalformedURLException e) {
                throw new RuntimeException(String.format("Cannot construct URL from string '%s'.", locationString), e);
            }
        }
        final FXMLLoader fxmlLoader = new FXMLLoader(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);

        // Actual instantiation of the component has to happen on the JavaFX thread.
        // We simply delegate the loading.
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                try {
                    final Object loaded = fxmlLoader.load();
                    if (loaded != instance) {
                        throw new IllegalStateException("Loading of FXML component went terribly wrong! :-(");
                    }
                } catch (final IOException e) {
                    throw new RuntimeException(e);
View Full Code Here

Examples of javafx.fxml.FXMLLoader

    private void showMainStage(final LauncherConfiguration launcherConfiguration) throws IOException {
        mainStage = new Stage(StageStyle.DECORATED);

        // launcher frame
        FXMLLoader fxmlLoader;
        Parent root;
        /* Fall back to default language if loading the FXML file files with the current locale */
        try {
            fxmlLoader = BundleUtils.getFXMLLoader("application");
            root = (Parent) fxmlLoader.load();
        } catch (IOException e) {
            fxmlLoader = BundleUtils.getFXMLLoader("application");
            fxmlLoader.setResources(ResourceBundle.getBundle("org.terasology.launcher.bundle.LabelsBundle", Languages.DEFAULT_LOCALE));
            root = (Parent) fxmlLoader.load();
        }
        final ApplicationController controller = fxmlLoader.getController();
        controller.initialize(launcherConfiguration.getLauncherDirectory(), launcherConfiguration.getDownloadDirectory(), launcherConfiguration.getTempDirectory(),
            launcherConfiguration.getLauncherSettings(), launcherConfiguration.getGameVersions(), mainStage);

        Scene scene = new Scene(root);
        scene.getStylesheets().add(BundleUtils.getStylesheet("css_terasology"));
View Full Code Here

Examples of javafx.fxml.FXMLLoader

        try {
            logger.info("Current Locale: {}", Languages.getCurrentLocale());
            Stage settingsStage = new Stage(StageStyle.UNDECORATED);
            settingsStage.initModality(Modality.APPLICATION_MODAL);

            FXMLLoader fxmlLoader;
            Parent root;
            /* Fall back to default language if loading the FXML file files with the current locale */
            try {
                fxmlLoader = BundleUtils.getFXMLLoader("settings");
                root = (Parent) fxmlLoader.load();
            } catch (IOException e) {
                fxmlLoader = BundleUtils.getFXMLLoader("settings");
                fxmlLoader.setResources(ResourceBundle.getBundle("org.terasology.launcher.bundle.LabelsBundle", Languages.DEFAULT_LOCALE));
                root = (Parent) fxmlLoader.load();
            }

            final SettingsController settingsController = fxmlLoader.getController();
            settingsController.initialize(launcherDirectory, downloadDirectory, launcherSettings, gameVersions, settingsStage);

            Scene scene = new Scene(root);
            settingsStage.setScene(scene);
            settingsStage.showAndWait();
View Full Code Here

Examples of javafx.fxml.FXMLLoader

        };
        this.lazyLoader = (Future<FXMLLoader>) THREAD_POOL.submit(initialization);
    }

    FXMLLoader loadAsynchronously(final URL resource, ResourceBundle bundle, final String conventionalName) throws IllegalStateException {
        final FXMLLoader loader = new FXMLLoader(resource, bundle);
        loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> p) {
                return InjectionProvider.instantiatePresenter(p);
            }
        });
        final Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    loader.load();
                } catch (IOException ex) {
                    throw new IllegalStateException("Cannot load " + conventionalName, ex);
                }
            }
        };
View Full Code Here

Examples of javafx.fxml.FXMLLoader

    private void init(Class clazz, String conventionalName) {
        final URL resource = clazz.getResource(conventionalName);
        String bundleName = getBundleName();
        ResourceBundle bundle = getResourceBundle(bundleName);
        this.loader = new FXMLLoader(resource, bundle);
        this.loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> p) {
                return InjectionProvider.instantiatePresenter(p);
            }
View Full Code Here

Examples of javafx.fxml.FXMLLoader

        this.url = url;
    }

    @Override
    protected Node createRootNode() throws NodeCreationException {
        fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(url);
        try {
            return (Node) fxmlLoader.load();
        } catch (IOException e) {
            throw new NodeCreationException(e.getMessage(), e);
View Full Code Here

Examples of javafx.fxml.FXMLLoader

        root = (Parent) FXMLLoader.load(getClass().getResource("Main.fxml"));
        Scene scene = new Scene(root);
        scene.setRoot(root);
       

        FXMLLoader fxmlLoader = new FXMLLoader();

//        FooController fooController = (FooController) fxmlLoader.getController();
        TgFX TgFXController = (TgFX) fxmlLoader.getController();



        stage.setMinHeight(648);
        stage.setMinWidth(1152);
View Full Code Here

Examples of javafx.fxml.FXMLLoader

        primaryStage.setTitle("Undecorator Scene Demo");

        // The UI (Client Area) to display
        Region root = null;
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ClientArea.fxml"));
            fxmlLoader.setController(this);
            root = (Region) fxmlLoader.load();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // The Undecorator as a Scene
        final UndecoratorScene undecoratorScene = new UndecoratorScene(primaryStage, root);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.