package ggh.dialog;

import com.nexes.wizard.WizardPanelDescriptor;
import flanagan.math.Matrix;
import ggh.GGHData;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class Dialog2_Encrypt_Descriptor extends WizardPanelDescriptor {
    public static final String IDENTIFIER = "DIALOG2_ENCRYPT";

    public Dialog2_Encrypt_Descriptor() {
        super(IDENTIFIER, new Dialog2_Encrypt());

    }

    @Override
    public Object getNextPanelDescriptor() {
        Dialog2_Encrypt dialog = (Dialog2_Encrypt) this.getPanelComponent();

        Matrix e_vector = dialog.get_e_vector();
        Matrix m_vector = dialog.get_m_vector();
        Matrix r_vector = dialog.get_r_vector();

        if (e_vector == null || m_vector == null || r_vector == null) {
            return Dialog2_Encrypt_Descriptor.IDENTIFIER;
        }

        return Dialog3_Decrypt_Descriptor.IDENTIFIER;
    }

    @Override
    public void aboutToDisplayPanel() { //nacteni dat z dialogu pred prepnutim dalsiho
        Dialog2_Encrypt dialog = (Dialog2_Encrypt) this.getPanelComponent();
        GGHData data = GGHData.getInstance();
        int dimension = data.getDimension();

        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
            if (i < dimension) {
                dialog.getE_data()[i].setEditable(true);
                dialog.getR_data()[i].setEditable(true);
                dialog.getM_data()[i].setEditable(true);

            }
            else {
                dialog.getE_data()[i].setEditable(false);
                dialog.getR_data()[i].setEditable(false);
                dialog.getM_data()[i].setEditable(false);
            }
        }
    }

    @Override
    public void aboutToHidePanel() {
        Dialog2_Encrypt dialog = (Dialog2_Encrypt) this.getPanelComponent();
        GGHData data = GGHData.getInstance();

        Matrix e_vector = dialog.get_e_vector();
        Matrix m_vector = dialog.get_m_vector();
        Matrix r_vector = dialog.get_r_vector();

        if (e_vector == null || m_vector == null || r_vector == null) {
            JOptionPane.showMessageDialog(dialog, "Nejsou zadaná všechna data!", "Chybná data", JOptionPane.ERROR_MESSAGE);
            return;
        }

        data.setE_vector(e_vector);
        data.setM_vector(m_vector);
        data.setR_vector(r_vector);

    }



    @Override
    public Object getBackPanelDescriptor() {
        return Dialog1_Start_Descriptor.IDENTIFIER;
    }
}
