MAJ V4.4.3

This commit is contained in:
pablo rodriguez 2023-02-24 18:22:58 +01:00
parent c0167d7e58
commit 7522ddb274
5 changed files with 485 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -16,6 +16,7 @@ import javax.swing.filechooser.FileSystemView;
import MEPTL.commandes;
import cXML.node;
import fenetres.SimpleTableDemo;
import fenetres.chargeEvaluations;
import fenetres.create;
@ -31,7 +32,8 @@ public class actOpenHistoriqueEvaluation extends AbstractAction{
public void actionPerformed(ActionEvent e) {
nodeEvaluations();
if(commandes.evaluationsBase!=null) {
chargeEvaluations.getInstance();
// chargeEvaluations.getInstance();
new SimpleTableDemo();
}else {
commandes.evaluationsBase = new node();
commandes.evaluationsBase.setNomElt("evaluations");

View File

@ -0,0 +1,477 @@
package fenetres;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Date;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileSystemView;
import MEPTL.commandes;
import MEPTL.meptl;
import MEPTL.verificationFichierAnalyse;
import cXML.Run;
import cXML.node;
public class SimpleTableDemo extends JFrame { /**
*
*/
private static final long serialVersionUID = 1L;
private static SimpleTableDemo instance;
JTable table = new JTable();
private JPanel panelHaut = new JPanel();
private JPanel panelBas = new JPanel();
JLabel lblInformationBaseEvluation = new JLabel("");
private JButton btnSupprimeEvaluation = new JButton("Supprimer une évaluation");
private JButton btnSaveEvaluation = new JButton("Enregistre l'évaluation actuelle");
private JButton btnValide = new JButton("Charger l'évaluation");
public static boolean isDispose = true;
int indexSelect=0;
ListSelectionModel lsm = null;
String[][] data = new String[0][5];
String[] columnNames = {"Nom de l'évaluation","Date d'enregistrement","Titre de l'exercice","Propriété personnalisé Sujet","Nom du fichier d'analyse"};
JScrollPane scrollPane = new JScrollPane();
public SimpleTableDemo() {
super();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 1200, 400);
int screenWidth = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth();
int screenHeight = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight();
setLocation(( (screenWidth) - getWidth()) / 2, (screenHeight - getHeight()) / 2);
ImageIcon img = new ImageIcon(getClass().getResource("/evalwriter.png") );
setIconImage(img.getImage());
setTitle(commandes.Titre + " - La base de données des évaluations");
setLayout(new BorderLayout(2, 2));
int NombreDeLigne = commandes.evaluationsBase.getNodes().size();
data = new String[NombreDeLigne][5];
for(int i = 0 ; i<commandes.evaluationsBase.getNodes().size(); i++ ) {
data[i][0] = commandes.evaluationsBase.getNodes().get(i).getAttributs().get("name");
data[i][1] = calcul.formatDateWriter.DateEnClairFR( calcul.formatDateWriter.DateLibreOffice(commandes.evaluationsBase.getNodes().get(i).getAttributs().get("date") ));
node fichier = commandes.evaluationsBase.getNodes().get(i).retourneFirstEnfantsByName("fichier");
data[i][2] = fichier.getAttributs().get("titre");
data[i][3] = fichier.getAttributs().get("metaSujet");
data[i][4] = fichier.getAttributs().get("filenameAnalyse");
}
table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
scrollPane = new JScrollPane(table);
//Add the scroll pane to this panel.
add(scrollPane,BorderLayout.CENTER);
//*Le bas de la fenêtre contenant les boutons
panelBas.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
btnSupprimeEvaluation.setForeground(new Color(255, 0, 0));
btnSupprimeEvaluation.setFont(new Font("Tahoma", Font.BOLD, 12));
panelBas.add(btnSupprimeEvaluation);
Component horizontalGlue = Box.createHorizontalGlue();
panelBas.add(horizontalGlue);
Component horizontalGlue_1 = Box.createHorizontalGlue();
panelBas.add(horizontalGlue_1);
btnSaveEvaluation.setForeground(new Color(0, 64, 128));
btnSaveEvaluation.setFont(new Font("Tahoma", Font.BOLD, 12));
panelBas.add(btnSaveEvaluation);
btnValide.setFont(new Font("Tahoma", Font.BOLD, 12));
btnValide.setForeground(new Color(0, 128, 0));
panelBas.add(btnValide);
add(panelBas, BorderLayout.SOUTH);
//*Le haut
String nombreEvluation = String.valueOf(commandes.evaluationsBase.getNodes().size());
lblInformationBaseEvluation.setText("<html>Date dernière modification : " +calcul.formatDateWriter.DateEnClairFR( calcul.formatDateWriter.DateLibreOffice(commandes.evaluationsBase.getAttributs().get("date"))) + " -- Nombre d'évaluation : " + nombreEvluation);
add(panelHaut, BorderLayout.NORTH);
lblInformationBaseEvluation.setFont(new Font("Tahoma", Font.BOLD, 14));
panelHaut.add(lblInformationBaseEvluation);
//*Détection de la ligne sélectionnée
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("No rows are selected.");
} else {
indexSelect = lsm.getMinSelectionIndex();
System.out.println("Row " + indexSelect
+ " is now selected.");
}
}
});
ListenerAction();
setVisible(true);
}
public static SimpleTableDemo getInstance() {
if(chargeEvaluations.isDispose) instance = null;
if (instance == null) {
instance = new SimpleTableDemo();
}
instance.setVisible(true);
isDispose=false;
return instance;
}
private void ListenerAction() {
/**
* Quitter le fenêtre.</br>
*/
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
isDispose=true;
dispose();
}
});
/**
* Bouton chargement de l'évaluation.</br>
*/
btnValide.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(lsm!=null) {
if (!lsm.isSelectionEmpty()) {
indexSelect = lsm.getMinSelectionIndex();
chargeEvaluationSelected(commandes.evaluationsBase.getNodes().get(indexSelect));
isDispose=true;
dispose();
}
}
}
});
/**
* Bouton Sauvegarde de l'évaluation.</br>
*/
btnSaveEvaluation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(commandes.fichierAnalyseValide) {
String name ="Nom de l'évaluation";
if(lsm!=null) {
if (!lsm.isSelectionEmpty()) {
indexSelect = lsm.getMinSelectionIndex();
name = data[indexSelect][0];
}
}
name = JOptionPane.showInputDialog(null,"Donner un nom à cette évaluation ?",name);
if(!name.isBlank()) {
if(!isEvaluationExist(name)) {
commandes.evaluationsBase.getNodes().add(0, creationNodeEvaluation(new node(), name));;
}else {
creationNodeEvaluation(commandes.evaluationsBase.retourneFirstNodeByNameAndAttributValueExactStrict("evaluation", "name", name), name);
}
//Mise à jour de la base de données
Date aujourdhui = new Date();
commandes.evaluationsBase.getAttributs().put("version", commandes.version);
try {
commandes.evaluationsBase.getAttributs().put("date", calcul.formatDateWriter.DateLibreOffice(aujourdhui));
ecritureBaseEvaluation(commandes.evaluationsBase);
isDispose=true;
dispose();
getInstance();
} catch (ParseException | IOException e1) {
e1.printStackTrace();
}
}
}
}
});
/**
* Bouton supprimer une évaluation.</br>
*/
btnSupprimeEvaluation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(lsm!=null) {
if (!lsm.isSelectionEmpty()) {
indexSelect = lsm.getMinSelectionIndex();
commandes.evaluationsBase.getNodes().remove(indexSelect);
try {
ecritureBaseEvaluation(commandes.evaluationsBase);
isDispose=true;
dispose();
getInstance();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
});
}
/**
* charge en mémoire l'évaluation sélectionnée.<br>
* @param evaluation
*/
private void chargeEvaluationSelected(node evaluation) {
//* Charge le node sujet provisoirement
commandes.path = evaluation.getAttributs().get("path"); //Dossier des fichiers des étudiants
commandes.sujet = evaluation.retourneFirstEnfantsByName("fichier"); // Chargement provisoire du node sujet depuis la base
commandes.nameSujet = evaluation.getAttributs().get("analysis_filename");
commandes.PathFilenameAnalysis = evaluation.getAttributs().get("PathFilenameAnalysis");
//** Les paramètres
commandes.version = evaluation.getAttributs().get("version");
commandes.fichierStudentMoodle = Boolean.valueOf(evaluation.getAttributs().get("fichierStudentMoodle"));
commandes.sansFeeback = Boolean.valueOf(evaluation.getAttributs().get("sansFeeback"));
commandes.noDetail = Boolean.valueOf(evaluation.getAttributs().get("noDetail"));
commandes.noNote = Boolean.valueOf(evaluation.getAttributs().get("noNote"));
commandes.zipfeedback = Boolean.valueOf(evaluation.getAttributs().get("zipfeedback"));
commandes.verifHisto2 = Boolean.valueOf(evaluation.getAttributs().get("verifHisto2"));
commandes.ecritNoteCSV = Boolean.valueOf(evaluation.getAttributs().get("ecritNoteCSV"));
commandes.newLogo = Boolean.valueOf(evaluation.getAttributs().get("newLogo"));
commandes.noLogo = Boolean.valueOf(evaluation.getAttributs().get("noLogo"));
commandes.fourniCSV = Boolean.valueOf(evaluation.getAttributs().get("fourniCSV"));
commandes.nameCSV = evaluation.getAttributs().get("nameCSV");
commandes.fourniCSV = Boolean.valueOf(evaluation.getAttributs().get("fourniCSV"));
commandes.nameSVG = evaluation.getAttributs().get("nameSVG");
commandes.nodeCSV = evaluation.retourneFirstEnfantsByName("fileCSV");
commandes.contenuFichierSVG = evaluation.retourneFirstEnfantsByName("nodSVG").retourneLesContenusEnfants("");
commandes.fichierAnalyseValide = true;
//* Rechercher la source
String CheminVersFileXML = "";
if(commandes.os.contains("Win")) {
commandes.PathFilenameAnalysis.replaceAll("/", "\\"); // Sur Windows
CheminVersFileXML = commandes.PathFilenameAnalysis + "\\" + commandes.nameSujet;
}else {
commandes.PathFilenameAnalysis.replaceAll("\\", "/"); // Sur Windows // Sur mac & Linux
CheminVersFileXML = commandes.PathFilenameAnalysis + "/" + commandes.nameSujet;
}
File file = new File(CheminVersFileXML);
if(file.exists()) {
chargeLeNodeSujet(file);
commandes.path = evaluation.getAttributs().get("path"); //Recharge le chemin vers le dossier contenant les fichiers des étudiants
}else {
JFrame frame = new JFrame();
JLabel texte = new JLabel("<html><p>Le fichier d'analyse de l'évaluation, " + commandes.nameSujet + ", <b>a été renommé ou supprimé</b>.</p><br>"
+ "<p>Le fichier d'analyse de l'évaluation <b><u>est récupéré</u></b> depuis la base de données des évaluations.</p></html>");
JOptionPane.showMessageDialog(frame, texte);
}
//** Remise à zéro de la base dans la mémoire de l'application
commandes.evaluationsBase = null;
//** Affichage de la fenêtre
if(!evaluate.isDispose) {
evaluate.getInstance();
};
if(!create.isDispose) {
create.getInstance();
};
isDispose=true;
}
/**
* Charge le fichier d'analyse de l'évaluation.<br>
* @param file
*/
private void chargeLeNodeSujet(File file) {
BufferedReader br;
try {
br = new BufferedReader(
new InputStreamReader(
new FileInputStream(file.getAbsoluteFile()), "UTF-8"));
String line;
StringBuilder targetString = new StringBuilder();
while ((line = br.readLine()) != null) {
targetString.append(line);
}
//node.node2(targetString);
node sujetLoad = new node(targetString.toString().replace("\t","").replace("\r", "").replace("\n", ""));
// Vérification de la conformité du fichier d'analyse
if(!ChargeFichierXML.fichierSujetValide(sujetLoad)) {
JOptionPane.showMessageDialog(null, "Le fichier d'analyse n'est pas valide.");
}else {
commandes.initialiseParametresSettingProprietes();
commandes.sujet = sujetLoad;
commandes.sujetSauvegarde = commandes.sujet.clone();
//Chargement des paramètres du fichier d'analyse
System.out.println( "Chargement des paramètres du fichier d'analyse");
meptl.chargementParametresFichierAnalyse();
// Rechercher des erreurs dans le fichier d'analyse
System.out.println( "Vérification du fichier d'analyse" );
new verificationFichierAnalyse();
}
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (Exception e) {
}
}
private void ecritureBaseEvaluation(node evaluations) throws IOException {
File directory = new File(FileSystemView.getFileSystemView().getDefaultDirectory().getPath());
Run.ecritureNodeEnXML(evaluations, "base_evaluations_analyseWriter.xml", directory.getAbsolutePath(), Run.TypeFile.Evaluation);
}
private boolean isEvaluationExist(String nameEvaluation) {
if(commandes.evaluationsBase.retourneFirstNodeByNameAndAttributValueExactStrict("evaluation", "name", nameEvaluation)!=null) return true;
return false;
}
private node creationNodeEvaluation(node evaluation, String name) {
evaluation.setNomElt("evaluation");
Date aujourdhui = new Date();
evaluation.getAttributs().put("version", commandes.version);
evaluation.getAttributs().put("name", name);
evaluation.getAttributs().put("PathFilenameAnalysis", commandes.PathFilenameAnalysis);
evaluation.getAttributs().put("path", commandes.path);
evaluation.getAttributs().put("fichierStudentMoodle", String.valueOf(commandes.fichierStudentMoodle));
evaluation.getAttributs().put("sansFeeback", String.valueOf(commandes.sansFeeback) );
evaluation.getAttributs().put("noDetail", String.valueOf(commandes.noDetail) );
evaluation.getAttributs().put("noNote", String.valueOf(commandes.noNote) );
evaluation.getAttributs().put("zipfeedback", String.valueOf(commandes.zipfeedback) );
evaluation.getAttributs().put("verifHisto2", String.valueOf(commandes.verifHisto2) );
evaluation.getAttributs().put("ecritNoteCSV", String.valueOf(commandes.ecritNoteCSV) );
evaluation.getAttributs().put("newLogo", String.valueOf(commandes.newLogo) );
evaluation.getAttributs().put("noLogo", String.valueOf(commandes.noLogo) );
//Supprime le node fichier s'il existe.
node nodremove = evaluation.retourneFirstEnfantsByName("fichier");
if(!nodremove.isVide()) evaluation.getNodes().remove(nodremove);
evaluation.getNodes().add(commandes.sujet);
if(commandes.sujet.getAttributs().get("analysis_filename").contains(".xml")) {
evaluation.getAttributs().put("analysis_filename",commandes.sujet.getAttributs().get("analysis_filename"));
}else {
evaluation.getAttributs().put("analysis_filename",commandes.nameSujet);
}
evaluation.getAttributs().put("fourniCSV", String.valueOf(commandes.fourniCSV) );
if(commandes.nameCSV!=null) {
evaluation.getAttributs().put("nameCSV", commandes.nameCSV );
}else {
evaluation.getAttributs().put("nameCSV", "");
}
evaluation.getAttributs().put("fourniCSV", String.valueOf(commandes.fourniCSV) );
if(commandes.nameSVG!=null) {
evaluation.getAttributs().put("nameSVG", commandes.nameSVG );
}else {
evaluation.getAttributs().put("nameSVG", "" );
}
//Supprime le node fichier s'il existe.
nodremove = evaluation.retourneFirstEnfantsByName("fileCSV");
if(!nodremove.isVide()) evaluation.getNodes().remove(nodremove);
evaluation.getNodes().add(commandes.nodeCSV);
try {
evaluation.getAttributs().put("date", calcul.formatDateWriter.DateLibreOffice(aujourdhui));
} catch (ParseException e) {
e.printStackTrace();
}
if(commandes.nameSVG!=null) {
if(!commandes.nameSVG.isBlank() && !commandes.contenuFichierSVG.isBlank()) {
node SVG = new node();
SVG.setNomElt("nodSVG");
SVG.setContenu(commandes.contenuFichierSVG);
evaluation.getNodes().add(SVG);
}
}
return evaluation;
}
}

View File

@ -175,7 +175,7 @@ public class chargeEvaluations extends JFrame {
String nombreEvluation = String.valueOf(commandes.evaluationsBase.getNodes().size());
lblInformationBaseEvluation.setText("<html>Date dernier enregistrement : " +calcul.formatDateWriter.DateEnClairFR( calcul.formatDateWriter.DateLibreOffice(commandes.evaluationsBase.getAttributs().get("date"))) + " -- Nombre d'évaluation : " + nombreEvluation);
lblInformationBaseEvluation.setText("<html>Date dernière modification : " +calcul.formatDateWriter.DateEnClairFR( calcul.formatDateWriter.DateLibreOffice(commandes.evaluationsBase.getAttributs().get("date"))) + " -- Nombre d'évaluation : " + nombreEvluation);
for(int i = 0 ; i<commandes.evaluationsBase.getNodes().size(); i++ ) {
LesRadioButtons.add(new JRadioButton(commandes.evaluationsBase.getNodes().get(i).getAttributs().get("name")));
@ -567,8 +567,9 @@ public class chargeEvaluations extends JFrame {
LeslabelsDate.clear();
LeslabelsTitre.clear();
LeslabelsFileNameAnalysis.clear();
LeslabelsMeta.clear();
LeslabelsMeta.clear();
panelCentre.removeAll();
panelCentre.setLayout(new MigLayout("gap rel 4", "[100px:n,grow][50px:n,grow][150px:n,grow 150][150px:n,grow 150][150px:n,grow 150]", "[20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0][20px:20px:20px,shrinkprio 0,shrink 0]"));
JLabel lblNewLabel = new JLabel("Nom de l'évaluation");
@ -601,7 +602,7 @@ public class chargeEvaluations extends JFrame {
String nombreEvluation = String.valueOf(commandes.evaluationsBase.getNodes().size());
lblInformationBaseEvluation.setText("<html>Date dernier enregistrement : " + dateDernierEnregistrement + " -- Nombre d'évaluation : " + nombreEvluation);
lblInformationBaseEvluation.setText("<html>Date dernière modification : " + dateDernierEnregistrement + " -- Nombre d'évaluation : " + nombreEvluation);
for(int i = 0 ; i<commandes.evaluationsBase.getNodes().size(); i++ ) {
LesRadioButtons.add(new JRadioButton(commandes.evaluationsBase.getNodes().get(i).getAttributs().get("name")));