<commit_before>package io.dimitris.scriptbar;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;

import org.apache.commons.lang3.text.WordUtils;
import org.eclipse.epsilon.egl.EglTemplateFactory;
import org.eclipse.epsilon.egl.EglTemplateFactoryModuleAdapter;
import org.eclipse.epsilon.egl.exceptions.EglRuntimeException;
import org.eclipse.epsilon.emc.plainxml.PlainXmlModel;
import org.eclipse.epsilon.eol.execute.context.Variable;

import apple.applescript.AppleScriptEngine;

public class ScriptBar extends JDialog {
	
	protected String directory = "scripts";
	protected GridLayout gridLayout = new GridLayout(1,1);
	protected File defaultDirectory = null;
	
	public static void main(String[] args) throws Exception {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		new ScriptBar().run();
	}

	@SuppressWarnings("unchecked")
	protected void run() throws Exception {
		
		File[] profiles = new File(directory).getCanonicalFile().listFiles();
		
		Arrays.sort(profiles, new Comparator<File>() {
			@Override
			public int compare(File f1, File f2) {
				return f1.getName().compareTo(f2.getName());
			}
		});
		
		JComboBox<Object> comboBox = new JComboBox<Object>(profiles);
		comboBox.putClientProperty("JComboBox.isPopDown", Boolean.TRUE);
		getContentPane().add(comboBox);
		comboBox.setRenderer(new FileCellRenderer(comboBox.getRenderer()));
		
		comboBox.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent e) {
				try {
					setProfile((File)e.getItem());
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		});
		
		addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                System.exit(0);
            }
        });
		
		this.getContentPane().setLayout(gridLayout);
		//this.setTitle("ScriptBar");
		this.setBounds((int)getToolkit().getScreenSize().getWidth() - 300, 200, 200, 500);
		
		this.setAlwaysOnTop(true);
		this.setResizable(false);
		
		for (File f : profiles) {
			if (f.isDirectory()) {
				setProfile(f);
				break;
			}
		}
		
		this.setVisible(true);
	}
	
	protected void setProfile(File profile) throws IOException {
		
		ArrayList<JButton> buttons = new ArrayList<JButton>();
		
		// Clear old buttons
		
		for (Component component : getContentPane().getComponents()) {
			if (component instanceof JButton) buttons.add((JButton) component);
		}
		
		for (JButton button : buttons) {
			getContentPane().remove(button);
		}
		
		buttons.clear();
		
		// Add new buttons
		
		File[] files = profile.getCanonicalFile().listFiles();
		
		Arrays.sort(files, new Comparator<File>() {
			@Override
			public int compare(File f1, File f2) {
				return f1.getName().compareTo(f2.getName());
			}<commit_msg>Filter out files from list of profiles<commit_after>package io.dimitris.scriptbar;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;

import org.apache.commons.lang3.text.WordUtils;
import org.eclipse.epsilon.egl.EglTemplateFactory;
import org.eclipse.epsilon.egl.EglTemplateFactoryModuleAdapter;
import org.eclipse.epsilon.egl.exceptions.EglRuntimeException;
import org.eclipse.epsilon.emc.plainxml.PlainXmlModel;
import org.eclipse.epsilon.eol.execute.context.Variable;

import apple.applescript.AppleScriptEngine;

public class ScriptBar extends JDialog {
	
	protected String directory = "scripts";
	protected GridLayout gridLayout = new GridLayout(1,1);
	protected File defaultDirectory = null;
	
	public static void main(String[] args) throws Exception {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		new ScriptBar().run();
	}

	@SuppressWarnings("unchecked")
	protected void run() throws Exception {
		
		File[] profiles = new File(directory).getCanonicalFile().listFiles(new java.io.FileFilter() {
			
			@Override
			public boolean accept(File pathname) {
				return pathname.isDirectory();
			}
		});
		
		Arrays.sort(profiles, new Comparator<File>() {
			@Override
			public int compare(File f1, File f2) {
				return f1.getName().compareTo(f2.getName());
			}
		});
		
		JComboBox<Object> comboBox = new JComboBox<Object>(profiles);
		comboBox.putClientProperty("JComboBox.isPopDown", Boolean.TRUE);
		getContentPane().add(comboBox);
		comboBox.setRenderer(new FileCellRenderer(comboBox.getRenderer()));
		
		comboBox.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent e) {
				try {
					setProfile((File)e.getItem());
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		});
		
		addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                System.exit(0);
            }
        });
		
		this.getContentPane().setLayout(gridLayout);
		//this.setTitle("ScriptBar");
		this.setBounds((int)getToolkit().getScreenSize().getWidth() - 300, 200, 200, 500);
		
		this.setAlwaysOnTop(true);
		this.setResizable(false);
		setProfile(profiles[0]);
		
		this.setVisible(true);
	}
	
	protected void setProfile(File profile) throws IOException {
		
		ArrayList<JButton> buttons = new ArrayList<JButton>();
		
		// Clear old buttons
		
		for (Component component : getContentPane().getComponents()) {
			if (component instanceof JButton) buttons.add((JButton) component);
		}
		
		for (JButton button : buttons) {
			getContentPane().remove(button);
		}
		
		buttons.clear();
		
		// Add new buttons
		
		File[] files = profile.getCanonicalFile().listFiles();
		
		Arrays.sort(files, new Comparator<File>() {
			@Override
			public int compare(File f1, File f2) {
				return f1.getName().compareTo(f2.getName());
			}
{'fraction_non_alphanumeric': 0.1197398114960839, 'fraction_numerical': 0.007035709544670118, 'mean_word_length': 4.487254187909687, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1888816', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2286, 'n_words': 455}