package ggh.dialog;

import ggh.GGHData;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
 *
 * @author Admin
 */
public class Dialog4_Summary extends JPanel {
    private JTextField[][] v_data = new JTextField[5][5];
    private JTextField[][] w_data = new JTextField[5][5];


    private JTextField[] m_data = new JTextField[5];
    private JTextField[] e_data = new JTextField[5];
    private JTextField[] r_data = new JTextField[5];

    private JTextField[] t_data = new JTextField[5];
    private JTextField[] v_grid_data = new JTextField[5];
    private JTextField[] m_decrypted_data = new JTextField[5];

    private javax.swing.ButtonGroup connectorGroup;
    private javax.swing.JCheckBox jCheckBox1;


    private JPanel contentPanel;
    private JLabel textLabel;
    private JPanel titlePanel;

    public Dialog4_Summary() {
        super();

        contentPanel = getContentPanel();
        contentPanel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10)));

        titlePanel = new javax.swing.JPanel();
        textLabel = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());


        titlePanel.setLayout(new java.awt.BorderLayout());
        titlePanel.setBackground(Color.white);

        textLabel.setBackground(Color.lightGray);
        textLabel.setFont(new Font("MS Sans Serif", Font.BOLD, 15));
        textLabel.setText("4. Shrnutí");
        textLabel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10)));
        textLabel.setOpaque(true);


        titlePanel.add(textLabel, BorderLayout.CENTER);


        add(titlePanel, BorderLayout.NORTH);
        JPanel secondaryPanel = new JPanel(new GridLayout(1,1));
        secondaryPanel.add(contentPanel);
        add(secondaryPanel, BorderLayout.CENTER);
    }

    public void addCheckBoxActionListener(ActionListener l) {
        jCheckBox1.addActionListener(l);
    }

    public boolean isCheckBoxSelected() {
        return jCheckBox1.isSelected();
    }

    public String getRadioButtonSelected() {
        return connectorGroup.getSelection().getActionCommand();
    }

    private JPanel getContentPanel() {

        JPanel contentPanel1 = new JPanel();
        BoxLayout layout = new BoxLayout(contentPanel1, BoxLayout.Y_AXIS);

        contentPanel1.setLayout(layout);

        //////////////////////////////////////////////////////////////////////
        ///////////////////////////I.//////////////////////////////////////

        JPanel section1 = new JPanel(new GridLayout(1,2,5,5));
        section1.setBorder(BorderFactory.createTitledBorder("I. Generování klíčů"));


        JPanel v_vectorBorder = new JPanel();
        JPanel v_vector = new JPanel(new GridLayout(5,5,5,5));
        v_vectorBorder.setBorder(BorderFactory.createTitledBorder("Soukromý klíč - matice v"));
        v_vectorBorder.add(v_vector);


        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            int index = i + 1;

            v_vector.add(new JLabel("<html><b>v</b><sub>" + index + "</sub></html>"));

            for (int j = 0; j < GGHData.MAX_DIMENSION; j++) {
                v_data[i][j] = new JTextField(5);
                v_data[i][j].setEditable(false);
                v_vector.add(v_data[i][j]);
            }

        }

        JPanel w_vectorBorder = new JPanel();
        w_vectorBorder.setBorder(BorderFactory.createTitledBorder("Veřejný klíč - matice w)"));
        JPanel w_vector = new JPanel(new GridLayout(5,5,5,5));

        w_vectorBorder.add(w_vector);


        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            int index = i + 1;
            w_vector.add(new JLabel("<html><b>w</b><sub>" + index + "</sub></html>", JLabel.CENTER));

            for (int j = 0; j < GGHData.MAX_DIMENSION; j++) {
                w_data[i][j] = new JTextField(7);
                w_data[i][j].setEditable(false);

                w_vector.add(w_data[i][j]);
            }

        }

        section1.add(v_vector);
        section1.add(w_vector);

        //////////////////////////////////////////////////////////////////////
        ///////////////////////////II.//////////////////////////////////////

        JPanel section2 = new JPanel(new GridLayout(2,1,5,5));
        section2.setBorder(BorderFactory.createTitledBorder("II. Šifrování"));

        JPanel subSection2 = new JPanel();

        JPanel m_vectorBorder = new JPanel();
        m_vectorBorder.setBorder(BorderFactory.createTitledBorder("Vektor m k zašifrování"));
        JPanel m_vector = new JPanel(new GridLayout(1,1,5,5));

        m_vectorBorder.add(m_vector);

        m_vector.add(new JLabel("<html><b>m</b><sub>", JLabel.LEFT));
        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            m_data[i] = new JTextField(12);
            m_data[i].setFont(new Font(null, Font.BOLD, 12));
            m_data[i].setEditable(false);
            m_vector.add(m_data[i]);
        }


        JPanel r_vectorBorder = new JPanel();
        r_vectorBorder.setBorder(BorderFactory.createTitledBorder("Volba malého náhodného vektoru r"));
        JPanel r_vector = new JPanel(new GridLayout(1,1,5,5));

        r_vectorBorder.add(r_vector);

        r_vector.add(new JLabel("<html><b>r</b><sub>", JLabel.LEFT));
        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            r_data[i] = new JTextField(8);
            r_data[i].setEditable(false);
            r_vector.add(r_data[i]);
        }


        JPanel e_vectorBorder = new JPanel();
        e_vectorBorder.setBorder(BorderFactory.createTitledBorder("Zašifrovaný vektor e = mW + r"));
        JPanel e_vector = new JPanel(new GridLayout(1,1,5,5));

        e_vectorBorder.add(e_vector);

        e_vector.add(new JLabel("<html><b>e</b><sub>", JLabel.LEFT));
        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            e_data[i] = new JTextField(8);
            e_data[i].setEditable(false);
            e_vector.add(e_data[i]);
        }

        section2.add(m_vectorBorder);
	subSection2.add(r_vectorBorder);
        subSection2.add(e_vectorBorder);
        section2.add(subSection2);
        
        
        
        //////////////////////////////////////////////////////////////////////
        ///////////////////////////III.//////////////////////////////////////

        JPanel section3 = new JPanel(new GridLayout(2,1,5,5));
        section3.setBorder(BorderFactory.createTitledBorder("III. Dešifrování"));

        JPanel subSection3 = new JPanel(new GridLayout(1,2));


        JPanel t_vectorBorder = new JPanel();
        t_vectorBorder.setBorder(BorderFactory.createTitledBorder("Koeficienty t"));
        JPanel t_vector = new JPanel(new GridLayout(1,5,5,5));

        t_vectorBorder.add(t_vector);

        t_vector.add(new JLabel("<html><b>t</b><sub>"));
        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
                t_data[i]= new JTextField(8);
                t_data[i].setEditable(false);
                t_vector.add(t_data[i]);
        }

        JPanel v_grid_vectorBorder = new JPanel();
        v_grid_vectorBorder.setBorder(BorderFactory.createTitledBorder("Výpočet vektoru mříže v = v1t1 + v2t2 + ... + tnvn, který je velmi blízko k e:"));
        JPanel v_grid_vector = new JPanel(new GridLayout(1,1,5,5));

        v_grid_vectorBorder.add(v_grid_vector);

        v_grid_vector.add(new JLabel("<html><b>v</b><sub>", JLabel.LEFT));
        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            v_grid_data[i] = new JTextField(8);
            v_grid_data[i].setEditable(false);
            v_grid_vector.add(v_grid_data[i]);
        }


        JPanel m_decrypted_vectorBorder = new JPanel();
        m_decrypted_vectorBorder.setBorder(BorderFactory.createTitledBorder("Dešifrovaný vektor m"));
        JPanel m_decrypted_vector = new JPanel(new GridLayout(1,1,5,5));

        m_decrypted_vectorBorder.add(m_decrypted_vector);

        m_decrypted_vector.add(new JLabel("<html><b>m</b><sub>", JLabel.LEFT));
        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            m_decrypted_data[i] = new JTextField(12);
            m_decrypted_data[i].setFont(new Font(null, Font.BOLD, 12));
            m_decrypted_data[i].setEditable(false);
            m_decrypted_vector.add(m_decrypted_data[i]);
        }

        subSection3.add(t_vectorBorder);
        subSection3.add(v_grid_vectorBorder);
        section3.add(subSection3);
        section3.add(m_decrypted_vectorBorder);

        JPanel summary_grid_vectorBorder = new JPanel();

        summary_grid_vectorBorder.setBorder(BorderFactory.createTitledBorder("IV. Závěr"));
        JLabel summary_text = new JLabel("<html>Pokud se původní vektor m určený k zašifrování rovná vektoru m získaného po dešifrování,<p>tak vstupní data byla dobře zadána a šifrovací metoda GGH pracuje správně.</p></html>", JLabel.CENTER);
        summary_text.setFont(new Font(null, Font.BOLD, 17));
        summary_grid_vectorBorder.add(summary_text);

	contentPanel1.add(section1);
	contentPanel1.add(section2);
        contentPanel1.add(section3);
        contentPanel1.add(summary_grid_vectorBorder);

        return contentPanel1;
    }

    public JTextField[] getE_data() {
        return e_data;
    }

    public void setE_data(JTextField[] e_data) {
        this.e_data = e_data;
    }

    public JTextField[] getM_data() {
        return m_data;
    }

    public void setM_data(JTextField[] m_data) {
        this.m_data = m_data;
    }

    public JTextField[] getM_decrypted_data() {
        return m_decrypted_data;
    }

    public void setM_decrypted_data(JTextField[] m_decrypted_data) {
        this.m_decrypted_data = m_decrypted_data;
    }

    public JTextField[] getR_data() {
        return r_data;
    }

    public void setR_data(JTextField[] r_data) {
        this.r_data = r_data;
    }

    public JTextField[] getT_data() {
        return t_data;
    }

    public void setT_data(JTextField[] t_data) {
        this.t_data = t_data;
    }

    public JTextField[][] getV_data() {
        return v_data;
    }

    public void setV_data(JTextField[][] v_data) {
        this.v_data = v_data;
    }

    public JTextField[] getV_grid_data() {
        return v_grid_data;
    }

    public void setV_grid_data(JTextField[] v_grid_data) {
        this.v_grid_data = v_grid_data;
    }

    public JTextField[][] getW_data() {
        return w_data;
    }

    public void setW_data(JTextField[][] w_data) {
        this.w_data = w_data;
    }

 

}
