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

import java.awt.Component;

import javax.swing.SwingUtilities;

/**
 * This is a variant of the SwingWorker
 * It works in conjunction with the GlassPane class
 * to allow users to execute timeconsuming task on a separate thread
 * The GlassPane addition can prevent users from executing another SwingWorker task
 * while one SwingWorker task is already executing
 *
 */
public abstract class CustomSwingWorker {

    private ThreadVar threadVar;

    private GlassPane glassPane;

    private Component aComponent;

    private Component parentCoponent;

    private boolean errorOccured;

    /** 
     * Class to maintain reference to current worker thread
     * under separate synchronization control.
     */
    private static class ThreadVar {

        private Thread thread;

        ThreadVar(Thread t) {
            thread = t;
        }

        synchronized Thread get() {
            return thread;
        }

        synchronized void clear() {
            thread = null;
        }
    }

    public CustomSwingWorker(Component aComponent) {
        this(aComponent, aComponent);
    }

    /**
     * Start a thread that will call the <code>construct</code> method
     * and then exit.
     * @param aComponent a reference to the UI component that's directly using
     * SwingWorker
     */
    public CustomSwingWorker(Component aComponent, Component parentCoponent) {
        this.parentCoponent = parentCoponent;
        setAComponent(aComponent);

        final Runnable doFinished = new Runnable() {

            public void run() {
                finished();
            }
        };

        Runnable doConstruct = new Runnable() {

            public void run() {
                try {
                    construct();
                } finally {
                    threadVar.clear();
                }

                // Execute the doFinished runnable on the Swing dispatcher thread
                SwingUtilities.invokeLater(doFinished);
            }
        };

        // Group the new worker thread in the same group as the "spawner" thread
        Thread t = new Thread(Thread.currentThread().getThreadGroup(), doConstruct);
        threadVar = new ThreadVar(t);
    }

    /**
     * Start a thread that will call the <code>construct</code> method
     * and then exit.
     * @param aComponent a reference to the UI component that's directly using
     * SwingWorker
     */
    public CustomSwingWorker(Component aComponent, Object object) {
        setAComponent(aComponent);

        final Runnable doFinished = new Runnable() {

            public void run() {
                finished();
            }
        };

        Runnable doConstruct = new Runnable() {

            public void run() {
                try {
                    construct();
                } finally {
                    threadVar.clear();
                }

                // Execute the doFinished runnable on the Swing dispatcher thread
                SwingUtilities.invokeLater(doFinished);
            }
        };

        // Group the new worker thread in the same group as the "spawner" thread
        Thread t = new Thread(Thread.currentThread().getThreadGroup(), doConstruct);
        threadVar = new ThreadVar(t);
    }

    /**
     * Activate the capabilities of glasspane
     * 
     */
    private void activateGlassPane() {
        // Mount the glasspane on the component window
        GlassPane aPane = GlassPane.mount(getAComponent(), true);

        // keep track of the glasspane as an instance variable
        setGlassPane(aPane);

        if (getGlassPane() != null) {
            // Start interception UI interactions
            getGlassPane().setVisible(true);
        }
    }

    /** 
     * Enable the glass pane (to disable unwanted UI manipulation), then spawn the non-UI logic on a separate thread.
     */
    private void construct() {
        activateGlassPane();
        try {
            doNonUILogic();
        } catch (Exception e) {
            errorOccured = true;
            CommonUtils.handleException(CommonUtils.getCab2bException(e), this.parentCoponent, true, true, false,
                                        false);
        }
    }

    /**
     * Deactivate the glasspane
     * 
     */<commit_msg>*** empty log message ***<commit_after>package edu.wustl.cab2b.client.ui.util;

import java.awt.Component;

import javax.swing.SwingUtilities;

/**
 * This is a variant of the SwingWorker
 * It works in conjunction with the GlassPane class
 * to allow users to execute timeconsuming task on a separate thread
 * The GlassPane addition can prevent users from executing another SwingWorker task
 * while one SwingWorker task is already executing
 *
 */
public abstract class CustomSwingWorker {

    private ThreadVar threadVar;

    private GlassPane glassPane;

    private Component aComponent;

    private Component parentCoponent;

    private boolean errorOccured;

    /** 
     * Class to maintain reference to current worker thread
     * under separate synchronization control.
     */
    private static class ThreadVar {

        private Thread thread;

        ThreadVar(Thread t) {
            thread = t;
        }

        synchronized Thread get() {
            return thread;
        }

        synchronized void clear() {
            thread = null;
        }
    }

    public CustomSwingWorker(Component aComponent) {
        this(aComponent, aComponent);
    }

    /**
     * Start a thread that will call the <code>construct</code> method
     * and then exit.
     * @param aComponent a reference to the UI component that's directly using
     * SwingWorker
     */
    public CustomSwingWorker(Component aComponent, Component parentCoponent) {
        this.parentCoponent = parentCoponent;
        setAComponent(aComponent);

        final Runnable doFinished = new Runnable() {

            public void run() {
                finished();
            }
        };

        Runnable doConstruct = new Runnable() {

            public void run() {
                try {
                    construct();
                } finally {
                    threadVar.clear();
                }

                // Execute the doFinished runnable on the Swing dispatcher thread
                SwingUtilities.invokeLater(doFinished);
            }
        };

        // Group the new worker thread in the same group as the "spawner" thread
        Thread t = new Thread(Thread.currentThread().getThreadGroup(), doConstruct);
        threadVar = new ThreadVar(t);
    }

    /**
     * Start a thread that will call the <code>construct</code> method
     * and then exit.
     * @param aComponent a reference to the UI component that's directly using
     * SwingWorker
     */
    public CustomSwingWorker(Component aComponent, Object object) {
        setAComponent(aComponent);

        final Runnable doFinished = new Runnable() {

            public void run() {
                finished();
            }
        };

        Runnable doConstruct = new Runnable() {

            public void run() {
                try {
                    construct();
                } finally {
                    threadVar.clear();
                }

                // Execute the doFinished runnable on the Swing dispatcher thread
                SwingUtilities.invokeLater(doFinished);
            }
        };

        // Group the new worker thread in the same group as the "spawner" thread
        Thread t = new Thread(Thread.currentThread().getThreadGroup(), doConstruct);
        threadVar = new ThreadVar(t);
    }

    /**
     * Activate the capabilities of glasspane
     * 
     */
    private void activateGlassPane() {
        // Mount the glasspane on the component window
        GlassPane aPane = GlassPane.mount(getAComponent(), true);

        // keep track of the glasspane as an instance variable
        setGlassPane(aPane);

        if (getGlassPane() != null) {
            // Start interception UI interactions
            getGlassPane().setVisible(true);
        }
    }

    /** 
     * Enable the glass pane (to disable unwanted UI manipulation), then spawn the non-UI logic on a separate thread.
     */
    private void construct() {
        activateGlassPane();
        try {
            doNonUILogic();
        } catch (Exception e) {
            errorOccured = true;
            CommonUtils.handleException(CommonUtils.getCab2bException(e), this.parentCoponent, true, true, true,
                                        false);
        }
    }

    /**
     * Deactivate the glasspane
     * 
     */
{'fraction_non_alphanumeric': 0.07675463870001152, 'fraction_numerical': 0.00046098882102109026, 'mean_word_length': 1.8257896450667535, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5833397', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2110, 'n_words': 696}