package ggh.dialog;

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

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

    public Dialog3_Decrypt_Descriptor() {
        super(IDENTIFIER, new Dialog3_Decrypt());

    }

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

        Matrix t_vector = dialog.get_t_vector();
        Matrix v_vector = dialog.get_v_vector();
        Matrix m_vector = dialog.get_m_vector();

        if (t_vector == null || v_vector == null || m_vector == null) {
            return Dialog3_Decrypt_Descriptor.IDENTIFIER;
        }


        return Dialog4_Summary_Descriptor.IDENTIFIER;
    }

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

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

            }
            else {
                dialog.getV_grid_data()[i].setEditable(false);
                dialog.getM_decrypted_data()[i].setEditable(false);
            }
        }

        for (int i = 0; i < GGHData.MAX_DIMENSION; i++) {
              dialog.getT_data()[i].setEditable(i < dimension);
        }
    }

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

        Matrix t_vector = dialog.get_t_vector();
        Matrix v_vector = dialog.get_v_vector();
        Matrix m_vector = dialog.get_m_vector();

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

        data.setT_vector(t_vector);
        data.setV_grid(v_vector);
        data.setM_decrypted(m_vector);

    }

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

}
