Package View

Source Code of View.Main

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package View;

import Config.Config;
import Crypto.Certificat;
import Modele.GestionKeyProf;
import Modele.Note;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author Tiphaine TEYSSIER
* @author Tan Phong HUYNH
*
* @version 1.0
*
*
* CNote 20/20
*
* Programme étudiant permettant de décrypter les notes.
*
* Projet réalisé dans le cadre de notre master 1 en 2013.
*
*
*/
public class Main extends javax.swing.JFrame {

        private Note note;

        /**
         * Creates new form Main
         */
        public Main() {
                // On execute les constructeur afin de charger les params des fichier XML
                Config.getInstance();
                GestionKeyProf.getInstance();
                try {
                        setIconImage(ImageIO.read(getClass().getResource("/View/ico.png")));
                } catch (IOException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
                initComponents();
        }

        /**
         * This method is called from within the constructor to initialize the
         * form. WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {

                jScrollPane2 = new javax.swing.JScrollPane();
                jTextPane1 = new javax.swing.JTextPane();
                menuBar = new javax.swing.JMenuBar();
                fileMenu = new javax.swing.JMenu();
                openMenuItem = new javax.swing.JMenuItem();
                exitMenuItem = new javax.swing.JMenuItem();
                editMenu = new javax.swing.JMenu();
                optionMenuItem = new javax.swing.JMenuItem();
                gestion_profMenuItem = new javax.swing.JMenuItem();
                helpMenu = new javax.swing.JMenu();
                contentsMenuItem = new javax.swing.JMenuItem();
                aboutMenuItem = new javax.swing.JMenuItem();

                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                setTitle("CNote 20/20");

                jTextPane1.setEditable(false);
                jScrollPane2.setViewportView(jTextPane1);

                fileMenu.setMnemonic('f');
                fileMenu.setText("Fichier");

                openMenuItem.setMnemonic('o');
                openMenuItem.setText("Ouvrir");
                openMenuItem.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                openMenuItemActionPerformed(evt);
                        }
                });
                fileMenu.add(openMenuItem);

                exitMenuItem.setMnemonic('x');
                exitMenuItem.setText("Quitter");
                exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                exitMenuItemActionPerformed(evt);
                        }
                });
                fileMenu.add(exitMenuItem);

                menuBar.add(fileMenu);

                editMenu.setMnemonic('e');
                editMenu.setText("Outils");

                optionMenuItem.setMnemonic('t');
                optionMenuItem.setText("Options");
                optionMenuItem.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                optionMenuItemActionPerformed(evt);
                        }
                });
                editMenu.add(optionMenuItem);

                gestion_profMenuItem.setMnemonic('y');
                gestion_profMenuItem.setText("Gestion prof");
                gestion_profMenuItem.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                                gestion_profMenuItemActionPerformed(evt);
                        }
                });
                editMenu.add(gestion_profMenuItem);

                menuBar.add(editMenu);

                helpMenu.setMnemonic('h');
                helpMenu.setText("Aide");
                helpMenu.setEnabled(false);

                contentsMenuItem.setMnemonic('c');
                contentsMenuItem.setText("Contents");
                helpMenu.add(contentsMenuItem);

                aboutMenuItem.setMnemonic('a');
                aboutMenuItem.setText("About");
                helpMenu.add(aboutMenuItem);

                menuBar.add(helpMenu);

                setJMenuBar(menuBar);

                javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
                getContentPane().setLayout(layout);
                layout.setHorizontalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 701, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                );
                layout.setVerticalGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                );

                pack();
        }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
            System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

        private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed

                String SAUT = System.getProperty("line.separator");
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setApproveButtonText("Ouvrir");
                fileChooser.setApproveButtonMnemonic('o');
                fileChooser.setFileFilter(new FileNameExtensionFilter("Fichier note", "note"));
                if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                        try {
                                // On recupere le fichier et on l'ouvre dans un nouveau tab
                                note = new Note(fileChooser.getSelectedFile().getAbsolutePath());
                                if (note.isIntegre()) {
                                        if (note.getSignePar().getLibelle() == null) {
                                                String message = "Expéditeur inconnu, voulez vous l'enregistrer en tant qu'expéditeur de confiance et afficher votre note ?";
                                                String result = (String) JOptionPane.showInputDialog(this, message, null, JOptionPane.WARNING_MESSAGE,
                                                        null, null, Certificat.getSender(Certificat.hexToX509Cert(note.getSignePar().getCertificat())));

                                                if (result != null) {
                                                        note.getSignePar().setLibelle(result);
                                                        note.getSignePar().save();
                                                        GestionKeyProf.getInstance().getKeysProf().addLast(note.getSignePar());
                                                }
                                        }

                                        if (note.getSignePar().getLibelle() != null) {
                                                jTextPane1.setText("Votre note : " + note.getValNote() + SAUT + SAUT
                                                        + "Signé par : " + Certificat.getSender(Certificat.hexToX509Cert(note.getSignePar().getCertificat())) + " (" + note.getSignePar().getLibelle() + ")" + SAUT + SAUT
                                                        + note.getMessage());
                                        }

                                } else {
                                        jTextPane1.setText("Intégrité du fichier compromise");
                                }
                        } catch (InvalidKeyException ex) {
                                jTextPane1.setText("Problème de décryptage, vérifier votre numéro d'étudiant");
                        } catch (NoSuchPaddingException ex) {
                                jTextPane1.setText("Problème de décryptage, vérifier votre numéro d'étudiant");
                        } catch (BadPaddingException ex) {
                                jTextPane1.setText("Problème de décryptage, vérifier votre numéro d'étudiant");
                        } catch (IllegalBlockSizeException ex) {
                                jTextPane1.setText("Problème de décryptage, vérifier votre numéro d'étudiant");
                        }


                }
        }//GEN-LAST:event_openMenuItemActionPerformed

        private void gestion_profMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gestion_profMenuItemActionPerformed

                new GestionKeyProfView().setVisible(true);
        }//GEN-LAST:event_gestion_profMenuItemActionPerformed

        private void optionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionMenuItemActionPerformed

                LinkedList<OptionIterface> option = new LinkedList<OptionIterface>();
                option.add(new OptionGeneral());
                new OptionView(this, true, option).setVisible(true);
        }//GEN-LAST:event_optionMenuItemActionPerformed

        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
                /* Set the Nimbus look and feel */
                //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
                 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
                 */
                try {
                        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                                if ("Nimbus".equals(info.getName())) {
                                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                                        break;
                                }
                        }
                } catch (ClassNotFoundException ex) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (InstantiationException ex) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                }
                //</editor-fold>

                /* Create and display the form */
                java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                                new Main().setVisible(true);
                        }
                });
        }
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JMenuItem aboutMenuItem;
        private javax.swing.JMenuItem contentsMenuItem;
        private javax.swing.JMenu editMenu;
        private javax.swing.JMenuItem exitMenuItem;
        private javax.swing.JMenu fileMenu;
        private javax.swing.JMenuItem gestion_profMenuItem;
        private javax.swing.JMenu helpMenu;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTextPane jTextPane1;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JMenuItem openMenuItem;
        private javax.swing.JMenuItem optionMenuItem;
        // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of View.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.