package GeneradorMiniexamenes.controllers;

import GeneradorMiniexamenes.Main;
import javafx.event.ActionEvent;
import javafx.scene.Node;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import java.io.File;

/**
 * Imports the subjects from either a .json file or from the .txt legacy
 * format to the model
 *
 * The .json file is imported each time the application is opened
 * The .txt is opened only when the user selects to import from the legacy
 * format from the menu
 */
public class Import {

    /**
     * onClick
     *
     * method that opens a file to import data
     *
     * @param ae actionEvent to get the Window
     */
    public void onClick(ActionEvent ae){
        Node source = (Node) ae.getSource();
        Stage theStage = (Stage) source.getScene().getWindow();

        // Opens file chooser
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Selecciona tu archivo (txt o json)");
        fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))
        );
        fileChooser.getExtensionFilters().addAll(
                new FileChooser.ExtensionFilter("TXT", "*.txt"),
                new FileChooser.ExtensionFilter("JSON", "*.json")
        );
        File file = fileChooser.showOpenDialog(theStage);

        System.out.println(file.getName());
    }

    private void importFromText(File file){

    }

}

@@ -41,43 +41,8 @@
 s;%0A%0A
-import GeneradorMiniexamenes.Main;%0A
 impo
@@ -177,16 +177,107 @@
 io.File;
+%0Aimport java.io.FileNotFoundException;%0Aimport java.io.FileReader;%0Aimport java.util.Scanner;
 %0A%0A/**%0A *
@@ -1362,91 +1362,1111 @@
     
-System.out.println(file.getName());%0A    %7D%0A%0A    private void importFromText(File fil
+// Checks the extension of the file selected (txt or json)%0A        String extension = %22%22;%0A        String name = %22%22;%0A        int i = file.getName().lastIndexOf('.');%0A        if(i %3E 0)%0A            extension = file.getName().substring(i + 1);%0A        name = file.getName().substring(0, i);%0A%0A        if(extension.equals(%22txt%22))%0A            importFromText(file, name);%0A        else%0A            importFromJson(file, name);%0A    %7D%0A%0A    /**%0A     * importFromText%0A     *%0A     * method that lets us import miniExam from a txt file%0A     *%0A     * @param file that contains miniexam%0A     */%0A    private void importFromText(File file, String fileName)%7B%0A        // Tries to open the file%0A        System.out.println(file.getPath());%0A        try %7B%0A            Scanner in = new Scanner(new FileReader(file.getPath()));%0A            String line = %22%22;%0A            while(in.hasNextLine())%7B%0A                line = in.nextLine();%0A            %7D%0A        %7D catch (FileNotFoundException e) %7B%0A            System.out.println(%22El archivo no pudo ser abierto%22);%0A        %7D%0A    %7D%0A%0A    private void importFromJson(File file, String fileNam
 e)%7B%0A

Add OpenFile