|
@@ -54,12 +54,27 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
54
|
54
|
/** Total data transfered */
|
55
|
55
|
private long transferCount = 0;
|
56
|
56
|
|
|
57
|
+ /** Time Started */
|
|
58
|
+ private long timeStarted = 0;
|
|
59
|
+
|
57
|
60
|
/** Progress Bar */
|
58
|
61
|
private final JProgressBar progress = new JProgressBar();
|
59
|
62
|
|
60
|
63
|
/** Status Label */
|
61
|
64
|
private final JLabel status = new JLabel("Status: Waiting");
|
62
|
65
|
|
|
66
|
+ /** Speed Label */
|
|
67
|
+ private final JLabel speed = new JLabel("Speed: Unknown");
|
|
68
|
+
|
|
69
|
+ /** Time Label */
|
|
70
|
+ private final JLabel remaining = new JLabel("Time Remaining: Unknown");
|
|
71
|
+
|
|
72
|
+ /** Time Taken */
|
|
73
|
+ private final JLabel taken = new JLabel("Time Taken: 00:00");
|
|
74
|
+
|
|
75
|
+ /** Button */
|
|
76
|
+ private final JButton button = new JButton("Cancel");
|
|
77
|
+
|
63
|
78
|
/**
|
64
|
79
|
* Creates a new instance of DCCSendWindow with a given DCCSend object.
|
65
|
80
|
*
|
|
@@ -78,8 +93,6 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
78
|
93
|
|
79
|
94
|
getContentPane().setLayout(new MigLayout());
|
80
|
95
|
|
81
|
|
- transferCount = dcc.getFileStart();
|
82
|
|
-
|
83
|
96
|
progress.setMinimum(0);
|
84
|
97
|
progress.setMaximum(100);
|
85
|
98
|
progress.setStringPainted(true);
|
|
@@ -93,11 +106,12 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
93
|
106
|
getContentPane().add(new JLabel("From: "+targetNick), "wrap");
|
94
|
107
|
}
|
95
|
108
|
getContentPane().add(status, "wrap");
|
|
109
|
+ getContentPane().add(speed, "wrap");
|
|
110
|
+ getContentPane().add(remaining, "wrap");
|
|
111
|
+ getContentPane().add(taken, "wrap");
|
96
|
112
|
getContentPane().add(progress, "growx, wrap");
|
97
|
113
|
|
98
|
|
- final JButton button = new JButton("Cancel");
|
99
|
114
|
button.addActionListener(this);
|
100
|
|
-
|
101
|
115
|
getContentPane().add(button, "wrap, align right");
|
102
|
116
|
|
103
|
117
|
plugin.addWindow(this);
|
|
@@ -106,7 +120,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
106
|
120
|
/** {@inheritDoc} */
|
107
|
121
|
public void actionPerformed(final ActionEvent e) {
|
108
|
122
|
if (e.getActionCommand().equals("Cancel")) {
|
109
|
|
- ((JButton)e.getSource()).setEnabled(false);
|
|
123
|
+ button.setEnabled(false);
|
110
|
124
|
dcc.close();
|
111
|
125
|
}
|
112
|
126
|
}
|
|
@@ -119,7 +133,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
119
|
133
|
*/
|
120
|
134
|
public void dataTransfered(final DCCSend dcc, final int bytes) {
|
121
|
135
|
transferCount += bytes;
|
122
|
|
- final double percent = (100.00 / dcc.getFileSize()) * transferCount;
|
|
136
|
+ final double percent = (100.00 / dcc.getFileSize()) * (transferCount + dcc.getFileStart());
|
123
|
137
|
|
124
|
138
|
if (dcc.getType() == DCCSend.TransferType.SEND) {
|
125
|
139
|
status.setText("Status: Sending");
|
|
@@ -127,9 +141,51 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
127
|
141
|
status.setText("Status: Recieving");
|
128
|
142
|
}
|
129
|
143
|
|
|
144
|
+ updateSpeedAndTime();
|
|
145
|
+
|
130
|
146
|
progress.setValue((int)Math.floor(percent));
|
131
|
147
|
}
|
132
|
148
|
|
|
149
|
+ /**
|
|
150
|
+ * Update the transfer speed, time remaining and time taken labels.
|
|
151
|
+ */
|
|
152
|
+ public void updateSpeedAndTime() {
|
|
153
|
+ final long time = (System.currentTimeMillis() - timeStarted) / 1000;
|
|
154
|
+ final double bytesPerSecond = (time > 0) ? (transferCount / time) : 0;
|
|
155
|
+
|
|
156
|
+ if (bytesPerSecond > 1048576) {
|
|
157
|
+ speed.setText(String.format("Speed: %.2f MB/s", (bytesPerSecond/1048576)));
|
|
158
|
+ } else if (bytesPerSecond > 1024) {
|
|
159
|
+ speed.setText(String.format("Speed: %.2f KB/s", (bytesPerSecond/1024)));
|
|
160
|
+ } else {
|
|
161
|
+ speed.setText(String.format("Speed: %f B/s", bytesPerSecond));
|
|
162
|
+ }
|
|
163
|
+
|
|
164
|
+ final long remaningBytes = dcc.getFileSize() - dcc.getFileStart() - transferCount;
|
|
165
|
+ final double remainingSeconds = (bytesPerSecond > 0) ? (remaningBytes / bytesPerSecond) : 1;
|
|
166
|
+
|
|
167
|
+ remaining.setText(String.format("Time Remaining: %s", duration((int)Math.floor(remainingSeconds))));
|
|
168
|
+ taken.setText(String.format("Time Taken: %s", duration(time)));
|
|
169
|
+ }
|
|
170
|
+
|
|
171
|
+ /**
|
|
172
|
+ * Get the duration in seconds as a string.
|
|
173
|
+ *
|
|
174
|
+ * @param secondsInput to get duration for
|
|
175
|
+ * @return Duration as a string
|
|
176
|
+ */
|
|
177
|
+ private String duration(final long secondsInput) {
|
|
178
|
+ final StringBuilder result = new StringBuilder();
|
|
179
|
+ final long hours = (secondsInput / 3600);
|
|
180
|
+ final long minutes = (secondsInput / 60 % 60);
|
|
181
|
+ final long seconds = (secondsInput % 60);
|
|
182
|
+
|
|
183
|
+ if (hours > 0) { result.append(hours+":"); }
|
|
184
|
+ result.append(String.format("%0,2d:%0,2d",minutes,seconds));
|
|
185
|
+
|
|
186
|
+ return result.toString();
|
|
187
|
+ }
|
|
188
|
+
|
133
|
189
|
/**
|
134
|
190
|
* Called when the socket is closed
|
135
|
191
|
*
|
|
@@ -137,11 +193,13 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
137
|
193
|
*/
|
138
|
194
|
@Override
|
139
|
195
|
public void socketClosed(final DCCSend dcc) {
|
|
196
|
+ button.setEnabled(false);
|
140
|
197
|
if (transferCount == dcc.getFileSize()) {
|
141
|
198
|
status.setText("Status: Transfer Compelete.");
|
142
|
199
|
} else {
|
143
|
200
|
status.setText("Status: Transfer Failed.");
|
144
|
201
|
}
|
|
202
|
+ updateSpeedAndTime();
|
145
|
203
|
}
|
146
|
204
|
|
147
|
205
|
/**
|
|
@@ -152,6 +210,7 @@ public class DCCSendWindow extends DCCFrame implements DCCSendInterface, ActionL
|
152
|
210
|
@Override
|
153
|
211
|
public void socketOpened(final DCCSend dcc) {
|
154
|
212
|
status.setText("Status: Socket Opened");
|
|
213
|
+ timeStarted = System.currentTimeMillis();
|
155
|
214
|
}
|
156
|
215
|
|
157
|
216
|
/**
|