analyseWriter/src/app/evaluate.java

510 lines
20 KiB
Java

package app;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import MEPTL.commandes;
import MEPTL.meptl;
import cXML.Run;
import cXML.node;
import javax.swing.SwingConstants;
import java.awt.GridLayout;
import javax.swing.JScrollPane;
import javax.swing.JProgressBar;
import net.miginfocom.swing.MigLayout;
public class evaluate extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JLabel lblPath = new JLabel();
private JLabel lblFileAnalyse = new JLabel();
private JLabel lblFichierCSV = new JLabel();
private JLabel lblFichierSVG = new JLabel();
private JCheckBox chckbxfichiersEtudaints = new JCheckBox();
private JCheckBox chckbxZipfeedback = new JCheckBox();
private JCheckBox chckbxnoFeedback = new JCheckBox();
private JCheckBox chckbxNoNote = new JCheckBox();
private JCheckBox chckCSVNotes = new JCheckBox();
private JCheckBox chckbxNoLogo = new JCheckBox();
private JCheckBox chckbxVerif = new JCheckBox();
JCheckBox chckbxNewLogo = new JCheckBox();
private JTextPane txtpnmessages = new JTextPane();
private JProgressBar progressBar = new JProgressBar();
private JButton btnSelectFileAnalyse = new JButton();
private JButton btnSelectFolder = new JButton();
private JButton btnEvaluerLesFichiers = new JButton();
private JButton btnFichierCSV = new JButton();
private JButton btnAbout = new JButton();
private JButton btnFichierSVG = new JButton();
private JButton btnExit = new JButton();
private JButton btnInformationAnalyse = new JButton();
private JButton btnInfoListeEtudiant;
/**
* Create the frame.
*/
public evaluate() {
ImageIcon img = new ImageIcon(getClass().getResource("/evalwriter.png") );
this.setIconImage(img.getImage());
this.setTitle(commandes.Titre);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 960, 677);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JToolBar toolBar = new JToolBar();
contentPane.add(toolBar, BorderLayout.NORTH);
btnSelectFileAnalyse = new JButton("");
btnSelectFileAnalyse.setToolTipText("Sélection du fichier d'analyse");
btnSelectFileAnalyse.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierAnalyse.png")));
toolBar.add(btnSelectFileAnalyse);
btnInformationAnalyse = new JButton("");
btnInformationAnalyse.setToolTipText("Information sur l'analyse");
btnInformationAnalyse.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierAnalyseInfo.png")));
toolBar.add(btnInformationAnalyse);
btnSelectFolder = new JButton("");
btnSelectFolder.setIcon(new ImageIcon(evaluate.class.getResource("/resources/open2.png")));
btnSelectFolder.setSelectedIcon(new ImageIcon(evaluate.class.getResource("/resources/evalwriter.png")));
btnSelectFolder.setToolTipText("Sélectionner le dossier contenant les fichiers des étudiants");
toolBar.add(btnSelectFolder);
toolBar.addSeparator();
btnEvaluerLesFichiers = new JButton("");
btnEvaluerLesFichiers.setToolTipText("Evaluer les fichiers des étudiants");
btnFichierCSV = new JButton("");
btnFichierCSV.setToolTipText("Sélectionner la liste des étudiants");
btnFichierCSV.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierCSV.png")));
toolBar.add(btnFichierCSV);
btnInfoListeEtudiant = new JButton("");
btnInfoListeEtudiant.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierCSVInfo.png")));
btnInfoListeEtudiant.setToolTipText("Affichage liste des étudiants");
toolBar.add(btnInfoListeEtudiant);
toolBar.addSeparator();
btnFichierSVG = new JButton("");
btnFichierSVG.setToolTipText("Sélectionner le fichier Logo");
btnFichierSVG.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierSVG.png")));
toolBar.add(btnFichierSVG);
toolBar.addSeparator();
JButton btnNewButton_1 = new JButton("");
btnNewButton_1.setToolTipText("Créer un fichier d'analyse à partir d'un fichier ODF");
btnNewButton_1.setIcon(new ImageIcon(evaluate.class.getResource("/resources/fichierODF.png")));
toolBar.add(btnNewButton_1);
toolBar.addSeparator();
btnEvaluerLesFichiers.setIcon(new ImageIcon(evaluate.class.getResource("/resources/evaluate.png")));
toolBar.add(btnEvaluerLesFichiers);
toolBar.addSeparator();
toolBar.addSeparator();
btnAbout = new JButton("");
btnAbout.setIcon(new ImageIcon(evaluate.class.getResource("/resources/apropos.png")));
btnAbout.setToolTipText("Informations");
toolBar.add(btnAbout);
toolBar.addSeparator();
toolBar.addSeparator();
btnExit = new JButton("");
btnExit.setIcon(new ImageIcon(evaluate.class.getResource("/resources/exit.png")));
btnExit.setToolTipText("Fermer l'application");
toolBar.add(btnExit);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.WEST);
panel.setLayout(new MigLayout("", "[309px]", "[71px][71px][][71px][][74.00][][]"));
lblFileAnalyse = new JLabel("<HTML><B><U>Fichier de l'analyse</U></B> : </HTML>");
lblFileAnalyse.setHorizontalAlignment(SwingConstants.LEFT);
lblFileAnalyse.setFont(new Font("Tahoma", Font.BOLD, 14));
panel.add(lblFileAnalyse, "flowy,cell 0 0,alignx left,growy");
chckbxfichiersEtudaints = new JCheckBox("Les fichiers ne sont pas dans des dossiers nominatifs");
chckbxfichiersEtudaints.setFont(new Font("Tahoma", Font.PLAIN, 12));
chckbxfichiersEtudaints.setToolTipText("Cochez si les fichiers des étudiants ne sont pas dans des dossier nominatifs");
panel.add(chckbxfichiersEtudaints, "flowy,cell 0 1,grow");
lblFichierCSV = new JLabel("<HTML><B><U>Fichier CSV liste des étudiants</U></B></HTML> :");
lblFichierCSV.setFont(new Font("Tahoma", Font.BOLD, 14));
panel.add(lblFichierCSV, "flowy,cell 0 3,grow");
lblFichierSVG = new JLabel("<HTML><B><U>Fichier SVG</U></B> :</HTML>");
lblFichierSVG.setFont(new Font("Tahoma", Font.BOLD, 14));
panel.add(lblFichierSVG, "flowy,cell 0 5,growx");
chckCSVNotes = new JCheckBox("Créer un fichier CSV des notes");
chckCSVNotes.setToolTipText("Cochez si vous voulez importer les notes dans un fichier CSV.");
panel.add(chckCSVNotes, "cell 0 3,grow");
lblPath.setHorizontalAlignment(SwingConstants.LEFT);
lblPath.setFont(new Font("Tahoma", Font.BOLD, 14));
lblPath.setText("<HTML><B><U>Dossier de l'analyse</U></B> : " + commandes.path.substring(commandes.path.lastIndexOf("\\")+1,commandes.path.length()) + "</HTML>");
panel.add(lblPath, "cell 0 0,grow");
chckbxnoFeedback = new JCheckBox("Pas de feedback");
chckbxnoFeedback.setToolTipText("Cochez si vous ne voulez pas générer des feedbacks");
chckbxnoFeedback.setFont(new Font("Tahoma", Font.PLAIN, 12));
panel.add(chckbxnoFeedback, "cell 0 1,grow");
chckbxZipfeedback = new JCheckBox("Zip les feedbacks");
chckbxZipfeedback.setToolTipText("Cochez si vous voulez placer tous les feedbacks dans une archive ZIP");
chckbxZipfeedback.setFont(new Font("Tahoma", Font.PLAIN, 12));
panel.add(chckbxZipfeedback, "cell 0 1,grow");
chckbxNoNote = new JCheckBox("Pas de note dans les feedbacks");
chckbxNoNote.setToolTipText("Cochez si vous voulez pas faire apparaître les notes dans les feedbacks");
chckbxNoNote.setFont(new Font("Tahoma", Font.PLAIN, 12));
panel.add(chckbxNoNote, "cell 0 1,grow");
chckbxVerif = new JCheckBox("Vérification des historiques avant analyse");
chckbxVerif.setToolTipText("Cochez si vous voulez vérifier les échanges de fichiers entre les étudiants.");
chckbxVerif.setFont(new Font("Tahoma", Font.PLAIN, 12));
panel.add(chckbxVerif, "cell 0 1, grow");
chckbxNewLogo = new JCheckBox("Nouveau logo");
chckbxNewLogo.setToolTipText("Cochez si vous voulez remplacer le logo par celui au-dessus.");
chckbxNewLogo.setFont(new Font("Tahoma", Font.PLAIN, 12));
panel.add(chckbxNewLogo, "cell 0 5");
chckbxNoLogo = new JCheckBox("Pas de logo");
chckbxNoLogo.setToolTipText("Cochez si vous voulez pas de logo dans les feedbacks.");
chckbxNoLogo.setFont(new Font("Tahoma", Font.PLAIN, 12));
panel.add(chckbxNoLogo, "cell 0 5");
JPanel panel_1 = new JPanel();
contentPane.add(panel_1, BorderLayout.CENTER);
panel_1.setLayout(new GridLayout(1, 0, 0, 0));
JScrollPane scrollPane = new JScrollPane();
panel_1.add(scrollPane);
progressBar = new JProgressBar();
progressBar.setEnabled(false);
scrollPane.setColumnHeaderView(progressBar);
txtpnmessages = new JTextPane();
txtpnmessages.setFont(new Font("Tahoma", Font.PLAIN, 14));
txtpnmessages.setText("Charger un fichier d'analyse.");
scrollPane.setViewportView(txtpnmessages);
CommandeListener();
refreshLabel();
setVisible(true);
}
/**
* Raffraichi les informations
*/
private void refreshLabel() {
if(!commandes.fichierAnalyseValide) {
txtpnmessages.setText(MEPTL.verificationFichierAnalyse.messageErreur.toString());
chckbxfichiersEtudaints.setEnabled(false);
chckbxZipfeedback.setEnabled(false);
chckbxnoFeedback.setEnabled(false);
chckbxNoNote.setEnabled(false);
chckCSVNotes.setEnabled(false);
chckbxNewLogo.setEnabled(false);
chckbxNoLogo.setEnabled(false);
chckbxVerif.setEnabled(false);
}else {
chckbxfichiersEtudaints.setEnabled(true);
chckbxZipfeedback.setEnabled(true);
chckbxnoFeedback.setEnabled(true);
chckbxNoNote.setEnabled(true);
chckCSVNotes.setEnabled(true);
chckbxNewLogo.setEnabled(true);
chckbxNoLogo.setEnabled(true);
chckbxVerif.setEnabled(true);
StringBuilder text = new StringBuilder();
text.append("\n***********************************************");
text.append("\n INFORMATIONS");
text.append("\n***********************************************");
text.append("\nLe titre de l'exercice est : " + commandes.analyse_titre);
text.append("\n");
text.append("\nLe sujet (metaSujet) est : " + commandes.analyse_metaSujet);
text.append("\n");
text.append("\nL'auteur de l'exercice est : " + commandes.analyse_auteur);
text.append("\n");
if(commandes.analyse_baremeABC==true) {
text.append("\nLa notation est sous la forme d'un barème alphabétique ABCDE.");
text.append("\n\tLa progression est de " + String.valueOf(commandes.analyse_progression));
}else {
text.append("\nLa notation est sous la forme d'une note numérique.");
text.append("\n\tLe barème est sur " + String.valueOf(commandes.analyse_notefrom));
text.append("\n\tLa progression est de " + String.valueOf(commandes.analyse_progression));
}
text.append("\n______");
text.append("\nLe nom du fichier : " + commandes.analysis_filename);
text.append("\nLe hash de l'évaluation est : " + commandes.hash);
text.append("\n______");
text.append("\nHistoriques des modifications present : " + commandes.analyse_historiquePresent);
text.append("\n______");
text.append("\nVerification de la presence metaSujet : " + commandes.analyse_presenceMetaSujet);
text.append("\n______");
text.append("\nContrôle la date de céation : " + commandes.analyse_controleDateCreation);
text.append("\n______");
text.append("\nContrôle l'auteur initial du fichier : " + commandes.analyse_controle_Initial_Creator);
text.append("\n\n***********************************************");
text.append("\n\n***********************************************");
text.append("\nDossier de l'analyse contenant les fichiers des étudiants :");
text.append("\n"+commandes.path+"\n");
text.append("\nFichier d'analyse :");
text.append("\n"+commandes.PathFilenameAnalysis+"\n");
progressBar.setVisible(false);
txtpnmessages.setText(text.toString());
}
lblPath.setText("<HTML><B><U>Dossier de l'analyse</U></B> : " + commandes.path.substring(commandes.path.lastIndexOf("\\")+1,commandes.path.length()) + "</HTML>");
lblFileAnalyse.setText("<HTML><B><U>Fichier de l'analyse</U></B> : " + commandes.analysis_filename + "</HTML>");
lblFichierSVG.setText("<HTML><B><U>Fichier SVG</U></B> : " + commandes.nameSVG.substring(commandes.nameSVG.lastIndexOf("\\")+1,commandes.nameSVG.length()) + "</HTML>");
lblFichierCSV.setText("<HTML><B><U>Fichier CSV</U></B> : " + commandes.nameCSV + "</HTML>");
}
/**
* Les actionListener
*/
private void CommandeListener() {
// Sélectionne un dossier pour analyser le contenu
btnSelectFolder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File(commandes.path));
chooser.setDialogTitle("Sélectionner le dossier contenant les fichiers des étudiants.");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath());
commandes.path = chooser.getSelectedFile().getAbsolutePath();
} else {
System.out.println("No Selection ");
}
refreshLabel();
}
});
// Sélectionne un fichier d'analyse
btnSelectFileAnalyse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new filechooserXML();
refreshLabel();
}
});
// Analyse le contenu du dossier
btnEvaluerLesFichiers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(commandes.fichierAnalyseValide) {
try {
msgBox V = new msgBox("Je travaille dure.",false,false,"Attendez");
Thread.sleep(200);
evaluerLesFichiersEtudiants();
V.close();
} catch (ParserConfigurationException | SAXException | IOException | CloneNotSupportedException e1) {
e1.printStackTrace();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}else {
new msgBox("Le fichier d'analyse n'est pas valide.",true,false,"Avertissement");
}
}
});
// Sélectionne un fichier CSV
btnFichierCSV.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Choisir un fichier CSV");
chooser.setCurrentDirectory(new java.io.File(commandes.path));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Format CSV", "csv");
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(true);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath());
commandes.nameCSV = chooser.getSelectedFile().getAbsolutePath();
commandes.fourniCSV=true;
commandes.nodeCSV = meptl.chargementFichierCSV();
txtpnmessages.setText(Run.ecritureNode(commandes.nodeCSV, 0).toString());
} else {
commandes.nameCSV = "";
commandes.fourniCSV=false;
System.out.println("No Selection ");
commandes.nodeCSV = new node();
refreshLabel();
}
}
});
// Bouton SVG
btnFichierSVG.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Choisir un fichier SVG");
chooser.setCurrentDirectory(new java.io.File(commandes.path));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Format SVG", "svg");
chooser.setFileFilter(filter);
chooser.setAcceptAllFileFilterUsed(true);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : " + chooser.getSelectedFile().getAbsolutePath());
commandes.nameSVG = chooser.getSelectedFile().getAbsolutePath();
commandes.contenuFichierSVG= meptl.chargementFichierSVG();
txtpnmessages.setText(commandes.contenuFichierSVG);
} else {
commandes.nameSVG = "";
commandes.contenuFichierSVG="";
System.out.println("No Selection ");
}
refreshLabel();
}
});
// Bouton About
btnAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new about();
}
});
// Exit
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
// Information
btnInformationAnalyse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(commandes.fichierAnalyseValide) {
refreshLabel();
}else {
txtpnmessages.setText("*** Veuillez charger un fichier d'analyse ***");
}
}
});
// liste des étudiants
btnInfoListeEtudiant.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(commandes.fourniCSV) {
txtpnmessages.setText(Run.ecritureNode(commandes.nodeCSV, 0).toString());
}else {
txtpnmessages.setText("*** Veuillez sélectionner un fichier CSV contenant la liste des étudiants ***");
}
}
});
}
/**
* Permet l'évaluation des fichiers des étudaints.
* @throws ParserConfigurationException
* @throws SAXException
* @throws IOException
* @throws CloneNotSupportedException
*/
private void evaluerLesFichiersEtudiants() throws ParserConfigurationException, SAXException, IOException, CloneNotSupportedException {
commandes.analyse=true;
progressBar.setVisible(true);
if(chckbxfichiersEtudaints.isSelected()) commandes.fichierStudentMoodle=true;
if(chckbxZipfeedback.isSelected()) commandes.zipfeedback=true;
if(chckbxnoFeedback.isSelected()) commandes.sansFeeback=true;
if(chckbxNoNote.isSelected()) commandes.noNote=true;
if(chckCSVNotes.isSelected()) commandes.ecritNoteCSV=true;
if(chckbxNewLogo.isSelected()) commandes.newLogo=true;
if(chckbxNoLogo.isSelected()) commandes.noLogo = true;
if(chckbxVerif.isSelected()) commandes.verifHisto2 = true;
meptl.analyseVerifieHistoriqueLesFichiersEtudiantsEtExportNoteCSV();
txtpnmessages.setText(commandes.message.toString());
progressBar.setVisible(false);
}
}