<commit_before>package gui;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import shared.EvolveDirector;

/**
 * @author linneasahlberg
 * @author jasonfortunato
 * @author alexdennis
 *
 * Started 9/18/16
 * The main GUI class. Combines all of the panes into one JFrame.
 *
 */

public class GUI extends JPanel {

	private static final long serialVersionUID = 1L;
	public static boolean DEBUG_MATE = false;
	public static boolean DEBUG_REPRO = false;
	public static boolean DEBUG_MIGRATION = false;
	public static boolean DEBUG_SURVIVAL = false;
	public static boolean DEBUG_MUTATION = false;
	public static boolean DEBUG_SUMMARY = false;

	boolean firstRun = true;

	// we'll put args here
	shared.SessionParameters parms;

	// GUI buttons
	JButton submit;

	// Error stuff for invalid inputs
	JFrame errorFrame;
	JButton okay;

  HeaderPane hp = new HeaderPane();
  InitPopPane pp = new InitPopPane();
	GeneticDriftPane gd = new GeneticDriftPane();
	SelectionPane sp = new SelectionPane();
	MutationPane mp = new MutationPane();
	MigrationPane mip = new MigrationPane();
	SexSelectPane ssp = new SexSelectPane();

  JPanel mainPanel;

	/**
	 * Member to enable singleton class
	 */
	public static GUI instance = null;

	/**
	 * Returns singleton instance of SimulationEngine
	 * @return singleton instance of SimulationEngine
	 */
	public static GUI getInstance() {
		if (instance == null) {
			instance  = new GUI();
		}
		return instance;
	}

	/**
	 * This is the panel that will be added to the window (the frame)
	 */
	private GUI() {
		super();

    setLayout(new BorderLayout());
    mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));

    mainPanel.add(hp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(pp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(gd);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(sp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(mp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(mip);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(ssp);

    JScrollPane mainScroll = new JScrollPane(mainPanel);
    mainScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    add(mainScroll, BorderLayout.CENTER);

		submit = new JButton("<html><span style='font-size:13px'>Run Simulation");
		Color buttonColor = new Color(115, 229, 103);
		submit.setBackground(buttonColor);
		add(submit, BorderLayout.PAGE_END);

    modeThreeAlleles(false);

		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// Create a new, blank sesh parms object on each submit click
				parms = new shared.SessionParameters();
				try {
					applyInfo();
					EvolveDirector.getInstance().resetSimulationEngine();
					EvolveDirector.getInstance().storeSessionParameters(parms);
					new SimWorker().execute();

				} catch (Exception e1) {
					errorFrame = new JFrame();
					JLabel errorText = new JLabel("<html><font color = red> <b> One or more inputs are incorrect.  Verify every active box has the appropriate input.");
					//errorText.setFont(new Font("Serif", Font.PLAIN, 32));
					errorFrame.setTitle("Invalid input");
					errorFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

					Border padding = BorderFactory.createEmptyBorder(20, 20, 20, 20);
					errorText.setBorder(padding);
					errorFrame.add(errorText, BorderLayout.NORTH);
					okay = new JButton("Okay");
					errorFrame.add(okay, BorderLayout.EAST);
					errorFrame.pack();
					errorFrame.setVisible(true);
					okay.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							errorFrame.dispatchEvent(new WindowEvent(errorFrame, WindowEvent.WINDOW_CLOSING));
						}
					});
					e1.printStackTrace();
				}
			}
		});
	} // end of constructor

	public void modeThreeAlleles(boolean b){
		pp.modeThreeAlleles(b);
		sp.modeThreeAlleles(b);
		mp.modeThreeAlleles(b);
		mip.modeThreeAlleles(b);
		ssp.modeThreeAlleles(b);
	}

	/**
	 *  pushes data to sesh parms
	 */
	public void applyInfo() { //throws Exception {
		// Submit info from the EvoPanes if necessary
		//fp.submit(parms);
    hp.submit(parms);
		pp.submit(parms);
		if(parms.isPopSizeChecked())
			gd.submit(parms);<commit_msg>Fixing scrolling bug<commit_after>package gui;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.Scrollable;
import javax.swing.BoxLayout;
import javax.swing.JSeparator;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import shared.EvolveDirector;

/**
 * @author linneasahlberg
 * @author jasonfortunato
 * @author alexdennis
 *
 * Started 9/18/16
 * The main GUI class. Combines all of the panes into one JFrame.
 *
 */

public class GUI extends JPanel {

	private static final long serialVersionUID = 1L;
	public static boolean DEBUG_MATE = false;
	public static boolean DEBUG_REPRO = false;
	public static boolean DEBUG_MIGRATION = false;
	public static boolean DEBUG_SURVIVAL = false;
	public static boolean DEBUG_MUTATION = false;
	public static boolean DEBUG_SUMMARY = false;

	// we'll put args here
	shared.SessionParameters parms;

	// GUI buttons
	JButton submit;

	// Error stuff for invalid inputs
	JFrame errorFrame;
	JButton okay;

  HeaderPane hp = new HeaderPane();
  InitPopPane pp = new InitPopPane();
	GeneticDriftPane gd = new GeneticDriftPane();
	SelectionPane sp = new SelectionPane();
	MutationPane mp = new MutationPane();
	MigrationPane mip = new MigrationPane();
	SexSelectPane ssp = new SexSelectPane();

	/**
	 * Member to enable singleton class
	 */
	public static GUI instance = null;

	/**
	 * Returns singleton instance of SimulationEngine
	 * @return singleton instance of SimulationEngine
	 */
	public static GUI getInstance() {
		if (instance == null) {
			instance  = new GUI();
		}
		return instance;
	}

	/**
	 * This is the panel that will be added to the window (the frame)
	 */
	private GUI() {
		super();

    setLayout(new BorderLayout());
    EvoScrollable mainPanel = new EvoScrollable();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));

    mainPanel.add(hp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(pp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(gd);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(sp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(mp);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(mip);
    mainPanel.add(new JSeparator(JSeparator.HORIZONTAL));
    mainPanel.add(ssp);

    JScrollPane mainScroll = new JScrollPane(mainPanel);
    mainScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    add(mainScroll, BorderLayout.CENTER);

		submit = new JButton("<html><span style='font-size:13px'>Run Simulation");
		Color buttonColor = new Color(115, 229, 103);
		submit.setBackground(buttonColor);
		add(submit, BorderLayout.PAGE_END);

    modeThreeAlleles(false);

		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// Create a new, blank sesh parms object on each submit click
				parms = new shared.SessionParameters();
				try {
					applyInfo();
					EvolveDirector.getInstance().resetSimulationEngine();
					EvolveDirector.getInstance().storeSessionParameters(parms);
					new SimWorker().execute();

				} catch (Exception e1) {
					errorFrame = new JFrame();
					JLabel errorText = new JLabel("<html><font color = red> <b> One or more inputs are incorrect.  Verify every active box has the appropriate input.");
					//errorText.setFont(new Font("Serif", Font.PLAIN, 32));
					errorFrame.setTitle("Invalid input");
					errorFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

					Border padding = BorderFactory.createEmptyBorder(20, 20, 20, 20);
					errorText.setBorder(padding);
					errorFrame.add(errorText, BorderLayout.NORTH);
					okay = new JButton("Okay");
					errorFrame.add(okay, BorderLayout.EAST);
					errorFrame.pack();
					errorFrame.setVisible(true);
					okay.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							errorFrame.dispatchEvent(new WindowEvent(errorFrame, WindowEvent.WINDOW_CLOSING));
						}
					});
					e1.printStackTrace();
				}
			}
		});
	} // end of constructor

  public class EvoScrollable extends JPanel implements Scrollable {
    public Dimension getPreferredScrollableViewportSize() {
      return getPreferredSize();
    }

    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
      return 10;
    }

    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
      return 100;
    }

    public boolean getScrollableTracksViewportWidth() {
      return true;
    }

    public boolean getScrollableTracksViewportHeight() {
      return false;
    }
  }

	public void modeThreeAlleles(boolean b){
		pp.modeThreeAlleles(b);
		sp.modeThreeAlleles(b);
		mp.modeThreeAlleles(b);
		mip.modeThreeAlleles(b);
		ssp.modeThreeAlleles(b);
	}

	/**
	 *  pushes data to sesh parms
	 */
	public void applyInfo() { //throws Exception {
		// Submit info from the EvoPanes if necessary
		//fp.submit(parms);
    hp.submit(parms);
		pp.submit(parms);
		if(parms.isPopSizeChecked())
			gd.submit(parms);
{'fraction_non_alphanumeric': 0.10659848559347035, 'fraction_numerical': 0.006195299439472908, 'mean_word_length': 4.136363636363637, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3050106', 'n_tokens_mistral': 3576, 'n_tokens_neox': 3175, 'n_words': 761}