analyseWriter/src/app/create.java

1917 lines
66 KiB
Java

package app;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
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;
import cXML.node;
import java.awt.event.InputEvent;
public class create extends JFrame {
private static final long serialVersionUID = 1L;
// les élément de create
private JTree tree = new JTree();
private JEditorPane textNodeSelect = new JEditorPane();
private JToolBar toolBar = new JToolBar();
private JMenuBar menuBar = new JMenuBar();
/**
* Create the application.
*/
public create() {
try {
initialize();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
setVisible(true);
}
/**
* Initialize the contents of the frame.
* @throws UnsupportedLookAndFeelException
*/
private void initialize() throws UnsupportedLookAndFeelException {
// UIManager.setLookAndFeel(new NimbusLookAndFeel());
/*Chargement des images*/
// ImageIcon img1 = new ImageIcon(getClass().getResource("/attribut.png") );
// ImageIcon img3 = new ImageIcon(getClass().getResource("/property.png") );
// ImageIcon img4 = new ImageIcon(getClass().getResource("/content.png") );
// ImageIcon img2 = new ImageIcon(getClass().getResource("/structurepage.png") );
//frame = new JFrame();
// System.out.println(this.getClass());
// this.setExtendedState(MAXIMIZED_BOTH);
setSize(1400,920);
//setExtendedState(getExtendedState()|JFrame.MAXIMIZED_BOTH );
// setTitle("analyseWriter - Evaluer les fichiers des étudiants");
ImageIcon img = new ImageIcon(getClass().getResource("/evalwriter.png") );
setIconImage(img.getImage());
setLocationRelativeTo( null );
// frame.setBounds(0, 0, 860, 500);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// Construction et injection de la barre de menu
setJMenuBar( this.createMenuBar() );
tree.setVisibleRowCount(30);
// Ajoute le menu contextuel de la tree
tree.setComponentPopupMenu(null);
// Construction et injection de la barre d'outils
JPanel contentPane = (JPanel) getContentPane();
this.createToolBar();
this.createPopupMenuTree(null);
getContentPane().setLayout(new BorderLayout(2, 2));
contentPane.add( toolBar, BorderLayout.NORTH );
toolBar.addSeparator();
JButton button_2 = toolBar.add( actExit );
button_2.setHideActionText( true );
// The content of the window
if(commandes.fichierAnalyseValide) tree = commandes.tree;
// JTextArea J = new JTextArea();
// contentPane.add(J,BorderLayout.EAST);
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JScrollPane leftScrollPane = new JScrollPane( );
leftScrollPane.setPreferredSize( new Dimension( 200, 0 ) );
JScrollPane rightScrollPane = new JScrollPane( );
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane );
splitPane.setBounds(10, 10, 1364, 783);
panel.add(splitPane);
rightScrollPane.setViewportView(textNodeSelect);
textNodeSelect.setFont(new Font("Monospaced", Font.PLAIN, 15));
leftScrollPane.setViewportView(tree);
tree.setFont(new Font("Tahoma", Font.PLAIN, 14));
if(commandes.fichierAnalyseValide) constructionTree();
ListenerAction();
}
private void ListenerAction() {
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(tree.getSelectionPath()!=null) {
refeshNodeSelected();
}
}
});
// tree.addTreeWillExpandListener(new MyTreeWillExpandListener());
// tree.addTreeExpansionListener(new MyTreeExpansionListener());
}
public void refeshNodeSelected() {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
if(tree.getSelectionPath()!=null) {
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
node nodeParent = nod.getParent();
StringBuilder sb = new StringBuilder();
sb.append(balisestyles());
sb.append("<p class=\"p1\">Parent = " + nodeParent.getNomElt() + "</p><br>");
sb.append("<hr>");
sb.append("<br><h1>Nom du node : " + nod.getNomElt() + "</h1><br>");
sb.append("<hr>");
if(nod.getAttributs().size()>0) {
if(nod.getAttributs().size()==1) sb.append("<br><h4><u>L'ATTRIBUT DU NODE</u></h4>");
if(nod.getAttributs().size()>1) sb.append("<br><h4><u>LES ATTRIBUTS DU NODE</u></h4>");
}
if(nod.getAttributs().size()<=0) {
if(nod.getAttributs().size()==1) sb.append("<br><h4><u>PAS D'ATTRIBUT DANS CE NODE</u></h4>");
}
Enumeration<String> key = nod.getAttributs().keys();
List<String> Lesattributsdunode = new ArrayList<String>();
while(key.hasMoreElements()) {
String K = key.nextElement();
Lesattributsdunode.add(K);
}
//permet le tri par ordre alphabétique des clés du dictionnaire
Lesattributsdunode = Lesattributsdunode.stream().sorted().collect(Collectors.toList());
if(nod.getAttributs().get("evaluer")!=null) if(nod.getAttributs().get("evaluer").equalsIgnoreCase("true")) {
sb.append("<br>");
sb.append("<ul>");
sb.append("<li class=\"p2\"><b><u>Les attributs d'analyseWriter</u></b></li>");
for(int i=0; i < Lesattributsdunode.size();i++) {
if(listeAttributsAnalyseWriter.isAttributAnalyseWriter(Lesattributsdunode.get(i))) {
sb.append("<li class=\"p2\"><b>" + Lesattributsdunode.get(i) + "=\"" + nod.getAttributs().get(Lesattributsdunode.get(i))+"\"</b></li>");
}
}
sb.append("</ul>");
sb.append("<br>");
sb.append("<ul>");
sb.append("<li class=\"p2\"><b><u>Les attributs de Writer</u></b></li>");
for(int i=0; i < Lesattributsdunode.size();i++) {
if(!listeAttributsAnalyseWriter.isAttributAnalyseWriter(Lesattributsdunode.get(i))) {
sb.append("<li class=\"p2\"><b>" + Lesattributsdunode.get(i) + "=\"" + nod.getAttributs().get(Lesattributsdunode.get(i))+"\"</b></li>");
}
}
sb.append("</ul>");
}
if(nod.getAttributs().get("evaluer")!=null) if(!nod.getAttributs().get("evaluer").equalsIgnoreCase("true")) {
sb.append("<br>");
sb.append("<ul>");
sb.append("<li class=\"p3\"><b><u>Les attributs d'analyseWriter</u></b></li>");
for(int i=0; i < Lesattributsdunode.size();i++) {
if(listeAttributsAnalyseWriter.isAttributAnalyseWriter(Lesattributsdunode.get(i))) {
sb.append("<li class=\"p3\"><b>" + Lesattributsdunode.get(i) + "=\"" + nod.getAttributs().get(Lesattributsdunode.get(i))+"\"</b></li>");
}
}
sb.append("</ul>");
sb.append("<br>");
sb.append("<ul>");
sb.append("<li class=\"p3\"><b><u>Les attributs de Writer</u></b></li>");
for(int i=0; i < Lesattributsdunode.size();i++) {
if(!listeAttributsAnalyseWriter.isAttributAnalyseWriter(Lesattributsdunode.get(i))) {
sb.append("<li class=\"p3\"><b>" + Lesattributsdunode.get(i) + "=\"" + nod.getAttributs().get(Lesattributsdunode.get(i))+"\"</b></li>");
}
}
sb.append("</ul>");
}
if(nod.getAttributs().size()>0) {
if(nod.getAttributs().get("evaluer")==null) {
sb.append("<br>");
sb.append("<ul>");
sb.append("<li class=\"p3\"><b><u>Les attributs d'analyseWriter</u></b></li>");
for(int i=0; i < Lesattributsdunode.size();i++) {
if(listeAttributsAnalyseWriter.isAttributAnalyseWriter(Lesattributsdunode.get(i))) {
sb.append("<li class=\"p3\"><b>" + Lesattributsdunode.get(i) + "=\"" + nod.getAttributs().get(Lesattributsdunode.get(i))+"\"</b></li>");
}
}
sb.append("</ul>");
sb.append("<br>");
sb.append("<ul>");
sb.append("<li class=\"p3\"><b><u>Les attributs de Writer</u></b></li>");
for(int i=0; i < Lesattributsdunode.size();i++) {
if(!listeAttributsAnalyseWriter.isAttributAnalyseWriter(Lesattributsdunode.get(i))) {
sb.append("<li class=\"p3\"><b>" + Lesattributsdunode.get(i) + "=\"" + nod.getAttributs().get(Lesattributsdunode.get(i))+"\"</b></li>");
}
}
sb.append("</ul>");
}
}
if(!nod.retourneLesContenusEnfants("").trim().isEmpty()) {
sb.append("<br><br><h4><u>Contenu</u></h4><br> " + nod.retourneLesContenusEnfants("") );
}
textNodeSelect.setText("<html>"+sb.toString()+"</html>");
createPopupMenuTree(nod);
}
}
/**
* Création du menu contextuel du tree
* @return
*/
private void createPopupMenuTree(node nod) {
if(nod!=null) {
boolean pasCeNode = false;
if(nod.chemin().contains("setting")) pasCeNode=true;
JMenu mnEvaluer = new JMenu("Evaluer");
mnEvaluer.add(actEvalueTrue);
mnEvaluer.add(actEvalueFalse);
JMenu mnManageTree = new JMenu("Arbre");
mnManageTree.add(actUpNode);
mnManageTree.add(actDownNode);
mnManageTree.addSeparator();
mnManageTree.add(actExpandAll);
mnManageTree.add(actExpandNode);
mnManageTree.addSeparator();
mnManageTree.add(actCollapseAll);
mnManageTree.add(actCollapseNode);
JMenu mnSaut = new JMenu("Saut de ligne avant");
mnSaut.setIcon( new ImageIcon(create.class.getResource("/resources/sautmini.png")));
mnSaut.add(actsauttrue);
mnSaut.add(actsautfalse);
JMenu mnTitre = new JMenu("Titre");
mnTitre.setIcon( new ImageIcon(create.class.getResource("/resources/titremini.png")));
mnTitre.add(actTitrePrincipal);
mnTitre.add(actTitre1);
mnTitre.add(actTitre2);
mnTitre.add(actTitre3);
mnTitre.addSeparator();
mnTitre.add(actSupprimeTitre);
JMenu mnAddMenu= new JMenu("Lien"); //addMenu
mnAddMenu.add(actAddMenuTrue);
mnAddMenu.add(actAddMenuFalse);
JMenu mnEvalNameNode = new JMenu("Evaluer la présence du node");
mnEvalNameNode.setIcon(new ImageIcon(create.class.getResource("/resources/evalnodemini.png")));
mnEvalNameNode.add(actEvalNameNodeOui);
mnEvalNameNode.add(actEvalNameNodeNon);
JMenu mnNodePrincipal = new JMenu("Node niveau " + nod.getLevel());
if(nod.getLevel()==1) {
mnNodePrincipal.add(actCoefficient);
mnNodePrincipal.addSeparator();
}
mnNodePrincipal.add(mnSaut);
mnNodePrincipal.addSeparator();
mnNodePrincipal.add(mnTitre);
if(nod.getLevel()>1) {
mnNodePrincipal.addSeparator();
mnNodePrincipal.add(mnEvalNameNode);
mnNodePrincipal.addSeparator();
mnNodePrincipal.add(mnAddMenu);
mnNodePrincipal.addSeparator();
mnNodePrincipal.add("allContent");
}
if(nod.getNomElt().equals("meta:initial-creator")) {
mnNodePrincipal.addSeparator();
mnNodePrincipal.add("evalNameInitialCreator");
}
//La popupMenu
JPopupMenu mnPopupTree = new JPopupMenu();
if(!pasCeNode) mnPopupTree.add(mnEvaluer);
if(!pasCeNode) { //nod.getLevel()==1 && !avertissement
mnPopupTree.addSeparator();
mnPopupTree.add(mnNodePrincipal);
}
if(nod.getLevel()>1 && !pasCeNode) {
mnPopupTree.addSeparator();
mnPopupTree.add(actAttribut);
}
mnPopupTree.addSeparator();
mnPopupTree.add(actNodeFichier);
mnPopupTree.addSeparator();
mnPopupTree.add(mnManageTree);
mnPopupTree.addSeparator();
mnPopupTree.add(actDeleteNode);
tree.setComponentPopupMenu(mnPopupTree);
}
if(nod==null){
JMenu mnManageTree = new JMenu("Arbre");
mnManageTree.add(actUpNode);
mnManageTree.add(actDownNode);
mnManageTree.addSeparator();
mnManageTree.add(actExpandAll);
mnManageTree.add(actExpandNode);
mnManageTree.addSeparator();
mnManageTree.add(actCollapseAll);
mnManageTree.add(actCollapseNode);
JPopupMenu mnPopupTree = new JPopupMenu();
mnPopupTree.add(mnManageTree);
tree.setComponentPopupMenu(mnPopupTree);
}
}
/* Methode de construction de la barre de menu */
private JMenuBar createMenuBar() {
// La barre de menu à proprement parler
menuBar = new JMenuBar();
// Définition du menu déroulant "File" et de son contenu
JMenu mnuFile = new JMenu( "Fichier" );
mnuFile.setMnemonic( 'F' );
/*JMenuItem mnuNewFile =*/
mnuFile.add( actSave );
mnuFile.add( actSaveAs );
mnuFile.addSeparator();
mnuFile.add( actExit );
menuBar.add(mnuFile);
// Définition du menu déroulant "Edit" et de son contenu
JMenu mnuEdit = new JMenu( "Edition" );
mnuEdit.setMnemonic( 'E' );
mnuEdit.add( actUndo );
mnuEdit.add( actRedo );
mnuEdit.addSeparator();
mnuEdit.add( actCopy );
mnuEdit.add( actCut );
mnuEdit.add( actPaste );
menuBar.add(mnuEdit);
// menu Modifier
JMenu mnuModif= new JMenu( "Modifier" );
mnuModif.setMnemonic( 'M' );
mnuModif.add( actOpen );
mnuModif.add( actNodeFichier );
mnuModif.addSeparator();
mnuModif.add( actNewFichierAnalyse );
menuBar.add(mnuModif);
// Définition du menu déroulant "Edit" et de son contenu
JMenu mnuExercice = new JMenu( "Création évaluation" );
mnuExercice.setMnemonic( 'N' );
mnuExercice.add(actEvaluer);
menuBar.add(mnuExercice);
// Définition du menu déroulant "Help" et de son contenu
JMenu mnuHelp = new JMenu( "Aide" );
mnuHelp.setMnemonic( 'H' );
mnuHelp.add( actAPropos);
mnuHelp.add( actDocumentation);
menuBar.add( mnuHelp );
return menuBar;
}
/* Methode de construction de la barre d'outils */
private void createToolBar() {
toolBar = new JToolBar();
JButton buttonLoadFile = toolBar.add( actOpen );
buttonLoadFile.setIcon(new ImageIcon(create.class.getResource("/resources/fichierAnalyse.png")));
buttonLoadFile.setHideActionText(true);
toolBar.add(buttonLoadFile);
JButton btnNewFichierAnalyse = toolBar.add( actNewFichierAnalyse );
btnNewFichierAnalyse.setIcon(new ImageIcon(create.class.getResource("/resources/fichierODF.png")));
btnNewFichierAnalyse.setHideActionText(true);
toolBar.add(btnNewFichierAnalyse);
JButton btnNodeFichier = toolBar.add( actNodeFichier );
btnNodeFichier.setIcon(new ImageIcon(create.class.getResource("/resources/nodeFichier.png")));
btnNodeFichier.setHideActionText(true);
toolBar.add(btnNodeFichier);
toolBar.addSeparator();
JButton btnAbout = toolBar.add( actAbout );
btnAbout.setIcon(new ImageIcon(create.class.getResource("/resources/apropos.png")));
btnAbout.setHideActionText( true );
toolBar.add(btnAbout);
JButton btnDocumentation = toolBar.add(actDocumentation);
btnDocumentation.setIcon(new ImageIcon(create.class.getResource("/resources/documentation.png")));
btnDocumentation.setHideActionText(true);
toolBar.add(btnDocumentation);
toolBar.addSeparator();
JButton button = toolBar.add( actEvaluer );
button.setIcon(new ImageIcon(create.class.getResource("/resources/evaluate.png")));
// if(commandes.fichierAnalyseValide) {
// toolBar.add( actConfiguration ).setEnabled(true);
// toolBar.add( actEvaluer ).setEnabled(true);
// }else {
// toolBar.add( actConfiguration ).setEnabled( false );
// toolBar.add( actEvaluer ).setEnabled(false);
// }
}
/**
* Ouvre et affiche le fichier d'analyse
*/
private AbstractAction actOpen = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Ouvrir un fichier d'analyse" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/fichierAnalysemini.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_O );
putValue( Action.SHORT_DESCRIPTION, "Ouvrir un nouveau fichier d'analyse (CTRL+O)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK) );
}
@Override public void actionPerformed( ActionEvent e ) {
new filechooserXML();
if(commandes.fichierAnalyseValide) {
constructionTree();
textNodeSelect.setContentType("text/html");
textNodeSelect.setText(balisestyles() + "<br><hr><h1>Le chargement du fichier d'analyseWriter est réussi.</h1><hr>");
}else {
constructionTree();
textNodeSelect.setContentType("text/plain");
textNodeSelect.setText(commandes.message.toString());
}
System.out.println( "Open" );
}
};
/**
*
*/
private AbstractAction actNodeFichier = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Modifier les paramètres de l'évaluation" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/nodeFichiermini.png")) );
putValue( Action.LARGE_ICON_KEY, new ImageIcon(create.class.getResource("/resources/nodeFichier.png")) );
putValue( Action.SHORT_DESCRIPTION, "Modifier les paramètres de l'évaluation" );
}
@Override public void actionPerformed( ActionEvent e ) {
if(commandes.sujet.getNomElt().equals("fichier")) {
new proprieteFichierAnalyse();
}
System.out.println( "ouvre la fenêtre propriété du fichier d'analyse" );
}
};
/**
*
*/
private AbstractAction actAttribut = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Evaluer les attributs" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/attributmini.png")) );
putValue( Action.LARGE_ICON_KEY, new ImageIcon(create.class.getResource("/resources/attributmini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Evaluer les attributs" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
new attributs(nod);
System.out.println( "ouvre la fenêtre attributs" );
}
};
/**
* Affiche la fenêtre d'information sur analyseWriter
*/
private AbstractAction actAbout = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Informations" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/aproposmini.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_I );
putValue( Action.SHORT_DESCRIPTION, "Informations (CTRL+I)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK) );
}
@Override public void actionPerformed( ActionEvent e ) {
new about();
System.out.println( "About" );
}
};
/**
*
*/
private AbstractAction actSave = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Enregister" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/save.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_S );
putValue( Action.SHORT_DESCRIPTION, "Enregistrer (CTRL+S)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
Pattern p = Pattern.compile("[.xml]\\b");
Matcher m = p.matcher(commandes.nameSujet);
String message="";
if(m.find()) {
message="\"Voulez-vous enregistrer le fichier \"" + commandes.nameSujet + "\"\n"
+ "Dans le dossier " + commandes.path;
}else {
message="\"Voulez-vous enregistrer le fichier \"" + commandes.nameSujet + ".xml\"\n"
+ "Dans le dossier " + commandes.path;
commandes.nameSujet = commandes.nameSujet + ".xml";
}
int input = JOptionPane.showConfirmDialog(null, message);
if(input==0) {
try {
verificationFichierAnalyse.MiseAJourHashNomFichierAnalyse(commandes.nameSujet);
Run.ecritureNodeEnXML(commandes.sujet, commandes.nameSujet ,commandes.path,"sujet");
if(m.find()) {
textNodeSelect.setText("Le fichier \"" + commandes.nameSujet + " a été renregistré.\n\n"
+ "Il se trouve dans le dossier " + commandes.path);
}else {
textNodeSelect.setText("Le fichier \"" + commandes.nameSujet + ".xml\" a été renregistré.\n\n"
+ "Il se trouve dans le dossier " + commandes.path);
}
System.out.println( input + "Save" );
} catch (IOException | CloneNotSupportedException e1) {
e1.printStackTrace();
}
}
}
};
/**
*
*/
private AbstractAction actSaveAs = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Enregistrer sous..." );
putValue( Action.SMALL_ICON, new ImageIcon(getClass().getResource("/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(!commandes.nameSujet.isEmpty()) {
file = new File(commandes.path ); //+ "\\" + 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());
Run.ecritureNodeEnXML(commandes.sujet, fileToSave.getName(), fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\")),"sujet" );
commandes.nameSujet = fileToSave.getName();
commandes.path = fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\"));
Pattern p = Pattern.compile("[.xml]\\b");
Matcher m = p.matcher(commandes.nameSujet);
if(m.find()) {
file = new File(commandes.path + "\\" + commandes.nameSujet);
textNodeSelect.setText("Le fichier \"" + commandes.nameSujet + " a été renregistré.\n\nIl se trouve dans le dossier " + commandes.path);
}else {
file = new File(commandes.path + "\\" + commandes.nameSujet + ".xml");
textNodeSelect.setText("Le fichier \"" + commandes.nameSujet + ".xml\" a été renregistré.\n\nIl se trouve dans le dossier " + commandes.path);
}
} catch (IOException e1) {
e1.printStackTrace();
} catch (CloneNotSupportedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Save as file: " + fileToSave.getAbsolutePath());
}
System.out.println( "Save as" );
}
};
/**
* Quitter l'application
*/
private AbstractAction actExit = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Quitter" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/exitmini.png")) );
putValue( Action.LARGE_ICON_KEY, new ImageIcon(create.class.getResource("/resources/exit.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_Q );
putValue( Action.SHORT_DESCRIPTION, "Quitter (CRTL+Q)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous quitter l'application?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
if(a == JOptionPane.YES_NO_OPTION) {
System.out.println( "Le choix : " + a);
System.out.println( "Exit" + e.getSource().toString());
create.this.dispose();
}
}
};
/**
*
*/
private AbstractAction actUndo = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Annuler" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/undo.png") ) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_U );
putValue( Action.SHORT_DESCRIPTION, "Annuler (CTRL+Z)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
System.out.println( "Undo" );
}
};
/**
*
*/
private AbstractAction actRedo = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Refaire" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/redo.png") ) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_R );
putValue( Action.SHORT_DESCRIPTION, "Refaire (CTRL+U)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
System.out.println( "Redo" );
}
};
/**
*
*/
private AbstractAction actCopy = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Copier" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/copy.png") ) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_C );
putValue( Action.SHORT_DESCRIPTION, "Copier (CTRL+C)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
System.out.println( "Copy" );
}
};
/**
*
*/
private AbstractAction actCut = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Couper" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/cut.png") ) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_T );
putValue( Action.SHORT_DESCRIPTION, "Couper (CTRL+X)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
System.out.println( "Cut" );
}
};
/**
* Ajoute ou modifie le poid d'un node
*/
private AbstractAction actCoefficient = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Coefficient (poids)" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/poidsmini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Coefficient (poids)" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
int poids = 1;
if(nod.getAttributs().get("poids")!=null) {
poids = Integer.valueOf(nod.getAttributs().get("poids"));
}
String a = JOptionPane.showInputDialog(null,"Quel est le coefficient de cette partie de l'évaluation?",poids);
if(!a.isEmpty()) {
try {
poids = Integer.valueOf(a);
if(poids<=0) {
nod.poids(Integer.valueOf(1));
textNodeSelect.setText(balisestyles());
textNodeSelect.setText("<h2>Erreur la valeur doit être un nombre entier POSITIF supérieur à zéro.<br>Cependant,la valeur a été modifiée.<br>poids=1.</h2>");
}else {
nod.poids(Integer.valueOf(poids));
refeshNodeSelected();
}
} catch (Exception e2) {
textNodeSelect.setText(balisestyles());
textNodeSelect.setText("<h2>Erreur la valeur doit être un nombre entier.<br>La valeur n'a pas été modifiée.</h2>");
}
}
}
};
/**
* Evalue la présence de ce node
*/
private AbstractAction actEvalNameNodeOui = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Oui, combien de point?" );
putValue( Action.SHORT_DESCRIPTION, "Evaluer la présence de ce node" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
int point = 0;
if(nod.getAttributs().get("evalNameNode")!=null) {
point = Integer.valueOf(nod.getAttributs().get("evalNameNode"));
}
String a = JOptionPane.showInputDialog(null,"Quel est le nombre de point?",point);
if(!a.isEmpty()) {
try {
point = Integer.valueOf(a);
if(point<=0) {
nod.getAttributs().put("evalNameNode", String.valueOf(0));
textNodeSelect.setText(balisestyles());
textNodeSelect.setText("<h2>Erreur la valeur doit être un nombre entier POSITIF supérieur à zéro.<br>Cependant,la valeur a été modifiée.<br>evalNameNode=0.</h2>");
}else {
nod.getAttributs().put("evalNameNode", String.valueOf(point));
}
} catch (Exception e2) {
textNodeSelect.setText(balisestyles());
textNodeSelect.setText("<h2>Erreur la valeur doit être un nombre entier.<br>L'attribut n'a pas été modifiée.</h2>");
}
}
refeshNodeSelected();
}
};
/**
* Evalue la présence de ce node
*/
private AbstractAction actEvalNameNodeNon = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Supprime l'évaluation de la présence du node" );
putValue( Action.SHORT_DESCRIPTION, "Supprime l'évaluation de la présence du node" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
nod.supprimeAttribut("evalNameNode");
refeshNodeSelected();
}
};
/**
* Ajoute ou modifie le titre principal
*/
private AbstractAction actTitrePrincipal = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Titre principal" );
putValue( Action.SHORT_DESCRIPTION, "Titre principal" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
String titre = "";
if(nod.getAttributs().get("titre")!=null) {
titre = nod.getAttributs().get("titre");
}
String a = JOptionPane.showInputDialog(null,"Quel est le titre?",titre);
nod.titre(a);
refeshNodeSelected();
}
};
/**
* Ajoute ou modifie le titre principal
*/
private AbstractAction actSupprimeTitre = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Titre principal" );
putValue( Action.SHORT_DESCRIPTION, "Titre principal" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
if(nod.getAttributs().get("titre")!=null) {
nod.supprimeAttribut("titre");
}
if(nod.getAttributs().get("titre1")!=null) {
nod.supprimeAttribut("titre1");
}
if(nod.getAttributs().get("titre2")!=null) {
nod.supprimeAttribut("titre2");
}
if(nod.getAttributs().get("titre3")!=null) {
nod.supprimeAttribut("titre3");
}
refeshNodeSelected();
}
};
/**
* Ajoute ou modifie le titre 1
*/
private AbstractAction actTitre1 = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Titre 1" );
putValue( Action.SHORT_DESCRIPTION, "Titre 1" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
String titre = "";
if(nod.getAttributs().get("titre1")!=null) {
titre = nod.getAttributs().get("titre1");
}
String a = JOptionPane.showInputDialog(null,"Quel est le titre?",titre);
nod.titre1(a);
refeshNodeSelected();
}
};
/**
* Ajoute ou modifie le titre 2
*/
private AbstractAction actTitre2 = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Titre 2" );
putValue( Action.SHORT_DESCRIPTION, "Titre 2" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
String titre = "";
if(nod.getAttributs().get("titre2")!=null) {
titre = nod.getAttributs().get("titre2");
}
String a = JOptionPane.showInputDialog(null,"Quel est le titre?",titre);
nod.titre2(a);
refeshNodeSelected();
}
};
/**
* Ajoute ou modifie le titre 3
*/
private AbstractAction actTitre3 = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Titre 3" );
putValue( Action.SHORT_DESCRIPTION, "Titre 3" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
node nod = (node) selectNode.getUserObject();
String titre = "";
if(nod.getAttributs().get("titre3")!=null) {
titre = nod.getAttributs().get("titre3");
}
String a = JOptionPane.showInputDialog(null,"Quel est le titre?",titre);
nod.titre3(a);
refeshNodeSelected();
}
};
/**
* Ajoute ou modifie un saut de ligne à true.
*/
private AbstractAction actsauttrue = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "true" );
putValue( Action.SHORT_DESCRIPTION, "true" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
TreeNode[] chemin = selectNode.getPath();
boolean avertissement=false;
for(int i = 0 ; i < chemin.length; i++) {
if(chemin[i].toString().contains("setting")) avertissement = true;
System.out.println(chemin[i].toString());
}
if(!avertissement) {
nod.saut(true);
refeshNodeSelected();
}else {
JOptionPane.showMessageDialog(null, "Ce node ne peut pas être évaluer." );
}
}
};
/**
* Ajoute ou modifie un saut de ligne à true.
*/
private AbstractAction actsautfalse = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "false" );
putValue( Action.SHORT_DESCRIPTION, "false" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
TreeNode[] chemin = selectNode.getPath();
boolean avertissement=false;
for(int i = 0 ; i < chemin.length; i++) {
if(chemin[i].toString().contains("setting")) avertissement = true;
System.out.println(chemin[i].toString());
}
if(!avertissement) {
nod.saut(false);
refeshNodeSelected();
}else {
JOptionPane.showMessageDialog(null, "Ce node ne peut pas être évaluer." );
}
}
};
/**
*
*/
private AbstractAction actPaste = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Coller" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/paste.png") ) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_P );
putValue( Action.SHORT_DESCRIPTION, "Coller (CTRL+V)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK ) );
}
@Override public void actionPerformed( ActionEvent e ) {
System.out.println( "Paste" );
}
};
/**
* Affiche la fenêtre informaton sur la version
*/
private AbstractAction actAPropos = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Informations" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/aproposmini.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_M );
putValue( Action.SHORT_DESCRIPTION, "Informations (CTRL+I)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK) );
}
@Override public void actionPerformed( ActionEvent e ) {
new about();
System.out.println( "A propos" );
}
};
/**
* Supprime un node
*/
private AbstractAction actDeleteNode = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Supprime" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/supprimemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Supprime" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
if(tree.getSelectionPath()!=null) {
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous supprimer le node " + selectNode.toString() + "?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
if(a == JOptionPane.YES_NO_OPTION) {
node nod = (node) selectNode.getUserObject();
if(!(nod.getNomElt().equals("setting")||nod.getNomElt().equals("csv")||nod.getNomElt().equals("import_moodle")||nod.getNomElt().equals("zip")
||nod.getNomElt().equals("plagiarism")||nod.getNomElt().equals("text:similarity")||nod.getNomElt().equals("color") ||nod.getNomElt().equals("translation") )) {
nod.getParent().supprimeNodeEnfant(nod);
constructionTree();
}else {
JOptionPane.showMessageDialog(null,"Vous ne devez pas supprimer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
};
/**
* evaluer =true
*/
private AbstractAction actEvalueTrue = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_DOWN_MASK));
putValue( Action.NAME, "Evaluer true" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/evaluertruemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Evaluer true" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
TreeNode[] chemin = selectNode.getPath();
boolean avertissement=false;
for(int i = 0 ; i < chemin.length; i++) {
if(chemin[i].toString().contains("setting")) avertissement = true;
}
if(!avertissement) {
nod.evaluerTrue();
if(nod.getLevel()==1) {
nod.addMenu(true);
}
refeshNodeSelected();
}else {
JOptionPane.showMessageDialog(null, "Ce node ne peut pas être évaluer." );
}
}
};
/**
/**
* addMenu=true
*/
private AbstractAction actAddMenuTrue = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "true" );
putValue( Action.SHORT_DESCRIPTION, "true" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
TreeNode[] chemin = selectNode.getPath();
boolean avertissement=false;
for(int i = 0 ; i < chemin.length; i++) {
if(chemin[i].toString().contains("setting")) avertissement = true;
}
if(!avertissement) {
nod.evaluerTrue();
nod.addMenu(true);
refeshNodeSelected();
}else {
JOptionPane.showMessageDialog(null, "Ce node ne peut pas être évaluer." );
}
}
};
/**
* addMenu=false
*/
private AbstractAction actAddMenuFalse = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "false" );
putValue( Action.SHORT_DESCRIPTION, "false" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
TreeNode[] chemin = selectNode.getPath();
boolean avertissement=false;
for(int i = 0 ; i < chemin.length; i++) {
if(chemin[i].toString().contains("setting")) avertissement = true;
}
if(!avertissement) {
nod.evaluerTrue();
nod.addMenu(false);
refeshNodeSelected();
}else {
JOptionPane.showMessageDialog(null, "Ce node ne peut pas être évaluer." );
}
}
};
// public static void expandOrCollapsePath (JTree tree,TreePath treePath,int level,int currentLevel,boolean expand) {
// System.out.println("Exp level="+currentLevel+", exp="+expand + ", level=" + level);
// if (expand && level<=currentLevel && level>0) return;
//
// TreeNode treeNode = ( TreeNode ) treePath.getLastPathComponent();
// TreeModel treeModel=tree.getModel();
// if ( treeModel.getChildCount(treeNode) >= 0 ) {
// for ( int i = 0; i < treeModel.getChildCount(treeNode); i++ ) {
// TreeNode n = ( TreeNode )treeModel.getChild(treeNode, i);
// TreePath path = treePath.pathByAddingChild( n );
// expandOrCollapsePath(tree,path,level,currentLevel+1,expand);
// }
// if (!expand && currentLevel<level) return;
// }
// if (expand) {
// tree.expandPath( treePath );
//// System.err.println("Path expanded at level "+currentLevel+"-"+treePath);
// } else {
// tree.collapsePath(treePath);
//// System.err.println("Path collapsed at level "+currentLevel+"-"+treePath);
// }
// }
/**
*
*/
private AbstractAction actDocumentation = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Documentation" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/documentationmini.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_D );
putValue( Action.SHORT_DESCRIPTION, "Documentation (CTRL+D)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK) );
}
@Override public void actionPerformed( ActionEvent e ) {
Desktop d = Desktop.getDesktop();
try {
d.open(new File(evaluate.class.getResource("/resources/documentation.pdf").getPath()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println( "Affiche la documentation." );
}
};
/**
* N'évalue pas le node evaluer=false
*/
private AbstractAction actEvalueFalse = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
putValue( Action.NAME, "Evaluer false" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/evaluerfalsemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Evaluer false" );
}
@Override public void actionPerformed( ActionEvent e ) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
node nod = (node) selectNode.getUserObject();
nod.evaluerFalse();
refeshNodeSelected();
}
};
/**
* Expand all
*/
private AbstractAction actExpandAll= new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Tout étendre" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/expandallmini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Tout étendre" );
}
@Override public void actionPerformed( ActionEvent e ) {
expandAll();
refeshNodeSelected();
}
};
/**
* Calloapse all
*/
private AbstractAction actCollapseAll= new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Tout réduire" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/collapseallmini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Tout réduire" );
}
@Override public void actionPerformed( ActionEvent e ) {
collapseAll();
refeshNodeSelected();
}
};
/**
* Expand node
*/
private AbstractAction actExpandNode= new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Etendre ce node" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/expandnodemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Etendre ce node" );
}
@Override public void actionPerformed( ActionEvent e ) {
if(tree.getSelectionPath()!=null) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
expandNode(selectNode);
refeshNodeSelected();
}
}
};
/**
* Collapse node
*/
private AbstractAction actCollapseNode= new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Réduire ce node" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/collapsenodemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Réduire ce node" );
}
@Override public void actionPerformed( ActionEvent e ) {
if(tree.getSelectionPath()!=null) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
textNodeSelect.setContentType("text/html");
collapseNode(selectNode);
refeshNodeSelected();
}
}
};
/**
* Up node
*/
private AbstractAction actUpNode= new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Monter le node" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/upnodemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Monter le node" );
}
@Override public void actionPerformed( ActionEvent e ) {
if(tree.getSelectionPath()!=null) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous monter le node " + selectNode.toString() + "?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
if(a == JOptionPane.YES_NO_OPTION) {
node nod = (node) selectNode.getUserObject();
if(!nod.chemin().contains("setting")) {
nod.getParent().upNodeEnfant(nod);
constructionTree();
}else {
JOptionPane.showMessageDialog(null,"Vous ne devez pas déplacer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
};
private AbstractAction actDownNode= new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Descendre le node" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/downnodemini.png")) );
putValue( Action.SHORT_DESCRIPTION, "Descendre le node" );
}
@Override public void actionPerformed( ActionEvent e ) {
if(tree.getSelectionPath()!=null) {
DefaultMutableTreeNode selectNode = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
int a = JOptionPane.showConfirmDialog(null,"Voulez-vous descendre le node " + selectNode.toString() + "?", "Sélectionner un choix", JOptionPane.YES_NO_OPTION);
if(a == JOptionPane.YES_NO_OPTION) {
node nod = (node) selectNode.getUserObject();
if(!nod.chemin().contains("setting")) {
nod.getParent().downNodeEnfant(nod);
constructionTree();
}else {
JOptionPane.showMessageDialog(null,"Vous ne devez pas déplacer ce node !", "Oh non!!!", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
};
/**
* Gènère un nouveau fichier d'analyse à partir d'un fichier ODF
*/
private AbstractAction actNewFichierAnalyse = new 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 ) {
JFileChooser chooser = new JFileChooser();
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());
commandes.path = chooser.getCurrentDirectory().getAbsolutePath();
commandes.PathFilenameAnalysis = chooser.getSelectedFile().getAbsolutePath();
commandes.nameSujet = chooser.getSelectedFile().getName();
Run b = null;
try {
b = new Run(commandes.PathFilenameAnalysis);
node nodSujet = Run.XMLContent(b.getLectDossiers().getEC().getListeContentWriter().get(0));
nodSujet = meptl.LectureFichierEtudiantSousFormeDeNode(nodSujet,b,0);
nodSujet.getAttributs().put("analysis_filename","sujet.xml");
commandes.sujet = ecritureSujet.nodePourEcritureSujet(nodSujet,b,0);
new verificationFichierAnalyse();
if(commandes.fichierAnalyseValide) {
constructionTree();
}else {
textNodeSelect.setText("<h1>Le fichier n'est pas valise</h1>");
}
} catch (ParserConfigurationException | SAXException | IOException | CloneNotSupportedException e1) {
e1.printStackTrace();
}
} else {
refeshNodeSelected();
}
commandes.ecritCode = true;
}
};
/**
*
*/
private AbstractAction actEvaluer = new AbstractAction() {
private static final long serialVersionUID = 1L;
{
putValue( Action.NAME, "Evaluer" );
putValue( Action.SMALL_ICON, new ImageIcon( getClass().getResource("/evaluate.png") ) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_E );
putValue( Action.SHORT_DESCRIPTION, "Evaluer un node (CTRL+E)" );
putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK) );
}
@Override public void actionPerformed( ActionEvent e ) {
new evaluate();
dispose();
}
};
/**
* Construction du Tree avec le node sujet.
*/
public void constructionTree() {
Run.parentAndLevel(commandes.sujet, commandes.sujet, 0);
DefaultMutableTreeNode node0 = null;
DefaultMutableTreeNode node1 = null;
DefaultMutableTreeNode node2 = null;
DefaultMutableTreeNode node3 = null;
DefaultMutableTreeNode node4 = null;
DefaultMutableTreeNode node5 = null;
DefaultMutableTreeNode node6 = null;
commandes.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
commandes.tree.setExpandsSelectedPaths(true);
commandes.tree.setInvokesStopCellEditing(true);
tree.setExpandsSelectedPaths(true);
tree.setInvokesStopCellEditing(true);
if(commandes.sujet.getNomElt().equals("fichier")) {
node0 = new DefaultMutableTreeNode(commandes.sujet.getNomElt(),true);
if(commandes.sujet!=null) for(int i = 0 ; i < commandes.sujet.getNodes().size(); i++) {
node1 = new DefaultMutableTreeNode(commandes.sujet.getNodes().get(i));
if(commandes.sujet.getNodes().get(i)!=null) for(int j = 0 ; j < commandes.sujet.getNodes().get(i).getNodes().size();j++) {
node2 = new DefaultMutableTreeNode(commandes.sujet.getNodes().get(i).getNodes().get(j));
if(commandes.sujet.getNodes().get(i).getNodes().get(j)!=null) for(int k = 0 ; k<commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().size(); k++){
node3 = new DefaultMutableTreeNode(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k));
if(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k)!=null) for(int l = 0 ; l<commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().size(); l++){
node4 = new DefaultMutableTreeNode(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l));
if(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l)!=null) for(int m = 0 ; m<commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l).getNodes().size(); m++){
node5 = new DefaultMutableTreeNode(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l).getNodes().get(m));
if(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l).getNodes().get(m)!=null) for(int n = 0 ; n<commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l).getNodes().get(m).getNodes().size(); n++){
node6 = new DefaultMutableTreeNode(commandes.sujet.getNodes().get(i).getNodes().get(j).getNodes().get(k).getNodes().get(l).getNodes().get(m).getNodes().get(n));
node5.add(node6);
}
node4.add(node5);
}
node3.add(node4);
}
node2.add(node3);
}
node1.add(node2);
}
node0.add(node1);
}
}
commandes.tree = new JTree(node0);
DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) commandes.tree.getCellRenderer();
cellRenderer.setOpenIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
cellRenderer.setClosedIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
cellRenderer.setLeafIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
cellRenderer.setBackgroundNonSelectionColor(new Color(255, 255, 221));
cellRenderer.setBackgroundSelectionColor(new Color(0, 0, 128));
cellRenderer.setBorderSelectionColor(Color.black);
cellRenderer.setTextSelectionColor(Color.white);
cellRenderer.setTextNonSelectionColor(Color.blue);
tree.setCellRenderer(cellRenderer);
tree.setModel(commandes.tree.getModel()) ;
}
/**
* La balise de style pour le code HTML
* @return
*/
private static String balisestyles() {
return "<style type=\"text/css\">"
+ "h1 {margin-bottom: 0.25cm;font-size: 18pt;font-family:\"Arial\";text-align:center;font-weight: bold;}"
+ "h2 {color:red;margin-bottom: 0.25cm;font-size: 18pt;font-family:\"Arial\";text-align:center;font-weight: bold;}"
+ "h4 {text-align:left;font-family: \"Arial\"; font-size: 16pt; font-weight: bold; line-height: 110%;}"
+ "hr { display: block; margin-top: 0.5em; margin-bottom: 8em; margin-left: 2em; margin-right: 2em; border-style: inset; border-width: 4px;}"
+ "spanpablo { float: right; width: 8em; font-size: 250%; font-family: algerian, courier; line-height: 80%; margin-right: 1%; color: red; text-align: center}"
+ "p.p1{color:blue;font-family:\"Arial\";font-size: 14pt;margin-bottom: 0cm; margin-top: 0cm; line-height: 0%; background: transparent; margin-left: 0cm; white-space: pre;}"
+ "li.p2{color:green;font-family:\"Arial\";font-size: 14pt;margin-bottom: 0cm; margin-top: 0cm; line-height: 0%; background: transparent; margin-left: 0cm; white-space: pre;}"
+ "li.p3{color:red;font-family:\"Arial\";font-size: 14pt;margin-bottom: 0cm; margin-top: 0cm; line-height: 0%; background: transparent; margin-left: 0cm; white-space: pre;}"
+ "p.p4{margin-left: 0px; margin-bottom: 0cm; margin-top: 4px; line-height: 115%}"
+ "</style>";
}
private void expandAll() {
Enumeration<?> topLevelNodes = ((TreeNode) tree.getModel().getRoot()).children();
while(topLevelNodes.hasMoreElements()) {
DefaultMutableTreeNode N = (DefaultMutableTreeNode) topLevelNodes.nextElement();
tree.expandPath(new TreePath(N.getPath()));
expandNode( N);
}
}
private void collapseAll() {
Enumeration<?> topLevelNodes = ((TreeNode) tree.getModel().getRoot()).children();
while(topLevelNodes.hasMoreElements()) {
DefaultMutableTreeNode N = (DefaultMutableTreeNode) topLevelNodes.nextElement();
tree.collapsePath(new TreePath(N.getPath()));
collapseNode(N);
}
}
private void expandNode(DefaultMutableTreeNode N) {
Enumeration<?> topLevelNodes = ((TreeNode) N).children();
while(topLevelNodes.hasMoreElements()) {
DefaultMutableTreeNode N1 = (DefaultMutableTreeNode) topLevelNodes.nextElement();
tree.expandPath(new TreePath(N1.getPath()));
expandNode(N1);
}
}
private void collapseNode(DefaultMutableTreeNode N) {
Enumeration<?> topLevelNodes = ((TreeNode) N).children();
while(topLevelNodes.hasMoreElements()) {
DefaultMutableTreeNode N1 = (DefaultMutableTreeNode) topLevelNodes.nextElement();
tree.collapsePath(new TreePath(N1.getPath()));
collapseNode( N1 );
}
tree.collapsePath(new TreePath(N.getPath()));
}
// void saySomething(String eventDescription, TreeExpansionEvent e) {
// System.out.println(eventDescription + "; " + "path = " + e.getPath());
// }
//
//
// // Required by TreeExpansionListener interface.
// public void treeExpanded(TreeExpansionEvent e) {
// saySomething("Tree-expanded event detected", e);
// }
//
// // Required by TreeExpansionListener interface.
// public void treeCollapsed(TreeExpansionEvent e) {
// saySomething("Tree-collapsed event detected", e);
// }
}
//class MyTreeWillExpandListener implements TreeWillExpandListener {
//
//
// public void treeWillExpand(TreeExpansionEvent evt) throws ExpandVetoException {
// JTree tree = (JTree) evt.getSource();
//
// TreePath path = evt.getPath();
// boolean veto = false;
// if (veto) {
// throw new ExpandVetoException(evt);
// }
// }
//
// public void treeWillCollapse(TreeExpansionEvent evt) throws ExpandVetoException {
// JTree tree = (JTree) evt.getSource();
//
// TreePath path = evt.getPath();
// boolean veto = false;
// if (veto) {
// throw new ExpandVetoException(evt);
// }
// }
//}
//class MyTreeExpansionListener implements TreeExpansionListener {
//
// public ArrayList<TreePath> Chemin = new ArrayList<TreePath>();
//
// public ArrayList<TreePath> getChemin() {
// return Chemin;
// }
//
// public void setChemin(ArrayList<TreePath> chemin) {
// Chemin = chemin;
// }
//
// public void treeExpanded(TreeExpansionEvent evt) {
// TreePath path = evt.getPath();
// Chemin.add(path);
// System.out.println("treeExpanded");
// }
//
// public void treeCollapsed(TreeExpansionEvent evt) {
// TreePath path = evt.getPath();
// Chemin.remove(path);
// System.out.println("treeCollapsed");
//
// }
//}