Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.44 KB | None | 0 0
  1. package IHM;
  2.  
  3. import java.awt.Color;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.MouseEvent;
  7. import java.awt.event.MouseListener;
  8. import java.io.BufferedReader;
  9. import java.io.BufferedWriter;
  10. import java.io.FileReader;
  11. import java.io.FileWriter;
  12. import java.io.IOException;
  13. import java.io.PrintWriter;
  14. import java.io.Serializable;
  15. import java.util.ArrayList;
  16. import java.util.Iterator;
  17. import java.util.Vector;
  18. import java.util.regex.Pattern;
  19.  
  20. import javax.swing.GroupLayout;
  21. import javax.swing.GroupLayout.Alignment;
  22. import javax.swing.JButton;
  23. import javax.swing.JCheckBox;
  24. import javax.swing.JCheckBoxMenuItem;
  25. import javax.swing.JFileChooser;
  26. import javax.swing.JFrame;
  27. import javax.swing.JList;
  28. import javax.swing.JMenu;
  29. import javax.swing.JMenuBar;
  30. import javax.swing.JMenuItem;
  31. import javax.swing.JOptionPane;
  32. import javax.swing.JPanel;
  33. import javax.swing.JScrollPane;
  34. import javax.swing.JSplitPane;
  35. import javax.swing.JTextPane;
  36. import javax.swing.LayoutStyle.ComponentPlacement;
  37. import javax.swing.ListModel;
  38. import javax.swing.ListSelectionModel;
  39. import javax.swing.UIManager;
  40. import javax.swing.filechooser.FileFilter;
  41.  
  42. import Fichiers.Enregistrer;
  43. import Fichiers.Fichier_1;
  44. import Fichiers.Fichier_2;
  45. import Fichiers.Fichier_3;
  46. import Traitement.LSP;
  47.  
  48.  
  49. public class IHM extends JFrame implements Serializable{
  50.     /**
  51.      *
  52.      */
  53.     private static final long serialVersionUID = 1L;
  54.  
  55.     JCheckBox chckbxNewCheckBox;
  56.    
  57.     Fichier_1 fic1;
  58.     Fichier_2 fic2;
  59.     Fichier_3 fic3;
  60.    
  61.     int val_fichier3 = 0;
  62.    
  63.     String file, file2, file3;
  64.     String fichier = "";
  65.    
  66.     FileFilter filtre_txt;
  67.    
  68.     // Definition des differentes listes utiles
  69.     ArrayList<String> liste_objet_non_existant= new ArrayList<>();
  70.     ArrayList<String> liste_obj_Doublon = new ArrayList<>();
  71.     ArrayList<String> liste_obj_ecart = new ArrayList<>();
  72.     ArrayList<String> liste_tous_obj = new ArrayList<>();
  73.     ArrayList<String> liste_objet_non_ecart= new ArrayList<>();
  74.     ArrayList<String> liste_objet_3=new ArrayList<>();
  75.    
  76.     Vector<String> data = new Vector<String>();
  77.    
  78.     JTextPane textPane, textPane_1;
  79.    
  80.     JCheckBoxMenuItem chk_btn_debug;
  81.    
  82.     LSP lsp1, lsp2, lsp3;
  83.    
  84.     Object item;
  85.    
  86.     @SuppressWarnings("rawtypes")
  87.     JList list;
  88.     JButton btnCharger, btnEnregistrer, btnSauvegarder;
  89.    
  90.      JFrame frame;
  91.     // Methode de lecture du fichier
  92.             public String readFile(String file) {
  93.                 try {
  94.                     BufferedReader reader = new BufferedReader(new FileReader(file));
  95.                     String ligne;
  96.                     StringBuffer fichier = new StringBuffer();
  97.          
  98.                     while((ligne = reader.readLine()) != null){
  99.                         fichier.append(ligne);
  100.                         fichier.append("\n");          
  101.                     }
  102.                     reader.close();
  103.          
  104.                     return fichier.toString();     
  105.                 } catch (IOException e) {
  106.                     return e.getMessage();
  107.                 }
  108.             }
  109.  
  110.             // Methode de sauvegarde du résultat
  111.             public void saveFile(String contenu, String file) {
  112.                 try {
  113.                     PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
  114.          
  115.                     writer.write(contenu);
  116.          
  117.                     writer.close();
  118.                 } catch (IOException e) {
  119.                     e.printStackTrace();
  120.                 }
  121.             }
  122.        
  123.     public IHM() {
  124.         String fichier = "";
  125.         String fichier2 = "";
  126.         String fichier3 = "";
  127.        
  128.         frame = new JFrame();
  129.         frame.setBounds(100, 100, 1054, 687);
  130.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  131.        
  132.         JPanel panel_button = new JPanel();
  133.         panel_button.setLayout(null);
  134.        
  135.         JButton button_fic1 = new JButton("Fic.1");
  136.         button_fic1.setBounds(6, 4, 75, 23);
  137.         panel_button.add(button_fic1);
  138.        
  139.         JButton button_fic2 = new JButton("Fic.2");
  140.         button_fic2.setBounds(74, 4, 75, 23);
  141.         panel_button.add(button_fic2);
  142.        
  143.         JButton button_fic3 = new JButton("Fic.3");
  144.         button_fic3.setBounds(143, 4, 75, 23);
  145.         panel_button.add(button_fic3);
  146.        
  147.         JButton button_traiter = new JButton("Traiter");
  148.         button_traiter.addActionListener(new ActionListener() {
  149.             public void actionPerformed(ActionEvent e) {
  150.                
  151.                 // Recuperation des chemins des fichiers 1 et 2
  152.                 file = fic1.getPath_file();
  153.                 file2 = fic2.getPath_file();
  154.  
  155.                 // Si un fichier  3 a ete selectionne
  156.                 if( val_fichier3 == 1){
  157.                     // Recuperation du chemin du fichier 3
  158.                     file3 = fic3.getPath_file();
  159.  
  160.                     lsp3 = new LSP(file3); 
  161.                     liste_objet_3=lsp3.get_obj_fic3();
  162.                 }
  163.                 // Traitement
  164.                 lsp1 = new LSP(file);
  165.                 lsp1.parser();
  166.                 lsp2 = new LSP(file2);
  167.                 lsp2.parser(); 
  168.                 System.out.println("\nElement manquant\n");
  169.                
  170.                 ArrayList<Traitement.Package> liste_diff_package = lsp1.get_no_existant(lsp2);
  171.                 Iterator<Traitement.Package> i = liste_diff_package.iterator();
  172.                 while(i.hasNext()){
  173.                     Traitement.Package p = i.next();
  174.                     if(!liste_objet_non_existant.contains(p.get_nom())){
  175.                         liste_objet_non_existant.add(p.get_nom());
  176.                     }
  177.                 }
  178.                 ArrayList<Traitement.Package> liste_diff_package1 = lsp2.get_no_existant(lsp1);
  179.                 Iterator<Traitement.Package> i1 = liste_diff_package1.iterator();
  180.                 while(i1.hasNext()){
  181.                     Traitement.Package p1 = i1.next();
  182.                     if(!liste_objet_non_existant.contains(p1.get_nom())){
  183.                         liste_objet_non_existant.add(p1.get_nom());
  184.                     }
  185.                 }
  186. //              Iterator<String> i50 = liste_objet_non_existant.iterator();
  187. //              while(i50.hasNext()){
  188. //                  String p50 = i50.next();
  189. //                  System.out.println(p50);
  190. //              }
  191.                
  192.                
  193.                
  194.                 //DOUBLON
  195.  
  196.                
  197.                 System.out.println("\nDOUBLON\n");
  198.                 ArrayList<String> listeDoublon1=lsp1.get_doublon();
  199.                 Iterator<String> i11 = listeDoublon1.iterator();
  200.                 while(i11.hasNext()){
  201.                     String p11 = i11.next();
  202.                     if(!liste_obj_Doublon.contains(p11)){
  203.                     liste_obj_Doublon.add(p11);
  204.                     }
  205.                 }
  206.                 //System.out.println(listeDoublon1);
  207.                 ArrayList<String> listeDoublon2=lsp2.get_doublon();
  208.                 //System.out.println(listeDoublon2);
  209.                 Iterator<String> i12 = listeDoublon2.iterator();
  210.                 while(i12.hasNext()){
  211.                     String p12 = i12.next();
  212.                     if(!liste_obj_Doublon.contains(p12)){
  213.  
  214.                     liste_obj_Doublon.add(p12);
  215.                     }
  216.                 }
  217. //             
  218.                 Iterator<String> i13 = liste_obj_Doublon.iterator();
  219.                 while(i13.hasNext()){
  220.                     String p13 = i13.next();
  221.                     System.out.println(p13);
  222.                 }
  223. //             
  224. //             
  225. //              //SUPPRESSION DOUBLON
  226.                 System.out.println("suppr doublon 1\n");
  227.                 lsp1.deleteDoublon();
  228.                 System.out.println("suppr doublon 2\n");
  229.                 lsp2.deleteDoublon();
  230.                                    
  231.             //ELEMENT EN ECART
  232.            
  233.                 System.out.println("\nElement en equart\n");
  234.                 ArrayList<Traitement.Package> liste_package_ecart = lsp1.get_obj_ecart(lsp2);
  235.                 Iterator<Traitement.Package> i2 = liste_package_ecart.iterator();
  236.                 while(i2.hasNext()){
  237.                     Traitement.Package p2 = i2.next();
  238.                     if(!liste_obj_ecart.contains(p2.get_nom()) && !liste_obj_Doublon.contains(p2.get_nom())){
  239.                         liste_obj_ecart.add(p2.get_nom());
  240.                     //System.out.println(p2.get_nom());
  241.                     }
  242.                 }
  243.                
  244.                 ArrayList<Traitement.Package> liste_package_ecart1 = lsp2.get_obj_ecart(lsp1);
  245.                 Iterator<Traitement.Package> i3 = liste_package_ecart1.iterator();
  246.                 while(i3.hasNext()){
  247.                     Traitement.Package p3 = i3.next();
  248.                     if(!liste_obj_ecart.contains(p3.get_nom()) && !liste_obj_Doublon.contains(p3.get_nom())){
  249.                         liste_obj_ecart.add(p3.get_nom());
  250.                     //System.out.println(p3.get_nom());
  251.                     }
  252.                 }
  253.                
  254.                 //traitement de f3
  255.                 if( val_fichier3 == 1){
  256.                 System.out.println(fic3.getPath_file());
  257.  
  258.                 //if(fic3.getPath_file() != null){
  259.                 Iterator<String> i10 = liste_obj_ecart.iterator();
  260.                 while(i10.hasNext()){
  261.                     String p10 = i10.next();
  262.                     if(liste_objet_3.contains(p10)){
  263.                         System.out.println(p10);
  264.                         i10.remove();
  265.                     }
  266.                 }
  267.                 }
  268.                 System.out.println("\n--\n");
  269.                
  270.                 //liste objet ecart final
  271.                     Iterator<String> i15 = liste_obj_ecart.iterator();
  272.                     while(i15.hasNext()){
  273.                         String p15 = i15.next();
  274.                        
  275.                         System.out.println(p15);
  276.                            
  277.                     }
  278.            
  279.                 System.out.println("TOUS LES OBJETS\n");
  280.                
  281.                 ArrayList<String> liste_tous_obj1=lsp1.get_liste_objet();
  282.                 Iterator<String> i20 = liste_tous_obj1.iterator();
  283.                 while(i20.hasNext()){
  284.                     String p20 = i20.next();
  285.                     if(!liste_tous_obj.contains(p20)){
  286.                     liste_tous_obj.add(p20);
  287.                     }
  288.                 }
  289.                
  290.                 ArrayList<String> liste_tous_obj2=lsp2.get_liste_objet();
  291.                 Iterator<String> i21 = liste_tous_obj2.iterator();
  292.                 while(i21.hasNext()){
  293.                     String p21 = i21.next();
  294.                     if(!liste_tous_obj.contains(p21)){
  295.                     liste_tous_obj.add(p21);
  296.                     }
  297.                 }
  298. //             
  299. //              Iterator<String> i22 = liste_tous_obj.iterator();
  300. //              while(i22.hasNext()){
  301. //                  String p22 = i22.next();
  302. //                 
  303. //                  System.out.println(p22);
  304. //                     
  305. //              }
  306.                
  307.                 //LISTE OBJET NON ECART
  308.                 System.out.println("OBJETS NON ECARTS\n");
  309.  
  310.  
  311.                 Iterator<String> i30 = liste_tous_obj.iterator();
  312.                 while(i30.hasNext()){
  313.                     String p30 = i30.next();
  314.                     if(!liste_obj_ecart.contains(p30) && !liste_objet_non_existant.contains(p30)){
  315.                         liste_objet_non_ecart.add(p30);
  316.                     }
  317.                 }
  318.                
  319.                 Iterator<String> i40 = liste_objet_non_ecart.iterator();
  320.                 while(i40.hasNext()){
  321.                     String p40 = i40.next();
  322.                    
  323.                     System.out.println(p40);
  324.                        
  325.                 }
  326.                 JOptionPane.showMessageDialog(null, "Fichiers traités", "Information", JOptionPane.PLAIN_MESSAGE);
  327.             }  
  328.            
  329. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  330.        
  331.        
  332.         });
  333.         button_traiter.setBounds(212, 4, 91, 23);
  334.         panel_button.add(button_traiter);
  335.        
  336.         JMenuBar menuBar = new JMenuBar();
  337.        
  338.         JMenu menu_Fichier = new JMenu("Fichier");
  339.         JMenu menu_Filtre = new JMenu("Filtrer");
  340.         JMenu menu_Outils = new JMenu("Outils");
  341.         JMenu menu_Aide = new JMenu("Aide");
  342.        
  343.         JMenuItem tous = new JMenuItem("Afficher tous les objets");
  344.         JMenuItem ecart = new JMenuItem("Afficher les objets en écarts");
  345.         JMenuItem non_ecart = new JMenuItem("Afficher les objets non en écarts");
  346.         JMenuItem doublons = new JMenuItem("Afficher les doublons");
  347.         JMenuItem non_existants = new JMenuItem("Afficher les non existants");
  348.         JMenuItem debug = new JMenuItem("Debug");
  349.         JMenuItem informations = new JMenuItem("Informations");
  350.        
  351.         menu_Filtre.add(tous);
  352.         tous.addActionListener(new ActionListener() {
  353.             public void actionPerformed(ActionEvent e) {
  354.                 data.clear();
  355.                 list.setListData(data);
  356.                 Iterator<String> i13 = liste_tous_obj.iterator();
  357.                 while(i13.hasNext()){
  358.                     String p13 = i13.next();
  359.                     //System.out.println(p13);
  360.                
  361.                     data.addElement(""+p13);
  362.                     list.setListData(data);
  363.                     list.setSelectedIndex(0);
  364.                     list.setForeground(new Color(217,38,6));               
  365.                 }
  366.             }
  367.         });
  368.        
  369.         menu_Filtre.add(ecart);
  370.         ecart.addActionListener(new ActionListener() {
  371.             public void actionPerformed(ActionEvent e) {
  372.                 data.clear();
  373.                 //traitement de f3
  374.                 Iterator<String> i10 = liste_obj_ecart.iterator();
  375.                 while(i10.hasNext()){
  376.                     String p10 = i10.next();
  377.                     if(liste_objet_3.contains(p10)){
  378.                         //System.out.println(p10);
  379.                         liste_obj_ecart.remove(p10);
  380.                     }
  381.                 }
  382.                
  383.                 //liste objet ecart final
  384.             Iterator<String> i15 = liste_obj_ecart.iterator();
  385.                 while(i15.hasNext()){
  386.                 @SuppressWarnings("unused")
  387.                 String p20 = i15.next();
  388.                    
  389.                     //System.out.println(p20);
  390.                    
  391.                 }
  392.                 list.setListData(data);
  393.                 Iterator<String> i13 = liste_obj_ecart.iterator();
  394.                 while(i13.hasNext()){
  395.                     String p13 = i13.next();
  396.                     //System.out.println(p13);
  397.                
  398.                     data.addElement(""+p13);
  399.                     list.setListData(data);
  400.                     list.setSelectedIndex(0);
  401.                     list.setForeground(new Color(217,38,6));               
  402.                 }
  403.             }
  404.         });
  405.        
  406.         menu_Filtre.add(non_ecart);
  407.         non_ecart.addActionListener(new ActionListener(){
  408.             public void actionPerformed(ActionEvent e){
  409.                 data.clear();
  410.                 list.setListData(data);
  411.                 Iterator<String> i13 = liste_objet_non_ecart.iterator();
  412.                 while(i13.hasNext()){
  413.                     String p13 = i13.next();
  414.                     //System.out.println(p13);
  415.                
  416.                     data.addElement(""+p13);
  417.                     list.setListData(data);
  418.                     list.setSelectedIndex(0);
  419.                     list.setForeground(new Color(217,38,6));               
  420.                 }
  421.             }
  422.         });
  423.        
  424.         menu_Filtre.add(doublons);
  425.         doublons.addActionListener(new ActionListener(){
  426.             public void actionPerformed(ActionEvent e){
  427.                 data.clear();
  428.                 list.setListData(data);
  429.                 Iterator<String> i13 = liste_obj_Doublon.iterator();
  430.                 while(i13.hasNext()){
  431.                     String p13 = i13.next();
  432.                     //System.out.println(p13);
  433.                
  434.                     data.addElement(""+p13);
  435.                     list.setListData(data);
  436.                     list.setSelectedIndex(0);
  437.                     list.setForeground(new Color(217,38,6));               
  438.                 }
  439.             }
  440.         });
  441.        
  442.         menu_Filtre.add(non_existants);
  443.         // Existant dans un mais pas l'autre
  444.                 non_existants.addActionListener(new ActionListener() {
  445.                     public void actionPerformed(ActionEvent e) {
  446.                         data.clear();
  447.                         list.setListData(data);
  448.                         Iterator<String> i13 = liste_objet_non_existant.iterator();
  449.                         while(i13.hasNext()){
  450.                             String p13 = i13.next();
  451.                             //System.out.println(p13);
  452.                        
  453.                             data.addElement(""+p13);
  454.                             list.setListData(data);
  455.                             list.setSelectedIndex(0);
  456.                             list.setForeground(new Color(217,38,6));               
  457.                         }
  458.                     }
  459.                 });
  460.        
  461.                 chk_btn_debug = new JCheckBoxMenuItem("Mode Debug");
  462.                 chk_btn_debug.addActionListener(new ActionListener(){
  463.                     public void actionPerformed(ActionEvent e) {
  464.                         // Etat initial: boutons actifs
  465.                         button_fic1.setEnabled(true);
  466.                         button_fic2.setEnabled(true);
  467.                         button_fic3.setEnabled(true);
  468.                         button_traiter.setEnabled(true);
  469.                         btnSauvegarder.setEnabled(true);
  470.                         btnEnregistrer.setEnabled(true);
  471.                         btnCharger.setEnabled(true);
  472.                         menuBar.setEnabled(true);
  473.                         // Si le bouton est coché
  474.                         if(chk_btn_debug.isSelected()){
  475.                             // Boutons inactifs
  476.                             button_fic1.setEnabled(true);
  477.                             button_fic2.setEnabled(true);
  478.                             button_fic3.setEnabled(true);
  479.                             button_traiter.setEnabled(true);
  480.                             btnSauvegarder.setEnabled(true);
  481.                             btnEnregistrer.setEnabled(false);
  482.                             btnCharger.setEnabled(false);
  483.                             menuBar.setEnabled(true);
  484.                         }          
  485.                     }
  486.                 });
  487.                 menu_Outils.add(chk_btn_debug);
  488.        
  489.                
  490.                 button_fic1.addActionListener(new ActionListener() {
  491.                     public void actionPerformed(ActionEvent e) {
  492.                         fic1 = new Fichier_1(fichier);
  493.                         fic1.Chargement_fic1();
  494.                         file = fic1.getPath_file();
  495.                         textPane.setText("Fichier sélectionné: " +file);
  496.                     }
  497.                 });
  498.                
  499.                 button_fic2.addActionListener(new ActionListener() {
  500.                     public void actionPerformed(ActionEvent e) {
  501.                         fic2 = new Fichier_2(fichier);
  502.                         fic2.Chargement_fic2();
  503.                         file = fic2.getPath_file();
  504.                         textPane_1.setText("Fichier sélectionné: " +file);
  505.                     }
  506.                 });
  507.        
  508.                 button_fic3.addActionListener(new ActionListener() {
  509.                     public void actionPerformed(ActionEvent e) {
  510.                         fic3 = new Fichier_3(fichier3);
  511.                         fic3.Chargement_fic3();
  512.                         file = fic3.getPath_file();
  513.                         val_fichier3 =1;
  514.                         //LSP lsp3 = new LSP(fichier3);
  515.                         //ArrayList<String> liste_objet_3=lsp3.get_obj_fic3();
  516.                     }
  517.                 });
  518.                
  519.         menu_Aide.add(informations);
  520.         informations.addActionListener(new ActionListener(){
  521.             public void actionPerformed(ActionEvent e) {
  522.                 Message msg = new Message();
  523.                 msg.afficher_msg_info();
  524.             }
  525.         });
  526.        
  527.         menuBar.add(menu_Fichier);
  528.        
  529.         JMenu Sous_menu_Ouvrir = new JMenu("Ouvrir");
  530.         menu_Fichier.add(Sous_menu_Ouvrir);
  531.        
  532.         JMenuItem mntmFichier1 = new JMenuItem("Fichier 1");
  533.         mntmFichier1.addActionListener(new ActionListener() {
  534.             public void actionPerformed(ActionEvent e) {
  535.                 Fichier_1 fic1 = new Fichier_1(fichier);
  536.                 fic1.Chargement_fic1();
  537.                 String file = fic1.getPath_file();
  538.                 textPane.setText("Fichier sélectionné: " +file);
  539.             }
  540.         });
  541.         Sous_menu_Ouvrir.add(mntmFichier1);
  542.        
  543.         JMenuItem mntmFichier2 = new JMenuItem("Fichier 2");
  544.         mntmFichier2.addActionListener(new ActionListener() {
  545.             public void actionPerformed(ActionEvent e) {
  546.                 Fichier_2 fic2 = new Fichier_2(fichier2);
  547.                 fic2.Chargement_fic2();
  548.                 String file = fic2.getPath_file();
  549.                 textPane_1.setText("Fichier sélectionné: " +file);
  550.             }
  551.         });
  552.         Sous_menu_Ouvrir.add(mntmFichier2);
  553.        
  554.         JMenuItem mntmFichier3 = new JMenuItem("Fichier 3");
  555.         mntmFichier3.addActionListener(new ActionListener() {
  556.             public void actionPerformed(ActionEvent e) {
  557.                 Fichier_3 fic3 = new Fichier_3(fichier3);
  558.                 fic3.Chargement_fic3();
  559.                 @SuppressWarnings("unused")
  560.                 String file = fic3.getPath_file();
  561.             }
  562.         });
  563.         Sous_menu_Ouvrir.add(mntmFichier3);
  564.        
  565.         JMenuItem Sous_menu_Sauvegarder = new JMenuItem("Sauvegarder");
  566.         menu_Fichier.add(Sous_menu_Sauvegarder);
  567.         menuBar.add(menu_Filtre);
  568.         menuBar.add(menu_Outils);
  569.        
  570.         JMenu mnCouleurs = new JMenu("Couleurs");
  571.         menu_Outils.add(mnCouleurs);
  572.        
  573.         JCheckBoxMenuItem chckbxmntmNewCheckItem = new JCheckBoxMenuItem("Normal");
  574.         chckbxmntmNewCheckItem.addActionListener(new ActionListener() {
  575.             public void actionPerformed(ActionEvent e) {
  576.                 frame.getContentPane().setBackground(UIManager.getColor("Button.background"));
  577.                 frame.setBackground(UIManager.getColor("Button.background"));
  578.             }
  579.         });
  580.         mnCouleurs.add(chckbxmntmNewCheckItem);
  581.        
  582.         JCheckBoxMenuItem chckbxmntmNormal = new JCheckBoxMenuItem("Blanc");
  583.         chckbxmntmNormal.addActionListener(new ActionListener() {
  584.             public void actionPerformed(ActionEvent e) {
  585.                 frame.getContentPane().setBackground(new Color(255, 255, 255));
  586.                 frame.setBackground(new Color(255, 255, 255));
  587.             }
  588.         });
  589.         mnCouleurs.add(chckbxmntmNormal);
  590.        
  591.         JCheckBoxMenuItem chckbxmntmBleu = new JCheckBoxMenuItem("Bleu");
  592.         chckbxmntmBleu.addActionListener(new ActionListener() {
  593.             public void actionPerformed(ActionEvent e) {
  594.                 frame.getContentPane().setBackground(new Color(30, 144, 255));
  595.                 frame.setBackground(new Color(30, 144, 255));  
  596.             }
  597.         });
  598.         mnCouleurs.add(chckbxmntmBleu);
  599.        
  600.         JCheckBoxMenuItem chckbxmntmRouge = new JCheckBoxMenuItem("Rouge");
  601.         chckbxmntmRouge.addActionListener(new ActionListener() {
  602.             public void actionPerformed(ActionEvent e) {
  603.                 frame.getContentPane().setBackground(new Color(220, 20, 60));
  604.                 frame.setBackground(new Color(220, 20, 60));  
  605.             }
  606.         });
  607.         mnCouleurs.add(chckbxmntmRouge);
  608.        
  609.         JCheckBoxMenuItem chckbxmntmVert = new JCheckBoxMenuItem("Vert");
  610.         chckbxmntmVert.addActionListener(new ActionListener() {
  611.             public void actionPerformed(ActionEvent e) {
  612.                 frame.getContentPane().setBackground(new Color(104, 157, 113));
  613.                 frame.setBackground(new Color(104, 157, 113));  
  614.             }
  615.         });
  616.         mnCouleurs.add(chckbxmntmVert);
  617.        
  618.         JCheckBoxMenuItem chckbxmntmOrange = new JCheckBoxMenuItem("Orange");
  619.         chckbxmntmOrange.addActionListener(new ActionListener() {
  620.             public void actionPerformed(ActionEvent e) {
  621.                 frame.getContentPane().setBackground(new Color(255, 200, 128));
  622.                 frame.setBackground(new Color(255, 200, 128));  
  623.             }
  624.         });
  625.         mnCouleurs.add(chckbxmntmOrange);
  626.        
  627.         JCheckBoxMenuItem chckbxmntmGris = new JCheckBoxMenuItem("Gris");
  628.         chckbxmntmGris.addActionListener(new ActionListener() {
  629.             public void actionPerformed(ActionEvent e) {
  630.                 frame.getContentPane().setBackground(new Color(128, 128, 128));
  631.                 frame.setBackground(new Color(128, 128, 128));  
  632.             }
  633.         });
  634.         mnCouleurs.add(chckbxmntmGris);
  635.         menuBar.add(menu_Aide);
  636.        
  637.         JSplitPane splitPane = new JSplitPane();
  638.         splitPane.setResizeWeight(0.5);
  639.        
  640.         JScrollPane scrollPane_2 = new JScrollPane();
  641.        
  642.         GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
  643.         groupLayout.setHorizontalGroup(
  644.             groupLayout.createParallelGroup(Alignment.LEADING)
  645.                 .addGroup(groupLayout.createSequentialGroup()
  646.                     .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  647.                         .addGroup(groupLayout.createSequentialGroup()
  648.                             .addContainerGap()
  649.                             .addComponent(panel_button, GroupLayout.DEFAULT_SIZE, 1044, Short.MAX_VALUE))
  650.                         .addComponent(menuBar, GroupLayout.DEFAULT_SIZE, 1050, Short.MAX_VALUE))
  651.                     .addGap(4))
  652.                 .addGroup(groupLayout.createSequentialGroup()
  653.                     .addContainerGap()
  654.                     .addComponent(scrollPane_2, GroupLayout.PREFERRED_SIZE, 289, GroupLayout.PREFERRED_SIZE)
  655.                     .addPreferredGap(ComponentPlacement.UNRELATED)
  656.                     .addComponent(splitPane, GroupLayout.DEFAULT_SIZE, 741, Short.MAX_VALUE)
  657.                     .addContainerGap())
  658.         );
  659.         groupLayout.setVerticalGroup(
  660.             groupLayout.createParallelGroup(Alignment.LEADING)
  661.                 .addGroup(groupLayout.createSequentialGroup()
  662.                     .addComponent(menuBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  663.                     .addGap(2)
  664.                     .addComponent(panel_button, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
  665.                     .addPreferredGap(ComponentPlacement.RELATED)
  666.                     .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  667.                         .addComponent(scrollPane_2, GroupLayout.DEFAULT_SIZE, 599, Short.MAX_VALUE)
  668.                         .addComponent(splitPane, GroupLayout.DEFAULT_SIZE, 599, Short.MAX_VALUE))
  669.                     .addContainerGap())
  670.         );
  671.        
  672.         list = new JList();
  673.         list.setListData(data);
  674.         list.setSelectedIndex(0);
  675.         //ActionJList action = new ActionJList();
  676.        
  677.         chckbxNewCheckBox = new JCheckBox("Afficher uniquement la différence");
  678.         chckbxNewCheckBox.setBounds(801, 2, 243, 23);
  679.         panel_button.add(chckbxNewCheckBox);
  680.        
  681.         list.addMouseListener(new MouseListener(){
  682.  
  683.             @Override
  684.             public void mouseClicked(MouseEvent e) {
  685.                 // TODO Auto-generated method stub
  686.                 if(e.getClickCount() == 1){
  687.                     textPane_1.setText("");
  688.                     int index = list.locationToIndex(e.getPoint());
  689.                     @SuppressWarnings("rawtypes")
  690.                     ListModel dlm = list.getModel();
  691.                      
  692.                     String item = (String) dlm.getElementAt(index);
  693.                     list.ensureIndexIsVisible(index);
  694.                    
  695.                     if(chckbxNewCheckBox.isSelected()){                        
  696.                         ArrayList<String> txt1_val_ecart1=lsp1.get_val_ecart(item);
  697.                         ArrayList<String> txt1_val_ecart2=lsp2.get_val_ecart(item);
  698.                         textPane.setText("");  
  699.                         textPane_1.setText("");
  700.  
  701.                         Iterator<String> ite = txt1_val_ecart1.iterator();
  702.                         while(ite.hasNext()){
  703.                             String str = ite.next();
  704.                             textPane.setText(textPane.getText() + str+"\n");
  705.                         }
  706.                        
  707.  
  708.                         Iterator<String> ite2 = txt1_val_ecart2.iterator();
  709.                         while(ite2.hasNext()){
  710.                             String str2 = ite2.next();
  711.                             textPane_1.setText(textPane_1.getText() + str2+"\n");
  712.                         }                      
  713.                     }else{
  714.                    //   String txt1_val_ecart1=lsp1.get_val_ecart(item);
  715.                     //  String txt1_val_ecart2=lsp2.get_val_ecart(item);
  716.                         textPane.setText("");  
  717.                         textPane_1.setText("");
  718.                        
  719.                         //recuperer ecarts
  720.                         ArrayList<String> txt1_val_ecart1=lsp1.get_val_ecart(item);
  721.                         ArrayList<String> txt1_val_ecart2=lsp2.get_val_ecart(item);
  722.  
  723.                         //recuperer balise si ecart sur valeur
  724.                         ArrayList<String> txt1_bal_ecart1=lsp2.get_bal_ecart(item);
  725.                         ArrayList<String> txt1_bal_ecart2=lsp2.get_bal_ecart(item);
  726.  
  727.                         //pattern ecart
  728.                         ArrayList<Pattern> listpat= new ArrayList<Pattern>();
  729.                         ArrayList<Pattern> listpat2= new ArrayList<Pattern>();
  730.                         ArrayList<Pattern> listpat3= new ArrayList<Pattern>();
  731.                         ArrayList<Pattern> listpat4= new ArrayList<Pattern>();
  732.  
  733.                         //mettre ecart fichier 1 dans pattern
  734.                         Iterator<String> ite9 = txt1_val_ecart1.iterator();
  735.                         while(ite9.hasNext()){
  736.                             String str9 = ite9.next();
  737.                             listpat.add(Pattern.compile(str9));
  738.                         }
  739.                        
  740.                         //mettre ecart fichier 2 dans pattern
  741.                         Iterator<String> ite2 = txt1_val_ecart2.iterator();
  742.                         while(ite2.hasNext()){
  743.                             String str2 = ite2.next();
  744.                             listpat2.add(Pattern.compile(str2));
  745.  
  746.                         }      
  747.                        
  748.                         //mettre ecart fichier 1 dans pattern
  749.                         Iterator<String> ite10 = txt1_bal_ecart1.iterator();
  750.                         while(ite10.hasNext()){
  751.                             String str10 = ite10.next();
  752.                             listpat3.add(Pattern.compile(str10));
  753.                         }
  754.                        
  755.                         //mettre ecart fichier 2 dans pattern
  756.                         Iterator<String> ite11 = txt1_bal_ecart2.iterator();
  757.                         while(ite11.hasNext()){
  758.                             String str11 = ite11.next();
  759.                             listpat4.add(Pattern.compile(str11));
  760.  
  761.                         }      
  762.                        
  763.                         //recuperer objet en entier
  764.                         ArrayList<String> txt1_full_obj=lsp1.get_full_obj(item);
  765.                         ArrayList<String> txt1_full_obj2=lsp2.get_full_obj(item);
  766.                         int find=0;
  767.                        
  768.                         //parcours de l'objet et comparaison avec pattern
  769.                         Iterator<String> ite3 = txt1_full_obj.iterator();
  770.                         while(ite3.hasNext()){
  771.                             find=0;
  772.                             String str3 = ite3.next();
  773.                            
  774.                             Iterator<Pattern> itetext1 = listpat.iterator();
  775.                             while(itetext1.hasNext()){
  776.                                 Pattern pat1 = itetext1.next();
  777.                                 if (pat1.matcher(str3).find()){
  778.                                      Iterator<Pattern> itetext3 = listpat3.iterator();
  779.                                         while(itetext3.hasNext()){
  780.                                             Pattern pat3 = itetext3.next();
  781.                                             if (pat3.matcher(str3).find()){
  782.                                     //ligne en rouge
  783.                                     //str3.setForeground(Color.RED);
  784.                                     textPane.setText(textPane.getText() + "\n texte en rouguguguguffjjhejhjd");
  785.                                     find=1;
  786.                                             }
  787.                                         }
  788.                                    
  789.                                    
  790.                                 }
  791.                             }
  792.                             if(find==1){
  793.                                
  794.  
  795.                             }else{
  796.                                 textPane.setText(textPane.getText() + "\n"+str3);
  797.                             }
  798.                         }
  799.                        
  800.                         Iterator<String> ite4 = txt1_full_obj2.iterator();
  801.                         while(ite4.hasNext()){
  802.                             find=0;
  803.                             String str4 = ite4.next();
  804.                            
  805.                             Iterator<Pattern> itetext2 = listpat2.iterator();
  806.                             while(itetext2.hasNext()){
  807.                                 Pattern pat1 = itetext2.next();
  808.                                 if (pat1.matcher(str4).find()){
  809.                                      Iterator<Pattern> itetext4 = listpat4.iterator();
  810.                                         while(itetext4.hasNext()){
  811.                                             Pattern pat4 = itetext4.next();
  812.                                             if (pat4.matcher(str4).find()){
  813.                                     //ligne en rouge
  814.                                     //str3.setForeground(Color.RED);
  815.                                     textPane_1.setText(textPane_1.getText() + "\n texte en rouguguguguffjjhejhjd");
  816.                                     find=1;
  817.                                             }
  818.                                         }
  819.                                    
  820.                                    
  821.                                 }
  822.                             }
  823.                             if(find==1){
  824.                                
  825.  
  826.                             }else{
  827.                                 textPane_1.setText(textPane_1.getText() + "\n"+str4);
  828.                             }
  829.                         }
  830.                      //  txt1_val_ecart1.drawString("", 10, 30);
  831.                        
  832.                     }      
  833.                     //System.out.println("txt1_full_obj: " +txt1_full_obj);        
  834.                 }
  835.             }
  836.  
  837.             @Override
  838.             public void mousePressed(MouseEvent e) {
  839.                 // TODO Auto-generated method stub
  840.                
  841.             }
  842.  
  843.             @Override
  844.             public void mouseReleased(MouseEvent e) {
  845.                 // TODO Auto-generated method stub
  846.                
  847.             }
  848.  
  849.             @Override
  850.             public void mouseEntered(MouseEvent e) {
  851.                 // TODO Auto-generated method stub
  852.                
  853.             }
  854.  
  855.             @Override
  856.             public void mouseExited(MouseEvent e) {
  857.                 // TODO Auto-generated method stub
  858.                
  859.             }
  860.            
  861.         });
  862.         list.setValueIsAdjusting(true);
  863.         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  864.        
  865.         scrollPane_2.setViewportView(list);
  866.  
  867.         JScrollPane scrollPane = new JScrollPane();
  868.         splitPane.setLeftComponent(scrollPane);
  869.        
  870.         textPane = new JTextPane();
  871.         textPane.setForeground(Color.RED);
  872.         scrollPane.setViewportView(textPane);
  873.        
  874.         JScrollPane scrollPane_1 = new JScrollPane();
  875.         splitPane.setRightComponent(scrollPane_1);
  876.        
  877.         textPane_1 = new JTextPane();
  878.         scrollPane_1.setViewportView(textPane_1);
  879.        
  880.         btnCharger = new JButton("Charger");
  881.         btnCharger.setBounds(297, 4, 91, 23);
  882.         panel_button.add(btnCharger);
  883.        
  884.         btnEnregistrer = new JButton("Enregistrer");
  885.         btnEnregistrer.addActionListener(new ActionListener() {
  886.             public void actionPerformed(ActionEvent arg0) {
  887.                 Enregistrer enrg = new Enregistrer();
  888.                 try {
  889.                     enrg.enreg();
  890.                 } catch (IOException e) {
  891.                     // TODO Auto-generated catch block
  892.                     e.printStackTrace();
  893.                 }
  894.                
  895.             }
  896.         });
  897.         btnEnregistrer.setBounds(381, 4, 102, 23);
  898.         panel_button.add(btnEnregistrer);
  899.        
  900.         btnSauvegarder = new JButton("Sauvegarder");
  901.         btnSauvegarder.addActionListener(new ActionListener() {
  902.             public void actionPerformed(ActionEvent arg0) {
  903.                 JFileChooser chooser = new JFileChooser();
  904.                 chooser.setFileFilter(filtre_txt);
  905.      
  906.                 int returnVal = chooser.showSaveDialog(frame);
  907.      
  908.                 if(returnVal==JFileChooser.APPROVE_OPTION){
  909.                     String s = chooser.getSelectedFile().getPath();
  910.                     s = s.endsWith(".txt")?s:s+".txt";
  911.      
  912.                     saveFile(textPane_1.getText(), s);
  913.                 }
  914.             }
  915.         });
  916.         btnSauvegarder.setBounds(476, 4, 102, 23);
  917.         panel_button.add(btnSauvegarder);
  918.        
  919.         frame.getContentPane().setLayout(groupLayout);
  920.     }
  921. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement