/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.nplusc.izc.InstallPak;
import de.nplusc.izc.InstallPak.legacy.*;
import de.nplusc.izc.tools.IOtools.FileTK;
import de.nplusc.izc.tools.baseTools.Lock;
import de.nplusc.izc.tools.baseTools.Messagers;
import de.nplusc.izc.tools.baseTools.Tools;
import java.awt.Point;
import javax.swing.JFrame;
        

/**
 *
 * @author LH
 */
public class ExtendedInstallProgressGui extends javax.swing.JFrame
{
    InstallManager im = InstallManager.Main;
    private String[][] installMe;
    private Lock l = new Lock();
    /**
     * Creates new form InstallProgressGui
     * @param queue InstallActions intended to be installed with this GUI
     */
    public ExtendedInstallProgressGui(String[][]  queue)
    {
        installMe=queue;
        initComponents();
        updatePosition();
        btnExit.setVisible(false);
        pbarPacks.setVisible(false);
        
        startInstallation();
    }
    private void updatePosition()
    {
        lblVID.setText(Definitions.VERSION_GUI_TXT);
        Point p = new Point(Main.topleft_coords_x, Main.topleft_coords_y);
        setLocation(p);
    }
    
    public void startInstallation()
    {
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        int packs = installMe.length;
        pbarPacks.setMinimum(0);
        pbarPacks.setValue(0);
        pbarPacks.setMaximum(packs);
        if(packs>1)
        {
            pbarPacks.setVisible(true);
        }
        new Thread(()->{
        
            for (String[] installMe1 : installMe)
            {
                Tools.DebugHelperPrint("setupaction:type://"+installMe1[0], true, "iZsetup.enableCoreDebug");
                if (installMe1[0].equalsIgnoreCase("file"))
                {
                    InstallAction pack = new YInstallAction(installMe1[1]);
                    pack.doInstall(ptotal, pFilename, lblMsg, tempLog);
                }
                else if (installMe1[0].equalsIgnoreCase("waitdisk"))
                {
                        boolean rightDisk = FileTK.checkDirExist(installMe1[1]);
                        while(!rightDisk)
                        {
                            Messagers.SingleLineMsg(installMe1[2],"Okee...");
                            rightDisk = FileTK.checkDirExist(installMe1[1]);
                        }
                }
                java.awt.EventQueue.invokeLater(()->pbarPacks.setValue(pbarPacks.getValue()+1));
            }
            java.awt.EventQueue.invokeLater(()->btnExit.setVisible(true));
            java.awt.EventQueue.invokeLater(()->setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE));
            
        }).start();
    }

    /**
     * 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()
    {

        jScrollPane1 = new javax.swing.JScrollPane();
        tempLog = new javax.swing.JTextArea();
        lblMsg = new javax.swing.JLabel();
        ptotal = new javax.swing.JProgressBar();
        btnExit = new javax.swing.JButton();
        lblVID = new javax.swing.JLabel();
        pbarPacks = new javax.swing.JProgressBar();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        pFilename = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(852, 331));
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter()
        {
            public void componentMoved(java.awt.event.ComponentEvent evt)
            {
                formComponentMoved(evt);
            }
        });

        tempLog.setColumns(20);
        tempLog.setRows(5);
        jScrollPane1.setViewportView(tempLog);

        lblMsg.setText("Starte Installixierung");

        btnExit.setText("Beenden");
        btnExit.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnExitActionPerformed(evt);
            }
        });

        lblVID.setText("izSetup 1.0.0 (c) 2012 iZc");

        pbarPacks.setMinimum(10);
        pbarPacks.setOrientation(1);
        pbarPacks.setValue(3);

        jLabel1.setText("     ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ptotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblVID)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator4))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblMsg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnExit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(pFilename, javax.swing.GroupLayout.PREFERRED_SIZE, 763, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pbarPacks, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ptotal, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pFilename, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblMsg)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnExit))
                    .addComponent(pbarPacks, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblVID)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

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

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

    private void formComponentMoved(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentMoved
    {//GEN-HEADEREND:event_formComponentMoved
        Main.topleft_coords_x = getLocation().x;
        Main.topleft_coords_y = getLocation().x;
    }//GEN-LAST:event_formComponentMoved

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        System.out.println("Error 0x1D17");
        System.exit(0x1D17);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JLabel lblMsg;
    private javax.swing.JLabel lblVID;
    private javax.swing.JProgressBar pFilename;
    private javax.swing.JProgressBar pbarPacks;
    private javax.swing.JProgressBar ptotal;
    private javax.swing.JTextArea tempLog;
    // End of variables declaration//GEN-END:variables
}
