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

import de.nplusc.izc.tools.IOtools.FileTK;
import de.nplusc.izc.tools.IOtools.SimplifiedFile;
import de.nplusc.izc.tools.UiToolz.UiTools;
import de.nplusc.izc.tools.baseTools.Lock;
import de.nplusc.izc.tools.baseTools.Tools;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import org.yaml.snakeyaml.Yaml;

/**
 *
 * @author LH
 */
public class ManagerGUI extends javax.swing.JFrame
{
    private int ph,pw;
    private Graphics2D imagepreviewPanel;
    private Yaml yp = new Yaml();
    //public static Lock LoadLock = new Lock();
    private String pack;
    private WallpaperPackage wp;
    private boolean packageLoadedAlready = false;
    private DefaultListModel lm;
    private String selfile = "";
    /**
     * Creates new form ManagerGUI
     */
    public ManagerGUI()
    {
        initComponents();
        txfPath.setText(Settings.wallpaperTargetPath);
        previewRename(Settings.wallpaperTargetPath);
        imagepreviewPanel = (Graphics2D) pnlPreview.getGraphics();
        String[] packageDirs = FileTK.getDirectoryContent(Settings.cacheBaseDir);
        for (int i = 0; i < packageDirs.length; i++)
        {
            String dir = packageDirs[i];
            dir=FileTK.getFileName(dir);
            if(dir.equals("00_template")||dir.equals("at3d_install_2-11-7")||dir.equals("readme.txt"))
            {
                dir=null;
            }
            packageDirs[i]=dir;
        }
        ((DefaultComboBoxModel)cbxPackages.getModel()).removeElementAt(0);
        for (String string : packageDirs)
        {
            if(string!=null)
                cbxPackages.addItem(string);
        }
        lm=(DefaultListModel) lstFilezzz.getModel();
        ph=pnlPreview.getHeight();
        pw=pnlPreview.getWidth();
        imagepreviewPanel.setColor(Color.black);
    }

    
    //[392, 244]
    /**
     * 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()
    {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        txfPath = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator1 = new javax.swing.JSeparator();
        btnExexDigitAdd = new javax.swing.JButton();
        btnSelPath = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        lblBefore = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblAfter = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        cbxPackages = new javax.swing.JComboBox();
        loadPackage = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstFilezzz = new javax.swing.JList();
        pnlPreview = new javax.swing.JPanel();
        cxkeepaspect = new javax.swing.JCheckBox();
        cxBframe = new javax.swing.JCheckBox();
        processAndInstall = new javax.swing.JButton();
        btnReDraw = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        pProgress = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Patch WallpaperNames");

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        btnExexDigitAdd.setText("AddMoreDigits");
        btnExexDigitAdd.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnExexDigitAddActionPerformed(evt);
            }
        });

        btnSelPath.setText("Select Path");
        btnSelPath.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnSelPathActionPerformed(evt);
            }
        });

        jLabel2.setText("Aktuell");

        lblBefore.setText("jLabel3");

        jLabel4.setText("nach Änderung");

        lblAfter.setText("jLabel5");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1)
                            .addComponent(txfPath)
                            .addComponent(btnSelPath, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(btnExexDigitAdd))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel4))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(jLabel2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(lblBefore, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(lblAfter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(458, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txfPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSelPath)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblBefore))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblAfter))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExexDigitAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 150, Short.MAX_VALUE))
            .addComponent(jSeparator2)
        );

        jTabbedPane1.addTab("Utility", jPanel1);

        cbxPackages.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"Error@Init" }));

        loadPackage.setText("Package laden");
        loadPackage.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                loadPackageActionPerformed(evt);
            }
        });

        lstFilezzz.setModel(new javax.swing.DefaultListModel());
        lstFilezzz.addMouseListener(new java.awt.event.MouseAdapter()
        {
            public void mouseClicked(java.awt.event.MouseEvent evt)
            {
                lstFilezzzMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lstFilezzz);

        pnlPreview.setFocusable(false);

        javax.swing.GroupLayout pnlPreviewLayout = new javax.swing.GroupLayout(pnlPreview);
        pnlPreview.setLayout(pnlPreviewLayout);
        pnlPreviewLayout.setHorizontalGroup(
            pnlPreviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        pnlPreviewLayout.setVerticalGroup(
            pnlPreviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        cxkeepaspect.setText("keepAspectRatio");
        cxkeepaspect.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                cxkeepaspectActionPerformed(evt);
            }
        });

        cxBframe.setText("B-Frame");
        cxBframe.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                cxBframeActionPerformed(evt);
            }
        });

        processAndInstall.setText("Processs");
        processAndInstall.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                processAndInstallActionPerformed(evt);
            }
        });

        btnReDraw.setText("ReDraw");
        btnReDraw.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                btnReDrawActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(cbxPackages, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(loadPackage))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlPreview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnReDraw)
                        .addGap(35, 35, 35)
                        .addComponent(processAndInstall))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cxkeepaspect)
                            .addComponent(cxBframe))
                        .addGap(0, 285, Short.MAX_VALUE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbxPackages, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(loadPackage))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlPreview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cxkeepaspect)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(processAndInstall)
                            .addComponent(btnReDraw)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cxBframe)
                        .addContainerGap())))
        );

        jTabbedPane1.addTab("ProcessPackages", jPanel2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 747, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 311, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("#NN#", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
            .addComponent(pProgress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void previewRename(String path)
    {
        String[] tempo = FileTK.getDirectoryContent(path);
        String filename1 = FileTK.getFileName(tempo[0]);
        lblBefore.setText(filename1);
        lblAfter.setText("0"+filename1);
    }
    
    private void btnSelPathActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSelPathActionPerformed
    {//GEN-HEADEREND:event_btnSelPathActionPerformed
        String path = Tools.FileChooseDlg(this, true, true, new String[]{""});
        txfPath.setText(path);
        previewRename(path);
    }//GEN-LAST:event_btnSelPathActionPerformed

    private void btnExexDigitAddActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnExexDigitAddActionPerformed
    {//GEN-HEADEREND:event_btnExexDigitAddActionPerformed
        String path = txfPath.getText();
        String[] availFiles = FileTK.getDirectoryContent(path);
        for (String fileid : availFiles)
        {
            File f = new File(fileid);
            System.err.println(fileid);
            String ft1 = FileTK.getFilePath(fileid);
            String ft2 = FileTK.getFileName(fileid);
            fileid=ft1+"\\0"+ft2;
            System.err.println(f.renameTo(new File(fileid)));
        }
        previewRename(path);
    }//GEN-LAST:event_btnExexDigitAddActionPerformed

    private void btnReDrawActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnReDrawActionPerformed
    {//GEN-HEADEREND:event_btnReDrawActionPerformed
        //TESTER\/
        imagepreviewPanel.setColor(Color.black);
        imagepreviewPanel.drawRect(0, 0, /*3*/92, /*2*/44);
        imagepreviewPanel.fillRect(0, 0, /*3*/92, /*2*/44);
        try
        {
            BufferedImage bi = ImageIO.read(new File("T:\\icns\\mcicon.png"));
            imagepreviewPanel.drawImage(bi, 0, 0, null);
            //pnlPreview.repaint();
            //repaint();
            
            System.err.println("....");
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnReDrawActionPerformed

    private void loadPackageActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_loadPackageActionPerformed
    {//GEN-HEADEREND:event_loadPackageActionPerformed
     
        if(packageLoadedAlready)
        {
            String path = Settings.cacheBaseDir+pack;
            String sy = yp.dump(wp);
            FileTK.writeFile(sy, path+"\\meta.yml");
        }
        pack = (String)cbxPackages.getSelectedItem();
        String path = Settings.cacheBaseDir+pack;
        //            name,keepAspect,isBFrame,numericID;
        //\/  [itemcount][4]
        String[]         [] content=null;
        if(new File(path+"\\meta.yml").exists())
        {
            String cnt ="";
            String[] filecnt = FileTK.fileload(path+"\\meta.yml");
            for (String string : filecnt)
            {
                cnt+="\n"+string;
                
            }
            
            cnt=cnt.substring(1,cnt.length()-5);
            System.err.println(cnt);
            wp = (WallpaperPackage)yp.load(cnt);
            content = wp.FileList;
            for (String[] etr : content)
            {
                lm.addElement(etr[0]);
            }
        }
        else
        {
            wp=new WallpaperPackage();
            String[] fileList = FileTK.getDirectoryContent(path);
            for (int i = 0; i < fileList.length; i++)
            {
                String etr = fileList[i];
                if(new File(etr).isDirectory())
                {
                    fileList[i]=null;
                    continue;
                }
                if(FileTK.getFileExt(etr).equals("yml"))
                {
                    fileList[i]=null;
                    continue;
                }
                etr=FileTK.getFileName(etr);
                fileList[i]=etr;
            }
            lm.clear();
            int clength = 0;
            for (String etr : fileList)
            {
                if(etr!=null)
                {
                    lm.addElement(etr);
                    clength++;
                }
            }
                                        //name,keepAspect,isBFrame,numericID;
            content = new String[clength][4];
            int i = 0;
            for (String etr : fileList)
            {
                if(etr!=null)
                {
                    content[i][0] = etr;
                    i++;
                }
            }
            wp.FileList=content;
            packageLoadedAlready=true;
        }
        
    }//GEN-LAST:event_loadPackageActionPerformed

    @SuppressWarnings("empty-statement")//used here to make the hack workin like intended
    boolean switched = false;
    private void lstFilezzzMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_lstFilezzzMouseClicked
    {//GEN-HEADEREND:event_lstFilezzzMouseClicked
        try
        {
            //if(switched);
            String filename = (String) lm.get(lstFilezzz.getSelectedIndex());
            selfile=filename;
            String path = Settings.cacheBaseDir+pack+"\\"+filename;
            switched=true;
            UiTools.ScaleImageIntoFrame(path, imagepreviewPanel,ph,pw);
            //System.err.println(".........."+t);
            String[][] contentlist = wp.FileList;
            int ipos = 0;
            for (int i = 0; i < contentlist.length; i++)
            {
                if(contentlist[i][0].equals(selfile))
                {
                    ipos=i;
                    break;
                }
            }
            String bfrv=contentlist[ipos][2],keepaspv=contentlist[ipos][1];
            if(bfrv==null)
                bfrv="false";
            if(keepaspv==null)
                keepaspv="false";
            if(keepaspv.equals("true"))
            {
                cxkeepaspect.setSelected(true);
            }
            else
            {
                cxkeepaspect.setSelected(false);
            }
            if(bfrv.equals("true"))
                        {
                cxBframe.setSelected(true);
            }
            else
            {
                cxBframe.setSelected(false);
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_lstFilezzzMouseClicked

    private void cxBframeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cxBframeActionPerformed
    {//GEN-HEADEREND:event_cxBframeActionPerformed
        String[][] contentlist = wp.FileList;
        int ipos = 0;
        for (int i = 0; i < contentlist.length; i++)
        {
            if(contentlist[i][0].equals(selfile))
            {
                ipos=i;
                break;
            }
        }
        if(cxBframe.isSelected())
        {

            contentlist[ipos][2]="true";
        }
        else
        {
            contentlist[ipos][2]="false";
        }
    }//GEN-LAST:event_cxBframeActionPerformed

    private void cxkeepaspectActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cxkeepaspectActionPerformed
    {//GEN-HEADEREND:event_cxkeepaspectActionPerformed
        String[][] contentlist = wp.FileList;
        int ipos = 0;
        for (int i = 0; i < contentlist.length; i++)
        {
            if(contentlist[i][0].equals(selfile))
            {
                ipos=i;
                break;
            }
        }
        if(cxkeepaspect.isSelected())
        {

            contentlist[ipos][1]="true";
        }
        else
        {
            contentlist[ipos][1]="false";
        }
    }//GEN-LAST:event_cxkeepaspectActionPerformed

    
    
    //proportional_path=k_i_p
    //b-frames_path=b-frames
    //temptarget=p
    //scale-without-aspect=proc
    String[] imagcmds;
    private void processAndInstallActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_processAndInstallActionPerformed
    {//GEN-HEADEREND:event_processAndInstallActionPerformed
        
        //createBlackBackground nur einmal. bei settingschange wid das file gelöscht zur neuinitialisierung
        if(!new File(Settings.canvasDir).exists())
        {
            String initCanvas = "convert -size "+Settings.ScreenWidth+"x"+Settings.ScreenHeight+"xc:#000000 "+Settings.canvasDir;
            Tools.runSingleCmd(false,true,initCanvas);
        }
        String[][] filelist = wp.FileList;
        imagcmds = new String[filelist.length];
        String tpath="";
        //process_b_frames_after_that
        //keepaspect=1;b-frame=2;
        int i=0;
        for (String[] filesetr : filelist)
        {
            
            if(filesetr[1]==null)
                filesetr[1]="false";
            String spath = Settings.cacheBaseDir+pack+"\\"+filesetr[0];
            String cvt = tpath = Settings.cacheBaseDir+pack+"\\"+"p"+"\\"+filesetr[0];
            if(filesetr[1].equals("true"))
            {
                tpath = Settings.cacheBaseDir+pack+"\\"+"k_i_p"+"\\"+filesetr[0];
                String cmdpart1 = "convert -geometry '"+Settings.ScreenWidth+"x"+Settings.ScreenHeight+"' -";/// <<<proportional danach mit && ein merge auf ne schwarze datei mit screensize
                String cmdpart2 = "composite -gravity center - "+Settings.canvasDir+" "+tpath+" "+cvt;
                imagcmds[i] = cmdpart1+"|"+cmdpart2;
            }
            else
            {
               tpath = Settings.cacheBaseDir+pack+"\\"+"proc"+"\\"+filesetr[0];
               //convert -geometry wodthxheight!
               imagcmds[i] = "convert -geometry '"+Settings.ScreenWidth+"x"+Settings.ScreenHeight+"!' "+tpath+" "+cvt;
               
            }
            //FileTK.kopierpaste(new File(spath),new File(tpath));
            i++;
        }
        pProgress.setMinimum(0);
        pProgress.setMaximum(imagcmds.length);
        
        new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                int i=0;
                for (String cmd : imagcmds)
                {
                    System.err.println(cmd);
                    //Tools.runSingleCmd(false, true, cmd);
                    pProgress.setValue(i);
                    i++;
                }
            }
        }).start();
    }//GEN-LAST:event_processAndInstallActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex)
        {
            java.util.logging.Logger.getLogger(ManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            java.util.logging.Logger.getLogger(ManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            java.util.logging.Logger.getLogger(ManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex)
        {
            java.util.logging.Logger.getLogger(ManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                //new IconMgrDBV().setVisible(true);
                new ManagerGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExexDigitAdd;
    private javax.swing.JButton btnReDraw;
    private javax.swing.JButton btnSelPath;
    private javax.swing.JComboBox cbxPackages;
    private javax.swing.JCheckBox cxBframe;
    private javax.swing.JCheckBox cxkeepaspect;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblAfter;
    private javax.swing.JLabel lblBefore;
    private javax.swing.JButton loadPackage;
    private javax.swing.JList lstFilezzz;
    private javax.swing.JProgressBar pProgress;
    private javax.swing.JPanel pnlPreview;
    private javax.swing.JButton processAndInstall;
    private javax.swing.JTextField txfPath;
    // End of variables declaration//GEN-END:variables
}
