Example usage for javafx.fxml JavaFXBuilderFactory JavaFXBuilderFactory

List of usage examples for javafx.fxml JavaFXBuilderFactory JavaFXBuilderFactory

Introduction

In this page you can find the example usage for javafx.fxml JavaFXBuilderFactory JavaFXBuilderFactory.

Prototype

public JavaFXBuilderFactory() 

Source Link

Document

Default constructor.

Usage

From source file:retsys.client.controller.LoginController.java

private Initializable replaceSceneContent(String fxml) throws Exception {

    URL location = getClass().getResource(fxml);
    FXMLLoader fxmlLoader = new FXMLLoader();

    fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
    InputStream in = getClass().getResourceAsStream(fxml);
    Parent root;//w  ww  . j ava2s  .  c o m

    fxmlLoader.setLocation(location);
    AnchorPane page;
    try {
        page = (AnchorPane) fxmlLoader.load(in);
    } finally {
        in.close();
    }

    Scene scene = new Scene(page);
    scene.getStylesheets().add(this.getClass().getResource("/retsys/client/css/styles.css").toExternalForm());
    stage.setScene(scene);
    stage.setFullScreen(true);
    //stage.sizeToScene();

    return (Initializable) fxmlLoader.getController();
}

From source file:com.bekwam.mavenpomupdater.Main.java

@Override
public void start(Stage primaryStage) throws Exception {

    ////from ww  w. java2 s .co  m
    // handle command line options
    //
    Application.Parameters params = getParameters();

    List<String> unnamedList = params.getUnnamed();

    Options options = new Options();
    options.addOption("help", false, "Print this message");
    options.addOption("hidpi", false, "Use high-DPI scaling");

    CommandLineParser p = new BasicParser();
    CommandLine cmd = p.parse(options, unnamedList.toArray(new String[0]));

    HelpFormatter formatter = new HelpFormatter();

    if (cmd.hasOption("help")) {
        if (log.isDebugEnabled()) {
            log.debug("[START] running as help command");
        }
        formatter.printHelp("Main", options);
        return;
    }

    AbstractModule module = null;
    if (runningAsJNLP()) {

        if (log.isInfoEnabled()) {
            log.info("using jnlp module and jnlp favorites store");
        }
        module = new MPUJNLPModule();
    } else {

        if (log.isInfoEnabled()) {
            log.info("using standalone module and in-memory favorites store");
        }
        module = new MPUStandaloneModule();
    }

    //
    // setup google guice
    //
    final Injector injector = Guice.createInjector(module);

    BuilderFactory builderFactory = new JavaFXBuilderFactory();

    Callback<Class<?>, Object> guiceControllerFactory = clazz -> injector.getInstance(clazz);

    //
    // setup icons
    //
    primaryStage.getIcons().add(new Image("images/mpu_icon_64.png"));

    //
    // load fxml and wire controllers
    //
    FXMLLoader mainViewLoader = new FXMLLoader(getClass().getResource("mavenpomupdater.fxml"), null,
            builderFactory, guiceControllerFactory);
    Parent mainView = mainViewLoader.load();
    MainViewController mainViewController = mainViewLoader.getController();

    FXMLLoader alertViewLoader = new FXMLLoader(getClass().getResource("alert.fxml"), null, builderFactory,
            guiceControllerFactory);
    Parent alertView = alertViewLoader.load();

    //
    // i'm continuing this manual wiring to 1) accommodate a potential
    // bi-directional reference problem and 2) to make sure that guice
    // doesn't return different object for the main -> alert and alert ->
    // main dependency injections
    //

    final AlertController alertController = alertViewLoader.getController();
    mainViewController.alertController = alertController;
    alertController.mainViewControllerRef = new WeakReference<MainViewController>(mainViewController);

    //
    // add FlowPane, StackPane objects (defined in program and outside of 
    // FXML)
    //
    final FlowPane fp = new FlowPane();
    fp.setAlignment(Pos.CENTER);
    fp.getChildren().add(alertView);
    fp.getStyleClass().add("alert-background-pane");

    final StackPane sp = new StackPane();
    sp.getChildren().add(fp); // initially hide the alert
    sp.getChildren().add(mainView);

    //
    // setup scene
    //
    Scene scene = new Scene(sp);
    scene.getStylesheets().add("com/bekwam/mavenpomupdater/mpu.css");

    scene.setOnKeyPressed(keyEvent -> {
        KeyCode key = keyEvent.getCode();
        if (key == KeyCode.ESCAPE && (sp.getChildren().get(1) == fp)) {
            if (log.isDebugEnabled()) {
                log.debug("[ESCAPE]");
            }
            alertController.action();
        }
    });

    //
    // setup stage
    //
    primaryStage.setTitle("Maven POM Version Updater");
    primaryStage.setScene(scene);

    if (cmd.hasOption("hidpi")) {

        if (log.isInfoEnabled()) {
            log.info("running in Hi-DPI display mode");
        }
        primaryStage.setWidth(2560.0);
        primaryStage.setHeight(1440.0);
        primaryStage.setMinWidth(1920.0);
        primaryStage.setMinHeight(1080.0);

        mainViewController.adjustForHiDPI();

    } else {
        if (log.isInfoEnabled()) {
            log.info("running in normal display mode");
        }

        primaryStage.setWidth(1280.0);
        primaryStage.setHeight(800.0);
        primaryStage.setMinWidth(1024.0);
        primaryStage.setMinHeight(768.0);

    }

    primaryStage.show();
}

From source file:cz.lbenda.gui.controls.TextAreaFrmController.java

/** Create new instance return main node and controller of this node and sub-nodes */
public static Tuple2<Parent, TextAreaFrmController> createNewInstance() {
    URL resource = TextAreaFrmController.class.getResource(FXML_RESOURCE);
    try {/*from  w  w  w.j a v  a  2  s .c om*/
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(resource);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        Parent node = loader.load(resource.openStream());
        TextAreaFrmController controller = loader.getController();
        return new Tuple2<>(node, controller);
    } catch (IOException e) {
        LOG.error("Problem with reading FXML", e);
        throw new RuntimeException("Problem with reading FXML", e);
    }
}

From source file:cz.lbenda.dataman.db.frm.DbConfigFrmController.java

/** Create new instance return main node and controller of this node and sub-nodes */
public static Tuple2<Parent, DbConfigFrmController> createNewInstance() {
    URL resource = DbConfigFrmController.class.getResource(FXML_RESOURCE);
    try {//from w w  w.  j  a v a2 s  .  c o  m
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(resource);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        Parent node = loader.load(resource.openStream());
        DbConfigFrmController controller = loader.getController();
        return new Tuple2<>(node, controller);
    } catch (IOException e) {
        LOG.error("Problem with reading FXML", e);
        throw new RuntimeException("Problem with reading FXML", e);
    }
}

From source file:com.jf.javafx.Application.java

/**
 * Load a node and its controller.// w ww . j a v  a2s  .c  o  m
 * 
 * @param path
 * @return the node
 */
public Pair<Node, ?> createNode(String path) {
    final Application app = this;
    File fxml = getTemplateFile(path + ".fxml");
    Node node;
    Object controller = null;
    try {
        ResourceBundle bundle;
        try {
            bundle = getResourceBundle("controllers/" + path);
        } catch (Exception ex) {
            bundle = null;
        }

        FXMLLoader loader = new FXMLLoader(fxml.toURL(), bundle, new JavaFXBuilderFactory(),
                (Class<?> param) -> {
                    try {
                        Class cls = Controller.class;

                        if (cls.isAssignableFrom(param)) {
                            try {
                                return param.getConstructor(Application.class).newInstance(app);
                            } catch (Exception ex) {
                                Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
                                return param.newInstance();
                            }
                        } else {
                            return param.newInstance();
                        }
                    } catch (IllegalAccessException | IllegalArgumentException | InstantiationException
                            | SecurityException ex) {
                        MsgBox.showException(ex);
                        return null;
                    }
                });
        node = loader.load();
        controller = loader.getController();
    } catch (IOException ex) {
        MsgBox.showException(ex, "Error while navigate to path: " + path);

        // customize error screen
        AnchorPane p = new AnchorPane();

        //            StringWriter sw = new StringWriter();
        //            ex.printStackTrace(new PrintWriter(sw));
        //            p.getChildren().add(new Label(sw.toString()));

        node = p;
    }

    return new Pair(node, controller);
}

From source file:io.github.moosbusch.permagon.configuration.builder.spi.AbstractPermagonBuilder.java

public AbstractPermagonBuilder(PermagonApplicationContext applicationContext, Class<?> type) {
    this(applicationContext, type, new JavaFXBuilderFactory());
}