1 package snow.utils.gui; 2 3 import snow.utils.StringUtils; 4 import snow.Language.Language; 5 import java.awt.*; 6 import java.awt.event.*; 7 import javax.swing.*; 8 import javax.swing.border.*; 9 import java.util.*; 10 11 13 public final class EstimatedProgressDialog extends ProgressModalDialog 14 { 15 16 final private long startTime = System.currentTimeMillis(); 17 final private java.util.Timer timer = new java.util.Timer ("ProgressModalDialog_Timer", true); 18 19 public EstimatedProgressDialog( JFrame owner, String title, boolean modal) 20 { 21 super(owner,title,true,modal); 22 setSize(400,111); 23 } 25 26 public EstimatedProgressDialog( JDialog owner, String title) 27 { 28 super(owner,title,true); 29 setSize(400,111); 30 } 32 33 35 public void setIndeterminate(final long estimatedTime, boolean showRemaining) 36 { 37 if(!showRemaining) 38 { 39 EventQueue.invokeLater(new Runnable () 40 { 41 public void run() 42 { 43 progress.setIndeterminate(true); 44 TimerTask tt = new TimerTask() 46 { 47 public void run() 48 { 49 EventQueue.invokeLater(new Runnable () 50 { 51 public void run() 52 { 53 long done = System.currentTimeMillis()-startTime; 54 progress.setString( 55 Language.translate("Duration = %",StringUtils.formatTime(done))+""); 56 } 57 }); 58 } 59 }; 60 timer.scheduleAtFixedRate(tt, 10000, 1000); 61 } 62 }); 63 } 64 else 65 { 66 EventQueue.invokeLater(new Runnable () 67 { 68 public void run() 69 { 70 progress.setIndeterminate(false); 71 progress.setMaximum(1000); 72 } 73 }); 74 75 TimerTask tt = new TimerTask() 76 { 77 public void run() 78 { 79 double p = System.currentTimeMillis()-startTime; 81 p = p/((double) estimatedTime)*1000.0; 82 83 long doneMS = System.currentTimeMillis()-startTime; 84 long remaining = estimatedTime-doneMS; 85 86 if(p>1000) p=990; 87 setProgressValue((int) p, "Estimated remaining time = "+StringUtils.formatTime(remaining)+""); 88 } 89 }; 90 timer.scheduleAtFixedRate(tt, 1000, 500); 91 92 } 93 } 94 95 96 98 public void closeDialog() 99 { 100 105 timer.cancel(); 106 super.closeDialog(); 107 } 108 109 110 111 } | Popular Tags |