Example usage for javafx.fxml FXMLLoader setRoot

List of usage examples for javafx.fxml FXMLLoader setRoot

Introduction

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

Prototype

public void setRoot(Object root) 

Source Link

Document

Sets the root of the object hierarchy.

Usage

From source file:org.sleuthkit.autopsy.timeline.FXMLConstructor.java

static public void construct(Node n, String fxmlFileName) {
    final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/"
            + fxmlFileName; // NON-NLS
    System.out.println(name);//from  w ww  .java 2  s.  com

    try {
        FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
        fxmlLoader.setRoot(n);
        fxmlLoader.setController(n);

        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            try {
                fxmlLoader.setClassLoader(FXMLLoader.getDefaultClassLoader());
                fxmlLoader.load();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.sleuthkit.autopsy.timeline.ShowInTimelineDialog.java

/**
 * Common Private Constructor/*from w w w  .  ja  va2  s  .co  m*/
 *
 * @param controller The controller for this Dialog.
 * @param eventIDS   A List of eventIDs to present to the user to choose
 *                   from.
 */
@NbBundle.Messages({
        "ShowInTimelineDialog.amountValidator.message=The entered amount must only contain digits." })
private ShowInTimelineDialog(TimeLineController controller, List<Long> eventIDS) {
    this.controller = controller;

    //load dialog content fxml
    final String name = "nbres:/"
            + StringUtils.replace(ShowInTimelineDialog.class.getPackage().getName(), ".", "/")
            + "/ShowInTimelineDialog.fxml"; // NON-NLS
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
        fxmlLoader.setRoot(contentRoot);
        fxmlLoader.setController(this);

        fxmlLoader.load();
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, "Unable to load FXML, node initialization may not be complete.", ex); //NON-NLS
    }
    //assert that fxml loading happened correctly
    assert eventTable != null : "fx:id=\"eventTable\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert typeColumn != null : "fx:id=\"typeColumn\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert dateTimeColumn != null : "fx:id=\"dateTimeColumn\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert amountSpinner != null : "fx:id=\"amountsSpinner\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert unitComboBox != null : "fx:id=\"unitChoiceBox\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";

    //validat that spinner has a integer in the text field.
    validationSupport.registerValidator(amountSpinner.getEditor(), false, Validator.createPredicateValidator(
            NumberUtils::isDigits, Bundle.ShowInTimelineDialog_amountValidator_message()));

    //configure dialog properties
    PromptDialogManager.setDialogIcons(this);
    initModality(Modality.APPLICATION_MODAL);

    //add scenegraph loaded from fxml to this dialog.
    DialogPane dialogPane = getDialogPane();
    dialogPane.setContent(contentRoot);
    //add buttons to dialog
    dialogPane.getButtonTypes().setAll(SHOW, ButtonType.CANCEL);

    ///configure dialog controls
    amountSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1000));
    amountSpinner.getValueFactory().setConverter(new IntegerStringConverter() {
        /**
         * Convert the String to an Integer using Integer.valueOf, but if
         * that throws a NumberFormatException, reset the spinner to the
         * last valid value.
         *
         * @param string The String to convert
         *
         * @return The Integer value of string.
         */
        @Override
        public Integer fromString(String string) {
            try {
                return super.fromString(string);
            } catch (NumberFormatException ex) {
                return amountSpinner.getValue();
            }
        }
    });

    unitComboBox.setButtonCell(new ChronoFieldListCell());
    unitComboBox.setCellFactory(comboBox -> new ChronoFieldListCell());
    unitComboBox.getItems().setAll(SCROLL_BY_UNITS);
    unitComboBox.getSelectionModel().select(ChronoField.MINUTE_OF_HOUR);

    typeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getEventType()));
    typeColumn.setCellFactory(param -> new TypeTableCell<>());

    dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getStartMillis()));
    dateTimeColumn.setCellFactory(param -> new DateTimeTableCell<>());

    //add events to table
    eventTable.getItems().setAll(
            eventIDS.stream().map(controller.getEventsModel()::getEventById).collect(Collectors.toSet()));
    eventTable.setPrefHeight(Math.min(200, 24 * eventTable.getItems().size() + 28));
}

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  a v a  2 s  . com*/
        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());
                }
            });
}