/*
 * MainApplet3.java
 *
 * Created on 10. unor 2006, 0:44
 */

package cz.pcland.gavisualization;
import cz.pcland.ga.GAConfiguration;
import cz.pcland.ga.crossover.CrossoverOpearator;
import cz.pcland.ga.fitness.Evaluator;
import cz.pcland.ga.selection.*;
import cz.pcland.knapsack.*;
import cz.pcland.sat.SATPanel;
import cz.pcland.tsp.TSPPanel;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import cz.pcland.functions.*;
import cz.pcland.io.*;
import cz.pcland.scripting.*;
import cz.pcland.ga.*;
import cz.pcland.functions.syntax.*;

//import java.io.*;
/**
 *
 * @author  petr
 */
public class MainApplet3 extends javax.swing.JApplet implements Loadable {
    public static final SelectionOperator[] selectionMethods = {/*new RouletteSelection(),*/ new RouletteSelection2(), new TournamentSelection(), new RandomSelection(), new RankSelection()};
    public static CrossoverOpearator[] crossOverOperators = null; // = { new OnePointTSMCrossover(), new TwoPointTSMCrossover() };
    public static Evaluator[] evaluators = null;
    
    public boolean populationReady;
    public int showAfter;
    public boolean showProgress = false;
    public boolean showDistribution = true;
    public int totalSteps;
    public int popSize;
    public double probOfCrossover;
    public double probOfMutation;
    public int elite;
    public int GASteps;
    public int runSteps;
    public boolean reset;
    public boolean distributionEnable;
    public boolean setMinFitnessToZero = false;
    
    
    public GAConfiguration GAConfig;
    
    public BaseProblemPanel problemPanel = null;
    
    SwingWorker progressWorker;
    
    
    
    public SelectionOperator selectionObject;
    public Evaluator fitnessObject;
    public CrossoverOpearator crossoverObject;
    
    private boolean configHided = false;
    
    
    /** Initializes the applet MainApplet3 */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                    populationReady = false;
                    selectionObject = selectionMethods[0];
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public void loadFromString(String str) {
        runScript(str);
    }
    
    
    
    public boolean loadGAParams() {
        try{
            this.setMinFitnessToZero = this.chcksetMinFitnessToZero.isSelected();
            popSize = Integer.parseInt(this.inputPopSize.getText()); //throw NumberFormatException
            probOfCrossover = Double.parseDouble(this.inputProbCrossover.getText());
            probOfMutation = Double.parseDouble(this.inputProbMutation.getText());
            elite = Integer.parseInt(this.inputElite.getText());
            GASteps = Integer.parseInt(this.inputGASteps.getText());
            runSteps = Integer.parseInt(this.inputRunSteps.getText());
            showAfter = Integer.parseInt(this.inputShowAfter.getText());
            this.distributionEnable = this.checkViewDistribution.isSelected();
            if(elite > popSize) {
                JOptionPane.showMessageDialog(null,"error occured: Count of elite strings cant be greater than count of strings in population !"  ,"Input error", JOptionPane.ERROR_MESSAGE);
                return false;
            }
            return true;
        }catch(NumberFormatException e) {
            JOptionPane.showMessageDialog(null,"error occured: " + e.toString(), "Input error", JOptionPane.ERROR_MESSAGE);
            return false;
            //throw e;
        }
    }
    
    
    public void loadProblem() {
        this.comboFitness.removeAllItems();
        this.evaluators = problemPanel.getEvaluators();
        
        for(int i=0;i<evaluators.length;i++){
            this.comboFitness.insertItemAt(evaluators[i],i);
        }
        
        this.comboFitness.setSelectedIndex(0);
        
        this.comboCrossover.removeAllItems();
        this.crossOverOperators = problemPanel.getCrossoverOperators();
        for(int i=0;i<crossOverOperators.length;i++){
            this.comboCrossover.insertItemAt(crossOverOperators[i],i);
        }
        this.comboCrossover.setSelectedIndex(0);
        
        //GAConfiguration.firnessObj = (Evaluator)comboFitness.getSelectedItem();
        
        this.jSplitPane1.setLeftComponent(problemPanel);
    }
    
    public void runScript(String str) {
        //JOptionPane.showMessageDialog(null,str);
        try {
            Script.loadData(str, this);
            
            if(Script.prepared()) {
                Script.runNext();
            }
        }catch(ParseErrorException e){
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }
    
    public void configAndRun(boolean reset) {
        if( this.problemPanel != null) {
            
            if(reset) {
                loadGAParams();
                totalSteps = this.GASteps;
            } else {
                int pop = this.popSize;
                loadGAParams();
                this.popSize = pop;
                totalSteps = this.runSteps;
            }
            
            GAConfig = new GAConfiguration(popSize, probOfCrossover, probOfMutation, elite,selectionObject,fitnessObject, crossoverObject, 20, this.distributionEnable, setMinFitnessToZero, totalSteps, showAfter);
            
            // this.problemPanel.setData(/*GAConfig,*/ btnStart, btnSteps, btnCancel, checkShowProgress, checkViewDistribution, lblStatus, reset);
            
            this.btnSteps.setEnabled(false);
            this.btnStart.setEnabled(false);
            this.btnCancel.setEnabled(true);
            
            this.problemPanel.run(reset);
            //statusField.setText("Working...");
        }
    }
    
    
    
    
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel6 = new javax.swing.JPanel();
        inputGASteps = new javax.swing.JTextField();
        inputPopSize = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        inputProbCrossover = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        inputProbMutation = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        inputElite = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        comboReproduction = new JComboBox(selectionMethods);
        jLabel12 = new javax.swing.JLabel();
        comboFitness = new JComboBox();
        jLabel13 = new javax.swing.JLabel();
        inputShowAfter = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        comboCrossover = new javax.swing.JComboBox();
        checkShowProgress = new javax.swing.JCheckBox();
        checkViewDistribution = new javax.swing.JCheckBox();
        chcksetMinFitnessToZero = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        btnStart = new javax.swing.JButton();
        inputRunSteps = new javax.swing.JTextField();
        btnSteps = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem13 = new javax.swing.JMenuItem();
        jMenuItem14 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem7 = new javax.swing.JMenuItem();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        jSplitPane1.setResizeWeight(1.0);
        jScrollPane3.setMinimumSize(new java.awt.Dimension(210, 0));
        jScrollPane3.setPreferredSize(new java.awt.Dimension(175, 0));
        jPanel6.setLayout(null);

        jPanel6.setPreferredSize(new java.awt.Dimension(175, 0));
        inputGASteps.setText("500");
        inputGASteps.setMinimumSize(new java.awt.Dimension(40, 19));
        inputGASteps.setPreferredSize(new java.awt.Dimension(40, 19));
        jPanel6.add(inputGASteps);
        inputGASteps.setBounds(10, 80, 50, 19);

        inputPopSize.setText("200");
        inputPopSize.setMinimumSize(new java.awt.Dimension(40, 19));
        inputPopSize.setName("");
        inputPopSize.setPreferredSize(new java.awt.Dimension(40, 19));
        jPanel6.add(inputPopSize);
        inputPopSize.setBounds(10, 40, 50, 19);

        jLabel3.setText("Prob. crossover:");
        jPanel6.add(jLabel3);
        jLabel3.setBounds(10, 100, 98, 15);

        jLabel2.setText("Generations count:");
        jPanel6.add(jLabel2);
        jLabel2.setBounds(10, 60, 117, 15);

        inputProbCrossover.setText("0.6");
        inputProbCrossover.setMinimumSize(new java.awt.Dimension(40, 19));
        inputProbCrossover.setPreferredSize(new java.awt.Dimension(40, 19));
        jPanel6.add(inputProbCrossover);
        inputProbCrossover.setBounds(10, 120, 40, 19);

        jLabel4.setText("Prob. Mutation:");
        jPanel6.add(jLabel4);
        jLabel4.setBounds(10, 140, 94, 15);

        inputProbMutation.setText("0.01");
        inputProbMutation.setMinimumSize(new java.awt.Dimension(40, 19));
        inputProbMutation.setPreferredSize(new java.awt.Dimension(40, 19));
        jPanel6.add(inputProbMutation);
        inputProbMutation.setBounds(10, 160, 40, 19);

        jLabel5.setText("Selection:");
        jPanel6.add(jLabel5);
        jLabel5.setBounds(10, 220, 59, 15);

        jLabel6.setText("Elite strings:");
        jPanel6.add(jLabel6);
        jLabel6.setBounds(10, 180, 78, 15);

        inputElite.setText("1");
        inputElite.setMinimumSize(new java.awt.Dimension(40, 19));
        inputElite.setPreferredSize(new java.awt.Dimension(40, 19));
        jPanel6.add(inputElite);
        inputElite.setBounds(10, 200, 40, 19);

        jLabel1.setText("Population size:");
        jPanel6.add(jLabel1);
        jLabel1.setBounds(10, 20, 99, 15);

        comboReproduction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboReproductionActionPerformed(evt);
            }
        });

        jPanel6.add(comboReproduction);
        comboReproduction.setBounds(10, 240, 160, 24);

        jLabel12.setText("Fitness variant:");
        jPanel6.add(jLabel12);
        jLabel12.setBounds(10, 270, 95, 15);

        comboFitness.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboFitnessActionPerformed(evt);
            }
        });

        jPanel6.add(comboFitness);
        comboFitness.setBounds(10, 290, 160, 24);

        jLabel13.setText("Show every");
        jPanel6.add(jLabel13);
        jLabel13.setBounds(10, 370, 80, 15);

        inputShowAfter.setText("10");
        inputShowAfter.setPreferredSize(new java.awt.Dimension(40, 19));
        jPanel6.add(inputShowAfter);
        inputShowAfter.setBounds(90, 370, 40, 19);

        jLabel14.setText("step");
        jPanel6.add(jLabel14);
        jLabel14.setBounds(140, 370, 34, 15);

        jLabel15.setText("Crossover operator:");
        jPanel6.add(jLabel15);
        jLabel15.setBounds(10, 320, 123, 15);

        comboCrossover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboCrossoverActionPerformed(evt);
            }
        });

        jPanel6.add(comboCrossover);
        comboCrossover.setBounds(10, 340, 160, 24);

        checkShowProgress.setText("Show progress");
        checkShowProgress.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkShowProgressActionPerformed(evt);
            }
        });

        jPanel6.add(checkShowProgress);
        checkShowProgress.setBounds(10, 390, 150, 23);

        checkViewDistribution.setSelected(true);
        checkViewDistribution.setText("View fitness distribution");
        checkViewDistribution.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkViewDistributionActionPerformed(evt);
            }
        });

        jPanel6.add(checkViewDistribution);
        checkViewDistribution.setBounds(10, 410, 190, 23);

        chcksetMinFitnessToZero.setText("Min fitness to zero");
        chcksetMinFitnessToZero.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        chcksetMinFitnessToZero.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jPanel6.add(chcksetMinFitnessToZero);
        chcksetMinFitnessToZero.setBounds(14, 434, 140, 15);

        jScrollPane3.setViewportView(jPanel6);

        jSplitPane1.setRightComponent(jScrollPane3);

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jPanel2.setMinimumSize(new java.awt.Dimension(100, 100));
        jPanel2.setPreferredSize(new java.awt.Dimension(640, 480));
        jLabel7.setText("Select problem to solve in main menu ...");
        jPanel2.add(jLabel7, new java.awt.GridBagConstraints());

        jSplitPane1.setLeftComponent(jPanel2);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(jSplitPane1, gridBagConstraints);

        btnStart.setText("Start");
        btnStart.setName("btnStart");
        btnStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 12, 10, 17);
        getContentPane().add(btnStart, gridBagConstraints);

        inputRunSteps.setText("1");
        inputRunSteps.setMinimumSize(new java.awt.Dimension(40, 19));
        inputRunSteps.setPreferredSize(new java.awt.Dimension(40, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 3);
        getContentPane().add(inputRunSteps, gridBagConstraints);

        btnSteps.setText("steps");
        btnSteps.setName("btnSteps");
        btnSteps.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        getContentPane().add(btnSteps, gridBagConstraints);

        btnCancel.setText("Cancel");
        btnCancel.setEnabled(false);
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        getContentPane().add(btnCancel, gridBagConstraints);

        jLabel8.setText("Status: ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        getContentPane().add(jLabel8, gridBagConstraints);

        lblStatus.setText("Idle");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
        getContentPane().add(lblStatus, gridBagConstraints);

        jMenu5.setText("Problem selection");
        jMenuItem9.setText("Knap Sack");
        buttonGroup2.add(jMenuItem9);
        jMenuItem9.setSelected(true);
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });

        jMenu5.add(jMenuItem9);

        jMenuItem12.setText("SAT");
        buttonGroup2.add(jMenuItem12);
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });

        jMenu5.add(jMenuItem12);

        jMenuItem13.setText("Function maximum");
        buttonGroup2.add(jMenuItem13);
        jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem13ActionPerformed(evt);
            }
        });

        jMenu5.add(jMenuItem13);

        jMenuItem14.setText("Traveling salesman");
        buttonGroup2.add(jMenuItem14);
        jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem14ActionPerformed(evt);
            }
        });

        jMenu5.add(jMenuItem14);

        jMenuBar1.add(jMenu5);

        jMenu4.setText("Configuration");
        jMenuItem4.setText("Visualize Fitness");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });

        jMenu4.add(jMenuItem4);

        jMenuItem5.setText("Visualize solution evaluation");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });

        jMenu4.add(jMenuItem5);

        jMenuItem1.setText("Hide configuration");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });

        jMenu4.add(jMenuItem1);

        jMenuItem2.setText("Run script");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });

        jMenu4.add(jMenuItem2);

        jMenuItem3.setText("Script output");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });

        jMenu4.add(jMenuItem3);

        jMenuBar1.add(jMenu4);

        jMenu3.setText("Help");
        jMenuItem7.setText("About ...");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });

        jMenu3.add(jMenuItem7);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
// TODO add your handling code here:
        ScriptOutput so = new ScriptOutput(null, true);
        so.loadOutput();
        so.pack();
        so.setVisible(true);
        
    }//GEN-LAST:event_jMenuItem3ActionPerformed
    
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
        MyOptionPane.load(this,  jPanel2, jSplitPane1);
    }//GEN-LAST:event_jMenuItem2ActionPerformed
    
    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
// TODO add your handling code here:
        this.problemPanel.visualizeRank();
    }//GEN-LAST:event_jMenuItem5ActionPerformed
    
    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
// TODO add your handling code here:
        
        this.problemPanel.visualizeFitness();
    }//GEN-LAST:event_jMenuItem4ActionPerformed
    
    private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem14ActionPerformed
// TODO add your handling code here:
        problemPanel = new TSPPanel(this);
        loadProblem();
    }//GEN-LAST:event_jMenuItem14ActionPerformed
    
    private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem13ActionPerformed
// TODO add your handling code here:
        problemPanel = new FunctionPanel(this);
        loadProblem();
    }//GEN-LAST:event_jMenuItem13ActionPerformed
    
    private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed
// TODO add your handling code here:
        //this.jLabel7.setText("Loading environment ...");
//        problemPanel = new SATPanel();
        problemPanel = new SATPanel(this);
        loadProblem();
    }//GEN-LAST:event_jMenuItem12ActionPerformed
    
    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
// TODO add your handling code here:
        //this.jLabel7.setText("Loading environment ...");
        problemPanel = new KnapSackPanel(this);
        loadProblem();
    }//GEN-LAST:event_jMenuItem9ActionPerformed
    
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
        if(!configHided) {
            this.jSplitPane1.setDividerLocation(this.getWidth());
            this.jMenuItem1.setText("Show configuration");
            configHided = !configHided;
        }else {
            this.jSplitPane1.setDividerLocation(-1);
            this.jMenuItem1.setText("Hide configuration");
            configHided = !configHided;
        }
        
    }//GEN-LAST:event_jMenuItem1ActionPerformed
    
    private void checkViewDistributionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkViewDistributionActionPerformed
// TODO add your handling code here:
        
        
    }//GEN-LAST:event_checkViewDistributionActionPerformed
    
    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
// TODO add your handling code here:
        AboutDialog ad = new AboutDialog(null, true);
        ad.pack();
        ad.setVisible(true);
        //  this.jSplitPane1.setLeftComponent(new AboutPanel());
        
    }//GEN-LAST:event_jMenuItem7ActionPerformed
    
    /**
     *
     * @param evt
     */
    private void checkShowProgressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkShowProgressActionPerformed
// TODO add your handling code here:
        if(this.checkShowProgress.isSelected()) showProgress = true; else showProgress = false;
    }//GEN-LAST:event_checkShowProgressActionPerformed
    
    private void comboCrossoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCrossoverActionPerformed
// TODO add your handling code here:
        JComboBox combo = (JComboBox)evt.getSource();
        if(combo.getSelectedItem() instanceof CrossoverOpearator){
            CrossoverOpearator selected = (CrossoverOpearator)combo.getSelectedItem();
            crossoverObject = selected;
        }
    }//GEN-LAST:event_comboCrossoverActionPerformed
    
    private void comboFitnessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFitnessActionPerformed
// TODO add your handling code here:
        JComboBox combo = (JComboBox)evt.getSource();
        Object obj = combo.getSelectedItem();
        
        
        if(obj instanceof Evaluator){
            Evaluator selected = (Evaluator)combo.getSelectedItem();
            fitnessObject = selected;
            //GAConfiguration.firnessObj = fitnessObject;
        }
    }//GEN-LAST:event_comboFitnessActionPerformed
    
    private void comboReproductionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboReproductionActionPerformed
// TODO add your handling code here:
        JComboBox combo = (JComboBox)evt.getSource();
        SelectionOperator selected = (SelectionOperator)combo.getSelectedItem();
        
        
        if(selected instanceof TournamentSelection){
            String str = null;
            
            if(!Script.isTest) {
                str = JOptionPane.showInputDialog("Select tournament size",new Integer(2));
                try {
                    int count = Integer.parseInt(str);
                    TournamentSelection ts = (TournamentSelection)selected;
                    ts.setTournamentSize(count);
                    
                }catch(NumberFormatException e){
                    JOptionPane.showMessageDialog(null,"error occured: " + e.toString(), "Input error", JOptionPane.ERROR_MESSAGE);
                }
            }
            
            selectionObject = selected;
            
        }else  {
            selectionObject = selected;
        }
        
        
    }//GEN-LAST:event_comboReproductionActionPerformed
    
    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
        this.problemPanel.cancel();
    }//GEN-LAST:event_btnCancelActionPerformed
    
    private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
// TODO add your handling code here:
        
        JButton btn = (JButton)evt.getSource();
        if(btn.getName().equals("btnStart")){
            reset = true;
            
        }else if(btn.getName().equals("btnSteps")) {
            reset = false;
            
        }
        
        configAndRun(reset);
        
        
        
        
        
    }//GEN-LAST:event_btnStartActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton btnCancel;
    public javax.swing.JButton btnStart;
    public javax.swing.JButton btnSteps;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    public javax.swing.JCheckBox chcksetMinFitnessToZero;
    public javax.swing.JCheckBox checkShowProgress;
    public javax.swing.JCheckBox checkViewDistribution;
    public javax.swing.JComboBox comboCrossover;
    public javax.swing.JComboBox comboFitness;
    public javax.swing.JComboBox comboReproduction;
    public javax.swing.JTextField inputElite;
    public javax.swing.JTextField inputGASteps;
    public javax.swing.JTextField inputPopSize;
    public javax.swing.JTextField inputProbCrossover;
    public javax.swing.JTextField inputProbMutation;
    private javax.swing.JTextField inputRunSteps;
    private javax.swing.JTextField inputShowAfter;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem13;
    private javax.swing.JMenuItem jMenuItem14;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane3;
    public javax.swing.JSplitPane jSplitPane1;
    public javax.swing.JLabel lblStatus;
    // End of variables declaration//GEN-END:variables
    
}
