2022-06-19 21:01:30 +02:00
package fenetres.create_act ;
2022-12-07 20:44:00 +01:00
import java.awt.Component ;
import java.awt.HeadlessException ;
import java.awt.Image ;
2022-06-19 21:01:30 +02:00
import java.awt.event.ActionEvent ;
import java.awt.event.InputEvent ;
import java.awt.event.KeyEvent ;
import java.io.IOException ;
2022-12-17 17:11:22 +01:00
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.Enumeration ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2022-06-19 21:01:30 +02:00
import javax.swing.AbstractAction ;
import javax.swing.Action ;
import javax.swing.ImageIcon ;
2022-12-07 20:44:00 +01:00
import javax.swing.JDialog ;
2022-06-19 21:01:30 +02:00
import javax.swing.JFileChooser ;
import javax.swing.KeyStroke ;
import javax.swing.filechooser.FileNameExtensionFilter ;
import javax.xml.parsers.ParserConfigurationException ;
import org.xml.sax.SAXException ;
import MEPTL.commandes ;
import MEPTL.ecritureSujet ;
import MEPTL.meptl ;
import MEPTL.verificationFichierAnalyse ;
import cXML.Run ;
2022-12-17 17:11:22 +01:00
import cXML.node ;
2022-12-16 17:50:51 +01:00
import evaluer.evaluation ;
2022-06-19 21:01:30 +02:00
import fenetres.evaluate ;
public class actNewFichierAnalyse extends AbstractAction {
/ * *
*
* /
private static final long serialVersionUID = 1L ;
{
putValue ( Action . LARGE_ICON_KEY , new ImageIcon ( evaluate . class . getResource ( " /resources/fichierODF.png " ) ) ) ;
putValue ( Action . NAME , " Génère un nouveau fichier d'analyse " ) ;
putValue ( Action . SMALL_ICON , new ImageIcon ( evaluate . class . getResource ( " /resources/fichierODFmini.png " ) ) ) ;
putValue ( Action . MNEMONIC_KEY , KeyEvent . VK_N ) ;
putValue ( Action . SHORT_DESCRIPTION , " Générer un nouveau fichier d'analyse (CTRL+N) " ) ;
putValue ( Action . ACCELERATOR_KEY , KeyStroke . getKeyStroke ( KeyEvent . VK_N , InputEvent . CTRL_DOWN_MASK ) ) ;
}
@Override
public void actionPerformed ( ActionEvent e ) {
2022-12-07 20:44:00 +01:00
JFileChooser chooser = new JFileChooser ( ) {
private static final long serialVersionUID = 1L ;
@Override
protected JDialog createDialog ( Component parent ) throws HeadlessException {
JDialog dialog = super . createDialog ( parent ) ;
Image img = new ImageIcon ( getClass ( ) . getResource ( " /evalwriter.png " ) ) . getImage ( ) ;
dialog . setIconImage ( img ) ;
return dialog ;
}
} ;
2022-06-19 21:01:30 +02:00
chooser . setDialogTitle ( " Choisir un fichier ODF " ) ;
chooser . setCurrentDirectory ( new java . io . File ( commandes . path ) ) ;
chooser . setFileSelectionMode ( JFileChooser . FILES_ONLY ) ;
FileNameExtensionFilter filter = new FileNameExtensionFilter ( " Format ODF " , " odt " ) ;
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 ( ) ) ;
2022-07-08 11:13:46 +02:00
commandes . initialiseParametresSettingProprietes ( ) ; ;
2022-07-10 11:42:47 +02:00
commandes . fichierAnalyseValide = true ;
2022-06-19 21:01:30 +02:00
commandes . path = chooser . getCurrentDirectory ( ) . getAbsolutePath ( ) ;
commandes . PathFilenameAnalysis = chooser . getCurrentDirectory ( ) . getAbsolutePath ( ) ;
String cheminVersFichier = chooser . getSelectedFile ( ) . getAbsolutePath ( ) ;
commandes . nameSujet = chooser . getSelectedFile ( ) . getName ( ) ;
Run b = null ;
try {
b = new Run ( cheminVersFichier ) ;
commandes . sujet = Run . XMLContent ( b . getLectDossiers ( ) . getEC ( ) . getListeContentWriter ( ) . get ( 0 ) ) ;
2022-12-07 08:43:07 +01:00
//Supprime l'historique des modifications
commandes . sujet . supprimeTousLesNodesEnfantWithThisName ( " text:tracked-changes " ) ;
2022-12-15 08:52:32 +01:00
commandes . sujet . supprimeTousLesNodesEnfantWithThisName ( " text:deletion " ) ;
commandes . sujet . supprimeTousLesNodesEnfantWithThisName ( " text:change-start " ) ;
commandes . sujet . supprimeTousLesNodesEnfantWithThisName ( " text:change-end " ) ;
commandes . sujet . supprimeTousLesNodesEnfantWithThisName ( " text:tracked-changes " ) ;
commandes . sujet . supprimeTousLesNodesEnfantWithThisName ( " text:change " ) ;
2022-12-07 08:43:07 +01:00
2022-06-19 21:01:30 +02:00
commandes . sujet = meptl . LectureFichierEtudiantSousFormeDeNode ( commandes . sujet , b , 0 ) ;
2023-01-01 12:43:53 +01:00
2022-12-17 17:11:22 +01:00
//Pour les sujets, il faut rechercher les nodes en doublons (par exemple : text:p, text:h, text:list-item)
2022-12-30 17:55:33 +01:00
//L'information sera portée par l'attribut isDoublon="true"
2022-12-17 17:11:22 +01:00
// Cela permet de recherche par le numéro du child.
2022-12-18 16:22:56 +01:00
placeIsDoublonInStructure ( commandes . sujet . retourneFirstEnfantsByName ( " structurepage " ) ) ;
2022-12-30 17:55:33 +01:00
placeIsDoublonInStylePage ( commandes . sujet . retourneFirstEnfantsByName ( " style:page " ) ) ;
2022-12-17 17:11:22 +01:00
2022-06-19 21:01:30 +02:00
commandes . sujet . getAttributs ( ) . put ( " analysis_filename " , " sujet.xml " ) ;
commandes . sujet = ecritureSujet . nodePourEcritureSujet ( commandes . sujet , b , 0 ) ;
2022-12-16 17:50:51 +01:00
// chargemnt de la traduction
evaluation . chargeTraduction ( Run . translation ( ) ) ;
2022-06-19 21:01:30 +02:00
2022-11-15 09:00:37 +01:00
// try {
// Run.ecritureNodeEnXML(commandes.sujet , commandes.nameSujet+".xml",commandes.path,"Sujet");
// } catch (IOException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
2022-12-07 08:43:07 +01:00
2022-06-19 21:01:30 +02:00
new verificationFichierAnalyse ( ) ;
if ( commandes . fichierAnalyseValide ) {
2022-07-10 11:42:47 +02:00
commandes . sujetSauvegarde = commandes . sujet . clone ( ) ;
2022-12-13 08:27:40 +01:00
fenetres . create . getTree ( ) . setVisible ( true ) ;
2022-06-19 21:01:30 +02:00
fenetres . create . constructionTree ( ) ;
2022-12-21 17:54:28 +01:00
fenetres . create . getTextNodeSelect ( ) . afficheChargementFichierAnalyse ( ) ;
2022-06-19 21:01:30 +02:00
} else {
2022-11-13 08:58:51 +01:00
fenetres . create . getTextNodeSelect ( ) . setText ( " <h1>Le fichier n'est pas valide</h1> " ) ;
2022-06-19 21:01:30 +02:00
}
} catch ( ParserConfigurationException | SAXException | IOException | CloneNotSupportedException e1 ) {
e1 . printStackTrace ( ) ;
}
} else {
fenetres . create . getTextNodeSelect ( ) . refreshAffichage ( null ) ;
}
commandes . ecritCode = true ;
}
2022-12-17 17:11:22 +01:00
2022-12-18 16:22:56 +01:00
public static void placeIsDoublonInStructure ( node nod ) {
2022-12-17 17:11:22 +01:00
Enumeration < node > pages = Collections . enumeration ( nod . getNodes ( ) ) ;
while ( pages . hasMoreElements ( ) ) {
node nodLaPage = pages . nextElement ( ) ;
2022-12-30 17:55:33 +01:00
Pattern p = Pattern . compile ( " ^text:p$|^text:h$|^text:list$|^text:list-item$|^text:line-break$|^text:span$|^text:tab$ " ) ; //le node qui peuvent rechercher par le contenu textuel
2022-12-17 17:11:22 +01:00
ArrayList < String > listTextesInPage = new ArrayList < String > ( ) ;
for ( int i = 0 ; i < nodLaPage . getNodes ( ) . size ( ) ; i + + ) {
Matcher m = p . matcher ( nodLaPage . getNodes ( ) . get ( i ) . getNomElt ( ) ) ;
if ( m . find ( ) ) {
String content = nodLaPage . getNodes ( ) . get ( i ) . retourneLesContenusEnfants ( " " ) ;
if ( listTextesInPage . contains ( content ) ) {
nodLaPage . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " isDoublon " , " true " ) ;
} else {
nodLaPage . getNodes ( ) . get ( i ) . getAttributs ( ) . remove ( " isDoublon " ) ;
listTextesInPage . add ( content ) ;
}
2022-12-18 16:22:56 +01:00
if ( nodLaPage . getNodes ( ) . get ( i ) . getNodes ( ) . size ( ) > 0 ) {
placeIsDoublon ( nodLaPage . getNodes ( ) . get ( i ) ) ;
}
2022-12-17 17:11:22 +01:00
}
}
}
2022-12-18 16:22:56 +01:00
}
2022-12-30 17:55:33 +01:00
public static void placeIsDoublonInStylePage ( node nod ) {
Enumeration < node > pages = Collections . enumeration ( nod . getNodes ( ) ) ;
while ( pages . hasMoreElements ( ) ) {
node nodLaPage = pages . nextElement ( ) ;
Pattern p = Pattern . compile ( " ^text:p$|^text:h$|^text:list$|^text:list-item$|^text:line-break$|^text:span$|^text:tab$ " ) ; //le node qui peuvent rechercher par le contenu textuel
ArrayList < String > listTextesInPage = new ArrayList < String > ( ) ;
for ( int i = 0 ; i < nodLaPage . getNodes ( ) . size ( ) ; i + + ) {
Matcher m = p . matcher ( nodLaPage . getNodes ( ) . get ( i ) . getNomElt ( ) ) ;
if ( m . find ( ) ) {
String content = nodLaPage . getNodes ( ) . get ( i ) . retourneLesContenusEnfants ( " " ) ;
if ( listTextesInPage . contains ( content ) ) {
nodLaPage . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " isDoublon " , " true " ) ;
} else {
nodLaPage . getNodes ( ) . get ( i ) . getAttributs ( ) . remove ( " isDoublon " ) ;
listTextesInPage . add ( content ) ;
}
}
if ( nodLaPage . getNodes ( ) . get ( i ) . getNodes ( ) . size ( ) > 0 ) {
placeIsDoublon ( nodLaPage . getNodes ( ) . get ( i ) ) ;
}
}
}
}
2022-12-18 16:22:56 +01:00
/ * *
*
* @param nod
* /
private static void placeIsDoublon ( node nod ) {
2022-12-30 17:55:33 +01:00
Pattern p = Pattern . compile ( " ^text:p$|^text:h$|^text:list$|^text:list-item$|^text:line-break$|^text:span$|^text:tab$ " ) ; //le node qui peuvent rechercher par le contenu textuel
2022-12-18 16:22:56 +01:00
ArrayList < String > listTextesInPage = new ArrayList < String > ( ) ;
for ( int i = 0 ; i < nod . getNodes ( ) . size ( ) ; i + + ) {
Matcher m = p . matcher ( nod . getNodes ( ) . get ( i ) . getNomElt ( ) ) ;
if ( m . find ( ) ) {
String content = nod . getNodes ( ) . get ( i ) . retourneLesContenusEnfants ( " " ) ;
if ( listTextesInPage . contains ( content ) ) {
nod . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " isDoublon " , " true " ) ;
} else {
nod . getNodes ( ) . get ( i ) . getAttributs ( ) . remove ( " isDoublon " ) ;
listTextesInPage . add ( content ) ;
}
if ( nod . getNodes ( ) . get ( i ) . getNodes ( ) . size ( ) > 0 ) {
placeIsDoublon ( nod . getNodes ( ) . get ( i ) ) ;
}
}
}
2022-12-17 17:11:22 +01:00
}
2022-12-18 16:22:56 +01:00
2022-06-19 21:01:30 +02:00
}