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:genrsa.GenRSAController.java

/**
 * Mtodo usado para cargar la ventana de Factorizacin
 * @param event /*from w ww  . ja  v a  2 s  . c  om*/
 */
public void Factorize(ActionEvent event) {
    FXMLLoader fxmlLoader;
    Parent root;

    try {
        secondStage = new Stage();
        fxmlLoader = new FXMLLoader(getClass().getResource("/Factorize/Factorize.fxml"));
        root = fxmlLoader.load();

        FactorizeController factorController = fxmlLoader.<FactorizeController>getController();
        factorController.setRadix(this.radix);

        if (this.RSA != null) {
            factorController.getModulus().setText(this.RSA.getN().toString(this.radix).toUpperCase());
        }

        disableOnProgress(true);

        Scene scene = new Scene(root);
        secondStage.initModality(Modality.NONE);
        secondStage.getIcons()
                .add(new Image(GenRSAController.class.getResourceAsStream("/allImages/genRSA.png")));
        secondStage.setTitle("genRSA - Ataque por Factorizacin");
        secondStage.setScene(scene);
        secondStage.show();

        secondStage.setOnCloseRequest(closeEvent -> {
            factorController.getFactorizeAttack().setIsCancelled(true);
            this.disableOnProgress(false);
            this.disableButtons();
        });

    } catch (IOException ex) {
        //no pongo mensaje de error, porque no se puede dar el caso
    }

}

From source file:genrsa.GenRSAController.java

/**
 * Mtodo usado para cargar la ventana de ataque por la paradoja del cumpleaos
 * @param event //  w  w w. j  a v  a2 s. co  m
 */
public void Paradox(ActionEvent event) {
    FXMLLoader fxmlLoader;
    Parent root;

    try {
        secondStage = new Stage();
        fxmlLoader = new FXMLLoader(getClass().getResource("/Paradox/Paradox.fxml"));
        root = fxmlLoader.load();

        ParadoxController paradoxController = fxmlLoader.<ParadoxController>getController();
        paradoxController.setRadix(this.radix);

        if (this.RSA != null) {
            paradoxController.getModulus().setText(this.RSA.getN().toString(this.radix).toUpperCase());
            paradoxController.getExponent().setText(this.RSA.getE().toString(this.radix).toUpperCase());
        } else {
            paradoxController.setFirstTime(false);
        }

        disableOnProgress(true);

        Scene scene = new Scene(root);
        secondStage.initModality(Modality.NONE);
        secondStage.getIcons()
                .add(new Image(GenRSAController.class.getResourceAsStream("/allImages/genRSA.png")));
        secondStage.setTitle("genRSA - Ataque por la Paradoja del Cumpleaos");
        secondStage.setScene(scene);
        secondStage.show();

        secondStage.setOnCloseRequest(closeEvent -> {
            paradoxController.getParadoxAttack().setIsCancelled(true);

            this.disableOnProgress(false);
            this.disableButtons();
        });

    } catch (IOException ex) {
        //no pongo mensaje de error, porque no se puede dar el caso
    }

}

From source file:com.jf.javafx.Application.java

/**
 * Load a node and its controller./*from   w ww  . j  a v  a  2s  .c om*/
 * 
 * @param path
 * @return the node
 */
public Pair<Node, ?> createNode(String path) {
    final Application app = this;
    File fxml = getTemplateFile(path + ".fxml");
    Node node;
    Object controller = null;
    try {
        ResourceBundle bundle;
        try {
            bundle = getResourceBundle("controllers/" + path);
        } catch (Exception ex) {
            bundle = null;
        }

        FXMLLoader loader = new FXMLLoader(fxml.toURL(), bundle, new JavaFXBuilderFactory(),
                (Class<?> param) -> {
                    try {
                        Class cls = Controller.class;

                        if (cls.isAssignableFrom(param)) {
                            try {
                                return param.getConstructor(Application.class).newInstance(app);
                            } catch (Exception ex) {
                                Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
                                return param.newInstance();
                            }
                        } else {
                            return param.newInstance();
                        }
                    } catch (IllegalAccessException | IllegalArgumentException | InstantiationException
                            | SecurityException ex) {
                        MsgBox.showException(ex);
                        return null;
                    }
                });
        node = loader.load();
        controller = loader.getController();
    } catch (IOException ex) {
        MsgBox.showException(ex, "Error while navigate to path: " + path);

        // customize error screen
        AnchorPane p = new AnchorPane();

        //            StringWriter sw = new StringWriter();
        //            ex.printStackTrace(new PrintWriter(sw));
        //            p.getChildren().add(new Label(sw.toString()));

        node = p;
    }

    return new Pair(node, controller);
}

From source file:genrsa.GenRSAController.java

/**
 * Mtodo usado para cargar la ventana de Firma
 * @param event /*ww w. j  av  a  2  s.  co  m*/
 */
public void Sign(ActionEvent event) {
    FXMLLoader fxmlLoader;
    Parent root;
    int iterator;

    try {
        secondStage = new Stage();
        fxmlLoader = new FXMLLoader(getClass().getResource("/Sign/Sign.fxml"));
        root = fxmlLoader.load();

        SignController SignCtr = fxmlLoader.<SignController>getController();

        SignCtr.setPubKeyBI(this.RSA.getE());
        SignCtr.setModulusBI(this.RSA.getN());
        SignCtr.setRadix(this.radix);

        //parte grfica
        SignCtr.getModulus().setText(
                this.utilidades.putPoints(this.RSA.getN().toString(this.radix).toUpperCase(), this.radix));
        SignCtr.getPubKey().setText(
                this.utilidades.putPoints(this.RSA.getE().toString(this.radix).toUpperCase(), this.radix));

        SignCtr.getModulus1().setText(
                this.utilidades.putPoints(this.RSA.getN().toString(this.radix).toUpperCase(), this.radix));
        //obtengo todas las claves privadas parejas
        String[] PPK = this.claves_parejas.getText().split("\n");
        //quito la informacion acerca de los bits "--> XXbits"

        //las meto en el comboBox
        ComboBox comboBox = SignCtr.getPrivKeys();
        comboBox.getItems().add("Clave Privada");
        comboBox.getItems()
                .add(this.utilidades.putPoints(this.RSA.getD().toString(this.radix).toUpperCase(), this.radix));
        comboBox.getItems().add("Claves Privadas Parejas");
        for (iterator = 0; iterator < PPK.length; iterator++) {
            comboBox.getItems().add(PPK[iterator]);
        }
        comboBox.setValue(
                this.utilidades.putPoints(this.RSA.getD().toString(this.radix).toUpperCase(), this.radix));
        comboBox.setVisibleRowCount(7);

        disableOnProgress(true);

        Scene scene = new Scene(root);
        secondStage.initModality(Modality.NONE);
        secondStage.getIcons()
                .add(new Image(GenRSAController.class.getResourceAsStream("/allImages/genRSA.png")));
        secondStage.setTitle("genRSA - Firma y Validacin");
        secondStage.setScene(scene);
        secondStage.show();

        secondStage.setOnCloseRequest(closeEvent -> {
            this.disableOnProgress(false);
            this.disableButtons();
        });

    } catch (IOException ex) {
        //no pongo mensaje de error, porque no se puede dar el caso
    }

}

From source file:genrsa.GenRSAController.java

/**
 * Mtodo usado para cargar la ventana de Cifra
 * @param event /*from   w ww .jav a2s .com*/
 */
public void DeCipher(ActionEvent event) {
    FXMLLoader fxmlLoader;
    Parent root;
    int iterator;

    try {
        secondStage = new Stage();
        fxmlLoader = new FXMLLoader(getClass().getResource("/DeCipher/DeCipher.fxml"));
        root = fxmlLoader.load();

        DeCipherController DeCipherCtr = fxmlLoader.<DeCipherController>getController();

        DeCipherCtr.setPubKeyBI(this.RSA.getE());
        DeCipherCtr.setModulusBI(this.RSA.getN());
        DeCipherCtr.setRadix(this.radix);

        //parte grfica
        DeCipherCtr.getModulus().setText(
                this.utilidades.putPoints(this.RSA.getN().toString(this.radix).toUpperCase(), this.radix));
        DeCipherCtr.getPubKey().setText(
                this.utilidades.putPoints(this.RSA.getE().toString(this.radix).toUpperCase(), this.radix));

        DeCipherCtr.getModulus1().setText(
                this.utilidades.putPoints(this.RSA.getN().toString(this.radix).toUpperCase(), this.radix));
        //obtengo todas las claves privadas parejas
        String[] PPK = this.claves_parejas.getText().split("\n");

        //las meto en el comboBox
        ComboBox comboBox = DeCipherCtr.getPrivKeys();
        comboBox.getItems().add("Clave Privada");
        comboBox.getItems()
                .add(this.utilidades.putPoints(this.RSA.getD().toString(this.radix).toUpperCase(), this.radix));
        comboBox.getItems().add("Claves Privadas Parejas");
        for (iterator = 0; iterator < PPK.length; iterator++) {
            comboBox.getItems().add(PPK[iterator]);
        }
        comboBox.setValue(
                this.utilidades.putPoints(this.RSA.getD().toString(this.radix).toUpperCase(), this.radix));
        comboBox.setVisibleRowCount(7);

        disableOnProgress(true);

        Scene scene = new Scene(root);
        secondStage.initModality(Modality.NONE);
        secondStage.getIcons()
                .add(new Image(GenRSAController.class.getResourceAsStream("/allImages/genRSA.png")));
        secondStage.setTitle("genRSA - Cifrado y Descifrado");
        secondStage.setScene(scene);
        secondStage.show();

        secondStage.setOnCloseRequest(closeEvent -> {
            this.disableOnProgress(false);
            this.disableButtons();
        });

    } catch (IOException ex) {
        //no pongo mensaje de error, porque no se puede dar el caso
    }

}

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 {//  w w  w . jav  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");
}

From source file:UI.MainStageController.java

@FXML
/**/*w  ww .  j av  a  2s  .co m*/
 * runs when the optionsButton is clicked
 * opens the Options stage
 *
 */
private void optionsButtonClicked() {
    FXMLLoader fxmlLoader = new FXMLLoader();
    Parent root = null;
    try {
        fxmlLoader.setLocation(Main.class.getClassLoader().getResource("UI/optionsGui.fxml"));
        root = fxmlLoader.load();

    } catch (Exception e) {
        try {
            fxmlLoader.setLocation(
                    new URL("file:" + new File("").getCanonicalPath().concat("src/UI/optionsGui.fxml")));
            root = fxmlLoader.load();
        } catch (Exception e2) {
            System.err.println("ERROR: Couldn't find optionsGui.fxml!");
        }
    }

    this.optionsStage = new Stage();
    optionsStage.setTitle("Options");
    Scene optionsScene = new Scene(root, 1000, 700);
    optionsStage.setScene(optionsScene);
    optionsScene.getStylesheets().add(GlobalConstants.LIGHTTHEME);
    optionsStage.show();
}

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  w  w.ja v  a2  s  .  c  om*/
        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:UI.MainStageController.java

/**
 * Opens new PopUp Window with Image Export options.
 *//*from  w ww .  ja  v  a2s.c om*/
@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:snpviewer.SnpViewer.java

public void showAbout(ActionEvent ev) {
    try {//from ww  w  . j  a v a 2  s. c  om
        FXMLLoader loader = new FXMLLoader(getClass().getResource("about.fxml"));
        Pane page = (Pane) loader.load();
        Scene scene = new Scene(page);
        Stage stage = new Stage();
        stage.setScene(scene);
        scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm());
        AboutController controller = loader.getController();
        controller.setVersion(VERSION);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
        stage.setTitle("About SnpViewer");

        stage.show();
    } catch (Exception ex) {
        Dialogs.showErrorDialog(null, "Error showing about information - see" + " details for stack trace",
                "ERROR!", "SnpViewer", ex);
    }
}