Example usage for javafx.fxml FXMLLoader FXMLLoader

List of usage examples for javafx.fxml FXMLLoader FXMLLoader

Introduction

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

Prototype

public FXMLLoader(Charset charset) 

Source Link

Document

Creates a new FXMLLoader instance.

Usage

From source file:com.sunkur.springjavafxcontroller.screen.ScreensContoller.java

public void loadScreen(String fxml) {
    BaseScreenController oldScreenController = this.getCurrentController();
    try {/*from w  w w .ja  v  a2s  .c o m*/

        Class controllerClass = FXMLUtils.getControllerClass(fxml);
        final BaseScreenController fxmlController = (BaseScreenController) applicationContext
                .getBean(controllerClass);

        if (this.screens.get(fxmlController.getScreenId()) == null) {
            FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));
            loader.setControllerFactory(new Callback<Class<?>, Object>() {
                @Override
                public Object call(Class<?> aClass) {
                    return fxmlController;
                }
            });
            Parent root = loader.load();
            fxmlController.setRoot(root);
            this.screens.put(fxmlController.getScreenId(), fxmlController);
        }

        this.currentScreenId = fxmlController.getScreenId();
        swapScreen(getCurrentController().getRoot());
        if (oldScreenController != null) {
            if (oldScreenController.getClass().isAnnotationPresent(ScreenScoped.class)) {
                this.screens.remove(oldScreenController.getScreenId());
                this.screenScope.remove(oldScreenController.getScreenId());
            }
        }

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:tworpus.client.mainwindow.MainWindowController.java

@FXML
public void showCorpusForm() {
    try {/*  w  ww  .jav  a 2s .co  m*/
        FXMLLoader loader = new FXMLLoader(createCorpusFXML);
        Pane pane = (Pane) loader.load();

        // @TODO: may be deleted. Just for demonstation how to get controller
        CreateCorpusController controller = loader.getController();

        maincontent = pane;
        borderPane.centerProperty().set(maincontent);
    } catch (IOException ex) {
        Logger.getLogger(MainWindowController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:context.ui.control.codebooknetwork.CodebookNetworkController.java

/**
 *
 *//*w ww. j  a v  a 2s . com*/
public CodebookNetworkController() {
    super();
    try {
        setTaskname(NamingPolicy.generateTaskName(CodebookNetworkTaskInstance.class));
        setTaskInstance(new CodebookApplicationTaskInstance(getTaskname()));

        FXMLLoader loader2 = new FXMLLoader(
                getClass().getResource(CodebookNetworkConfigurationController.path));
        Parent s2Content = (Parent) loader2.load();
        configurationController = (CodebookNetworkConfigurationController) loader2.getController();

        setStep2Content(s2Content);

        super.postInitialize();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:spdxedit.license.LicenseExtractControl.java

public Pane getUi() {
    try {/*from w ww . ja  va2s  .  com*/
        FXMLLoader loader = new FXMLLoader(
                LicenseExtractControl.class.getResource("/ExtractLicenseDialog.fxml"));
        loader.setController(this);
        Pane pane = loader.load();
        return pane;
    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load scene for License editor dialog");
    }
}

From source file:com.toyota.carservice.config.config2.java

public Object newStage2(Stage stage, Button lb, String load, String judul, boolean resize, StageStyle style,
        boolean maximized) {
    try {/*from   ww w .j  av  a  2  s .  c om*/
        Stage st = new Stage();
        stage = (Stage) lb.getScene().getWindow();
        FXMLLoader root = new FXMLLoader(getClass().getResource(load));

        Scene scene = new Scene(root.load());
        st.initStyle(style);
        st.setResizable(resize);
        st.setMaximized(maximized);
        st.setTitle(judul);
        st.setScene(scene);
        ApplicationContext appContex = config.getInstance().getApplicationContext();
        Resource resource = appContex.getResource("classpath:com/toyota/carservice/img/kallatoyota.png");
        st.getIcons().add(new Image(resource.getURI().toString()));
        st.show();
        stage.close();
        return root.getController();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.esri.geoevent.test.performance.ui.ProducerUI.java

@Override
public void start(Stage primaryStage) {
    String modeStr = "Producer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();//from   w  ww. jav a2s  .c  om
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {
    case Producer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ProducerController();
        break;
    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        ProducerUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.esri.geoevent.test.performance.ui.ConsumerUI.java

@Override
public void start(Stage primaryStage) {

    String modeStr = "Consumer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();/*from  ww  w .  j a  v  a2 s.  c o m*/
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {

    case Consumer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ConsumerController();
        break;

    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        ConsumerUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.fishbeans.app.FXMLComponentBase.java

private FXMLLoader doLoad(URL fxml) throws IllegalStateException {

    FXMLLoader loader = new FXMLLoader(fxml);
    loader.setControllerFactory(this::createControllerAsBean);

    try {//from  w  w w  .  j a v  a2 s .  com
        loader.load();
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }

    return loader;
}

From source file:com.esri.geoevent.test.performance.ui.OrchestratorUI.java

@Override
public void start(Stage primaryStage) {

    Parameters parameters = getParameters();
    Map<String, String> args = parameters.getNamed();
    String modeStr = args.get("mode");
    if (modeStr == null) {
        modeStr = "Orchestrator";
    }//  w ww  .ja v a2s  .  co  m
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {

    case Orchestrator:
        fxmlFile = "Orchestrator.fxml";
        //controller = new OrchestratorController();
        break;
    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        // set the stage on the orchestrator
        if (loader.getController() instanceof OrchestratorController) {
            OrchestratorController orchestratorController = loader.getController();
            orchestratorController.setStage(primaryStage);
        }

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        OrchestratorUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:io.uploader.drive.auth.webbrowser.SimpleBrowserImpl.java

public SimpleBrowserImpl(Stage stage, String url) throws IOException {

    super();/*from ww w .j  a  v a 2s  .  co m*/

    Preconditions.checkNotNull(stage);

    this.stage = stage;
    stage.setTitle("Drive Uploader - Authentication");
    UiUtils.setStageAppSize(stage);
    Scene scene = new Scene(new Group());

    AnchorPane root = new AnchorPane();

    final WebView browser = new WebView();
    webEngine = browser.getEngine();

    /*
    Menu settingsMenu = new Menu ("Settings") ;
    MenuItem proxy = new MenuItem ("Proxy") ;
    settingsMenu.getItems().add(proxy) ;
    MenuBar menuBar = new MenuBar () ;
    menuBar.getMenus().add(settingsMenu) ;
    proxy.setOnAction(new EventHandler<ActionEvent> () {
            
     @Override
     public void handle(ActionEvent event) {
    try {
       ProxySettingDialog dlg = new ProxySettingDialog (stage, Configuration.INSTANCE) ;
       dlg.showDialog();
    } catch (IOException e) {
       logger.error("Error occurred while opening the proxy setting dialog", e);
    }
     }});*/

    FXMLLoader mainMenuLoader = new FXMLLoader(getClass().getResource("/fxml/MainMenu.fxml"));
    VBox mainMenuBar = (VBox) mainMenuLoader.load();
    AnchorPane.setTopAnchor(mainMenuBar, 0.0);
    AnchorPane.setLeftAnchor(mainMenuBar, 0.0);
    AnchorPane.setRightAnchor(mainMenuBar, 0.0);
    MainMenuController mainMenuController = mainMenuLoader.<MainMenuController>getController();
    mainMenuController.setOwner(stage);
    mainMenuController.setConfiguration(Configuration.INSTANCE);
    mainMenuController.hideAccountMenu(true);

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);
    scrollPane.setFitToWidth(true);
    scrollPane.setFitToHeight(true);

    if (StringUtils.isNotEmpty(url)) {
        goTo(url);
    }

    if (DriveUploader.isMacOsX()) {
        AnchorPane.setTopAnchor(scrollPane, 5.0);
    } else {
        AnchorPane.setTopAnchor(scrollPane, 35.0);
    }
    AnchorPane.setLeftAnchor(scrollPane, 5.0);
    AnchorPane.setRightAnchor(scrollPane, 5.0);
    AnchorPane.setBottomAnchor(scrollPane, 5.0);

    root.getChildren().add(mainMenuBar);
    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
}