2023-02-05 17:46:02 +01:00
package action ;
2022-06-19 21:01:30 +02:00
import java.awt.event.ActionEvent ;
import java.awt.event.KeyEvent ;
import java.io.File ;
import java.io.IOException ;
2023-03-02 12:31:59 +01:00
import java.text.ParseException ;
2022-06-19 21:01:30 +02:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import javax.swing.AbstractAction ;
import javax.swing.Action ;
import javax.swing.ImageIcon ;
import javax.swing.JFileChooser ;
import MEPTL.commandes ;
2024-04-09 14:50:03 +02:00
import MEPTL.verificationFichierAnalyse_node_commandesSujet ;
2022-06-19 21:01:30 +02:00
import cXML.Run ;
public class actSaveAs extends AbstractAction {
/ * *
*
* /
private static final long serialVersionUID = 1L ;
{
2023-02-16 21:47:23 +01:00
putValue ( Action . NAME , " Enregistrer le fichier d'analyse sous... " ) ;
2022-06-19 21:01:30 +02:00
putValue ( Action . SMALL_ICON , new ImageIcon ( getClass ( ) . getResource ( " /save_as.png " ) ) ) ;
putValue ( Action . MNEMONIC_KEY , KeyEvent . VK_A ) ;
2023-02-16 21:47:23 +01:00
putValue ( Action . SHORT_DESCRIPTION , " Enregistrer le fichier d'analyse de l'évaluation sous... " ) ;
2022-06-19 21:01:30 +02:00
}
@Override
public void actionPerformed ( ActionEvent e ) {
JFileChooser fileChooser = new JFileChooser ( ) ;
fileChooser . setDialogTitle ( " Enregistrer sous... " ) ;
File file = null ;
if ( ! commandes . nameSujet . isEmpty ( ) ) {
file = new File ( commandes . PathFilenameAnalysis ) ; //+ "\\" + utils.filename + ".xml"
2022-11-24 21:49:39 +01:00
System . out . println ( " commandes.PathFilenameAnalysis= " + commandes . PathFilenameAnalysis ) ;
2022-06-19 21:01:30 +02:00
}
fileChooser . setCurrentDirectory ( file ) ;
int userSelection = fileChooser . showSaveDialog ( null ) ;
if ( userSelection = = JFileChooser . APPROVE_OPTION ) {
File fileToSave = fileChooser . getSelectedFile ( ) ;
try {
2024-04-09 14:50:03 +02:00
verificationFichierAnalyse_node_commandesSujet . MiseAJourHashNomFichierAnalyse ( fileToSave . getName ( ) ) ;
2023-03-02 12:31:59 +01:00
//Mise à jour de la date d'enregistrement du fichier d'analyse
try {
commandes . sujet . getAttributs ( ) . put ( " date " , calcul . formatDateWriter . dateTodayLibreOffice ( ) ) ;
} catch ( ParseException e1 ) {
e1 . printStackTrace ( ) ;
}
2022-11-24 21:49:39 +01:00
if ( commandes . os . contains ( " Win " ) ) {
2022-12-23 19:24:59 +01:00
Run . ecritureNodeEnXML ( commandes . sujet , fileToSave . getName ( ) , fileToSave . getPath ( ) . substring ( 0 , fileToSave . getPath ( ) . lastIndexOf ( " \\ " ) ) , Run . TypeFile . Sujet ) ;
2022-11-25 08:26:06 +01:00
} else {
2022-12-23 19:24:59 +01:00
Run . ecritureNodeEnXML ( commandes . sujet , fileToSave . getName ( ) , fileToSave . getPath ( ) . substring ( 0 , fileToSave . getPath ( ) . lastIndexOf ( " / " ) ) , Run . TypeFile . Sujet ) ;
2022-11-24 21:49:39 +01:00
}
2022-06-19 21:01:30 +02:00
commandes . nameSujet = fileToSave . getName ( ) ;
2022-11-24 21:49:39 +01:00
if ( commandes . os . contains ( " Win " ) ) {
commandes . PathFilenameAnalysis = fileToSave . getPath ( ) . substring ( 0 , fileToSave . getPath ( ) . lastIndexOf ( " \\ " ) ) ;
2022-11-25 08:26:06 +01:00
} else {
2022-11-24 21:49:39 +01:00
commandes . PathFilenameAnalysis = fileToSave . getPath ( ) . substring ( 0 , fileToSave . getPath ( ) . lastIndexOf ( " / " ) ) ;
}
2022-06-19 21:01:30 +02:00
Pattern p = Pattern . compile ( " [.xml] \\ b " ) ;
Matcher m = p . matcher ( commandes . nameSujet ) ;
if ( m . find ( ) ) {
file = new File ( commandes . PathFilenameAnalysis + " \\ " + commandes . nameSujet ) ;
fenetres . create . getTextNodeSelect ( ) . setText ( " Le fichier \" " + commandes . nameSujet + " a été renregistré. \ n \ nIl se trouve dans le dossier " + commandes . PathFilenameAnalysis ) ;
} else {
file = new File ( commandes . PathFilenameAnalysis + " \\ " + commandes . nameSujet + " .xml " ) ;
fenetres . create . getTextNodeSelect ( ) . setText ( " Le fichier \" " + commandes . nameSujet + " .xml \" a été renregistré. \ n \ nIl se trouve dans le dossier " + commandes . PathFilenameAnalysis ) ;
}
} catch ( IOException e1 ) {
e1 . printStackTrace ( ) ;
} catch ( CloneNotSupportedException e1 ) {
e1 . printStackTrace ( ) ;
}
System . out . println ( " Save as file: " + fileToSave . getAbsolutePath ( ) ) ;
}
System . out . println ( " Save as " ) ;
}
}