<commit_before>package gui;
import java.awt.Color;
import java.awt.Desktop;
import java.io.File;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import messages.Message;
import net.miginfocom.swing.MigLayout;
import utilities.Controller;
import utilities.FileDrop;
import utilities.FileHandler;
import utilities.PreferencesManager;
import utilities.ProgramState;
import utilities.ResourceLoader;
@SuppressWarnings({"serial", "static-access"})
public class FileCopyManager extends JFrame {
	Controller controller = new Controller();
	StatusFrame status = new StatusFrame();
	private FileHandler fHandler = new FileHandler();
	private ResourceLoader rc = new ResourceLoader(fHandler);
	private PreferencesManager pManager = new PreferencesManager(this);
	private Message msg = new Message();
	private JMenuBar menuBar = new JMenuBar();
	private JMenu fileMenu = new JMenu("File"), editMenu = new JMenu("Edit");
	private JMenuItem saveList = new JMenuItem("Save queue"),
			exit = new JMenuItem("Exit"),
			loadList = new JMenuItem("Load queue"),
			showPreferences = new JMenuItem("Preferences"),
			exportPreferences = new JMenuItem("Export Preferences"),
			deleteApp=new JMenuItem("Delete app settings"),
			restartApp=new JMenuItem("Restart Application");
	private File selectedFile = null;
	private String destinationPath;
	private ArrayList<File> files = new ArrayList<>();
	private JPanel panel = new JPanel();
	private JFileChooser chooser = new JFileChooser();
	private JButton addFiles, selectDestination, copyFile, copyFiles,
			deleteFile, deleteAll, openDestinationFolder;
	private JComboBox<String> fileNames;
	private DefaultComboBoxModel<String> model;
	private int selectedFileIndex;
	private JTextField dragPanel = new JTextField(20);
	private JLabel dragLabel;
	String sep = File.separator;
	private File listFile = new File("app"+PreferencesManager.sep+"userList.dat");
	public void showFiles() {
		fileNames.setVisible(files.size() > 0);
	}
	public void restart(){
		//First close the current instance of the program
		this.dispose();
		//and create a new instance
		new FileCopyManager();
	}
	private void init() {
		fileMenu.add(saveList);
		fileMenu.add(loadList);
		fileMenu.add(exit);
		editMenu.add(showPreferences);
		editMenu.add(exportPreferences);
		editMenu.add(restartApp);
		editMenu.add(deleteApp);
		menuBar.add(fileMenu);
		menuBar.add(editMenu);
		addFiles = new JButton("Add files to copy");
		copyFiles = new JButton("Copy all files");
		deleteFile = new JButton("Delete file from list");
		selectDestination = new JButton("Select Destination Folder");
		openDestinationFolder = new JButton("Open Destination Folder");
		deleteAll = new JButton("Delete all files from list");
		model = new DefaultComboBoxModel<String>();
		JFrame curFrame = this;
		fileNames = new JComboBox<String>(model);
		fileNames.setVisible(false);
		addFiles.addActionListener((e) -> {
			chooser.setMultiSelectionEnabled(true);
			chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
			chooser.setDialogTitle("Select files to copy");
			int r = chooser.showOpenDialog(panel);
			if (r != JFileChooser.APPROVE_OPTION)
				return;
			for (File f : chooser.getSelectedFiles()) {
				files.add(f);
				String name = f.getName()
						+ (f.isDirectory() ? " (Folder)" : "");
				model.addElement(name);
			}
			selectedFile = files.get(0);
			selectedFileIndex = 0;
			fileNames.setSelectedIndex(0);
			fileNames.setVisible(files.size() > 0);
			this.pack();
		});
		fileNames.addActionListener((e) -> {
			selectedFileIndex = files.size()==1?0:fileNames.getSelectedIndex();
			selectedFile = selectedFileIndex == -1 ?null:files.get(selectedFileIndex);
		});
		copyFile = new JButton("Copy selected file");
		copyFile.addActionListener((e) -> {
			String message = destinationPath== null && selectedFile == null?"Selecte at least a file and a destination folder "
					:selectedFile == null?" Select at least one file to copy":"Select a directory to copy selected file(s) in";
			if (destinationPath == null || selectedFile == null) {
				msg.error(panel, message);
				return;
			}
			fHandler.copy(selectedFile, destinationPath);
		});

		copyFiles.addActionListener((e) -> {
			if(destinationPath == null)
				msg.error(panel, "Please select a destination folder","No destination folder selected");
			try{
				for(File f:files){
					SwingUtilities.invokeLater(()->{
						status.text(f.getName()).showStatus();
						fHandler.copy(f,destinationPath);
					});	
				}	
			}
			catch(Exception ee){
				msg.error(panel, "Error occured.Se log file for more", "Error");
				fHandler.log(ee.getMessage());
			}
			finally{
				status.dispose();
			}
		});

		deleteFile.addActionListener((e) -> {
			if (selectedFile == null) {<commit_msg>A new thread is used every time you want to copy one or multiple files to prevent UI from freezing when copying large files<commit_after>package gui;
import java.awt.Color;
import java.awt.Desktop;
import java.io.File;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import messages.Message;
import net.miginfocom.swing.MigLayout;
import utilities.Controller;
import utilities.FileDrop;
import utilities.FileHandler;
import utilities.PreferencesManager;
import utilities.ProgramState;
import utilities.ResourceLoader;
@SuppressWarnings({"serial", "static-access"})
public class FileCopyManager extends JFrame {
	Controller controller = new Controller();
	StatusFrame status = new StatusFrame();
	private FileHandler fHandler = new FileHandler();
	private ResourceLoader rc = new ResourceLoader(fHandler);
	private PreferencesManager pManager = new PreferencesManager(this);
	private Message msg = new Message();
	private JMenuBar menuBar = new JMenuBar();
	private JMenu fileMenu = new JMenu("File"), editMenu = new JMenu("Edit");
	private JMenuItem saveList = new JMenuItem("Save queue"),
			exit = new JMenuItem("Exit"),
			loadList = new JMenuItem("Load queue"),
			showPreferences = new JMenuItem("Preferences"),
			exportPreferences = new JMenuItem("Export Preferences"),
			deleteApp=new JMenuItem("Delete app settings"),
			restartApp=new JMenuItem("Restart Application");
	private File selectedFile = null;
	private String destinationPath;
	private ArrayList<File> files = new ArrayList<>();
	private JPanel panel = new JPanel();
	private JFileChooser chooser = new JFileChooser();
	private JButton addFiles, selectDestination, copyFile, copyFiles,
			deleteFile, deleteAll, openDestinationFolder;
	private JComboBox<String> fileNames;
	private DefaultComboBoxModel<String> model;
	private int selectedFileIndex;
	private JTextField dragPanel = new JTextField(20);
	private JLabel dragLabel;
	String sep = File.separator;
	private File listFile = new File("app"+PreferencesManager.sep+"userList.dat");
	public void showFiles() {
		fileNames.setVisible(files.size() > 0);
	}
	public void restart(){
		//First close the current instance of the program
		this.dispose();
		//and create a new instance
		new FileCopyManager();
	}
	private void init() {
		fileMenu.add(saveList);
		fileMenu.add(loadList);
		fileMenu.add(exit);
		editMenu.add(showPreferences);
		editMenu.add(exportPreferences);
		editMenu.add(restartApp);
		editMenu.add(deleteApp);
		menuBar.add(fileMenu);
		menuBar.add(editMenu);
		addFiles = new JButton("Add files to copy");
		copyFiles = new JButton("Copy all files");
		deleteFile = new JButton("Delete file from list");
		selectDestination = new JButton("Select Destination Folder");
		openDestinationFolder = new JButton("Open Destination Folder");
		deleteAll = new JButton("Delete all files from list");
		model = new DefaultComboBoxModel<String>();
		JFrame curFrame = this;
		fileNames = new JComboBox<String>(model);
		fileNames.setVisible(false);
		addFiles.addActionListener((e) -> {
			chooser.setMultiSelectionEnabled(true);
			chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
			chooser.setDialogTitle("Select files to copy");
			int r = chooser.showOpenDialog(panel);
			if (r != JFileChooser.APPROVE_OPTION)
				return;
			for (File f : chooser.getSelectedFiles()) {
				files.add(f);
				String name = f.getName()
						+ (f.isDirectory() ? " (Folder)" : "");
				model.addElement(name);
			}
			selectedFile = files.get(0);
			selectedFileIndex = 0;
			fileNames.setSelectedIndex(0);
			fileNames.setVisible(files.size() > 0);
			this.pack();
		});
		fileNames.addActionListener((e) -> {
			selectedFileIndex = files.size()==1?0:fileNames.getSelectedIndex();
			selectedFile = selectedFileIndex == -1 ?null:files.get(selectedFileIndex);
		});
		copyFile = new JButton("Copy selected file");
		copyFile.addActionListener((e) -> {
			String message = destinationPath== null && selectedFile == null?"Selecte at least a file and a destination folder "
					:selectedFile == null?" Select at least one file to copy":"Select a directory to copy selected file(s) in";
			if (destinationPath == null || selectedFile == null) {
				msg.error(panel, message);
				return;
			}
			new Thread(()->{
				fHandler.copy(selectedFile, destinationPath);
			}).start();
		});

		copyFiles.addActionListener((e) -> {
			if(destinationPath == null)
				msg.error(panel, "Please select a destination folder","No destination folder selected");
			try{
				new Thread(()->{
					for(File f:files){
						status.text(f.getName()).showStatus();
						fHandler.copy(f,destinationPath);		
					}
				}).start();
			}
			catch(Exception ee){
				msg.error(panel, "Error occured.Se log file for more", "Error");
				fHandler.log(ee.getMessage());
			}
			finally{
				status.dispose();
			}
		});

		deleteFile.addActionListener((e) -> {
			if (selectedFile == null) {
{'fraction_non_alphanumeric': 0.12044283260164153, 'fraction_numerical': 0.001908761213972132, 'mean_word_length': 4.943845717526942, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 32, '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': '1527275', 'n_tokens_mistral': 3432, 'n_tokens_neox': 3079, 'n_words': 800}