// Big bunch of AJOUTS public boolean ajouterVideo( String titre, int annee, boolean type, int eval, String comments, String categories) { try { // Creer un objet video avec TITRE ANNEE TYPE EVAL COMMENTS Video video = new Video(titre, annee, eval, type); video.setCommentaires(comments); String[] arrayCategories = categories.split(System.getProperty("line.separator")); boolean confirmation = false; // Ajouter cette video dans toutes les categories for (String categorie : arrayCategories) { confirmation = liste.ajouter(categorie, video); } if (confirmation) { JOptionPane.showMessageDialog(fenetre, video.getTitre() + " ajouté à la liste!"); return true; } else { JOptionPane.showMessageDialog( fenetre, video.getTitre() + " n'a pas été ajouté à la liste!"); return false; } } catch (Exception ex) { this.messageErreur(ex.getMessage()); return false; } }
// Mode modification public void modeModification() { resetCollection(); loadCollection(); resetCategorie(); loadCategorie(); comboCollection.setEnabled(true); textTitre.setVisible(true); textTitre.setEnabled(true); textTitre.setEditable(true); textAnnee.setVisible(true); textAnnee.setEnabled(true); textAnnee.setEditable(true); comboType.setVisible(true); comboType.setEnabled(true); comboEval.setVisible(true); comboEval.setEnabled(true); scrollCom.setEnabled(true); scrollCat.setEnabled(true); textCommentaires.setEnabled(true); textCommentaires.setEditable(true); textCommentaires.setBackground(Color.WHITE); textCommentaires.setText(""); textCategories.setEnabled(true); textCategories.setEditable(false); textCategories.setBackground(GRIS); textCategories.setText(""); for (int i = 0; i < infos_film.length; i++) { infos_film[i].setVisible(false); } for (int k = 0; k < modeButton.length; k++) { modeButton[k].setEnabled(false); modeButton[k].setVisible(false); } modeButton[3].setVisible(true); // Boutton Modifier modeButton[4].setVisible(true); // Boutton Supprimer boolean enabled = true; if (listeEstVide()) { enabled = false; } modeButton[3].setEnabled(enabled); modeButton[4].setEnabled(enabled); optionCategories[0].setEnabled(true); // Boutton ajouter categorie optionCategories[1].setEnabled(true); // Place the first element of combobox in the grid comboCollection.setSelectedIndex(0); Video video = this.obtenirVideo(comboCollection.getSelectedItem().toString()); afficherFilmChoisis(video.getTitre()); }
public void afficherFilmChoisis(String titre) { Video film = this.obtenirVideo(titre); String catos = this.obtenirCategoriesEnString( comboCollection.getItemAt(comboCollection.getSelectedIndex()).toString()); if (mode[0].isSelected()) { String filmOuSerie = "SERIE TV"; String eval = ""; if (film.getEval() == 1) { eval = String.valueOf(film.getEval()) + " etoile"; } else if (film.getEval() > 1) { eval = String.valueOf(film.getEval()) + " etoiles"; } if (film.isFilm()) { filmOuSerie = "FILM"; } infos_film[0].setText(titre); infos_film[1].setText(String.valueOf(film.getAnnee())); infos_film[2].setText(filmOuSerie); infos_film[3].setText(eval); } else { textTitre.setText(film.getTitre()); textAnnee.setText(String.valueOf(film.getAnnee())); comboEval.setSelectedIndex(film.getEval()); boolean isFilm = film.isFilm(); if (isFilm) { comboType.setSelectedIndex(1); } else { comboType.setSelectedIndex(2); } } textCommentaires.setText(film.getCommentaires()); textCategories.setText(catos); }
// Mode consultation public void modeConsultation() { resetCollection(); loadCollection(); comboCollection.setEnabled(true); textTitre.setVisible(false); textTitre.setEditable(false); textAnnee.setVisible(false); textAnnee.setEditable(false); comboType.setVisible(false); comboType.setEnabled(false); comboEval.setVisible(false); comboEval.setEnabled(false); // Juste au cas que ca foire scrollCom.setEnabled(true); scrollCat.setEnabled(true); textCommentaires.setEnabled(true); textCommentaires.setEditable(false); textCategories.setEnabled(true); textCategories.setEditable(false); textCommentaires.setBackground(GRIS); textCategories.setBackground(GRIS); for (int k = 0; k < infos_film.length; k++) { infos_film[k].setVisible(true); } // Place the first element of combobox in the grid DEPRECATED by Enoncé comboCollection.setSelectedIndex(comboCollection.getSelectedIndex()); for (int l = 0; l < modeButton.length; l++) { if (l < 2) { modeButton[0].setEnabled(false); modeButton[0].setVisible(true); if (comboCollection.getItemCount() > 1) { modeButton[l].setEnabled(true); modeButton[l].setVisible(true); } else { modeButton[l].setEnabled(false); modeButton[l].setVisible(true); } // modeButton[l].setEnabled(true); // modeButton[l].setVisible(true); } else { modeButton[l].setEnabled(false); modeButton[l].setVisible(false); } } optionCategories[0].setEnabled(false); optionCategories[1].setEnabled(false); // Get the collection and place in combobox Video video = this.obtenirVideo(comboCollection.getSelectedItem().toString()); afficherFilmChoisis(video.getTitre()); }
public void sauvegarder() { final String PATH = "./videos.txt"; File fichier = new File(PATH); String formatDeSortie = ""; for (Video video : this.obtenirCollection()) { String catos = this.obtenirCategoriesEnString(video.getTitre()); catos = catos.replace("\n", "::"); String comments = video.getCommentaires(); comments = comments.replace("\n", "[*]"); formatDeSortie += video.getTitre() + "::"; formatDeSortie += video.getAnnee() + "::"; if (video.isFilm()) { formatDeSortie += "FILM" + "::"; } else { formatDeSortie += "SÉRIE TV" + "::"; } formatDeSortie += video.getEval() + "::"; formatDeSortie += comments; // Comments formatDeSortie += "::"; formatDeSortie += catos; // Catos formatDeSortie += "\r\n"; // Petit fix pour que les new lines append au fichier txt } formatDeSortie = formatDeSortie.substring(0, formatDeSortie.length() - 1); try { FileWriter ecrivain = new FileWriter(fichier); ecrivain.write(formatDeSortie); ecrivain.close(); } catch (IOException io) { io.getMessage(); } }
// Obtenir une video public Video obtenirVideo(String titre) { // Obtenir la video en naviguant dans les categories Video video = null; ArrayList categories = liste.obtenirCles(); for (Object categorie : categories) { ArrayList<Video> videosOfCategorie = liste.obtenirElements((String) categorie); for (Video vid : videosOfCategorie) { Video temp = (Video) vid; if (temp.getTitre().equals(titre)) { video = temp; } } } // Return return video; }
public void gererEventBouttons(ActionEvent e) { if (e.getSource() == modeButton[0]) { // Boutton precedent // Verify if (comboCollection.getItemAt(comboCollection.getSelectedIndex() - 1) == null) { // modeButton[0].setVisible(false); modeButton[0].setEnabled(false); // messageErreur("Il n'y a pas d'element precedent a la collection"); messageErreur(MSG_ERREUR_BTN_PRECEDENT); } else { comboCollection.setSelectedIndex(comboCollection.getSelectedIndex() - 1); // Get Video video = this.obtenirVideo( comboCollection .getItemAt(comboCollection.getSelectedIndex()) .toString()); // String titre String catos = this.obtenirCategoriesEnString( comboCollection.getItemAt(comboCollection.getSelectedIndex()).toString()); afficherFilmChoisis(video.getTitre()); modeButton[1].setVisible(true); modeButton[1].setEnabled(true); if (comboCollection.getItemAt(comboCollection.getSelectedIndex() - 1) == null) { modeButton[0].setEnabled(false); } } } else if (e.getSource() == modeButton[1]) { // Boutton suivant // Verify if (comboCollection.getItemAt(comboCollection.getSelectedIndex() + 1) == null) { // modeButton[1].setVisible(false); modeButton[1].setEnabled(false); // messageErreur("Il n'y a pas d'element suivant a la collection"); messageErreur(MSG_ERREUR_BTN_SUIVANT); } else { comboCollection.setSelectedIndex(comboCollection.getSelectedIndex() + 1); // Get Video video = this.obtenirVideo( comboCollection .getItemAt(comboCollection.getSelectedIndex()) .toString()); // String titre String catos = this.obtenirCategoriesEnString( comboCollection.getItemAt(comboCollection.getSelectedIndex()).toString()); afficherFilmChoisis(video.getTitre()); modeButton[0].setVisible(true); modeButton[0].setEnabled(true); if (comboCollection.getItemAt(comboCollection.getSelectedIndex() + 1) == null) { modeButton[1].setEnabled(false); } } } else if (e.getSource() == modeButton[2]) { // Boutton ajouter // Verify if (textTitre.getText() == null || textTitre.getText().equals("")) { messageErreur(MSG_ERREUR_CHAMPS_TITRE); } else if (textAnnee.getText() == null || textAnnee.getText().equals("") || !textAnnee.getText().matches("^[0-9]+$")) { messageErreur(MSG_ERREUR_CHAMPS_ANNEE); } /*else if(textCommentaires.getText() == null){ messageErreur("Champs commentaires null"); } */ else if (textCategories.getText() == null) { messageErreur(MSG_ERREUR_CHAMP_CAT); } else { boolean type; if (comboType.getSelectedIndex() == 0) { messageErreur(MSG_ERREUR_CHAMP_TYPE); type = false; } else { if (comboType.getSelectedIndex() == 1) { type = true; } else { type = false; } int eval; if (comboEval.getSelectedIndex() == 0) { messageErreur(MSG_ERREUR_EVALUATION); } else { eval = comboEval.getSelectedIndex(); // Place this.ajouterVideo( textTitre.getText(), Integer.parseInt(textAnnee.getText()), type, eval, textCommentaires.getText(), textCategories .getText()); // String titre, int annee, boolean type, int eval, String // comments, String categories } } } } else if (e.getSource() == modeButton[3]) { // Boutton modifier // Verify if (textTitre.getText() == null || textTitre.getText().equals("")) { messageErreur(MSG_ERREUR_CHAMPS_TITRE); } else if (textAnnee.getText() == null || textAnnee.getText().equals("") || !textAnnee.getText().matches("^[0-9]+$")) { messageErreur(MSG_ERREUR_CHAMPS_ANNEE); } /*else if(textCommentaires.getText() == null){ messageErreur("Champs commentaires null"); } */ else if (textCategories.getText() == null) { messageErreur(MSG_ERREUR_CHAMP_CAT); } else { int eval; if (comboEval.getSelectedIndex() == 0) { messageErreur(MSG_ERREUR_EVALUATION); } else { eval = comboEval.getSelectedIndex(); boolean type; if (comboType.getSelectedIndex() == 0) { messageErreur(MSG_ERREUR_CHAMP_TYPE); type = false; } else if (comboType.getSelectedIndex() == 1) { type = true; } else { type = false; } // Place if (this.modifierVideo( comboCollection.getSelectedItem().toString(), textTitre.getText(), Integer.parseInt(textAnnee.getText()), eval, type, textCommentaires.getText(), textCategories .getText())) { // String titre, int annee, int eval, boolean type, String // comments, String categories messageSuccess("La video a ete modifier."); } else { messageSuccess("La video n'a pas ete modifier."); } } } } else if (e.getSource() == modeButton[4]) { // Boutton supprimer // Verify ... nothing... // Place if (this.supprimerVideo(comboCollection.getSelectedItem().toString())) { JOptionPane.showMessageDialog( fenetre, comboCollection.getSelectedItem().toString() + " a ete retirer de la collection!"); } else { messageErreur(MSG_ERREUR_FIM_NON_SUPPRIMER); } } else if (e.getSource() == modeButton[5]) { // Boutton rechercher int eval = comboEval.getSelectedIndex(); /* -1: Pas de recherche par evaluation 0: 0 étoile 1: 1 étoile 2: 2 étoiles 3: 3 étoiles 4: 4 étoiles 5: 5 étoiles */ /* -1: Pas de recherche par type 0: FILM 1: SERIE TV */ int type = comboType.getSelectedIndex() - 1; ArrayList<Video> videosTrouver = new ArrayList<Video>(); if (!textAnnee.getText().equals("")) { videosTrouver = rechercherVideos( textTitre.getText(), Integer.parseInt(textAnnee.getText()), eval, type, textCategories.getText()); } else { videosTrouver = rechercherVideos(textTitre.getText(), -1, eval, type, textCategories.getText()); } // comboCollection.removeAllItems(); ArrayList itemsInComboCollection = new ArrayList(); for (Video video : videosTrouver) { if (!itemsInComboCollection.contains(video)) { itemsInComboCollection.add(video); comboCollection.addItem(video.getTitre()); } } comboCollection.setEnabled(true); modeButton[0].setVisible(true); modeButton[1].setVisible(true); if (comboCollection.getSelectedIndex() != 0 && comboCollection.getItemCount() != 0) { modeButton[0].setEnabled(true); } else { modeButton[0].setEnabled(false); } if (comboCollection.getSelectedIndex() != comboCollection.getItemCount() && comboCollection.getItemCount() != 0) { modeButton[1].setEnabled(true); } else { modeButton[1].setEnabled(false); } modeButton[5].setVisible(false); modeButton[6].setVisible(true); } else if (e.getSource() == modeButton[6]) { // Bouton Nouvelle Recherche modeRecherche(); } else if (e.getSource() == optionCategories[0]) { // Boutton ajouter categorie // Get String[] categoriesDuFilm = textCategories.getText().split("\n"); ArrayList listeDeCategories = ArrayToArrayList(categoriesDuFilm); if (listeDeCategories.get(0).equals("")) { listeDeCategories.clear(); } selectionCategorie.removeAllItems(); ArrayList cater = new ArrayList(); for (String categorie : liste.obtenirCles()) { if (!cater.contains(categorie)) { cater.add(categorie); selectionCategorie.addItem(categorie); } } popUpSelection.add(selectionCategorie); fenetre.getContentPane().add(popUpSelection); int action = JOptionPane.showConfirmDialog( null, popUpSelection, "Categorie", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (action) { case 0: if (((String) selectionCategorie.getSelectedItem()).equals("Autres...")) { popUpSelection.remove(selectionCategorie); String categorieEntree = JOptionPane.showInputDialog(popUpSelection, "Ajouter une categorie"); if (categorieEntree != null) { if (!categorieExiste(listeDeCategories, categorieEntree)) { if (listeDeCategories.isEmpty()) { textCategories.setText(categorieEntree); } else { textCategories.setText(textCategories.getText() + "\n" + categorieEntree); } optionCategories[1].setEnabled(true); } else { messageErreur(MSG_ERREUR_CAT_EXST); } } else { messageErreur(MSG_ERREUR_ENTREE_NULL); } } else { if (!categorieExiste( listeDeCategories, (String) selectionCategorie.getSelectedItem())) { if (listeDeCategories.isEmpty()) { textCategories.setText(selectionCategorie.getSelectedItem().toString()); } else { textCategories.setText( textCategories.getText() + "\n" + (String) selectionCategorie.getSelectedItem()); } } else { messageErreur(MSG_ERREUR_CAT_EXST); } } break; case 1: break; } } else if (e.getSource() == optionCategories[1]) { // Boutton supprimer categorie // Get String[] categoriesDuFilm = textCategories.getText().trim().split("\\n"); ArrayList listeDeCategories = ArrayToArrayList(categoriesDuFilm); selectionCategorie.removeAllItems(); for (Object categorie : listeDeCategories) { selectionCategorie.addItem(categorie.toString()); } popUpSelection.add(selectionCategorie); fenetre.getContentPane().add(popUpSelection); int action = JOptionPane.showConfirmDialog( null, popUpSelection, "Categorie", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (action) { case 0: String categorieASupprimer = (String) selectionCategorie.getSelectedItem(); String output = ""; if (!listeDeCategories.isEmpty()) { listeDeCategories.remove(categorieASupprimer); for (int i = 0; i < listeDeCategories.size(); i++) { output += (String) listeDeCategories.get(i); if (i + 1 != listeDeCategories.size()) { output += "\n"; } } textCategories.setText(output); } else { optionCategories[1].setEnabled(false); } break; case 1: break; } } }
// Recherche avec les informations dans TITRE, ANNEE, TYPE, EVALUATION, COMMENTAIRES, CATEGORIES // en && // Considère les champs vides comme des */ALL // Donne un array de videos qui respecte la query public ArrayList<Video> rechercherVideos( String titre, int annee, int eval, int type, String categories) { ArrayList<Video> listeCollection = new ArrayList<>(); ArrayList<Video> correctCollection = new ArrayList<>(); for (String categorie : liste.obtenirCles()) { for (Video video : liste.obtenirElements(categorie)) { if (!listeCollection.contains(video)) { listeCollection.add(video); } } } correctCollection.addAll(listeCollection); String[] arrayCategories = categories.split("\\r?\\n"); if (!titre.equals("") && titre != null) { for (Video video : listeCollection) { if (!video.getTitre().contains(titre)) { correctCollection.remove(video); } } } if (annee != -1) { for (Video video : listeCollection) { if (video.getAnnee() != annee) { // correctCollection.add(video); correctCollection.remove(video); } } } if (type != -1) { boolean controle; if (type == 0) { controle = true; } else { controle = false; } for (Video video : listeCollection) { if (video.isFilm() != controle) { // correctCollection.add(video); correctCollection.remove(video); } } } ArrayList<Video> categoriesCollection = new ArrayList<Video>(); if (!categories.equals("")) { for (String categorie : arrayCategories) { for (String cato : liste.obtenirCles()) {} ArrayList<Video> f**k = liste.obtenirElements(liste.obtenirCles().get(liste.obtenirCles().indexOf(categorie))); // for(Video video : // liste.obtenirElements(liste.obtenirCles().get(liste.obtenirCles().indexOf(categorie)))){ // for(Video video : liste.obtenirElements(categorie)){ for (Video video : f**k) { if (!categoriesCollection.contains(video)) { categoriesCollection.add(video); } } } for (Video video : listeCollection) { if (!categoriesCollection.contains(video)) { correctCollection.remove(video); } } } return correctCollection; }
public void loadCollection() { ArrayList<Video> collections = obtenirCollection(); for (Video video : collections) { comboCollection.addItem(video.getTitre()); } }