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:ninja.eivind.hotsreplayuploader.window.nodes.HotsLogsNode.java

public HotsLogsNode(FXMLLoaderFactory factory) throws IOException {
    super();// w  w w  . j a  v a 2  s. co m
    URL resource = getClass().getResource("HotsLogsNode.fxml");
    FXMLLoader loader = factory.get();
    loader.setLocation(resource);
    loader.setRoot(this);
    loader.setController(this);
    loader.load();
}

From source file:com.rvantwisk.cnctools.controls.ToolParametersControl.java

public ToolParametersControl() {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ToolParameters.fxml"));
    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);
    try {/* ww  w.j  av a  2s .com*/
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}

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

/**
 * Initialize view/* www  .j a  va2  s.c  o m*/
 */
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:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java

public void showExportXPathToRuleWizard() throws IOException {
    ExportXPathWizardController wizard = new ExportXPathWizardController(xpathExpressionProperty());

    FXMLLoader loader = new FXMLLoader(getClass().getResource("fxml/xpath-export-wizard.fxml"));
    loader.setController(wizard);

    final Stage dialog = new Stage();
    dialog.initOwner(designerRoot.getMainStage());
    dialog.setOnCloseRequest(e -> wizard.shutdown());
    dialog.initModality(Modality.WINDOW_MODAL);

    Parent root = loader.load();/*from w w w  .  ja va2 s .  co m*/
    Scene scene = new Scene(root);
    //stage.setTitle("PMD Rule Designer (v " + PMD.VERSION + ')');
    dialog.setScene(scene);
    dialog.show();
}

From source file:org.apache.cayenne.modeler.layout.LayoutSupport.java

default FXMLLoader loadFXML(final String fxmlPath) throws IOException {
    final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxmlPath));

    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);
    fxmlLoader.load();/* ww w  .  j  a  v  a 2  s .c o  m*/

    // Note: Must manually initialize the layout because JavaFX will not
    //       automatically call the "initialize" method when the FXML is
    //       loaded from an interface's default method.  To avoid confusion
    //       with the JavaFX "initialize" name, a different method name is
    //       used for the same purpose.
    initializeLayout();

    return fxmlLoader;
}

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

static public void construct(Node n, String fxmlFileName) {
    final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/"
            + fxmlFileName;/*from w w w .  j a v a  2  s. com*/
    //        System.out.println(name);

    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.imageanalyzer.gui.MetaDataPane.java

public MetaDataPane(ImageAnalyzerController controller) {
    this.controller = controller;

    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataPane.fxml"));
    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);

    try {/*from   w w  w.  j a  v a2 s  .  c o m*/
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.MetaDataPane.java

public MetaDataPane(ImageGalleryController controller) {
    this.controller = controller;

    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataPane.fxml"));
    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);

    try {//from   w ww .  j a v a 2  s.  co m
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}

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 w w .  j ava  2s . c  om*/

    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 ww  .java2  s  . com*/
 *
 * @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));
}