tout bon bb
This commit is contained in:
parent
afa5a06122
commit
c2026225d7
|
|
@ -4,13 +4,14 @@ import java.awt.BorderLayout;
|
|||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
|
@ -44,7 +45,7 @@ public class Inter extends JFrame {
|
|||
private String cheminDictionnaire;
|
||||
|
||||
// Cache des données
|
||||
// private final Map<Integer, List<String>> commentairesFilms = new HashMap<>();
|
||||
private final Map<Integer, List<String>> commentairesFilms = new HashMap<>();
|
||||
private final Map<Integer, Integer> notesFilms = new HashMap<>();
|
||||
private final Map<String, Integer> dictionnaireSentiments = new HashMap<>();
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ public class Inter extends JFrame {
|
|||
private void initialiserInterface() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
setTitle("Système de recommandation de films");
|
||||
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
|
@ -172,6 +174,12 @@ public class Inter extends JFrame {
|
|||
try {
|
||||
listeAvis = new ListeAvis(cheminBigCsv);
|
||||
|
||||
// Initialiser notre cache de commentaires
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
List<String> commentairesFilm = listeAvis.getCommentairesParFilm(i);
|
||||
commentairesFilms.put(i, new ArrayList<>(commentairesFilm));
|
||||
}
|
||||
|
||||
// Créer ou charger le dictionnaire
|
||||
Dictionnaire dictionnaire = new Dictionnaire();
|
||||
|
||||
|
|
@ -296,17 +304,32 @@ public class Inter extends JFrame {
|
|||
rafraichirPanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcule la note moyenne pour un film
|
||||
*/
|
||||
private int calculerNoteMoyenne(int filmNumber) {
|
||||
int totalNotes= 0;
|
||||
Dictionnaire dico=new Dictionnaire(cheminDictionnaire);
|
||||
Dictionnaire dico = new Dictionnaire(cheminDictionnaire);
|
||||
Avis av = new Avis();
|
||||
List<String> commentaires = getCommentairesFilm(filmNumber);
|
||||
|
||||
totalNotes += av.Analyse(listeAvis.getCommentairesParFilm(filmNumber), dico);
|
||||
System.out.println(totalNotes);
|
||||
if (commentaires.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int totalNotes = av.Analyse(commentaires, dico);
|
||||
return totalNotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les commentaires d'un film depuis notre cache local
|
||||
*/
|
||||
private List<String> getCommentairesFilm(int filmNumber) {
|
||||
if (!commentairesFilms.containsKey(filmNumber)) {
|
||||
commentairesFilms.put(filmNumber, new ArrayList<>());
|
||||
}
|
||||
return commentairesFilms.get(filmNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche les détails d'un film
|
||||
*/
|
||||
|
|
@ -325,7 +348,7 @@ public class Inter extends JFrame {
|
|||
infoPanel.setLayout(new BorderLayout(MARGIN, MARGIN));
|
||||
|
||||
// Titre du film
|
||||
JLabel titreLabel = new JLabel("Titre + Infos");
|
||||
JLabel titreLabel = new JLabel("Film " + filmNumber + " - Titre + Infos");
|
||||
titreLabel.setFont(TITLE_FONT);
|
||||
titreLabel.setBorder(BorderFactory.createLineBorder(java.awt.Color.BLACK));
|
||||
titreLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
|
@ -335,7 +358,8 @@ public class Inter extends JFrame {
|
|||
JPanel centralPanel = new JPanel();
|
||||
centralPanel.setLayout(new GridLayout(1, 2, MARGIN, 0));
|
||||
|
||||
List<String> commentaires = listeAvis.getCommentairesParFilm(filmNumber);
|
||||
// Récupérer les commentaires à jour depuis notre cache
|
||||
List<String> commentaires = getCommentairesFilm(filmNumber);
|
||||
|
||||
// Panel pour la note et les commentaires affichés
|
||||
JPanel notePanel = creerPanelNote(filmNumber, commentaires);
|
||||
|
|
@ -439,7 +463,7 @@ public class Inter extends JFrame {
|
|||
commentPanel.setLayout(new BorderLayout(0, 5));
|
||||
commentPanel.setBorder(BorderFactory.createLineBorder(java.awt.Color.BLACK));
|
||||
|
||||
JLabel commentLabel = new JLabel("Exemple de commentaires");
|
||||
JLabel commentLabel = new JLabel("Ajouter un commentaire");
|
||||
commentLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
commentPanel.add(commentLabel, BorderLayout.NORTH);
|
||||
|
||||
|
|
@ -450,15 +474,30 @@ public class Inter extends JFrame {
|
|||
commentArea.setLineWrap(true);
|
||||
commentArea.setWrapStyleWord(true);
|
||||
|
||||
// Ajouter un écouteur pour la touche Entrée
|
||||
commentArea.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER && !e.isShiftDown()) {
|
||||
e.consume(); // Empêcher le saut de ligne
|
||||
String commentaire = commentArea.getText().trim();
|
||||
if (!commentaire.isEmpty()) {
|
||||
ajouterCommentaire(filmNumber, commentaire);
|
||||
commentArea.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(commentArea);
|
||||
commentPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// Bouton pour enregistrer le commentaire
|
||||
JButton saveButton = new JButton("Entrer");
|
||||
JButton saveButton = new JButton("Ajouter le commentaire");
|
||||
saveButton.addActionListener(e -> {
|
||||
String commentaire = commentArea.getText();
|
||||
String commentaire = commentArea.getText().trim();
|
||||
|
||||
if (commentaire.trim().isEmpty()) {
|
||||
if (commentaire.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(panel,
|
||||
"Veuillez entrer un commentaire.",
|
||||
"Erreur",
|
||||
|
|
@ -487,14 +526,14 @@ public class Inter extends JFrame {
|
|||
/**
|
||||
* Ajoute un commentaire à un film et met à jour l'interface
|
||||
*/
|
||||
private void ajouterCommentaire(int filmNumber, String c) {
|
||||
// Récupérer la liste des commentaires
|
||||
Dictionnaire dico = new Dictionnaire(cheminDictionnaire);
|
||||
Avis av =new Avis();
|
||||
List<String> commentaires = listeAvis.getCommentairesParFilm(filmNumber);
|
||||
commentaires.add(c);
|
||||
private void ajouterCommentaire(int filmNumber, String commentaire) {
|
||||
// Ajouter le commentaire à notre cache local
|
||||
List<String> commentaires = getCommentairesFilm(filmNumber);
|
||||
commentaires.add(commentaire);
|
||||
|
||||
// Calculer la nouvelle note moyenne
|
||||
Dictionnaire dico = new Dictionnaire(cheminDictionnaire);
|
||||
Avis av = new Avis();
|
||||
int noteMoyenne = av.Analyse(commentaires, dico);
|
||||
notesFilms.put(filmNumber, noteMoyenne);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue