<commit_before>package edu.wustl.cab2b.client.ui.filter;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;

import edu.wustl.cab2b.client.ui.WindowUtilities;
import edu.wustl.cab2b.client.ui.controls.Cab2bButton;
import edu.wustl.cab2b.client.ui.controls.Cab2bPanel;
import edu.wustl.cab2b.client.ui.mainframe.NewWelcomePanel;
import edu.wustl.cab2b.client.ui.experiment.ExperimentDataCategoryGridPanel;

/**
 * Class to implement the filter pop-up
 * 
 * @author hrishikesh_rajpathak
 * 
 */
public abstract class Cab2bFilterPopup extends Cab2bPanel {

	protected JDialog dialog;

	protected Cab2bButton okButton, cancelButton;

	protected String columnName;

	protected int columnIndex;

	/**
	 * Constructor to generate pop-up
	 * 
	 * @param colName
	 * @param colIndex
	 */
	public Cab2bFilterPopup(String colName, int colIndex) {
		this.columnName = colName;
		this.columnIndex = colIndex;
		// Cancle button listener
		cancelButton = new Cab2bButton("Cancel");
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dialog.dispose();
			}
		});
		// Generic OK button listener
		okButton = new Cab2bButton("Ok");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				CaB2BFilterInterface filter = okActionPerformed(e);

				ExperimentDataCategoryGridPanel.addFilter(columnName, filter);
				dialog.dispose();
			}

		});
	}

	/**
	 * Abstract method to be implemented by individual pop-ups on "OK" buttom
	 * click.
	 * 
	 * @param e
	 * @return
	 */
	protected abstract CaB2BFilterInterface okActionPerformed(ActionEvent e);

	public JDialog showInDialog() {
		dialog = WindowUtilities.setInDialog(NewWelcomePanel.mainFrame, this,
				"Set Filter", new Dimension(250, 150), true, false);
		dialog.setVisible(true);
		return dialog;
	}<commit_msg>Filter pop-up size adaption according to the size of the filter<commit_after>package edu.wustl.cab2b.client.ui.filter;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;

import edu.wustl.cab2b.client.ui.WindowUtilities;
import edu.wustl.cab2b.client.ui.controls.Cab2bButton;
import edu.wustl.cab2b.client.ui.controls.Cab2bPanel;
import edu.wustl.cab2b.client.ui.mainframe.NewWelcomePanel;
import edu.wustl.cab2b.client.ui.experiment.ExperimentDataCategoryGridPanel;

/**
 * Class to implement the filter pop-up
 * 
 * @author hrishikesh_rajpathak
 * 
 */
public abstract class Cab2bFilterPopup extends Cab2bPanel {

	protected JDialog dialog;

	protected Cab2bButton okButton, cancelButton;

	protected String columnName;

	protected int columnIndex;

	/**
	 * Constructor to generate pop-up
	 * 
	 * @param colName
	 * @param colIndex
	 */
	public Cab2bFilterPopup(String colName, int colIndex) {
		this.columnName = colName;
		this.columnIndex = colIndex;
		// Cancle button listener
		cancelButton = new Cab2bButton("Cancel");
		cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dialog.dispose();
			}
		});
		// Generic OK button listener
		okButton = new Cab2bButton("Ok");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				CaB2BFilterInterface filter = okActionPerformed(e);

				ExperimentDataCategoryGridPanel.addFilter(columnName, filter);
				dialog.dispose();
			}

		});
	}

	/**
	 * Abstract method to be implemented by individual pop-ups on "OK" buttom
	 * click.
	 * 
	 * @param e
	 * @return
	 */
	protected abstract CaB2BFilterInterface okActionPerformed(ActionEvent e);

	public JDialog showInDialog() {
		Dimension dimension=null;
		if(this instanceof PatternPopup)
		{
			dimension=new Dimension(250,100);
		}
		else
			if(this instanceof RangePopup)
			{
				dimension=new Dimension(250,125);
			}
			else
				if(this instanceof EnumeratedFilterPopUp)
				{
					dimension=new Dimension(250,175);
				}
		dialog = WindowUtilities.setInDialog(NewWelcomePanel.mainFrame, this,
				"Set Filter", dimension, true, false);
		dialog.setVisible(true);
		return dialog;
	}
{'fraction_non_alphanumeric': 0.1003796867584243, 'fraction_numerical': 0.013289036544850499, 'mean_word_length': 4.355781448538755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5397977', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1359, 'n_words': 291}