1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.r66gui;
22
23 import javax.swing.JEditorPane;
24 import javax.swing.JProgressBar;
25
26 import openr66.client.ProgressBarTransfer;
27 import openr66.protocol.networkhandler.NetworkTransaction;
28 import openr66.protocol.utils.R66Future;
29
30
31
32
33
34 public class ProgressDirectTransfer extends ProgressBarTransfer {
35 private JProgressBar progressBar;
36 private JEditorPane textFieldStatus;
37 private boolean firstCall = true;
38 private int nbBlock = 1;
39 private long lastTime = System.currentTimeMillis();
40 private int lastRank = 0;
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public ProgressDirectTransfer(R66Future future, String remoteHost,
55 String filename, String rulename, String fileinfo, boolean isMD5,
56 int blocksize, long id, NetworkTransaction networkTransaction,
57 long callbackdelay, JProgressBar progressBar, JEditorPane textFieldStatus) {
58 super(future, remoteHost, filename, rulename, fileinfo, isMD5,
59 blocksize, id, networkTransaction, callbackdelay);
60 this.textFieldStatus = textFieldStatus;
61 this.progressBar = progressBar;
62 this.progressBar.setIndeterminate(true);
63 this.progressBar.setValue(0);
64 this.progressBar.setVisible(true);
65 this.textFieldStatus.setText("Initializing transfer...");
66 }
67
68
69
70
71 @Override
72 public void callBack(int currentBlock, int blocksize) {
73 if (firstCall) {
74 if (filesize != 0) {
75 this.progressBar.setIndeterminate(false);
76 nbBlock = (int) (Math.ceil(((double)filesize/(double)blocksize)));
77 }
78 firstCall = false;
79 }
80 long newtime = System.currentTimeMillis()+1;
81 int sendsize = ((currentBlock-lastRank)*blocksize);
82 long time = ((newtime-lastTime)*1024)/1000;
83 long speedKB = sendsize/time;
84 if (filesize == 0) {
85 this.textFieldStatus.setText("Bytes transmitted: "+(currentBlock*blocksize)+" at "+speedKB+" KB/s");
86 } else {
87 this.progressBar.setValue(currentBlock*100/nbBlock);
88 this.textFieldStatus.setText("Bytes transmitted: "+(currentBlock*blocksize)+
89 " on "+filesize+" at "+speedKB+" KB/s");
90 }
91 lastTime = newtime-1;
92 lastRank = currentBlock;
93 }
94
95
96
97
98 @Override
99 public void lastCallBack(boolean success, int currentBlock, int blocksize) {
100 this.progressBar.setIndeterminate(false);
101 if (filesize == 0) {
102 this.textFieldStatus.setText("Finally Bytes transmitted: "+(currentBlock*blocksize)+" with Status: "+success);
103 } else {
104 this.progressBar.setValue(100);
105 this.textFieldStatus.setText("Finally Bytes transmitted: "+(currentBlock*blocksize)+" with Status: "+success);
106 }
107 }
108 }