/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on Jan 23, 2011, 3:22:24 PM
 */

package ajcon.UI;

import ajcon.AppletExtractor.ExtractionHandler;
import ajcon.JavaML.JavaMLHandler;
import ajcon.custom.util.elements.CMethod;
import ajcon.helpers.Traverser;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import org.jdesktop.application.Action;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;


public class MainWindow extends javax.swing.JFrame {
    private ArrayList<Integer> progress;
    private ArrayList<String> logs;
    private ArrayList<JLabel> projectNames;
    private ArrayList<JLabel> sourceFolders;
    private ArrayList<JLabel> destinationFolders;
    private ArrayList<JProgressBar> progressBar;
    private ArrayList<JCheckBox> checkboxes;

    private ArrayList<String> appletSourcePaths;

    private int totalProjectNumber;

    //public String projectPath = "C:\\Users\\ozge\\Desktop\\bitirme-src\\groupteaplet\\";
    public String projectPath = System.getProperty("user.dir") + "\\";  // get project path

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
        
        logs = new ArrayList<String>();
        progress = new ArrayList<Integer>();

        projectNames = new ArrayList<JLabel>();
        sourceFolders = new ArrayList<JLabel>();
        destinationFolders = new ArrayList<JLabel>();
        progressBar = new ArrayList<JProgressBar>();
        checkboxes = new ArrayList<JCheckBox>();

        totalProjectNumber = 0;

        String initial = "";
        logs.add(initial);
        logs.add(initial);
        logs.add(initial);
        logs.add(initial);
        logs.add(initial);
         
        // Hide Destination Folders
        
        textfielddf1.setVisible(false);
        destinationFolders.add(textfielddf1);
        textfielddf2.setVisible(false);
        destinationFolders.add(textfielddf2);
        textfielddf3.setVisible(false);
        destinationFolders.add(textfielddf3);
        textfielddf4.setVisible(false);
        destinationFolders.add(textfielddf4);
        textfielddf5.setVisible(false);
        destinationFolders.add(textfielddf5);

        // Hide Source Folders
        textfieldsf1.setVisible(false);
        sourceFolders.add(textfieldsf1);
        textfieldsf2.setVisible(false);
        sourceFolders.add(textfieldsf2);
        textfieldsf3.setVisible(false);
        sourceFolders.add(textfieldsf3);
        textfieldsf4.setVisible(false);
        sourceFolders.add(textfieldsf4);
        textfieldsf5.setVisible(false);
        sourceFolders.add(textfieldsf5);

        // Hide Project Names
        textfieldpn1.setVisible(false);
        projectNames.add(textfieldpn1);
        textfieldpn2.setVisible(false);
        projectNames.add(textfieldpn2);
        textfieldpn3.setVisible(false);
        projectNames.add(textfieldpn3);
        textfieldpn4.setVisible(false);
        projectNames.add(textfieldpn4);
        textfieldpn5.setVisible(false);
        projectNames.add(textfieldpn5);

        // Hide progrss bars
        jProgressBar1.setVisible(false);
        progressBar.add(jProgressBar1);
        jProgressBar2.setVisible(false);
        progressBar.add(jProgressBar2);
        jProgressBar3.setVisible(false);
        progressBar.add(jProgressBar3);
        jProgressBar4.setVisible(false);
        progressBar.add(jProgressBar4);
        jProgressBar5.setVisible(false);
        progressBar.add(jProgressBar5);

        // Hide Checkboxes
        jCheckBox1.setVisible(false);
        checkboxes.add(jCheckBox1);
        jCheckBox2.setVisible(false);
        checkboxes.add(jCheckBox2);
        jCheckBox3.setVisible(false);
        checkboxes.add(jCheckBox3);
        jCheckBox4.setVisible(false);
        checkboxes.add(jCheckBox4);
        jCheckBox5.setVisible(false);
        checkboxes.add(jCheckBox5);
    }

    public ArrayList<String> getLogs() {
        return logs;
    }

    public void setLogs(ArrayList<String> logs) {
        this.logs = logs;
    }

    public ArrayList<Integer> getProgress() {
        return progress;
    }

    public void setProgress(ArrayList<Integer> progress) {
        this.progress = progress;
    }

    public int getTotalProjectNumber() {
        return totalProjectNumber;
    }

    public void setTotalProjectNumber(int totalProjectNumber) {
        this.totalProjectNumber = totalProjectNumber;
    }

    public ArrayList<JCheckBox> getCheckboxes() {
        return checkboxes;
    }

    public void setCheckboxes(ArrayList<JCheckBox> checkboxes) {
        this.checkboxes = checkboxes;
    }

    public ArrayList<JLabel> getDestinationFolders() {
        return destinationFolders;
    }

    public void setDestinationFolders(ArrayList<JLabel> destinationFolders) {
        this.destinationFolders = destinationFolders;
    }

    public ArrayList<JProgressBar> getProgressBar() {
        return progressBar;
    }

    public void setProgressBar(ArrayList<JProgressBar> progressBar) {
        this.progressBar = progressBar;
    }

    public ArrayList<JLabel> getProjectNames() {
        return projectNames;
    }

    public void setProjectNames(ArrayList<JLabel> projectNames) {
        this.projectNames = projectNames;
    }

    public ArrayList<JLabel> getSourceFolders() {
        return sourceFolders;
    }

    public void setSourceFolders(ArrayList<JLabel> sourceFolders) {
        this.sourceFolders = sourceFolders;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        textfieldsf1 = new javax.swing.JLabel();
        textfielddf1 = new javax.swing.JLabel();
        textfieldpn1 = new javax.swing.JLabel();
        textfieldpn2 = new javax.swing.JLabel();
        textfieldsf2 = new javax.swing.JLabel();
        textfielddf2 = new javax.swing.JLabel();
        textfieldpn3 = new javax.swing.JLabel();
        textfieldsf3 = new javax.swing.JLabel();
        textfielddf3 = new javax.swing.JLabel();
        textfieldpn4 = new javax.swing.JLabel();
        textfieldsf4 = new javax.swing.JLabel();
        textfielddf4 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jProgressBar2 = new javax.swing.JProgressBar();
        jProgressBar3 = new javax.swing.JProgressBar();
        jProgressBar4 = new javax.swing.JProgressBar();
        textfieldpn5 = new javax.swing.JLabel();
        textfieldsf5 = new javax.swing.JLabel();
        textfielddf5 = new javax.swing.JLabel();
        jProgressBar5 = new javax.swing.JProgressBar();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jButton3 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(675, 300));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Project Name");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Source Folder");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Destination Folder");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setText("Progress");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("Select");
        jLabel5.setName("jLabel5"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        textfieldsf1.setText("Source Folder");
        textfieldsf1.setName("textfieldsf1"); // NOI18N

        textfielddf1.setText("Destination Folder");
        textfielddf1.setName("textfielddf1"); // NOI18N

        textfieldpn1.setText("Project Name");
        textfieldpn1.setName("textfieldpn1"); // NOI18N

        textfieldpn2.setText("Project Name");
        textfieldpn2.setName("textfieldpn2"); // NOI18N

        textfieldsf2.setText("Source Folder");
        textfieldsf2.setName("textfieldsf2"); // NOI18N

        textfielddf2.setText("Destination Folder");
        textfielddf2.setName("textfielddf2"); // NOI18N

        textfieldpn3.setText("Project Name");
        textfieldpn3.setName("textfieldpn3"); // NOI18N

        textfieldsf3.setText("Source Folder");
        textfieldsf3.setName("textfieldsf3"); // NOI18N

        textfielddf3.setText("Destination Folder");
        textfielddf3.setName("textfielddf3"); // NOI18N

        textfieldpn4.setText("Project Name");
        textfieldpn4.setName("textfieldpn4"); // NOI18N

        textfieldsf4.setText("Source Folder");
        textfieldsf4.setName("textfieldsf4"); // NOI18N

        textfielddf4.setText("Destination Folder");
        textfielddf4.setName("textfielddf4"); // NOI18N

        jProgressBar1.setName("jProgressBar1"); // NOI18N

        jProgressBar2.setName("jProgressBar2"); // NOI18N

        jProgressBar3.setName("jProgressBar3"); // NOI18N

        jProgressBar4.setName("jProgressBar4"); // NOI18N

        textfieldpn5.setText("Project Name");
        textfieldpn5.setName("textfieldpn5"); // NOI18N

        textfieldsf5.setText("Source Folder");
        textfieldsf5.setName("textfieldsf5"); // NOI18N

        textfielddf5.setText("Destination Folder");
        textfielddf5.setName("textfielddf5"); // NOI18N

        jProgressBar5.setName("jProgressBar5"); // NOI18N

        jCheckBox1.setName("jCheckBox1"); // NOI18N

        jCheckBox2.setName("jCheckBox2"); // NOI18N

        jCheckBox3.setName("jCheckBox3"); // NOI18N

        jCheckBox4.setName("jCheckBox4"); // NOI18N

        jCheckBox5.setName("jCheckBox5"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(MainWindow.class, this);
        jButton3.setAction(actionMap.get("buttonStartConversionClickedAction")); // NOI18N
        jButton3.setText("Start Conversion");
        jButton3.setName("jButton3"); // NOI18N

        jButton1.setAction(actionMap.get("buttonNewProjectClickedAction")); // NOI18N
        jButton1.setText("New Project");
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("buttonRemoveProjectClickedAction")); // NOI18N
        jButton2.setText("Remove Project");
        jButton2.setName("jButton2"); // NOI18N

        jButton4.setAction(actionMap.get("buttonViewLogClickedAction")); // NOI18N
        jButton4.setText("View Log");
        jButton4.setName("jButton4"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 723, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 117, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel5))
                    .add(layout.createSequentialGroup()
                        .add(textfieldpn1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(textfieldsf1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(textfielddf1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(30, 30, 30)
                        .add(jCheckBox1))
                    .add(layout.createSequentialGroup()
                        .add(textfieldpn2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(textfieldsf2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(textfielddf2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jProgressBar2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(30, 30, 30)
                        .add(jCheckBox2))
                    .add(layout.createSequentialGroup()
                        .add(textfieldpn3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(textfieldsf3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(textfielddf3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jProgressBar3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(29, 29, 29)
                        .add(jCheckBox3))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(textfieldpn4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(textfieldsf4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(textfielddf4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jProgressBar4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(textfieldpn5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(textfieldsf5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(textfielddf5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jProgressBar5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 108, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .add(30, 30, 30)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jCheckBox5)
                            .add(jCheckBox4)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton3)
                    .add(layout.createSequentialGroup()
                        .add(jButton1)
                        .add(18, 18, 18)
                        .add(jButton2))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton4))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel3)
                    .add(jLabel4)
                    .add(jLabel5))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(textfieldpn1)
                        .add(textfieldsf1)
                        .add(textfielddf1))
                    .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jCheckBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jProgressBar2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(textfieldpn2)
                        .add(textfieldsf2)
                        .add(textfielddf2))
                    .add(jCheckBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(textfieldpn3)
                            .add(textfieldsf3)
                            .add(textfielddf3))
                        .add(jProgressBar3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jCheckBox3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(textfieldpn4)
                            .add(textfieldsf4)
                            .add(textfielddf4))
                        .add(jProgressBar4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jCheckBox4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(textfieldpn5)
                            .add(textfieldsf5)
                            .add(textfielddf5))
                        .add(jProgressBar5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jCheckBox5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 6, Short.MAX_VALUE)
                .add(jButton3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton4)
                .addContainerGap())
        );

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

    @Action
    public void buttonNewProjectClickedAction(){
        new ProjectWindow(this).setVisible(true);
        
    }

    @Action
    public void buttonRemoveProjectClickedAction() throws Exception {
        int i=0;

        while(i<5){
            // if(i>=totalProjectNumber)    break;
            
            if(checkboxes.get(i).isSelected()){
                projectNames.get(i).setVisible(false);
                sourceFolders.get(i).setVisible(false);
                destinationFolders.get(i).setVisible(false);
                progressBar.get(i).setVisible(false);
                checkboxes.get(i).setVisible(false);

                checkboxes.get(i).setSelected(false);

                totalProjectNumber--;
            }
            i++;
        }

        i=0;
        while(i<totalProjectNumber){
            if(!projectNames.get(i).isVisible()){
                progressBar.get(i).setValue(0);
                progress.remove(i);
                logs.set(i, "");
            }
            i++;
        }

        shiftProjectComponents();

    }

    private void shiftProjectComponents(){
        int l=0, f=0;

        while(l<5){
            if(projectNames.get(f).isVisible() && projectNames.get(l).isVisible()){
                f++;
                l++;
            }
            else if(!projectNames.get(f).isVisible() && !projectNames.get(l).isVisible()){
                l++;
            }
            else if(projectNames.get(f).isVisible() && !projectNames.get(l).isVisible()){
                f++;
                l++;
            }
            else{
                projectNames.get(f).setText(projectNames.get(l).getText());
                sourceFolders.get(f).setText(sourceFolders.get(l).getText());
                destinationFolders.get(f).setText(destinationFolders.get(l).getText());
                progressBar.get(f).setValue(progressBar.get(l).getValue());
                checkboxes.get(f).setSelected(checkboxes.get(l).isSelected());
                logs.set(f, logs.get(l));

                projectNames.get(f).setVisible(true);
                sourceFolders.get(f).setVisible(true);
                destinationFolders.get(f).setVisible(true);
                progressBar.get(f).setVisible(true);
                checkboxes.get(f).setVisible(true);

                projectNames.get(l).setVisible(false);
                sourceFolders.get(l).setVisible(false);
                destinationFolders.get(l).setVisible(false);
                progressBar.get(l).setVisible(false);
                
                checkboxes.get(l).setVisible(false);
                checkboxes.get(l).setSelected(false);
                l++;
                f++;
            }
        }
    }

    @Action
    public void buttonViewLogClickedAction() throws InterruptedException {
        int i = 0;
        while(i<5){
            if(checkboxes.get(i).isSelected()){
                new LogWindow(this, i).setVisible(true);
            }
            i++;
        }

       // JavaMLHandler jm = new JavaMLHandler(logs, this);
       
        
    }

    @Action
    public void buttonStartConversionClickedAction() throws SAXException, IOException {

       for(int i=0; i<5 ;i++){
           if(checkboxes.get(i).isSelected()){

               String projectPath = sourceFolders.get(i).getText();
               ExtractionHandler eh = new ExtractionHandler("config.txt", projectPath);
               eh.parseAndExtractApplet(eh.getSourceFilesPath());
               appletSourcePaths = eh.getAppletSourcePaths();

               String newString = "\n\nApplet source codes were extracted: \n";
               logs.set(i, logs.get(i).concat(newString));

               for(int k = 0; k< appletSourcePaths.size() ; k++){
                   logs.set(i, logs.get(i).concat("\t" + appletSourcePaths.get(k) + "\n"));
               }

               progress.set(i,10);
               progressBar.get(i).setValue(10);

               /* java ml */

               String jikespath = this.projectPath + "javaml-2.0-RC5";
               JavaMLHandler jm = new JavaMLHandler(appletSourcePaths, projectPath, jikespath,  this);
               jm.runJavaML();

               logs.set(i, logs.get(i).concat("\nJava-ML part was executed, .xml files were created.\n"));

               progress.set(i,40);
               progressBar.get(i).setValue(40);

               //ParseJavaMLOutput p = new ParseJavaMLOutput(appletSourcePaths);
               //p.startParse();

               int size= appletSourcePaths.size();
		for(int j=0; j<size ;j++){   // loop for every JavaML XML output
                        //System.out.println("Applet file path: " + appletSourcePaths.get(j));
			startParse(i,appletSourcePaths.get(j), destinationFolders.get(i).getText() + "\\", this.projectPath);
                }

               for(int j=0; j<size ;j++){
                   deleteJavaMLFiles(appletSourcePaths.get(j));
               }

               logs.set(i, logs.get(i).concat("\tJavaML output files (.java.xml, .class, .java.unparse) were deleted. \n"));
               
               progress.set(i,100);
               progressBar.get(i).setValue(100);
               

           }
       }
    }

    public void startParse(int projectNo, String path, String output, String ourProjectPath){
        try{
            logs.set(projectNo, logs.get(projectNo).concat("\n"+ path + " applet file: \n"));

            String fileName = path;
            String xmlFile = path  + ".xml";
            XMLReader xr = XMLReaderFactory.createXMLReader();
            GeneralManager handler = new GeneralManager(output);
            xr.setContentHandler(handler);
            xr.setErrorHandler(handler);
            xr.parse(xmlFile);

            logs.set(projectNo, logs.get(projectNo).concat("\tIt was taken into memory.\n"));

            Object initMethod = handler.container.getReferenceTable().get(handler.classId+"init()V");
            Traverser t = new Traverser(path, handler.container, (CMethod) initMethod, handler.topObject, output,ourProjectPath);
            t.traverse();

            logs.set(projectNo, logs.get(projectNo).concat("\t"+ t.logs));
            logs.set(projectNo, logs.get(projectNo).concat("\tTranslation is completed! \n"));

            //BeanGenerator beanGenerator = new BeanGenerator(fileName, handler.topObject);
            //beanGenerator.generate();

            int dummy = 1;

        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

    private void deleteJavaMLFiles(String path) {
        String dirPath = path.substring(0,path.lastIndexOf("\\"));
        File f = new File(dirPath);

        // Make sure the file or directory exists and isn't write protected
        if (!f.exists())
          throw new IllegalArgumentException(
              "Delete: no such directory: " + dirPath);

        if (!f.canWrite())
          throw new IllegalArgumentException("Delete: write protected: "
              + dirPath);

        // If it is a directory, make sure it is empty
        if (f.isDirectory()) {
          String[] files = f.list();

          for(int i=0; i<files.length ;i++){

            String fileName = dirPath + "\\" + files[i];
            String extension = files[i].substring(files[i].lastIndexOf(".")+1, files[i].length());
            if(extension.equals("class") || extension.equals("unparse") || extension.equals("xml")){
                try{
                    File file = new File(fileName);

                    boolean success = file.delete();
                  
                    if (!success)
                        throw new IllegalArgumentException("Delete: deletion failed");

                }catch (Exception e){
                    //e.printStackTrace();
                }

            }

          }
           
        }

    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JProgressBar jProgressBar2;
    private javax.swing.JProgressBar jProgressBar3;
    private javax.swing.JProgressBar jProgressBar4;
    private javax.swing.JProgressBar jProgressBar5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel textfielddf1;
    private javax.swing.JLabel textfielddf2;
    private javax.swing.JLabel textfielddf3;
    private javax.swing.JLabel textfielddf4;
    private javax.swing.JLabel textfielddf5;
    private javax.swing.JLabel textfieldpn1;
    private javax.swing.JLabel textfieldpn2;
    private javax.swing.JLabel textfieldpn3;
    private javax.swing.JLabel textfieldpn4;
    private javax.swing.JLabel textfieldpn5;
    private javax.swing.JLabel textfieldsf1;
    private javax.swing.JLabel textfieldsf2;
    private javax.swing.JLabel textfieldsf3;
    private javax.swing.JLabel textfieldsf4;
    private javax.swing.JLabel textfieldsf5;
    // End of variables declaration//GEN-END:variables



}
