Example usage for javafx.fxml FXMLLoader load

List of usage examples for javafx.fxml FXMLLoader load

Introduction

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

Prototype

public <T> T load() throws IOException 

Source Link

Document

Loads an object hierarchy from a FXML document.

Usage

From source file:com.rvantwisk.cnctools.controllers.TaskEditController.java

public void setTask(final Project project, final TaskRunnable taskRunnable) {
    currentTaskRunnable = taskRunnable;/* ww  w  . j  a  v a2s.  c om*/
    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:main.Content.java

public void showTreeView() {
    try {//ww w  .jav a2 s .  c  o  m
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Main.class.getResource("view/TreePane.fxml"));
        AnchorPane activityPaneOverview = (AnchorPane) loader.load();

        TreeViewController controller = loader.getController();
        ScrollPane scrollPane = new ScrollPane();

        controller.setMainApp(this);
        controller.setTableData(data);
        controller.startTreeView();

        TreeView<String> treeView = controller.getTree();

        scrollPane.setContent(treeView);
        treeView.autosize();

        activityPaneOverview.getStylesheets()
                .add(Main.class.getResource("view/DarkTheme.css").toExternalForm());

        activityPaneOverview.getChildren().add(scrollPane);
        activityPaneOverview.setTopAnchor(scrollPane, 10.0);
        activityPaneOverview.setLeftAnchor(scrollPane, 10.0);
        activityPaneOverview.setRightAnchor(scrollPane, 10.0);
        activityPaneOverview.setBottomAnchor(scrollPane, 10.0);

        scrollPane.setFitToHeight(true);
        scrollPane.setFitToWidth(true);

        rootLayout.setLeft(activityPaneOverview);

        System.out.println("showTreeOveerview u therrit" + index);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

/**
 * Perform functionality associated with "About" menu selection or CTRL-A.
 *///  w  w  w  .  j  a va2  s .c o  m
private void provideAboutFunctionality() {
    try {
        // Load the fxml file and create a new stage for the popup
        FXMLLoader loader = new FXMLLoader(getClass().getResource("AboutDialog.fxml"));
        Parent page = (Parent) loader.load();
        Stage dialogStage = new Stage();
        dialogStage.setTitle(UIMessages.getMessage("UI_HELP_ABOUT_MENU_ITEM_LABEL"));
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        dialogStage.initOwner(stage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the person into the controller
        AboutDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);

        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

/**
 * Perform functionality associated with "About" menu selection or CTRL-A.
 *//*  w w  w  .ja va2 s  .c o  m*/
private void showLoggerDialog() {
    try {
        // Load the fxml file and create a new stage for the popup
        FXMLLoader loader = new FXMLLoader(getClass().getResource("LoggerDialog.fxml"));
        Parent page = (Parent) loader.load();
        Stage dialogStage = new Stage();
        dialogStage.setTitle(UIMessages.getMessage("UI_LOGGER_BOX_LABEL"));
        dialogStage.initModality(Modality.NONE);
        dialogStage.initOwner(stage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the person into the controller
        LoggerDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setOutputBuffer(outputBuffer.toString());
        controller.onClearLoggerEvent(() -> outputBuffer = new StringBuffer());

        // Show the dialog
        dialogStage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

private void addFixtureTab(final Fixture fixture, boolean isDefault) {
    try {//w  w  w.j a  va2  s  .c  om
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Fixture.fxml"));
        Parent fixtureTab = (Parent) loader.load();

        FixtureController controller = loader.getController();
        controller.setFixture(fixture);
        controller.setIsDefault(isDefault);

        Tab newTab = new Tab(fixture.getName());
        newTab.setContent(fixtureTab);
        newTab.closableProperty().setValue(!isDefault);
        newTab.setOnCloseRequest(event -> {
            boolean isOkClicked = showConfirmationDialog(
                    UIMessages.getMessage("UI_CLOSE_TAB_LABEL", fixture.getName()));
            if (!isOkClicked) {
                event.consume();
            } else {
                fixtures.getFixtures().remove(fixture);
            }
        });
        fixtureTabPane.getTabs().add(newTab);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

/**
 * Shows the confirmation dialog//from   w  ww .j a  va  2 s. c o  m
 */
private boolean showConfirmationDialog(String msg) {
    try {
        // Load the fxml file and create a new stage for the popup
        FXMLLoader loader = new FXMLLoader(getClass().getResource("ConfirmationDialog.fxml"));
        Parent page = (Parent) loader.load();
        Stage dialogStage = new Stage();
        dialogStage.setTitle(UIMessages.getMessage("UI_CLOSE_TAB_TITLE"));
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        dialogStage.initOwner(stage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the person into the controller
        ConfirmationDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setConfirmationMsg(msg);

        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
        return controller.isOkClicked();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.exalttech.trex.ui.views.importPcap.ImportedPacketTableView.java

/**
 * Initialize view/*  w  ww . jav a 2s. c  om*/
 */
private void initView() {
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/ImportedPacketTableView.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        fxmlLoader.load();

        initTableRowsColumns();
        extractExistingNames();
    } catch (Exception ex) {
        LOG.error("Error setting UI", ex);
    }
}

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

/**
 * Shows the report options dialog//from  ww  w.j a v  a2s  .c  om
 */
private void showReportOptionsDialog() {
    try {
        // Load the fxml file and create a new stage for the popup
        FXMLLoader loader = new FXMLLoader(getClass().getResource("ReportOptions.fxml"));
        AnchorPane page = (AnchorPane) loader.load();
        Stage dialogStage = new Stage();
        dialogStage.setTitle(UIMessages.getMessage("UI_REPORT_OPTIONS_TITLE"));
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        dialogStage.initOwner(stage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the person into the controller
        ReportOptionsController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setReport(this.fixtures.getReport()); //TODO: we need to clone our Report Object Here

        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
        if (controller.isOkClicked()) {
            this.fixtures.setReport(controller.getReport());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@FXML
void onProgenesisImport(ActionEvent event) {
    try {/*from ww w .  j  av  a 2  s .  c  o m*/
        FXMLLoader loader = new FXMLLoader(getClass().getResource("progenesis/importer.fxml"));
        loader.load();
        Parent root = loader.getRoot();
        Stage stage = new Stage();
        stage.setScene(new Scene(root));

        ProgenesisImporterController controller = loader.getController();
        controller.setMainWindowController(this);
        controller.setStage(stage);
        stage.setTitle("Import data from Progenesis CSV and Sample Info Excel");
        stage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@FXML
void onOpen(ActionEvent event) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open Metabolome Analysis File");
    fileChooser.getExtensionFilters()/* w  w w  .  ja  v a  2 s  . com*/
            .addAll(new FileChooser.ExtensionFilter("Supported Files", Arrays.asList("*.zip", "*.csv")));
    File file = fileChooser.showOpenDialog(stage);
    if (file == null)
        return;
    if (!opened) {
        openData(file);
    } else {
        try {
            Stage primaryStage = new Stage();
            FXMLLoader loader = new FXMLLoader(getClass().getResource("mainwindow.fxml"));
            loader.load();
            MainWindowController controller = loader.getController();
            controller.setStage(primaryStage);
            VBox root = loader.getRoot();
            Scene scene = new Scene(root);
            primaryStage.setScene(scene);
            controller.openData(file);
            primaryStage.show();
        } catch (IOException e) {
            e.printStackTrace();
            AlertHelper.showExceptionAlert("Cannot open", null, e);
        }
    }
}