/*
 * MainView.java
 */

package edu.umbc.combio.erilllab.jfitom.gui;

import edu.umbc.combio.erilllab.jfitom.Util.JFitomWUtil;
import edu.umbc.combio.erilllab.jfitom.core.FilterStrategy;
import edu.umbc.combio.erilllab.jfitom.core.Motif;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.logging.FileHandler;
import java.util.logging.LogManager;
import java.util.logging.SimpleFormatter;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * The application's main frame.
 */
public class MainView extends FrameView {

    private final static Logger LOGGER = Logger.getLogger(MainView.class.getName());
    static private FileHandler logFileHandler;
    private static LogManager lm = LogManager.getLogManager();

    private String defaultPath = "";
    private String optionsFileName = "";
    private String jarPath = "";

    
    

//    String clGenomeFilePath, clSitesFilePath, optionsFilePath;

    public MainView(SingleFrameApplication app, String optionsFilePath, String genomeFilePath, String sitesFilePath) {
        super(app); 

        
        initComponents();
//        log(Level.INFO, "Components initialized.");
        initializeUIControlsFromOptionsFile(optionsFilePath, genomeFilePath, sitesFilePath);

        if(!System.getProperty("os.name").startsWith("Windows")){
            // Get the default toolkit
		Toolkit toolkit = Toolkit.getDefaultToolkit();

		// Get the current screen size
		Dimension scrnsize = toolkit.getScreenSize();

		// Print the screen size
		System.out.println ("Screen size : " + scrnsize);

                mainPanel.setSize(new Dimension((int)(scrnsize.getWidth() * 0.54), (int)(scrnsize.getHeight() * 0.87)));
                mainPanel.setMaximumSize(new Dimension((int)(scrnsize.getWidth() * 0.54), (int)(scrnsize.getHeight() * 0.87)));
                mainPanel.repaint();

                System.out.println ("Window size : " + mainPanel.getSize(scrnsize));


        }
//        log(Level.INFO, "UI controls initialized from options file.");
        
        try {
            setLogger();
        } catch (IOException ex) {
            Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
        }

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    
                }
            }
        });
    }

    private void setLogger() throws IOException{
        LOGGER.setLevel(Level.SEVERE);

      lm.addLogger(LOGGER);
      logFileHandler = new FileHandler("jfitom.log");
      logFileHandler.setFormatter(new SimpleFormatter());
      LOGGER.addHandler(logFileHandler);
    }

    /**
        This method sets the UI controls with default values.
     */
    public void initializeUIControlsWithDefaultValues(){
        log(Level.INFO, "UI controls initialized with default values.");
        setStatusBarText("UI controls initialized with default values.");
        if(Options.DEFAULT_IS_PALINDROME.equals("Y")){
            palindromeCheckBox.setSelected(true);
        } else {
            palindromeCheckBox.setSelected(false);
        }

        resultFilePathTextField.setText(Options.DEFAULT_OUTPUT_FILE);

        if(Integer.parseInt(Options.DEFAULT_SCORE_METHOD) == Motif.SCORE_METHOD_RI){
            riRadioButton.setSelected(true);
        } else if(Integer.parseInt(Options.DEFAULT_SCORE_METHOD) == Motif.SCORE_METHOD_RI_RSEQ){
            ri_rseqRadioButton.setSelected(true);
        } else if(Integer.parseInt(Options.DEFAULT_SCORE_METHOD) == Motif.SCORE_METHOD_ISEQ){
            iseqRadioButton.setSelected(true);
        } else if(Integer.parseInt(Options.DEFAULT_SCORE_METHOD) == Motif.SCORE_METHOD_ISEQ_RE){
            iseq_reRadioButton.setSelected(true);
        }

        maxHysteresisLimitTextField.setText(Options.DEFAULT_MAX_HYSTERESIS_LIMIT);
        maxInterGenicDistanceTextField.setText(Options.DEFAULT_MAX_INTERGENIC_DISTANCE);
        maxOperatorDistanceOutGeneTextField.setText(Options.DEFAULT_MAX_OPERATOR_DISTANCE_OUT);
        maxOperatorDistanceInGeneTextField.setText(Options.DEFAULT_MAX_OPERATOR_DISTANCE_IN);

        if(Integer.parseInt(Options.DEFAULT_RESULT_SIZE_METHOD) == FilterStrategy.LIST_SIZE_IN_NUMBER){
            listSizeAbsoluteRadioButton.setSelected(true);
            listSizeAbsoluteTextField.setEditable(true);
            listSizeAbsoluteTextField.setText(Options.DEFAULT_RESULT_SIZE_METHOD_VALUE);
            listSizeRelativeRadioButton.setSelected(false);
            listSizeRelativeTextField.setEditable(false);
            listSizeRelativeTextField.setText("");
        } else if(Integer.parseInt(Options.DEFAULT_RESULT_SIZE_METHOD) == FilterStrategy.LIST_SIZE_IN_PERCENT){
            listSizeAbsoluteRadioButton.setSelected(false);
            listSizeAbsoluteTextField.setEditable(false);
            listSizeAbsoluteTextField.setText("");
            listSizeRelativeRadioButton.setSelected(true);
            listSizeRelativeTextField.setEditable(true);
            listSizeRelativeTextField.setText(Options.DEFAULT_RESULT_SIZE_METHOD_VALUE);
        }

        if(Integer.parseInt(Options.DEFAULT_THRESHOLD_SCORE_METHOD) == FilterStrategy.THRESHOLD_METHOD_NORMALIZED){
            thresholdNormalizedRadioButton.setSelected(true);
            thresholdNormalizedTextField.setEditable(true);
            thresholdNormalizedTextField.setText(Options.DEFAULT_THRESHOLD_SCORE_VALUE);
            thresholdSDBandRadioButton.setSelected(false);
            thresholdSDBandTextField.setEditable(false);
            thresholdSDBandTextField.setText("");
        } else if(Integer.parseInt(Options.DEFAULT_THRESHOLD_SCORE_METHOD) == FilterStrategy.THRESHOLD_METHOD_SD_BAND){
            thresholdNormalizedRadioButton.setSelected(false);
            thresholdNormalizedTextField.setEditable(false);
            thresholdNormalizedTextField.setText("");
            thresholdSDBandRadioButton.setSelected(true);
            thresholdSDBandTextField.setEditable(true);
            thresholdSDBandTextField.setText(Options.DEFAULT_THRESHOLD_SCORE_VALUE);
        }

        if(Options.DEFAULT_GENERATE_LOGS.equals("Y")){
            generateLogsCheckBox.setSelected(true);
        } else {
            generateLogsCheckBox.setSelected(false);
        }

        if(Options.DEFAULT_VIEW_RESULT.equals("Y")){
            viewResultsCheckBox.setSelected(true);
        } else {
            viewResultsCheckBox.setSelected(false);
        }

        setStatusBarText("Options are set to default.");
    }

    /**
        We shall initialize the UI controls based on the options file.
     */
    public void initializeUIControlsFromOptionsFile(String overridingOptionsFile, String genomeFilePath, String sitesFilePath){
        try {
            System.out.println(System.getProperty("user.dir"));
            BufferedReader optionsFile = new BufferedReader(new FileReader("JFITOM.OPT"));
            // We read the options first
            if(overridingOptionsFile != null){
                optionsFile = new BufferedReader(new FileReader(overridingOptionsFile));
                log(Level.INFO, "Options file overriden by user chosen file.");
                setStatusBarText("Options file overriden by user chosen file.");
            }
            
            // Reading line by line
            String currentLine = null;
            try {
                log(Level.INFO, "Started reading options file.");
                setStatusBarText("Started reading options file.");
                while ((currentLine = optionsFile.readLine()) != null) {
                    if(!currentLine.startsWith("#")){
                        // Now we check which property, this line corresponds to
                        String[] optionValuePair = currentLine.split("=");
                        String option = optionValuePair[0].trim();
                        String value = optionValuePair[1].trim();

                        if(genomeFilePath == null || genomeFilePath.trim().equals("")){
                            if(Options.OPTION_LATEST_GENOME_FILE.equals(option)){
                                genomeFilePathTextField.setText(value);
                            }
                        } else {
                            genomeFilePathTextField.setText(genomeFilePath);
                        }

                        if(sitesFilePath == null || sitesFilePath.trim().equals("")){
                            if(Options.OPTION_LATEST_SITES_FILE.equals(option)){
                                sitesFilePathTextField.setText(value);
                            }
                        } else {
                            sitesFilePathTextField.setText(sitesFilePath);
                        }


                        if(Options.OPTION_IS_PALINDROME.equals(option)){
                            if("Y".equals(value)){
                                palindromeCheckBox.setSelected(true);
                            } else {
                                palindromeCheckBox.setSelected(false);
                            }
                        }

                        if(Options.OPTION_OUTPUT_FILE.equals(option)){
                            resultFilePathTextField.setText(value);
                        }

                        if(Options.OPTION_SCORE_METHOD.equals(option)){
                            if(Motif.SCORE_METHOD_RI == Integer.parseInt(value)){
                                riRadioButton.setSelected(true);
                            } else if(Motif.SCORE_METHOD_RI_RSEQ == Integer.parseInt(value)){
                                ri_rseqRadioButton.setSelected(true);
                            } else if(Motif.SCORE_METHOD_ISEQ == Integer.parseInt(value)){
                                iseqRadioButton.setSelected(true);
                            } else if(Motif.SCORE_METHOD_ISEQ_RE == Integer.parseInt(value)){
                                iseq_reRadioButton.setSelected(true);
                            }
                        }

                        if(Options.OPTION_MAX_HYSTERESIS_LIMIT.equals(option)){
                            maxHysteresisLimitTextField.setText(value);
                        }

                        if(Options.OPTION_MAX_INTERGENIC_DISTANCE.equals(option)){
                            maxInterGenicDistanceTextField.setText(value);
                        }

                        if(Options.OPTION_MAX_OPERATOR_DISTANCE_OUT.equals(option)){
                            maxOperatorDistanceOutGeneTextField.setText(value);
                        }

                        if(Options.OPTION_MAX_OPERATOR_DISTANCE_IN.equals(option)){
                            maxOperatorDistanceInGeneTextField.setText(value);
                        }

                        if(Options.OPTION_RESULT_SIZE_METHOD.equals(option)){
                            if(FilterStrategy.LIST_SIZE_IN_NUMBER == Integer.parseInt(value)){
                                listSizeAbsoluteRadioButton.setSelected(true);
                                listSizeAbsoluteTextField.setEditable(true);
                                listSizeRelativeRadioButton.setSelected(false);
                                listSizeRelativeTextField.setEditable(false);
                            } else if(FilterStrategy.LIST_SIZE_IN_PERCENT == Integer.parseInt(value)){
                                listSizeAbsoluteRadioButton.setSelected(false);
                                listSizeAbsoluteTextField.setEditable(false);
                                listSizeRelativeRadioButton.setSelected(true);
                                listSizeRelativeTextField.setEditable(true);
                            }
                        }

                        if(Options.OPTION_RESULT_SIZE_METHOD_VALUE.equals(option)){
                            if(listSizeAbsoluteRadioButton.isSelected()){
                                listSizeAbsoluteTextField.setText(value);
                            } else {
                                listSizeRelativeTextField.setText(value);
                            }
                        }

                        if(Options.OPTION_THRESHOLD_SCORE_METHOD.equals(option)){
                            if(FilterStrategy.THRESHOLD_METHOD_NORMALIZED == Integer.parseInt(value)){
                                thresholdNormalizedRadioButton.setSelected(true);
                                thresholdNormalizedTextField.setEditable(true);
                                thresholdSDBandRadioButton.setSelected(false);
                                thresholdSDBandTextField.setEditable(false);
                            } else if(FilterStrategy.THRESHOLD_METHOD_SD_BAND == Integer.parseInt(value)){
                                thresholdNormalizedRadioButton.setSelected(false);
                                thresholdNormalizedTextField.setEditable(false);
                                thresholdSDBandRadioButton.setSelected(true);
                                thresholdSDBandTextField.setEditable(true);
                            }
                        }

                        if(Options.OPTION_THRESHOLD_SCORE_VALUE.equals(option)){
                            if(thresholdNormalizedRadioButton.isSelected()){
                                thresholdNormalizedTextField.setText(value);
                            } else {
                                thresholdSDBandTextField.setText(value);
                            }
                        }

                        if(Options.OPTION_GENERATE_LOGS.equals(option)){
                            if("Y".equals(value)){
                                generateLogsCheckBox.setSelected(true);
                            } else {
                                generateLogsCheckBox.setSelected(false);
                            }
                        }

                        if(Options.OPTION_VIEW_RESULT.equals(option)){
                            if("Y".equals(value)){
                                viewResultsCheckBox.setSelected(true);
                            } else {
                                viewResultsCheckBox.setSelected(false);
                            }
                        }

                        setStatusBarText("Options are set according to the options file.");
                    } // If not a commented line
                    
                }// while
            } catch (IOException ex) {
                log(Level.SEVERE, "I/O exception in reading options file.");
                setStatusBarText("I/O exception in reading options file.");
                // If we cannot read the optionsFile, we use the default values
                initializeUIControlsWithDefaultValues();
//                Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (FileNotFoundException ex) {
//            ex.printStackTrace();
            log(Level.SEVERE, "No options file found.");
            setStatusBarText("No options file found.");
            // If we do not find the optionsFile, we use the default values
            initializeUIControlsWithDefaultValues();
//            Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = Main.getApplication().getMainFrame();
            aboutBox = new MainAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        Main.getApplication().show(aboutBox);
    }

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

        mainPanel = new javax.swing.JPanel();
        filesPanel = new javax.swing.JPanel();
        genomeFilePathTextField = new javax.swing.JTextField();
        genomeFileButton = new javax.swing.JButton();
        sitesFilePathTextField = new javax.swing.JTextField();
        sitesFileButton = new javax.swing.JButton();
        resultFilePathTextField = new javax.swing.JTextField();
        saveResultButton = new javax.swing.JButton();
        palindromeCheckBox = new javax.swing.JCheckBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        scoringMethodsPanel = new javax.swing.JPanel();
        riRadioButton = new javax.swing.JRadioButton();
        ri_rseqRadioButton = new javax.swing.JRadioButton();
        iseqRadioButton = new javax.swing.JRadioButton();
        iseq_reRadioButton = new javax.swing.JRadioButton();
        annotationStrategyPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        maxHysteresisLimitTextField = new javax.swing.JTextField();
        maxInterGenicDistanceTextField = new javax.swing.JTextField();
        maxOperatorDistanceOutGeneTextField = new javax.swing.JTextField();
        maxOperatorDistanceInGeneTextField = new javax.swing.JTextField();
        filteringStrategyPanel = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        listSizeAbsoluteRadioButton = new javax.swing.JRadioButton();
        listSizeAbsoluteTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        listSizeRelativeRadioButton = new javax.swing.JRadioButton();
        listSizeRelativeTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        thresholdNormalizedRadioButton = new javax.swing.JRadioButton();
        thresholdNormalizedTextField = new javax.swing.JTextField();
        thresholdSDBandRadioButton = new javax.swing.JRadioButton();
        thresholdSDBandTextField = new javax.swing.JTextField();
        resultOptionsPanel = new javax.swing.JPanel();
        generateLogsCheckBox = new javax.swing.JCheckBox();
        viewResultsCheckBox = new javax.swing.JCheckBox();
        generateResultButton = new javax.swing.JButton();
        defaultOptionsButton = new javax.swing.JButton();
        pathOptionsFilePanel = new javax.swing.JPanel();
        setDefaultPathLabel = new javax.swing.JLabel();
        setDefaultPathTextField = new javax.swing.JTextField();
        setDefaultPathBrowseButton = new javax.swing.JButton();
        currentOptionsFileLabel = new javax.swing.JLabel();
        currentOptionsFileValueLabel = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        genomeFileChooser = new javax.swing.JFileChooser();
        sitesFileChooser = new javax.swing.JFileChooser();
        resultsFileChooser = new javax.swing.JFileChooser();
        scoringMethodButtonGroup = new javax.swing.ButtonGroup();
        resultListSizeButtonGroup = new javax.swing.ButtonGroup();
        thresholdScorebuttonGroup = new javax.swing.ButtonGroup();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        setDefaultPathFileChooser = new javax.swing.JFileChooser();
        optionsFileChooser = new javax.swing.JFileChooser();
        saveOptionFileBeforeGeneratingResultFileChooser = new javax.swing.JFileChooser();

        mainPanel.setMaximumSize(new java.awt.Dimension(550, 732));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setNextFocusableComponent(genomeFilePathTextField);
        mainPanel.setPreferredSize(new java.awt.Dimension(550, 732));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(edu.umbc.combio.erilllab.jfitom.gui.Main.class).getContext().getResourceMap(MainView.class);
        filesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("filesPanel.border.title"))); // NOI18N
        filesPanel.setName("filesPanel"); // NOI18N
        filesPanel.setPreferredSize(new java.awt.Dimension(550, 732));

        genomeFilePathTextField.setBackground(resourceMap.getColor("genomeFilePathTextField.background")); // NOI18N
        genomeFilePathTextField.setEditable(false);
        genomeFilePathTextField.setForeground(resourceMap.getColor("genomeFilePathTextField.foreground")); // NOI18N
        genomeFilePathTextField.setText(resourceMap.getString("genomeFilePathTextField.text")); // NOI18N
        genomeFilePathTextField.setToolTipText(resourceMap.getString("genomeFilePathTextField.toolTipText")); // NOI18N
        genomeFilePathTextField.setName("genomeFilePathTextField"); // NOI18N

        genomeFileButton.setText(resourceMap.getString("genomeFileButton.text")); // NOI18N
        genomeFileButton.setToolTipText(resourceMap.getString("genomeFileButton.toolTipText")); // NOI18N
        genomeFileButton.setName("genomeFileButton"); // NOI18N
        genomeFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                genomeFileButtonMouseClicked(evt);
            }
        });

        sitesFilePathTextField.setBackground(resourceMap.getColor("sitesFilePathTextField.background")); // NOI18N
        sitesFilePathTextField.setEditable(false);
        sitesFilePathTextField.setForeground(resourceMap.getColor("sitesFilePathTextField.foreground")); // NOI18N
        sitesFilePathTextField.setText(resourceMap.getString("sitesFilePathTextField.text")); // NOI18N
        sitesFilePathTextField.setToolTipText(resourceMap.getString("sitesFilePathTextField.toolTipText")); // NOI18N
        sitesFilePathTextField.setName("sitesFilePathTextField"); // NOI18N

        sitesFileButton.setText(resourceMap.getString("sitesFileButton.text")); // NOI18N
        sitesFileButton.setToolTipText(resourceMap.getString("sitesFileButton.toolTipText")); // NOI18N
        sitesFileButton.setName("sitesFileButton"); // NOI18N
        sitesFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sitesFileButtonMouseClicked(evt);
            }
        });

        resultFilePathTextField.setBackground(resourceMap.getColor("resultFilePathTextField.background")); // NOI18N
        resultFilePathTextField.setEditable(false);
        resultFilePathTextField.setForeground(resourceMap.getColor("resultFilePathTextField.foreground")); // NOI18N
        resultFilePathTextField.setText(resourceMap.getString("resultFilePathTextField.text")); // NOI18N
        resultFilePathTextField.setToolTipText(resourceMap.getString("resultFilePathTextField.toolTipText")); // NOI18N
        resultFilePathTextField.setName("resultFilePathTextField"); // NOI18N

        saveResultButton.setText(resourceMap.getString("saveResultButton.text")); // NOI18N
        saveResultButton.setToolTipText(resourceMap.getString("saveResultButton.toolTipText")); // NOI18N
        saveResultButton.setName("saveResultButton"); // NOI18N
        saveResultButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                saveResultButtonMouseClicked(evt);
            }
        });

        palindromeCheckBox.setSelected(true);
        palindromeCheckBox.setText(resourceMap.getString("palindromeCheckBox.text")); // NOI18N
        palindromeCheckBox.setName("palindromeCheckBox"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        javax.swing.GroupLayout filesPanelLayout = new javax.swing.GroupLayout(filesPanel);
        filesPanel.setLayout(filesPanelLayout);
        filesPanelLayout.setHorizontalGroup(
            filesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filesPanelLayout.createSequentialGroup()
                .addComponent(jLabel9)
                .addContainerGap(223, Short.MAX_VALUE))
            .addGroup(filesPanelLayout.createSequentialGroup()
                .addComponent(jLabel10)
                .addContainerGap())
            .addGroup(filesPanelLayout.createSequentialGroup()
                .addGroup(filesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, filesPanelLayout.createSequentialGroup()
                        .addComponent(sitesFilePathTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sitesFileButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, filesPanelLayout.createSequentialGroup()
                        .addComponent(genomeFilePathTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(genomeFileButton)))
                .addGap(2, 2, 2))
            .addGroup(filesPanelLayout.createSequentialGroup()
                .addComponent(palindromeCheckBox)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, filesPanelLayout.createSequentialGroup()
                .addComponent(resultFilePathTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveResultButton))
            .addGroup(filesPanelLayout.createSequentialGroup()
                .addComponent(jLabel11)
                .addContainerGap())
        );

        filesPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {genomeFileButton, saveResultButton, sitesFileButton});

        filesPanelLayout.setVerticalGroup(
            filesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, filesPanelLayout.createSequentialGroup()
                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(filesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(genomeFilePathTextField)
                    .addComponent(genomeFileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(filesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sitesFilePathTextField)
                    .addComponent(sitesFileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(palindromeCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jLabel11)
                .addGap(2, 2, 2)
                .addGroup(filesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resultFilePathTextField)
                    .addComponent(saveResultButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(19, 19, 19))
        );

        scoringMethodsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("scoringMethodsPanel.border.title"))); // NOI18N
        scoringMethodsPanel.setName("scoringMethodsPanel"); // NOI18N

        scoringMethodButtonGroup.add(riRadioButton);
        riRadioButton.setSelected(true);
        riRadioButton.setText(resourceMap.getString("RI_RadioButton.text")); // NOI18N
        riRadioButton.setToolTipText(resourceMap.getString("RI_RadioButton.toolTipText")); // NOI18N
        riRadioButton.setName("RI_RadioButton"); // NOI18N

        scoringMethodButtonGroup.add(ri_rseqRadioButton);
        ri_rseqRadioButton.setText(resourceMap.getString("RI_RSEQ_RadioButton.text")); // NOI18N
        ri_rseqRadioButton.setName("RI_RSEQ_RadioButton"); // NOI18N

        scoringMethodButtonGroup.add(iseqRadioButton);
        iseqRadioButton.setText(resourceMap.getString("ISEQ_RadioButton.text")); // NOI18N
        iseqRadioButton.setName("ISEQ_RadioButton"); // NOI18N

        scoringMethodButtonGroup.add(iseq_reRadioButton);
        iseq_reRadioButton.setText(resourceMap.getString("ISEQ_RE_RadioButton.text")); // NOI18N
        iseq_reRadioButton.setName("ISEQ_RE_RadioButton"); // NOI18N

        javax.swing.GroupLayout scoringMethodsPanelLayout = new javax.swing.GroupLayout(scoringMethodsPanel);
        scoringMethodsPanel.setLayout(scoringMethodsPanelLayout);
        scoringMethodsPanelLayout.setHorizontalGroup(
            scoringMethodsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(scoringMethodsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(riRadioButton)
                .addGap(56, 56, 56)
                .addComponent(ri_rseqRadioButton)
                .addGap(28, 28, 28)
                .addComponent(iseqRadioButton)
                .addGap(43, 43, 43)
                .addComponent(iseq_reRadioButton)
                .addContainerGap(258, Short.MAX_VALUE))
        );
        scoringMethodsPanelLayout.setVerticalGroup(
            scoringMethodsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(scoringMethodsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(ri_rseqRadioButton)
                .addComponent(iseqRadioButton)
                .addComponent(iseq_reRadioButton)
                .addComponent(riRadioButton))
        );

        annotationStrategyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("annotationStrategyPanel.border.title"))); // NOI18N
        annotationStrategyPanel.setName("annotationStrategyPanel"); // NOI18N

        jLabel1.setText(resourceMap.getString("maxHysteresisLimitLabel.text")); // NOI18N
        jLabel1.setName("maxHysteresisLimitLabel"); // NOI18N

        jLabel2.setText(resourceMap.getString("maxInterGenicDistanceLabel.text")); // NOI18N
        jLabel2.setName("maxInterGenicDistanceLabel"); // NOI18N

        jLabel3.setText(resourceMap.getString("maxOpDistanceOutLabel.text")); // NOI18N
        jLabel3.setName("maxOpDistanceOutLabel"); // NOI18N

        jLabel4.setText(resourceMap.getString("maxOpDistanceInLabel.text")); // NOI18N
        jLabel4.setName("maxOpDistanceInLabel"); // NOI18N

        maxHysteresisLimitTextField.setText(resourceMap.getString("maxHysteresisLimitTextField.text")); // NOI18N
        maxHysteresisLimitTextField.setToolTipText(resourceMap.getString("maxHysteresisLimitTextField.toolTipText")); // NOI18N
        maxHysteresisLimitTextField.setName("maxHysteresisLimitTextField"); // NOI18N

        maxInterGenicDistanceTextField.setText(resourceMap.getString("maxInterGenicDistanceTextField.text")); // NOI18N
        maxInterGenicDistanceTextField.setToolTipText(resourceMap.getString("maxInterGenicDistanceTextField.toolTipText")); // NOI18N
        maxInterGenicDistanceTextField.setName("maxInterGenicDistanceTextField"); // NOI18N

        maxOperatorDistanceOutGeneTextField.setText(resourceMap.getString("maxOperatorDistanceOutGeneTextField.text")); // NOI18N
        maxOperatorDistanceOutGeneTextField.setToolTipText(resourceMap.getString("maxOperatorDistanceOutGeneTextField.toolTipText")); // NOI18N
        maxOperatorDistanceOutGeneTextField.setName("maxOperatorDistanceOutGeneTextField"); // NOI18N

        maxOperatorDistanceInGeneTextField.setText(resourceMap.getString("maxOperatorDistanceInGeneTextField.text")); // NOI18N
        maxOperatorDistanceInGeneTextField.setToolTipText(resourceMap.getString("maxOperatorDistanceInGeneTextField.toolTipText")); // NOI18N
        maxOperatorDistanceInGeneTextField.setName("maxOperatorDistanceInGeneTextField"); // NOI18N

        javax.swing.GroupLayout annotationStrategyPanelLayout = new javax.swing.GroupLayout(annotationStrategyPanel);
        annotationStrategyPanel.setLayout(annotationStrategyPanelLayout);
        annotationStrategyPanelLayout.setHorizontalGroup(
            annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(annotationStrategyPanelLayout.createSequentialGroup()
                .addGroup(annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(57, 57, 57)
                .addGroup(annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(maxInterGenicDistanceTextField)
                    .addComponent(maxOperatorDistanceOutGeneTextField)
                    .addComponent(maxOperatorDistanceInGeneTextField)
                    .addComponent(maxHysteresisLimitTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(372, Short.MAX_VALUE))
        );
        annotationStrategyPanelLayout.setVerticalGroup(
            annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(annotationStrategyPanelLayout.createSequentialGroup()
                .addGroup(annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(maxHysteresisLimitTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(maxInterGenicDistanceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(maxOperatorDistanceOutGeneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(annotationStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(maxOperatorDistanceInGeneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        filteringStrategyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("filteringStrategyPanel.border.title"))); // NOI18N
        filteringStrategyPanel.setName("filteringStrategyPanel"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        resultListSizeButtonGroup.add(listSizeAbsoluteRadioButton);
        listSizeAbsoluteRadioButton.setSelected(true);
        listSizeAbsoluteRadioButton.setText(resourceMap.getString("listSizeAbsoluteRadioButton.text")); // NOI18N
        listSizeAbsoluteRadioButton.setName("listSizeAbsoluteRadioButton"); // NOI18N
        listSizeAbsoluteRadioButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listSizeAbsoluteRadioButtonMouseClicked(evt);
            }
        });

        listSizeAbsoluteTextField.setText(resourceMap.getString("listSizeAbsoluteTextField.text")); // NOI18N
        listSizeAbsoluteTextField.setToolTipText(resourceMap.getString("listSizeAbsoluteTextField.toolTipText")); // NOI18N
        listSizeAbsoluteTextField.setName("listSizeAbsoluteTextField"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        resultListSizeButtonGroup.add(listSizeRelativeRadioButton);
        listSizeRelativeRadioButton.setText(resourceMap.getString("listSizeRelativeRadioButton.text")); // NOI18N
        listSizeRelativeRadioButton.setName("listSizeRelativeRadioButton"); // NOI18N
        listSizeRelativeRadioButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listSizeRelativeRadioButtonMouseClicked(evt);
            }
        });

        listSizeRelativeTextField.setText(resourceMap.getString("listSizeRelativeTextField.text")); // NOI18N
        listSizeRelativeTextField.setName("listSizeRelativeTextField"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        thresholdScorebuttonGroup.add(thresholdNormalizedRadioButton);
        thresholdNormalizedRadioButton.setSelected(true);
        thresholdNormalizedRadioButton.setText(resourceMap.getString("thresholdNormalizedRadioButton.text")); // NOI18N
        thresholdNormalizedRadioButton.setName("thresholdNormalizedRadioButton"); // NOI18N
        thresholdNormalizedRadioButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                thresholdNormalizedRadioButtonMouseClicked(evt);
            }
        });

        thresholdNormalizedTextField.setText(resourceMap.getString("thresholdNormalizedTextField.text")); // NOI18N
        thresholdNormalizedTextField.setToolTipText(resourceMap.getString("thresholdNormalizedTextField.toolTipText")); // NOI18N
        thresholdNormalizedTextField.setName("thresholdNormalizedTextField"); // NOI18N

        thresholdScorebuttonGroup.add(thresholdSDBandRadioButton);
        thresholdSDBandRadioButton.setText(resourceMap.getString("thresholdSDBandRadioButton.text")); // NOI18N
        thresholdSDBandRadioButton.setActionCommand(resourceMap.getString("thresholdSDBandRadioButton.actionCommand")); // NOI18N
        thresholdSDBandRadioButton.setName("thresholdSDBandRadioButton"); // NOI18N
        thresholdSDBandRadioButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                thresholdSDBandRadioButtonMouseClicked(evt);
            }
        });

        thresholdSDBandTextField.setText(resourceMap.getString("thresholdSDBandTextField.text")); // NOI18N
        thresholdSDBandTextField.setName("thresholdSDBandTextField"); // NOI18N

        javax.swing.GroupLayout filteringStrategyPanelLayout = new javax.swing.GroupLayout(filteringStrategyPanel);
        filteringStrategyPanel.setLayout(filteringStrategyPanelLayout);
        filteringStrategyPanelLayout.setHorizontalGroup(
            filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filteringStrategyPanelLayout.createSequentialGroup()
                .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(filteringStrategyPanelLayout.createSequentialGroup()
                        .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(listSizeRelativeRadioButton)
                                .addComponent(listSizeAbsoluteRadioButton))
                            .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel8)
                                .addComponent(jLabel5)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(listSizeRelativeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(listSizeAbsoluteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6)))
                    .addGroup(filteringStrategyPanelLayout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, filteringStrategyPanelLayout.createSequentialGroup()
                                .addComponent(thresholdSDBandRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(thresholdSDBandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(filteringStrategyPanelLayout.createSequentialGroup()
                                .addComponent(thresholdNormalizedRadioButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(thresholdNormalizedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(315, Short.MAX_VALUE))
        );

        filteringStrategyPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {thresholdNormalizedTextField, thresholdSDBandTextField});

        filteringStrategyPanelLayout.setVerticalGroup(
            filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filteringStrategyPanelLayout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listSizeAbsoluteRadioButton)
                    .addComponent(listSizeAbsoluteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listSizeRelativeRadioButton)
                    .addComponent(listSizeRelativeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(thresholdNormalizedRadioButton)
                    .addComponent(thresholdNormalizedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(filteringStrategyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(thresholdSDBandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(thresholdSDBandRadioButton)))
        );

        resultOptionsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("resultOptionsPanel.border.title"))); // NOI18N
        resultOptionsPanel.setName("resultOptionsPanel"); // NOI18N

        generateLogsCheckBox.setSelected(true);
        generateLogsCheckBox.setText(resourceMap.getString("generateLogsCheckBox.text")); // NOI18N
        generateLogsCheckBox.setName("generateLogsCheckBox"); // NOI18N

        viewResultsCheckBox.setSelected(true);
        viewResultsCheckBox.setText(resourceMap.getString("viewResultsCheckBox.text")); // NOI18N
        viewResultsCheckBox.setName("viewResultsCheckBox"); // NOI18N

        generateResultButton.setText(resourceMap.getString("generateResultButton.text")); // NOI18N
        generateResultButton.setName("generateResultButton"); // NOI18N
        generateResultButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                generateResultButtonMouseClicked(evt);
            }
        });

        defaultOptionsButton.setText(resourceMap.getString("defaultOptionsButton.text")); // NOI18N
        defaultOptionsButton.setName("defaultOptionsButton"); // NOI18N
        defaultOptionsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                defaultOptionsButtonMouseClicked(evt);
            }
        });
        defaultOptionsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultOptionsButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout resultOptionsPanelLayout = new javax.swing.GroupLayout(resultOptionsPanel);
        resultOptionsPanel.setLayout(resultOptionsPanelLayout);
        resultOptionsPanelLayout.setHorizontalGroup(
            resultOptionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultOptionsPanelLayout.createSequentialGroup()
                .addGroup(resultOptionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(generateResultButton)
                    .addComponent(generateLogsCheckBox))
                .addGap(18, 18, 18)
                .addGroup(resultOptionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(viewResultsCheckBox)
                    .addComponent(defaultOptionsButton))
                .addContainerGap(299, Short.MAX_VALUE))
        );
        resultOptionsPanelLayout.setVerticalGroup(
            resultOptionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultOptionsPanelLayout.createSequentialGroup()
                .addGroup(resultOptionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(generateLogsCheckBox)
                    .addComponent(viewResultsCheckBox))
                .addGap(18, 18, 18)
                .addGroup(resultOptionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(generateResultButton)
                    .addComponent(defaultOptionsButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pathOptionsFilePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("pathOptionsFilePanel.border.title"))); // NOI18N
        pathOptionsFilePanel.setName("pathOptionsFilePanel"); // NOI18N

        setDefaultPathLabel.setText(resourceMap.getString("setDefaultPathLabel.text")); // NOI18N
        setDefaultPathLabel.setName("setDefaultPathLabel"); // NOI18N

        setDefaultPathTextField.setForeground(resourceMap.getColor("setDefaultPathTextField.foreground")); // NOI18N
        setDefaultPathTextField.setText(resourceMap.getString("setDefaultPathTextField.text")); // NOI18N
        setDefaultPathTextField.setName("setDefaultPathTextField"); // NOI18N

        setDefaultPathBrowseButton.setText(resourceMap.getString("setDefaultPathBrowseButton.text")); // NOI18N
        setDefaultPathBrowseButton.setName("setDefaultPathBrowseButton"); // NOI18N
        setDefaultPathBrowseButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                setDefaultPathBrowseButtonMouseClicked(evt);
            }
        });

        currentOptionsFileLabel.setText(resourceMap.getString("currentOptionsFileLabel.text")); // NOI18N
        currentOptionsFileLabel.setName("currentOptionsFileLabel"); // NOI18N

        currentOptionsFileValueLabel.setForeground(resourceMap.getColor("currentOptionsFileValueLabel.foreground")); // NOI18N
        currentOptionsFileValueLabel.setText(resourceMap.getString("currentOptionsFileValueLabel.text")); // NOI18N
        currentOptionsFileValueLabel.setName("currentOptionsFileValueLabel"); // NOI18N

        javax.swing.GroupLayout pathOptionsFilePanelLayout = new javax.swing.GroupLayout(pathOptionsFilePanel);
        pathOptionsFilePanel.setLayout(pathOptionsFilePanelLayout);
        pathOptionsFilePanelLayout.setHorizontalGroup(
            pathOptionsFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(setDefaultPathLabel)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pathOptionsFilePanelLayout.createSequentialGroup()
                .addComponent(setDefaultPathTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(setDefaultPathBrowseButton))
            .addGroup(pathOptionsFilePanelLayout.createSequentialGroup()
                .addComponent(currentOptionsFileLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(currentOptionsFileValueLabel)
                .addGap(151, 151, 151))
        );
        pathOptionsFilePanelLayout.setVerticalGroup(
            pathOptionsFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pathOptionsFilePanelLayout.createSequentialGroup()
                .addComponent(setDefaultPathLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pathOptionsFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(setDefaultPathTextField)
                    .addComponent(setDefaultPathBrowseButton, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
                .addGap(28, 28, 28)
                .addGroup(pathOptionsFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(currentOptionsFileLabel)
                    .addComponent(currentOptionsFileValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE))
                .addContainerGap(113, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(filesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pathOptionsFilePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(scoringMethodsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(annotationStrategyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(filteringStrategyPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(resultOptionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pathOptionsFilePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(filesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scoringMethodsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(annotationStrategyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filteringStrategyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(resultOptionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(350, 350, 350))
        );

        resultOptionsPanel.getAccessibleContext().setAccessibleName(resourceMap.getString("resultOptionsPanel.AccessibleContext.accessibleName")); // NOI18N

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

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(edu.umbc.combio.erilllab.jfitom.gui.Main.class).getContext().getActionMap(MainView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        genomeFileChooser.setDialogTitle(resourceMap.getString("genomeFileChooser.dialogTitle")); // NOI18N
        genomeFileChooser.setName("genomeFileChooser"); // NOI18N

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

        resultsFileChooser.setDialogTitle(resourceMap.getString("resultsFileChooser.dialogTitle")); // NOI18N
        resultsFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
        resultsFileChooser.setName("resultsFileChooser"); // NOI18N

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

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

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

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

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

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 481, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setDefaultPathFileChooser.setDialogTitle(resourceMap.getString("setDefaultPathFileChooser.dialogTitle")); // NOI18N
        setDefaultPathFileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
        setDefaultPathFileChooser.setName("setDefaultPathFileChooser"); // NOI18N

        optionsFileChooser.setCurrentDirectory(null);
        optionsFileChooser.setDialogTitle(resourceMap.getString("optionsFileChooser.dialogTitle")); // NOI18N
        optionsFileChooser.setName("optionsFileChooser"); // NOI18N

        saveOptionFileBeforeGeneratingResultFileChooser.setDialogTitle(resourceMap.getString("saveOptionFileBeforeGeneratingResultFileChooser.dialogTitle")); // NOI18N
        saveOptionFileBeforeGeneratingResultFileChooser.setSelectedFile(new java.io.File("C:\\Program Files\\NetBeans 6.9.1\\JFitom.opt"));
        saveOptionFileBeforeGeneratingResultFileChooser.setName("saveOptionFileBeforeGeneratingResultFileChooser"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void genomeFileButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_genomeFileButtonMouseClicked
        genomeFileChooser.setCurrentDirectory(new File(jarPath));
        int returnVal = genomeFileChooser.showOpenDialog(Main.getApplication().getMainFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = genomeFileChooser.getSelectedFile();
            genomeFilePathTextField.setText(file.getAbsolutePath());
        
        } else {
            log(Level.SEVERE, "File access cancelled by user.");
            setStatusBarText("File access cancelled by user.");
        }

    }//GEN-LAST:event_genomeFileButtonMouseClicked

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);         // TODO add your handling code here:
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void sitesFileButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sitesFileButtonMouseClicked
        sitesFileChooser.setCurrentDirectory(new File(jarPath));
        int returnVal = sitesFileChooser.showOpenDialog(Main.getApplication().getMainFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = sitesFileChooser.getSelectedFile();
            sitesFilePathTextField.setText(file.getAbsolutePath());

        } else {
            log(Level.SEVERE, "File access cancelled by user.");
            setStatusBarText("File access cancelled by user.");
        }
    }//GEN-LAST:event_sitesFileButtonMouseClicked

    private void saveResultButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_saveResultButtonMouseClicked
        resultsFileChooser.setCurrentDirectory(new File(jarPath));
        int returnVal = resultsFileChooser.showOpenDialog(Main.getApplication().getMainFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = resultsFileChooser.getSelectedFile();
            resultFilePathTextField.setText(file.getAbsolutePath());

        } else {
            log(Level.SEVERE, "File access cancelled by user.");
            statusMessageLabel.setText("File access cancelled by user.");
        }
    }//GEN-LAST:event_saveResultButtonMouseClicked

    private boolean validateForm(){
        log(Level.INFO, "Validating form.");
        setStatusBarText("Validating form.");
        boolean formValidationPassed = true;

        // We need to set all the text fields background white
        // before starting validation
        genomeFilePathTextField.setBackground(Color.white);
        sitesFilePathTextField.setBackground(Color.white);
        resultFilePathTextField.setBackground(Color.white);
        maxHysteresisLimitTextField.setBackground(Color.white);
        maxInterGenicDistanceTextField.setBackground(Color.white);
        maxOperatorDistanceOutGeneTextField.setBackground(Color.white);
        maxOperatorDistanceInGeneTextField.setBackground(Color.white);
        listSizeAbsoluteTextField.setBackground(Color.white);
        listSizeRelativeTextField.setBackground(Color.white);
        thresholdNormalizedTextField.setBackground(Color.white);
        thresholdSDBandTextField.setBackground(Color.white);


        if("".equals(genomeFilePathTextField.getText().trim()) || "Show genome file".equals(genomeFilePathTextField.getText().trim())){
            // The user has not specified a genome file
            genomeFilePathTextField.setBackground(Color.yellow);
            return false;
        }

        if("".equals(sitesFilePathTextField.getText().trim()) || "Show sites file".equals(sitesFilePathTextField.getText().trim())){
            // The user has not specified a sites file
            sitesFilePathTextField.setBackground(Color.yellow);
            return false;
        }

        if("".equals(resultFilePathTextField.getText().trim()) || "Specify output file path".equals(resultFilePathTextField.getText().trim())){
            // The user has not specified an output file
            resultFilePathTextField.setBackground(Color.yellow);
            return false;
        }

        if("".equals(maxHysteresisLimitTextField.getText().trim())){
            // The user has not specified the maximum hysteresis limit
            maxHysteresisLimitTextField.setBackground(Color.yellow);
            return false;
        } else {
            // The input is non-empty. We check whether it is an integer
            try {
//                Integer.parseInt(maxHysteresisLimitTextField.getText().trim());
                if(Integer.parseInt(maxHysteresisLimitTextField.getText().trim()) > 500 || Integer.parseInt(maxHysteresisLimitTextField.getText().trim()) < 0){
                    maxHysteresisLimitTextField.setBackground(Color.yellow);
                    return false;
                }
            } catch (NumberFormatException e) {

                maxHysteresisLimitTextField.setBackground(Color.yellow);
                return false;
            }

        }

        if("".equals(maxInterGenicDistanceTextField.getText().trim())){
            // The user has not specified the maximum intergenic distance
            maxInterGenicDistanceTextField.setBackground(Color.yellow);
            return false;
        } else {
            // The input is non-empty. We check whether it is an integer
            try {
//                Integer.parseInt(maxInterGenicDistanceTextField.getText().trim());
                if(Integer.parseInt(maxInterGenicDistanceTextField.getText().trim()) > 500 || Integer.parseInt(maxInterGenicDistanceTextField.getText().trim()) < 0){
                    maxInterGenicDistanceTextField.setBackground(Color.yellow);
                    return false;
                }
            } catch (NumberFormatException e) {
                maxInterGenicDistanceTextField.setBackground(Color.yellow);
                return false;
            }

        }

        if("".equals(maxOperatorDistanceOutGeneTextField.getText().trim())){
            // The user has not specified the maximum operator distance outside of a gene
            maxOperatorDistanceOutGeneTextField.setBackground(Color.yellow);
            return false;
        } else {
            // The input is non-empty. We check whether it is an integer
            try {
//                Integer.parseInt(maxOperatorDistanceOutGeneTextField.getText().trim());
                if(Integer.parseInt(maxOperatorDistanceOutGeneTextField.getText().trim()) > 500 || Integer.parseInt(maxOperatorDistanceOutGeneTextField.getText().trim()) < 0){
                    maxOperatorDistanceOutGeneTextField.setBackground(Color.yellow);
                    return false;
                }
            } catch (NumberFormatException e) {
                maxOperatorDistanceOutGeneTextField.setBackground(Color.yellow);
                return false;
            }

        }

        if("".equals(maxOperatorDistanceInGeneTextField.getText().trim())){
            // The user has not specified the maximum operator distance inside of a gene
            maxOperatorDistanceInGeneTextField.setBackground(Color.yellow);
            return false;
        } else {
            // The input is non-empty. We check whether it is an integer
            try {
//                Integer.parseInt(maxOperatorDistanceInGeneTextField.getText().trim());
                if(Integer.parseInt(maxOperatorDistanceInGeneTextField.getText().trim()) > 500 || Integer.parseInt(maxOperatorDistanceInGeneTextField.getText().trim()) < 0){
                    maxOperatorDistanceInGeneTextField.setBackground(Color.yellow);
                    return false;
                }
            } catch (NumberFormatException e) {
                maxOperatorDistanceInGeneTextField.setBackground(Color.yellow);
                return false;
            }

        }

        if(listSizeAbsoluteRadioButton.isSelected()){
            // So the user has specified an absolute result size. Now we validate the size input.
            if("".equals(listSizeAbsoluteTextField.getText().trim())){
                // The user has not specified the the size of result
                listSizeAbsoluteTextField.setBackground(Color.yellow);
                return false;
            } else {
                // The input is non-empty. We check whether it is an integer
                try {
//                    Integer.parseInt(listSizeAbsoluteTextField.getText().trim());
                    if(Integer.parseInt(listSizeAbsoluteTextField.getText().trim()) > 150 || Integer.parseInt(listSizeAbsoluteTextField.getText().trim()) < 1){
                        listSizeAbsoluteTextField.setBackground(Color.yellow);
                        return false;
                    }
                } catch (NumberFormatException e) {
                    listSizeAbsoluteTextField.setBackground(Color.yellow);
                    return false;
                }

            }
        } else {
            // So the user has specified a relative result size. Now we validate the size input.
            if("".equals(listSizeRelativeTextField.getText().trim())){
                // The user has not specified the the size of result
                listSizeRelativeTextField.setBackground(Color.yellow);
                return false;
            } else {
                // The input is non-empty. We check whether it is an integer
                try {
//                    Integer.parseInt(listSizeRelativeTextField.getText().trim());
                    if(Integer.parseInt(listSizeRelativeTextField.getText().trim()) > 100 || Integer.parseInt(listSizeRelativeTextField.getText().trim()) < 0){
                        listSizeRelativeTextField.setBackground(Color.yellow);
                        return false;
                    }
                } catch (NumberFormatException e) {
                    listSizeRelativeTextField.setBackground(Color.yellow);
                    return false;
                }

            }
        }

        if(thresholdNormalizedRadioButton.isSelected()){
            // So the user has specified normalized threshold score. Now we validate the input.
            if("".equals(thresholdNormalizedTextField.getText().trim())){
                // The value field is blank
                thresholdNormalizedTextField.setBackground(Color.yellow);
                return false;
            } else {
                // The input is non-empty. We check whether it is an integer
                try {
//                    Double.parseDouble(thresholdNormalizedTextField.getText().trim());
                    if(Double.parseDouble(thresholdNormalizedTextField.getText().trim()) > 1.0 || Double.parseDouble(thresholdNormalizedTextField.getText().trim()) < 0.0){
                        thresholdNormalizedTextField.setBackground(Color.yellow);
                        return false;
                    }
                } catch (NumberFormatException e) {
                    thresholdNormalizedTextField.setBackground(Color.yellow);
                    return false;
                }

            }
        } else {
            // So the user has specified SD band as threshold score. Now we validate the input.
            if("".equals(thresholdSDBandTextField.getText().trim())){
                // The value field is blank
                thresholdSDBandTextField.setBackground(Color.yellow);
                return false;
            } else {
                // The input is non-empty. We check whether it is an integer
                try {
                    Double.parseDouble(thresholdSDBandTextField.getText());
                } catch (NumberFormatException e) {
                    thresholdSDBandTextField.setBackground(Color.yellow);
                    return false;
                }

            }
        }

        

        return formValidationPassed;
    }

    private void log(Level level, String logMessage){
        if(generateLogsCheckBox.isSelected()){
            LOGGER.log(level, logMessage);
        }
    }

    public void setStatusBarText(String text){
        statusMessageLabel.setText(text);
        statusMessageLabel.paintImmediately(statusMessageLabel.getVisibleRect());
    }

    private void generateResultButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_generateResultButtonMouseClicked
        File f = new File("JFITOM.OPT");
        setStatusBarText("Generating result...");
        log(Level.INFO, "Generating result");
        if(validateForm()){
            // All the inputs are validated
            log(Level.INFO, "Form validation passed.");
            setStatusBarText("Form validation passed.");
            
            // We always save options first.
            
                log(Level.INFO, "Saving options...");
                setStatusBarText("Saving options...");
                try {

                    // The user has not chosed any option file. So, JFitom askes 
                    // her to specify a file to save the options. If she doesn't
                    // specify any name the options will be saved in 
                    // JFitom.opt by default.
                    if("".equals(this.optionsFileName)){
                        saveOptionFileBeforeGeneratingResultFileChooser.setCurrentDirectory(new File(jarPath));
                        int retValue = saveOptionFileBeforeGeneratingResultFileChooser.showOpenDialog(Main.getApplication().getMainFrame());

                        if (retValue == JFileChooser.APPROVE_OPTION) {
                            f= saveOptionFileBeforeGeneratingResultFileChooser.getSelectedFile();
                            currentOptionsFileValueLabel.setText(f.getAbsolutePath());
                        } else if (retValue == JFileChooser.CANCEL_OPTION){
                            f = new File("JFITOM.OPT");
                            log(Level.SEVERE, "The user has not specified any options file. Using default file JFitom.opt available in the same directory.");
                            statusMessageLabel.setText("The user has not specified any options file. Using default file JFitom.opt available in the same directory.");
                        }
                    }
                    // Before saving the new options we have to delete the file.
                    System.out.println("Done with file choosing");

                    // Make sure the file or directory exists and isn't write protected
                    if (!f.exists()){
                        setStatusBarText("No options file exists.");
                        log(Level.INFO, "No options file exists.");
//                        return;
                    } else {
                        if (!f.canWrite()){
                            setStatusBarText("We cannot overwrite the options file.");
                            log(Level.INFO, "We cannot overwrite the options file.");
                            return;
                        }

                        // Attempt to delete it
                        boolean success = f.delete();

                        if (!success){
                            setStatusBarText("We cannot delete the old options file.");
                            log(Level.INFO, "We cannot delete the old options file.");
                            return;
                        }
                    }

                    

                    // We were able to delete the old options file.
//                    String NEW_LINE = "\n";
                    String NEW_LINE = System.getProperty("line.separator"); // Making it platform independent

                    // The user opted to save the options
                    FileWriter optionsFile = new FileWriter(f.getAbsolutePath());
                    System.out.println("Started saving the file");
                    optionsFile.append("latestGenomeFile=" + genomeFilePathTextField.getText().trim());
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("latestSitesFile=" + sitesFilePathTextField.getText().trim());
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("isPalindrome=" + (palindromeCheckBox.isSelected()? "Y" : "N"));
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("latestOutputFile=" + resultFilePathTextField.getText().trim());
                    optionsFile.append(NEW_LINE);

                    if(riRadioButton.isSelected()){
                        optionsFile.append("scoreMethod=" + Integer.toString(Motif.SCORE_METHOD_RI));
                    } else if(ri_rseqRadioButton.isSelected()){
                        optionsFile.append("scoreMethod=" + Integer.toString(Motif.SCORE_METHOD_RI_RSEQ));
                    } else if(iseqRadioButton.isSelected()){
                        optionsFile.append("scoreMethod="  + Integer.toString(Motif.SCORE_METHOD_ISEQ));
                    } else {
                        optionsFile.append("scoreMethod="  + Integer.toString(Motif.SCORE_METHOD_ISEQ_RE));
                    }

                    optionsFile.append(NEW_LINE);
                    optionsFile.append("maxHysteresisLimit=" + maxHysteresisLimitTextField.getText().trim());
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("maxIntergenicDistance=" + maxInterGenicDistanceTextField.getText().trim());
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("maxOperatorDistanceOut=" + maxOperatorDistanceOutGeneTextField.getText().trim());
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("maxOperatorDistanceIn=" + maxOperatorDistanceInGeneTextField.getText().trim());
                    optionsFile.append(NEW_LINE);
                    
                    if(listSizeAbsoluteRadioButton.isSelected()){
                        optionsFile.append("resultSizeMethod="  + Integer.toString(FilterStrategy.LIST_SIZE_IN_NUMBER));
                        optionsFile.append(NEW_LINE);
                        optionsFile.append("resultSizeMethodValue=" + listSizeAbsoluteTextField.getText().trim());
                        optionsFile.append(NEW_LINE);
                    } else {
                        optionsFile.append("resultSizeMethod=" + Integer.toString(FilterStrategy.LIST_SIZE_IN_PERCENT));
                        optionsFile.append(NEW_LINE);
                        optionsFile.append("resultSizeMethodValue=" + listSizeRelativeTextField.getText().trim());
                        optionsFile.append(NEW_LINE);
                    }

                    if(thresholdNormalizedRadioButton.isSelected()){
                        optionsFile.append("thresholdScoreMethod=" + Integer.toString(FilterStrategy.THRESHOLD_METHOD_NORMALIZED));
                        optionsFile.append(NEW_LINE);
                        optionsFile.append("thresholdScoreValue=" + thresholdNormalizedTextField.getText().trim());
                        optionsFile.append(NEW_LINE);
                    } else {
                        optionsFile.append("thresholdScoreMethod=" + Integer.toString(FilterStrategy.THRESHOLD_METHOD_SD_BAND));
                        optionsFile.append(NEW_LINE);
                        optionsFile.append("thresholdScoreValue=" + thresholdSDBandTextField.getText().trim());
                        optionsFile.append(NEW_LINE);
                    }

                    optionsFile.append("generateLog=" + (generateLogsCheckBox.isSelected() ? "Y" : "N"));
                    optionsFile.append(NEW_LINE);
                    optionsFile.append("viewResult=" + (viewResultsCheckBox.isSelected() ? "Y" : "N"));
                    optionsFile.append(NEW_LINE);

                    // Generating the file
		    optionsFile.flush();
		    optionsFile.close();
                    System.out.println("Done with writing");

                    setStatusBarText("New options saved.");


                } catch (IOException ex) {
                    setStatusBarText("I/O error occured while saving options.");
                    return;
                }
            

            // So writing the options is down. Now we start real business.
            JFitomWrapper commandLineWrapper = new JFitomWrapper();
            commandLineWrapper.loadOptionsFromFile("JFITOM.opt");
            commandLineWrapper.setMainView(this);
            commandLineWrapper.computeResult(genomeFilePathTextField.getText().trim(), sitesFilePathTextField.getText().trim());

            if(viewResultsCheckBox.isSelected()){
                Runtime run = Runtime.getRuntime();
                try {
//                    Process pr = run.exec(resultFilePathTextField.getText().trim());
                    Runtime.getRuntime().exec("cmd /c start excel.exe" + " \"" + resultFilePathTextField.getText().trim() + "\"");
                } catch (IOException ex) {
                    Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
                    log(Level.SEVERE, "Result cannot be opened using MS Excel.");
                    setStatusBarText("Result cannot be opened using MS Excel.");
                } catch (Exception e){
                    log(Level.SEVERE, "Result cannot be opened using MS Excel.");
                    setStatusBarText("Result cannot be opened using MS Excel.");
                }
            }


        } else {
            log(Level.SEVERE, "Form validation failed.");
            setStatusBarText("Form validation failed.");
        }
        
    }//GEN-LAST:event_generateResultButtonMouseClicked



    

    private void listSizeAbsoluteRadioButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listSizeAbsoluteRadioButtonMouseClicked
        listSizeAbsoluteTextField.setEditable(true);
        listSizeRelativeTextField.setEditable(false);
    }//GEN-LAST:event_listSizeAbsoluteRadioButtonMouseClicked

    private void listSizeRelativeRadioButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listSizeRelativeRadioButtonMouseClicked
        listSizeRelativeTextField.setEditable(true);
        listSizeAbsoluteTextField.setEditable(false);
    }//GEN-LAST:event_listSizeRelativeRadioButtonMouseClicked

    private void thresholdNormalizedRadioButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_thresholdNormalizedRadioButtonMouseClicked
        thresholdNormalizedTextField.setEditable(true);
        thresholdSDBandTextField.setEditable(false);
    }//GEN-LAST:event_thresholdNormalizedRadioButtonMouseClicked

    private void thresholdSDBandRadioButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_thresholdSDBandRadioButtonMouseClicked
        thresholdSDBandTextField.setEditable(true);
        thresholdNormalizedTextField.setEditable(false);
    }//GEN-LAST:event_thresholdSDBandRadioButtonMouseClicked

    private void defaultOptionsButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_defaultOptionsButtonMouseClicked
        initializeUIControlsWithDefaultValues();
    }//GEN-LAST:event_defaultOptionsButtonMouseClicked

    private void defaultOptionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultOptionsButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_defaultOptionsButtonActionPerformed

    private void setDefaultPathBrowseButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setDefaultPathBrowseButtonMouseClicked
        // TODO add your handling code here:
        setDefaultPathFileChooser.setCurrentDirectory(new File(jarPath));
        int returnVal = setDefaultPathFileChooser.showOpenDialog(Main.getApplication().getMainFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            // We save the new default path in file variable
            File file = setDefaultPathFileChooser.getSelectedFile();
            setDefaultPathTextField.setText(file.getAbsolutePath());
            defaultPath = file.getAbsolutePath();
            genomeFileChooser.setCurrentDirectory(file);
            sitesFileChooser.setCurrentDirectory(file);
            optionsFileChooser.setCurrentDirectory(file);

            // Now we get a list of options (.OPT) files under the default directory
            File[] optFiles = JFitomWUtil.getFilesWithExtUnderDirectory(defaultPath, ".OPT");

            // If there is atleast one options (.OPT) file
            if(optFiles.length > 0){
                // We allow the user to choose her option file.
               FileNameExtensionFilter filter = new FileNameExtensionFilter("Only the options files (.OPT)", "OPT");
               // We set the current directory of the options file chooser dialogue to default current directory
               optionsFileChooser.setCurrentDirectory(file);
               // Only the options files (OPT) will be displayed in the file list
               optionsFileChooser.setFileFilter(filter);
               int retValue = optionsFileChooser.showOpenDialog(Main.getApplication().getMainFrame());
               if(retValue == JFileChooser.APPROVE_OPTION){
                    File optionsFile = optionsFileChooser.getSelectedFile();
                    optionsFileName = optionsFile.getName();
                    currentOptionsFileValueLabel.setText(optionsFileName);

                    // Loading the options from file
                    initializeUIControlsFromOptionsFile(defaultPath + "\\"+ optionsFileName, "", "");
               } else if(retValue == JFileChooser.CANCEL_OPTION){
                    optionsFileName = "";
                    currentOptionsFileValueLabel.setText(optionsFileName);
               }
            }
        } else {
            log(Level.SEVERE, "User cancelled selecting default path.");
            setStatusBarText("User cancelled selecting default path.");
        }
    }//GEN-LAST:event_setDefaultPathBrowseButtonMouseClicked
    public void setJarPath(String path){
        this.jarPath = path;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JPanel annotationStrategyPanel;
    javax.swing.JLabel currentOptionsFileLabel;
    javax.swing.JLabel currentOptionsFileValueLabel;
    javax.swing.JButton defaultOptionsButton;
    javax.swing.JPanel filesPanel;
    javax.swing.JPanel filteringStrategyPanel;
    javax.swing.JCheckBox generateLogsCheckBox;
    javax.swing.JButton generateResultButton;
    javax.swing.JButton genomeFileButton;
    javax.swing.JFileChooser genomeFileChooser;
    javax.swing.JTextField genomeFilePathTextField;
    javax.swing.JRadioButton iseqRadioButton;
    javax.swing.JRadioButton iseq_reRadioButton;
    javax.swing.JLabel jLabel1;
    javax.swing.JLabel jLabel10;
    javax.swing.JLabel jLabel11;
    javax.swing.JLabel jLabel2;
    javax.swing.JLabel jLabel3;
    javax.swing.JLabel jLabel4;
    javax.swing.JLabel jLabel5;
    javax.swing.JLabel jLabel6;
    javax.swing.JLabel jLabel7;
    javax.swing.JLabel jLabel8;
    javax.swing.JLabel jLabel9;
    javax.swing.JRadioButton listSizeAbsoluteRadioButton;
    javax.swing.JTextField listSizeAbsoluteTextField;
    javax.swing.JRadioButton listSizeRelativeRadioButton;
    javax.swing.JTextField listSizeRelativeTextField;
    javax.swing.JPanel mainPanel;
    javax.swing.JTextField maxHysteresisLimitTextField;
    javax.swing.JTextField maxInterGenicDistanceTextField;
    javax.swing.JTextField maxOperatorDistanceInGeneTextField;
    javax.swing.JTextField maxOperatorDistanceOutGeneTextField;
    javax.swing.JMenuBar menuBar;
    javax.swing.JFileChooser optionsFileChooser;
    javax.swing.JCheckBox palindromeCheckBox;
    javax.swing.JPanel pathOptionsFilePanel;
    private javax.swing.JProgressBar progressBar;
    javax.swing.JTextField resultFilePathTextField;
    javax.swing.ButtonGroup resultListSizeButtonGroup;
    javax.swing.JPanel resultOptionsPanel;
    javax.swing.JFileChooser resultsFileChooser;
    javax.swing.JRadioButton riRadioButton;
    javax.swing.JRadioButton ri_rseqRadioButton;
    javax.swing.JFileChooser saveOptionFileBeforeGeneratingResultFileChooser;
    javax.swing.JButton saveResultButton;
    javax.swing.ButtonGroup scoringMethodButtonGroup;
    javax.swing.JPanel scoringMethodsPanel;
    javax.swing.JButton setDefaultPathBrowseButton;
    javax.swing.JFileChooser setDefaultPathFileChooser;
    javax.swing.JLabel setDefaultPathLabel;
    javax.swing.JTextField setDefaultPathTextField;
    javax.swing.JButton sitesFileButton;
    javax.swing.JFileChooser sitesFileChooser;
    javax.swing.JTextField sitesFilePathTextField;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    javax.swing.JPanel statusPanel;
    javax.swing.JRadioButton thresholdNormalizedRadioButton;
    javax.swing.JTextField thresholdNormalizedTextField;
    javax.swing.JRadioButton thresholdSDBandRadioButton;
    javax.swing.JTextField thresholdSDBandTextField;
    javax.swing.ButtonGroup thresholdScorebuttonGroup;
    javax.swing.JCheckBox viewResultsCheckBox;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
