Example usage for javafx.fxml FXMLLoader setController

List of usage examples for javafx.fxml FXMLLoader setController

Introduction

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

Prototype

public void setController(Object controller) 

Source Link

Document

Sets the controller associated with the root object.

Usage

From source file:sonicScream.controllers.CategoryTabController.java

public CategoryTabController(Category category) {
    URL location = getClass().getResource("/sonicScream/views/CategoryTab.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    loader.setRoot(this);
    loader.setController(this);
    try {/*from ww  w .  j av  a 2s . co m*/
        loader.load();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

    _category = category;

    this.textProperty().bind(_category.categoryNameProperty());
    CategoryTabComboBox.setItems(_category.getCategoryScripts());

    //These two bindings handle changing between categories with only a single 
    //script (items) and those with multiple (everything else)
    SimpleListProperty bindableList = new SimpleListProperty();
    bindableList.bind(new SimpleObjectProperty<>(_category.getCategoryScripts()));
    CategoryTabComboBox.visibleProperty().bind(Bindings.greaterThan(bindableList.sizeProperty(), 1));

    selectedScriptNodeProperty().bind(CategoryTabTreeView.getSelectionModel().selectedItemProperty());

    selectedScript.bind(CategoryTabComboBox.getSelectionModel().selectedItemProperty());

    if (_category.getCategoryScripts() != null && !_category.getCategoryScripts().isEmpty()) {
        CategoryTabComboBox.valueProperty().set(_category.getCategoryScripts().get(0));
        handleComboBoxChanged(null);
    }

    SwapDisplayModeButton.textProperty().bind(Bindings.when(displayMode.isEqualTo(CategoryDisplayMode.SIMPLE))
            .then("Advanced >>").otherwise("<< Simple"));

    CategoryTabTreeView.getSelectionModel().selectedItemProperty()
            .addListener((observable, oldValue, newValue) -> {
                if (newValue != null) {
                    TreeItem<String> scriptValue = TreeUtils.getRootMinusOne((TreeItem<String>) newValue);
                    TreeItem<String> selectedValue = (TreeItem<String>) newValue;
                    CategoryTabScriptValueLabel.setText(scriptValue.getValue());
                    selectedScriptNodeIsLeaf.set(selectedValue.isLeaf());
                }
            });
}

From source file:spdxedit.externalRef.ExternalRefListControl.java

public AnchorPane getUi() {
    try {/*w  ww . ja va  2s .c  om*/
        FXMLLoader loader = new FXMLLoader(ExternalRefListControl.class.getResource("/ExternalRefList.fxml"));
        loader.setController(this);
        AnchorPane pane = loader.load();
        return pane;
    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load scene for License editor dialog");
    }
}

From source file:spdxedit.license.LicenseEditControl.java

public Pane getUi() {
    try {/*w ww. ja v  a  2  s  . c  o m*/
        FXMLLoader loader = new FXMLLoader(LicenseEditControl.class.getResource("/LicenseEdit.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:spdxedit.license.LicenseExtractControl.java

public Pane getUi() {
    try {// w  w w  .  j av  a  2  s.c o m
        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:spdxedit.PackageEditor.java

/**
 * Opens the modal package editor for the provided package.
 *
 * @param pkg               The package to edit.
 * @param relatablePackages Packages to which the edited package may optionally have defined relationships
 * @param parentWindow      The parent window.
 *//*from  w w w  .j ava2  s. c  om*/
public static void editPackage(final SpdxPackage pkg, final List<SpdxPackage> relatablePackages,
        SpdxDocumentContainer documentContainer, Window parentWindow) {

    final PackageEditor packageEditor = new PackageEditor(pkg, relatablePackages, documentContainer);
    final Stage dialogStage = new Stage();
    dialogStage.setTitle("Edit SPDX Package: " + pkg.getName());
    dialogStage.initStyle(StageStyle.DECORATED);
    dialogStage.initModality(Modality.APPLICATION_MODAL);
    dialogStage.setY(parentWindow.getX() + parentWindow.getWidth() / 2);
    dialogStage.setY(parentWindow.getY() + parentWindow.getHeight() / 2);
    dialogStage.setResizable(false);
    try {
        FXMLLoader loader = new FXMLLoader(NewPackageDialog.class.getResource("/PackageEditor.fxml"));
        loader.setController(packageEditor);
        Pane pane = loader.load();
        Scene scene = new Scene(pane);
        dialogStage.setScene(scene);
        dialogStage.getIcons().clear();
        dialogStage.getIcons().add(UiUtils.ICON_IMAGE_VIEW.getImage());
        //Populate the file list on appearance
        dialogStage.setOnShown(event -> {
            try {
                final SpdxFile dummyfile = new SpdxFile(pkg.getName(), null, null, null, null, null, null, null,
                        null, null, null, null, null);
                TreeItem<SpdxFile> root = new TreeItem<>(dummyfile);
                packageEditor.filesTable.setRoot(root);
                //Assume a package without is external
                //TODO: replace with external packages or whatever alternate mechanism in 2.1
                packageEditor.btnAddFile.setDisable(pkg.getFiles().length == 0);
                root.getChildren()
                        .setAll(Stream.of(pkg.getFiles())
                                .sorted(Comparator.comparing(file -> StringUtils.lowerCase(file.getName()))) //Sort by file name
                                .map(TreeItem<SpdxFile>::new).collect(Collectors.toList()));
            } catch (InvalidSPDXAnalysisException e) {
                logger.error("Unable to get files for package " + pkg.getName(), e);
            }

            packageEditor.tabFiles.setExpanded(true);

        });

        //Won't assign this event through FXML - don't want to propagate the stage beyond this point.
        packageEditor.btnOk.setOnMouseClicked(event -> dialogStage.close());
        dialogStage.showAndWait();

    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load dialog", ioe);
    }
}

From source file:UI.MainStageController.java

/**
 * Opens new PopUp Window with Image Export options.
 *//*from   w  w w .  j a v  a  2  s  . co  m*/
@FXML
private void exportImages() {
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("src/UI/exportImageGUI"));
        loader.setLocation(
                new URL("file:" + new File("").getCanonicalPath().concat("/src/UI/exportImageGUI.fxml")));
        //Parent root = loader.load();
        ExportImageController exportImageController = new ExportImageController(viewPane);
        //ExportImageController exportImageController = loader.getController();
        //exportImageController.setViewPane(viewPane);
        loader.setController(exportImageController);
        Parent root = loader.load();
        exportImagesStage = new Stage();
        exportImagesStage.setTitle("Export Image");
        Scene exportImageScene = new Scene(root, 300, 200);
        exportImagesStage.setScene(exportImageScene);
        exportImageScene.getStylesheets().add(GlobalConstants.DARKTHEME);
        exportImagesStage.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:view.FXApplicationController.java

public FXApplicationController(DataController dataController, FeatureModel featureModel, FXViewModel viewModel,
        boolean recreateModelMode) {

    primaryStage = new Stage();

    // Creating FXML Loader
    FXMLLoader loader = new FXMLLoader(FXStartController.class.getResource("Application.fxml"));
    loader.setController(this);

    // Try to load fxml file
    try {//from w ww . j a v a 2s . co m
        mainGrid = loader.load();
    } catch (IOException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE,
                "Error during loading Application.fxml file!", e);
    }

    this.dataController = dataController;
    this.dataModel = dataController.getDataModel();

    //initialize important variables
    channelNames = dataModel.getChannelNames();
    displayBuffer = dataModel.data.clone();
    // Set Choice Box for the channels        
    //Set properties for the channels
    for (int i = 0; i < channelNames.length; i++) {
        if (i < 6) {
            //The first value represents wheater the channel is shown
            //The second value represents the current zoom level
            Double[] channelProp = new Double[2];
            channelProp[0] = 1.0;
            channelProp[1] = 1.0;
            allChannels.put(channelNames[i], channelProp);
        } else {
            //The first value represents wheater the channel is shown
            //The second value represents the current zoom level
            Double[] channelProp = new Double[2];
            channelProp[0] = 0.0;
            channelProp[1] = 1.0;
            allChannels.put(channelNames[i], channelProp);
        }

    }

    // Create stage with mainGrid
    scene = new Scene(mainGrid);
    primaryStage.setScene(scene);

    //Properties for stage
    primaryStage.setResizable(true);
    primaryStage.show();
    primaryStage.setTitle(dataModel.getFile().getName());

    ////////////
    this.viewModel = viewModel;
    this.featureModel = featureModel;
    this.featureController = new FeatureController(featureModel, dataModel);

    this.recreateModelMode = recreateModelMode;

    kcDetector = featureController.kcDetector;
    kcDetector.setHighpassCoefficients(featureController.getDisplayHighpassCoefficients());
    kcDetector.setLowpassCoefficients(featureController.getLowpassCoefficients());

    currentEpoch = featureModel.getCurrentEpoch();
    loadEpoch(currentEpoch);
    showEpoch();

    paintSpacing();

    //Configure lineChart
    lineChart.setSnapToPixel(false);

    choices = FXCollections.observableArrayList();
    updateChoiceBox();
    choiceBox.getSelectionModel().select(0);

    ObservableList<String> choicesModel = FXCollections.observableArrayList();

    File folder = new File("./Classifiers").getAbsoluteFile();
    for (File file : folder.listFiles()) {
        if (file.getName().contains("model")) {
            choicesModel.add(file.getName().replace("[model]", "").replace(".jo", ""));
            classifierList.add(file.getAbsolutePath());
        }
    }

    choiceBoxModel.setItems(choicesModel);
    choiceBoxModel.getSelectionModel().select(0);

    tooltips();

    scatterPlot = new FXScatterPlot(this, dataController, dataModel, featureModel, featureController,
            viewModel);
    hypnogram = new FXHypnogrammController(dataModel, featureModel, viewModel, this);

    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            if (recreateModelMode) {
                hypnogram.updateAll();
                hypnogram.hide();
            }
            updateWindows();
        }
    });

    if (((int) (dataModel.getSrate()) % 50) != 0) {
        showPopUp("Sampling rate not supported. Must be a multiple of 50 Hz and > 100 Hz.");
    }
}

From source file:view.FXApplicationController.java

@FXML
protected void aboutAction() {
    Stage stage = new Stage();
    AnchorPane addGrid = new AnchorPane();

    // Creating FXML Loader
    FXMLLoader loader = new FXMLLoader(FXStartController.class.getResource("About.fxml"));
    loader.setController(this);

    // Try to load fxml file
    try {/* www.j a  v a  2  s. c  o m*/
        addGrid = loader.load();
    } catch (IOException e) {
        System.err.println("Error during loading About.fxml file!");
    }

    Scene scene = new Scene(addGrid);

    stage.setResizable(false);
    stage.setScene(scene);

    stage.show();

    stage.setTitle("About");
}