/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.nplusc.izc.InstallPak;

import de.nplusc.izc.tools.baseTools.HidableTableColumnModel;
import java.awt.Point;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author LH
 */
public class SelectionGUI extends javax.swing.JFrame
{
    /**
     * Creates new form SelectionGUI
     */
    InstallManager im = InstallManager.Main;
    public SelectionGUI()
    {
        initComponents();
        updatePosition();
        lblVID.setText(InstallManager.VERSION_GUI_TXT);
        ((HidableTableColumnModel)(tblSelector.getColumnModel())).setColumnVisible(0, false);
        //^Tempcode fürs Testen
        int rows=1;
        String[] tablefill = im.getToggleAblePrograms();
        for (int i = 0; i < tablefill.length; i++)
        {
            String GRP = tablefill[i];
            String[] data = GRP.split("\\|");
            if(i>=rows)
                ((DefaultTableModel)tblSelector.getModel()).addRow(new String[3]);
            ((DefaultTableModel)tblSelector.getModel()).setValueAt(data[0], i, 0);
            ((DefaultTableModel)tblSelector.getModel()).setValueAt(data[1], i, 1);
            ((DefaultTableModel)tblSelector.getModel()).setValueAt("Wird installiert", i, 2);
        }
        
    }
    private void updatePosition()
    {
        Point p = new Point(ModeSel.topleft_coords_x, ModeSel.topleft_coords_y);
        setLocation(p);
    }
    /**
     * 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()
    {

        btnInstall = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblSelector = new javax.swing.JTable();
        lblVID = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addComponentListener(new java.awt.event.ComponentAdapter()
        {
            public void componentMoved(java.awt.event.ComponentEvent evt)
            {
                formComponentMoved(evt);
            }
        });

        btnInstall.setText("Install");
        btnInstall.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnInstallActionPerformed(evt);
            }
        });

        tblSelector.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][]
            {
                {null, null, null}
            },
            new String []
            {
                "meta:id", "Name", "Status"
            }
        )
        {
            Class[] types = new Class []
            {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean []
            {
                false, false, false
            };

            public Class getColumnClass(int columnIndex)
            {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex)
            {
                return canEdit [columnIndex];
            }
        });
        tblSelector.setColumnSelectionAllowed(true);
        tblSelector.getTableHeader().setReorderingAllowed(false);
        tblSelector.setColumnModel(new HidableTableColumnModel(tblSelector.getColumnModel()));
        tblSelector.addMouseListener(new java.awt.event.MouseAdapter()
        {
            public void mouseClicked(java.awt.event.MouseEvent evt)
            {
                tblSelectorMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblSelector);
        tblSelector.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tblSelector.getColumnModel().getColumn(0).setResizable(false);
        tblSelector.getColumnModel().getColumn(0).setPreferredWidth(1);
        tblSelector.getColumnModel().getColumn(2).setMinWidth(120);
        tblSelector.getColumnModel().getColumn(2).setPreferredWidth(120);
        tblSelector.getColumnModel().getColumn(2).setMaxWidth(120);

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, 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(jSeparator2))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 420, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(55, 55, 55)
                                .addComponent(btnInstall, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 412, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnInstall, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblVID, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

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

    private void btnInstallActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnInstallActionPerformed
    {//GEN-HEADEREND:event_btnInstallActionPerformed
        InstallManager.Main.createQueue();
        InstallProgressGui.main(null);
            this.setVisible(false);
    }//GEN-LAST:event_btnInstallActionPerformed

    private void tblSelectorMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_tblSelectorMouseClicked
    {//GEN-HEADEREND:event_tblSelectorMouseClicked
                //int y = tblSelector.getSelectedColumn();
        int x = tblSelector.getSelectedRow();
        boolean sel = ((DefaultTableModel)tblSelector.getModel()).getValueAt(x, 2).equals("Wird installiert");
        //if(evt.getClickCount()==2)
        {
            if(sel==false)
            {
                ((DefaultTableModel)tblSelector.getModel()).setValueAt("Wird installiert", x, 2);
                sel=true;
            }
            else
            {
                ((DefaultTableModel)tblSelector.getModel()).setValueAt("Wird nicht installiert", x, 2);
                sel=false;
            }
            im.setGroupState((String)((DefaultTableModel)tblSelector.getModel()).getValueAt(x, 0), sel);
        }
        
    }//GEN-LAST:event_tblSelectorMouseClicked

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
                        try {
	    UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
	} catch( Exception e ) { 
	    //e.printStackTrace();
	}
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new SelectionGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnInstall;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lblVID;
    private javax.swing.JTable tblSelector;
    // End of variables declaration//GEN-END:variables
}
