00001 package ProdDatabase; 00002 00003 import java.awt.*; 00004 import java.awt.event.*; 00005 import javax.swing.*; 00006 00007 00008 public class UploadProgressMonitor { 00009 public final static int ONE_SECOND = 1000; 00010 00011 private ProgressMonitor progressMonitor; 00012 private Timer timer; 00013 private UploaderTask task; 00014 private String newline = "\n"; 00015 private java.awt.Component guiControl; 00016 private boolean isInProgress=false; 00017 00018 public UploadProgressMonitor(java.awt.Component parent) { 00019 guiControl=parent; 00020 00021 } 00022 00023 public void start(int noModules, String cmd, boolean quitOnFinish) { 00024 task = new UploaderTask(noModules,cmd,quitOnFinish); 00025 //Create a timer. 00026 timer = new Timer(ONE_SECOND, new TimerListener()); 00027 00028 // start the upload 00029 startUpload(); 00030 } 00031 00032 00037 class TimerListener implements ActionListener { 00038 public void actionPerformed(ActionEvent evt) { 00039 progressMonitor.setProgress(task.getCurrent()); 00040 String s = task.getMessage(); 00041 if (s != null) { 00042 progressMonitor.setNote(s); 00043 } 00044 if (progressMonitor.isCanceled() || task.isDone()) { 00045 progressMonitor.close(); 00046 task.stop(); 00047 Toolkit.getDefaultToolkit().beep(); 00048 timer.stop(); 00049 if (task.isDone()) System.out.println("Task completed."); 00050 else System.out.println("Task cancelled."); 00051 isInProgress=false; 00052 } 00053 } 00054 } 00055 00059 public void startUpload() { 00060 isInProgress=true; 00061 progressMonitor = new ProgressMonitor(guiControl, 00062 "Uploading to SCT Database", 00063 "", 0, task.getLengthOfTask()); 00064 progressMonitor.setProgress(0); 00065 progressMonitor.setMillisToDecideToPopup(1 * ONE_SECOND); 00066 task.go(); 00067 timer.start(); 00068 } 00069 00070 public boolean isBusy() { 00071 return isInProgress; 00072 } 00073 00074 }