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