public void initialize(URL location, ResourceBundle resources) {

    model = new GestionDictionnaire();
    model.addObserver(this);

    model.loadDictionnaire();
  }
  /**
   * Supprime un mot sélectionné du dictionnaire
   *
   * @param event
   */
  @FXML
  void supprimerMot(ActionEvent event) {

    String msg = model.supprimerMot(listViewResultats.getSelectionModel().getSelectedItem());

    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("Dictionnaire");
    alert.setContentText(msg);
    alert.setHeaderText(null);
    alert.showAndWait();

    model.flagModif = true;
  }
  /** Met fin au programme et demande à l'utilisateur s'il veut sauvegarder. */
  protected void quitter() {

    if (model.flagModif) {

      Alert alert = new Alert(AlertType.CONFIRMATION);
      alert.setTitle("Sauvegarde du dictionnaire");
      alert.setContentText("Voulez-vous enregistrer les nouvelles modifications au dictionnaire?");
      alert.setHeaderText(null);

      ButtonType yes = new ButtonType("Oui");
      ButtonType no = new ButtonType("Non");

      alert.getButtonTypes().setAll(yes, no);
      Optional<ButtonType> result = alert.showAndWait();

      if (result.get() == yes) {
        try {
          model.sauvegardeFichier();
        } catch (IOException e) {
          e.printStackTrace();
          Alert alertSave = new Alert(AlertType.ERROR);
          alertSave.setTitle("IO Error");
          alertSave.setContentText("Save File error");
          alertSave.showAndWait();
        }
      }
    }
    System.exit(0);
  }
  /**
   * Methode servant à afficher les détails d'un mot sélectionné dans une autre fenêtre
   *
   * @param event
   */
  @FXML
  void consulterMot() {
    if (listViewResultats.getSelectionModel().getSelectedItem() != null) {
      if (!model.listeMotsEnConsultation.contains(
          listViewResultats.getSelectionModel().getSelectedItem())) {
        Stage stageConsultation = null;
        for (Mot m : model.listeResultats) {

          if (m.getLibelle().compareTo(listViewResultats.getSelectionModel().getSelectedItem())
              == 0) {
            model.motSelectionne = m;
            model.ajouterMotEnConsultation(m);
          }
        }

        stageConsultation = loadConsultation();
        model.listeResultats.clear();
        model.notifyObs(model.listeResultats);
        stageConsultation.show();

      } else {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Dictionnaire");
        alert.setContentText("Ce mot est déjà en consultation");
        alert.setHeaderText(null);
        alert.showAndWait();
      }

    } else {

      Alert alert = new Alert(AlertType.ERROR);
      alert.setTitle("Dictionnaire");
      alert.setContentText("Aucune selection");
      alert.setHeaderText(null);
      alert.showAndWait();
    }
  }
  /**
   * Méthode servant à ajouter un mot au dictionnaire
   *
   * @param event
   */
  @FXML
  void ajouterMot(ActionEvent event) {

    if (!motInput.getText().isEmpty() && motInput.getText().length() > 2) {

      if (!model.rechMotExiste(motInput.getText())) {

        Mot motAjout = new Mot(motInput.getText(), LocalDate.now());
        FabriqueDictionnaire.getInstance().getDictionnaire().put(motInput.getText(), motAjout);
        model.flagModif = true;

        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("Dictionnaire");
        alert.setContentText("Mot ajouté avec succès!");
        alert.setHeaderText(null);

        ButtonType ok = new ButtonType("Ok");

        alert.getButtonTypes().setAll(ok);
        Optional<ButtonType> result = alert.showAndWait();
      } else {

        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Dictionnaire");
        alert.setContentText("Mot déjà existant.");
        alert.setHeaderText(null);
        alert.showAndWait();
      }
    } else {

      Alert alert = new Alert(AlertType.ERROR);
      alert.setTitle("Dictionnaire");
      alert.setContentText("L'expression doit contenir minimum 3 lettres.");
      alert.setHeaderText(null);
      alert.showAndWait();
    }
  }
  /**
   * Methode qui gere la recherche lorsque le bouton recherche est cliqué
   *
   * @param event
   */
  @FXML
  void activerRecherche(ActionEvent event) {

    if (radioMotExact.isSelected()) {

      if (!motInput.getText().isEmpty() && motInput.getText().length() > 2) {

        model.rechMotExact(motInput.getText());

        if (checkBoxImage.isSelected()) {
          model.rechSelonImage();
        }

        if (checkBoxSaisieApres.isSelected() && datePickerSaisieApres.getValue() != null) {
          model.rechApresDateSaisie(datePickerSaisieApres.getValue());
        }

        if (checkBoxSaisieAvant.isSelected() && datePickerSaisieAvant.getValue() != null) {
          model.rechAvantDateSaisie(datePickerSaisieAvant.getValue());
        }

        if (checkBoxModifApres.isSelected() && datePickerModifApres.getValue() != null) {
          model.rechApresDateModif(datePickerModifApres.getValue());
        }

        if (checkBoxModifAvant.isSelected() && datePickerModifAvant.getValue() != null) {
          model.rechAvantDateModif(datePickerModifAvant.getValue());
        }

        if (model.listeResultats.isEmpty()) {

          Alert alert = new Alert(AlertType.ERROR);
          alert.setTitle("Dictionnaire");
          alert.setContentText("Mot introuvable.");
          alert.setHeaderText(null);
          alert.showAndWait();
        }

        model.notifyObs(model.listeResultats);

        for (Mot m : model.listeResultats) {

          System.out.println(m.getLibelle());
        }

      } else {

        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Dictionnaire");
        alert.setContentText("L'expression doit contenir minimum 3 lettres.");
        alert.setHeaderText(null);
        alert.showAndWait();
      }

    } else {

      if (!motInput.getText().isEmpty() && motInput.getText().length() > 2) {

        model.rechMotPartiel(".*" + motInput.getText() + ".*");

        if (checkBoxImage.isSelected()) {

          model.rechSelonImage();
        }

        if (checkBoxSaisieApres.isSelected() && datePickerSaisieApres.getValue() != null) {

          model.rechApresDateSaisie(datePickerSaisieApres.getValue());
        }

        if (checkBoxSaisieAvant.isSelected() && datePickerSaisieAvant.getValue() != null) {

          model.rechAvantDateSaisie(datePickerSaisieAvant.getValue());
        }

        if (checkBoxModifApres.isSelected() && datePickerModifApres.getValue() != null) {

          model.rechApresDateModif(datePickerModifApres.getValue());
        }

        if (checkBoxModifAvant.isSelected() && datePickerModifAvant.getValue() != null) {

          model.rechAvantDateModif(datePickerModifAvant.getValue());
        }

        if (model.listeResultats.isEmpty()) {

          Alert alert = new Alert(AlertType.ERROR);
          alert.setTitle("Dictionnaire");
          alert.setContentText("Mot introuvable.");
          alert.setHeaderText(null);
          alert.showAndWait();
        }

        model.notifyObs(model.listeResultats);

        for (Mot m : model.listeResultats) {

          System.out.println(m.getLibelle());
        }
      } else {

        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Dictionnaire");
        alert.setContentText("L'expression doit contenir minimum 3 lettres.");
        alert.setHeaderText(null);
        alert.showAndWait();
      }
    }
  }