118 lines
3.4 KiB
Java
118 lines
3.4 KiB
Java
package fenetres;
|
|
|
|
import java.awt.Component;
|
|
import java.awt.Dimension;
|
|
import java.awt.HeadlessException;
|
|
import java.awt.Image;
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
import MEPTL.commandes;
|
|
import cXML.node;
|
|
|
|
public class ChargePathBaseEvaluation extends JFileChooser {
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
public ChargePathBaseEvaluation() {
|
|
|
|
setDialogTitle("Sélectionner la base de données des évaluations.");
|
|
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Base de données des évaluations", "xml");
|
|
setFileFilter(filter);
|
|
setPreferredSize(new Dimension(550, 420));
|
|
|
|
int response = showOpenDialog(null);
|
|
if(response == JFileChooser.APPROVE_OPTION) {
|
|
|
|
|
|
File file = new File(getSelectedFile().getAbsolutePath());
|
|
String ext = file.getName().substring(file.getName().lastIndexOf("."));
|
|
|
|
if(ext.equals(".xml")){
|
|
openFileXML(file);
|
|
}
|
|
}
|
|
}
|
|
|
|
@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;
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @param file
|
|
*/
|
|
private void openFileXML(File file) {
|
|
|
|
|
|
if(commandes.os.contains("Win")) {
|
|
commandes.path = file.getPath().substring(0,file.getPath().lastIndexOf("\\")); // Sur Windows
|
|
}else {
|
|
commandes.path = file.getPath().substring(0,file.getPath().lastIndexOf("/")); // Sur mac & Linux
|
|
}
|
|
|
|
String PathFilenameAnalysis = getCurrentDirectory().getPath();
|
|
String nameSujet = file.getName().toString();
|
|
|
|
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 nodeEvaluation = new node(targetString.toString().replace("\t","").replace("\r", "").replace("\n", ""));
|
|
|
|
if(nodeEvaluation.getNomElt().equals("evaluations")) {
|
|
commandes.NameBaseEvaluations=nameSujet;
|
|
commandes.PathBaseEvaluations=PathFilenameAnalysis;
|
|
commandes.PathBaseEvalationDefaut=false;
|
|
if(!create.isDispose) create.getTextNodeSelect().afficheChargementCheminVersLaBase();
|
|
if(!evaluate.isDispose) evaluate.getTxtpnmessages().afficheChargementCheminVersLaBase();
|
|
}else {
|
|
commandes.PathBaseEvalationDefaut=false;
|
|
JFrame frame = new JFrame();
|
|
JLabel texte = new JLabel("<html><p>Ce n'est pas une base de données des évaluations.</p></html>");
|
|
JOptionPane.showMessageDialog(frame, texte);
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
e1.printStackTrace();
|
|
} catch (FileNotFoundException e1) {
|
|
e1.printStackTrace();
|
|
} catch (Exception e) {
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|