<commit_before>package me.rkfg.pfe.gui;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import me.rkfg.pfe.PFECore;
import me.rkfg.pfe.PFEListener;
import me.rkfg.pfe.TorrentActivity;

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.SWTResourceManager;

import com.frostwire.jlibtorrent.TorrentHandle;
import com.frostwire.jlibtorrent.swig.set_piece_hashes_listener;

public class FileReceiver extends Composite {

    PFECore pfeCore = PFECore.INSTANCE;
    private Label lblDropTargetHint;
    private DropTarget dropTarget;
    private ToolItem addFiles;
    private ToolItem addDirs;
    private ToolItem downloadTorrent;
    private Display display;

    ExecutorService executorService = Executors.newCachedThreadPool();
    private Map<String, Progress> progresses = new HashMap<>();
    private PathStorage pathStorage = new PathStorage();

    FileReceiver(Composite parent) {
        super(parent, SWT.NONE);
        display = getDisplay();
        setLayout(new GridLayout(1, false));

        ToolBar toolBar = new ToolBar(this, SWT.FLAT);
        toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

        addFiles = new ToolItem(toolBar, SWT.NONE);
        addFiles.setWidth(32);
        addFiles.setImage(SWTResourceManager.getImage(FileReceiver.class, "/me/rkfg/pfe/gui/icons/document-new.png"));
        addFiles.setToolTipText("Добавить файлы");

        addDirs = new ToolItem(toolBar, SWT.NONE);
        addDirs.setImage(SWTResourceManager.getImage(FileReceiver.class, "/me/rkfg/pfe/gui/icons/document-open-folder.png"));
        addDirs.setToolTipText("Добавить папку");

        downloadTorrent = new ToolItem(toolBar, SWT.NONE);
        downloadTorrent.setImage(SWTResourceManager.getImage(FileReceiver.class, "/me/rkfg/pfe/gui/icons/download.png"));
        downloadTorrent.setToolTipText("Скачать");

        createDropTarget();
        setHandlers();
        pfeCore.addPFEListener(new PFEListener() {

            @Override
            public void torrentProgress(Collection<TorrentActivity> torrentActivities) {
                for (final TorrentActivity torrentActivity : torrentActivities) {
                    if (torrentActivity.hash != null) {
                        final Progress progress = progresses.get(torrentActivity.hash);
                        if (progress != null) {
                            display.asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    progress.setProgress(torrentActivity.progress);
                                    if (progress.getTorrentName() == null && torrentActivity.name != null) {
                                        progress.setTorrentName(torrentActivity.name);
                                    }
                                }
                            });
                        }
                    }
                }
            }
        });
        layout();
    }

    private void setHandlers() {
        addFiles.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {<commit_msg>Handle stopped (paused) torrents.<commit_after>package me.rkfg.pfe.gui;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import me.rkfg.pfe.PFECore;
import me.rkfg.pfe.PFEListener;
import me.rkfg.pfe.TorrentActivity;

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.SWTResourceManager;

import com.frostwire.jlibtorrent.TorrentHandle;
import com.frostwire.jlibtorrent.swig.set_piece_hashes_listener;

public class FileReceiver extends Composite {

    PFECore pfeCore = PFECore.INSTANCE;
    private Label lblDropTargetHint;
    private DropTarget dropTarget;
    private ToolItem addFiles;
    private ToolItem addDirs;
    private ToolItem downloadTorrent;
    private Display display;

    ExecutorService executorService = Executors.newCachedThreadPool();
    private Map<String, Progress> progresses = new HashMap<>();
    private PathStorage pathStorage = new PathStorage();

    FileReceiver(Composite parent) {
        super(parent, SWT.NONE);
        display = getDisplay();
        setLayout(new GridLayout(1, false));

        ToolBar toolBar = new ToolBar(this, SWT.FLAT);
        toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

        addFiles = new ToolItem(toolBar, SWT.NONE);
        addFiles.setWidth(32);
        addFiles.setImage(SWTResourceManager.getImage(FileReceiver.class, "/me/rkfg/pfe/gui/icons/document-new.png"));
        addFiles.setToolTipText("Добавить файлы");

        addDirs = new ToolItem(toolBar, SWT.NONE);
        addDirs.setImage(SWTResourceManager.getImage(FileReceiver.class, "/me/rkfg/pfe/gui/icons/document-open-folder.png"));
        addDirs.setToolTipText("Добавить папку");

        downloadTorrent = new ToolItem(toolBar, SWT.NONE);
        downloadTorrent.setImage(SWTResourceManager.getImage(FileReceiver.class, "/me/rkfg/pfe/gui/icons/download.png"));
        downloadTorrent.setToolTipText("Скачать");

        createDropTarget();
        setHandlers();
        pfeCore.addPFEListener(new PFEListener() {

            @Override
            public void torrentProgress(Collection<TorrentActivity> torrentActivities) {
                for (final TorrentActivity torrentActivity : torrentActivities) {
                    if (torrentActivity.hash != null) {
                        final Progress progress = progresses.get(torrentActivity.hash);
                        if (progress != null) {
                            display.asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    progress.setProgress(torrentActivity.progress);
                                    if (progress.getTorrentName() == null && torrentActivity.name != null) {
                                        progress.setTorrentName(torrentActivity.name);
                                    }
                                }
                            });
                        }
                    }
                }
            }

            @Override
            public void torrentStopped(Collection<TorrentActivity> stopped) {
                for (final TorrentActivity torrentActivity : stopped) {
                    if (torrentActivity.hash != null) {
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                removeTorrent(torrentActivity.hash);
                            }
                        });
                    }
                }
            }
        });
        layout();
    }

    private void setHandlers() {
        addFiles.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
{'fraction_non_alphanumeric': 0.09789190401435299, 'fraction_numerical': 0.001121327651939897, 'mean_word_length': 2.391254752851711, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1453025', 'n_tokens_mistral': 2584, 'n_tokens_neox': 2469, 'n_words': 429}