81 lines
3.1 KiB
Java
81 lines
3.1 KiB
Java
package fenetres.create_act;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.KeyEvent;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
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 fenetres.create;
|
|
import nodeAC.Ecriture;
|
|
|
|
|
|
public class actSaveAs extends AbstractAction{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
{
|
|
putValue( Action.NAME, "Enregistrer sous..." );
|
|
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/save_as.png") ));
|
|
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_A );
|
|
putValue( Action.SHORT_DESCRIPTION, "Enregistrer sous..." );
|
|
}
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
fileChooser.setDialogTitle("Enregistrer sous...");
|
|
File file = null;
|
|
|
|
if(!calc.commandes.nameSujet.isEmpty()) {
|
|
file = new File(calc.commandes.PathFilenameAnalysis ); //+ "\\" + utils.filename + ".xml"
|
|
}
|
|
|
|
|
|
|
|
fileChooser.setCurrentDirectory(file);
|
|
|
|
int userSelection = fileChooser.showSaveDialog(null);
|
|
|
|
if (userSelection == JFileChooser.APPROVE_OPTION) {
|
|
File fileToSave = fileChooser.getSelectedFile();
|
|
try {
|
|
|
|
// verificationFichierAnalyse.MiseAJourHashNomFichierAnalyse(fileToSave.getName());
|
|
|
|
if(calc.commandes.sujet.retourneFirstEnfantsByName("settings")==null) {
|
|
Ecriture.addSetting(calc.commandes.sujet);
|
|
}
|
|
Ecriture.ecritureNodeEnXML(calc.commandes.sujet, fileToSave.getName(), fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\")),Ecriture.typeFichier.fichier_analyse);
|
|
calc.commandes.nameSujet = fileToSave.getName();
|
|
calc.commandes.PathFilenameAnalysis = fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\"));
|
|
|
|
Pattern p = Pattern.compile("[.xml]\\b");
|
|
Matcher m = p.matcher(calc.commandes.nameSujet);
|
|
|
|
if(m.find()) {
|
|
file = new File(calc.commandes.PathFilenameAnalysis + "\\" + calc.commandes.nameSujet);
|
|
fenetres.create.getTextNodeSelect().setText("Le fichier \"" + calc.commandes.nameSujet + " a été renregistré.\n\nIl se trouve dans le dossier " + calc.commandes.PathFilenameAnalysis);
|
|
}else {
|
|
file = new File(calc.commandes.PathFilenameAnalysis + "\\" + calc.commandes.nameSujet + ".xml");
|
|
fenetres.create.getTextNodeSelect().setText("Le fichier \"" + calc.commandes.nameSujet + ".xml\" a été renregistré.\n\nIl se trouve dans le dossier " + calc.commandes.PathFilenameAnalysis);
|
|
}
|
|
|
|
|
|
} catch (IOException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
System.out.println("Save as file: " + fileToSave.getAbsolutePath());
|
|
}
|
|
System.out.println( "Save as" );
|
|
}
|
|
|
|
}
|