<commit_before>package dr.app.bss;

import jam.panels.OptionsPanel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import dr.app.gui.components.RealNumberField;

/**
 * @author <NAME>
 * @version $Id$
 */
public class DemographicModelEditor {

	// Data
	private PartitionDataList dataList = null;
	private int row;
	
	// Settings
	private OptionsPanel optionPanel;
	private JComboBox demographicCombo;
	private RealNumberField[] demographicParameterFields;

	//Buttons
	private JButton done;
	private JButton cancel;
	
	// Window
	private JDialog window;
	private Frame owner;
	
	public DemographicModelEditor(PartitionDataList dataList, int row) {
		
		this.dataList = dataList;
		this.row = row;
		
		demographicParameterFields = new RealNumberField[PartitionData.demographicParameterNames.length];
		window = new JDialog(owner, "Setup demographic model for partition " + (row + 1));
		optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);
		
		demographicCombo = new JComboBox();
		demographicCombo.setOpaque(false);

		for (String demographicModel : PartitionData.demographicModels) {
			demographicCombo.addItem(demographicModel);
		}// END: fill loop

		demographicCombo.addItemListener(new ListenDemographicCombo());
		
		for (int i = 0; i < PartitionData.demographicParameterNames.length; i++) {
			demographicParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
			demographicParameterFields[i].setColumns(8);
			demographicParameterFields[i].setValue(this.dataList.get(row).demographicParameterValues[i]);
		}// END: fill loop

		setDemographicArguments();

		// Buttons
		JPanel buttonsHolder = new JPanel();
		buttonsHolder.setOpaque(false);
		
		cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
		cancel.addActionListener(new ListenCancel());
		buttonsHolder.add(cancel);
		
		done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
		done.addActionListener(new ListenOk());
		buttonsHolder.add(done);
		
		// Window
		owner = Utils.getActiveFrame();
		window.setLocationRelativeTo(owner);
		window.getContentPane().setLayout(new BorderLayout());
		window.getContentPane().add(optionPanel, BorderLayout.CENTER);
		window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH);
		window.pack();
		
		//return to the previously chosen index on start
		demographicCombo.setSelectedIndex(dataList.get(row).demographicModelIndex);
		
	}//END: Constructor
	
	private void setDemographicArguments() {

		optionPanel.removeAll();
		optionPanel.addComponents(new JLabel("Demographic model:"), demographicCombo);
		optionPanel.addSeparator();
		optionPanel.addLabel("Set parameter values:");

		int index = demographicCombo.getSelectedIndex();

		for (int i = 0; i < PartitionData.demographicParameterIndices[index].length; i++) {

			int k = PartitionData.demographicParameterIndices[index][i];

			JPanel panel = new JPanel(new BorderLayout(6, 6));
			panel.add(demographicParameterFields[k], BorderLayout.WEST);<commit_msg>labels on Tree model editor<commit_after>package dr.app.bss;

import jam.panels.OptionsPanel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import dr.app.gui.components.RealNumberField;

/**
 * @author <NAME>
 * @version $Id$
 */
public class DemographicModelEditor {

	// Data
	private PartitionDataList dataList = null;
	private int row;
	
	// Settings
	private OptionsPanel optionPanel;
	private JComboBox demographicCombo;
	private RealNumberField[] demographicParameterFields;

	//Buttons
	private JButton done;
	private JButton cancel;
	
	// Window
	private JDialog window;
	private Frame owner;
	
	public DemographicModelEditor(PartitionDataList dataList, int row) {
		
		this.dataList = dataList;
		this.row = row;
		
		demographicParameterFields = new RealNumberField[PartitionData.demographicParameterNames.length];
		window = new JDialog(owner, "Setup tree model for partition " + (row + 1));
		optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);
		
		demographicCombo = new JComboBox();
		demographicCombo.setOpaque(false);

		for (String demographicModel : PartitionData.demographicModels) {
			demographicCombo.addItem(demographicModel);
		}// END: fill loop

		demographicCombo.addItemListener(new ListenDemographicCombo());
		
		for (int i = 0; i < PartitionData.demographicParameterNames.length; i++) {
			demographicParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
			demographicParameterFields[i].setColumns(8);
			demographicParameterFields[i].setValue(this.dataList.get(row).demographicParameterValues[i]);
		}// END: fill loop

		setDemographicArguments();

		// Buttons
		JPanel buttonsHolder = new JPanel();
		buttonsHolder.setOpaque(false);
		
		cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
		cancel.addActionListener(new ListenCancel());
		buttonsHolder.add(cancel);
		
		done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
		done.addActionListener(new ListenOk());
		buttonsHolder.add(done);
		
		// Window
		owner = Utils.getActiveFrame();
		window.setLocationRelativeTo(owner);
		window.getContentPane().setLayout(new BorderLayout());
		window.getContentPane().add(optionPanel, BorderLayout.CENTER);
		window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH);
		window.pack();
		
		//return to the previously chosen index on start
		demographicCombo.setSelectedIndex(dataList.get(row).demographicModelIndex);
		
	}//END: Constructor
	
	private void setDemographicArguments() {

		optionPanel.removeAll();
		optionPanel.addComponents(new JLabel("Tree model:"), demographicCombo);
		optionPanel.addSeparator();
		optionPanel.addLabel("Set parameter values:");

		int index = demographicCombo.getSelectedIndex();

		for (int i = 0; i < PartitionData.demographicParameterIndices[index].length; i++) {

			int k = PartitionData.demographicParameterIndices[index][i];

			JPanel panel = new JPanel(new BorderLayout(6, 6));
			panel.add(demographicParameterFields[k], BorderLayout.WEST);
{'fraction_non_alphanumeric': 0.11166617690273288, 'fraction_numerical': 0.003526300323244196, 'mean_word_length': 5.427762039660057, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '4615503', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2013, 'n_words': 419}