Package net.datacrow.util

Source Code of net.datacrow.util.PollerTask

package net.datacrow.util;

import javax.swing.SwingUtilities;

import net.datacrow.console.windows.onlinesearch.ProgressDialog;

public class PollerTask extends Thread {
       
    private Thread thread;
   
    private boolean finished = false;
    private String title;
   
    public PollerTask(Thread thread, String title) {
        setPriority(Thread.MIN_PRIORITY);
        this.thread = thread;
        this.title = title;
    }
   
    public void finished(boolean b) {
        finished = b;
    }
   
    @Override
    public void run() {
        final ProgressDialog dlg = new ProgressDialog(title);
        while (!finished && thread.isAlive()) {
            SwingUtilities.invokeLater(
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            dlg.update();                               
                        }
                    }));
           
            try { sleep(10); } catch (Exception ignore) {}
        }
       
        SwingUtilities.invokeLater(
            new Thread(new Runnable() {
                @Override
                public void run() {
                    dlg.close();
                }
            }));
       
        thread = null;
    }
}
TOP

Related Classes of net.datacrow.util.PollerTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.