Fix so downloader actually shows progress

This commit is contained in:
drdev
2014-05-28 00:31:39 +00:00
parent 5c2f3ddf85
commit 99762835d1

View File

@@ -68,7 +68,7 @@ public abstract class GuiDownloadService implements Runnable {
private int type; private int type;
// Progress variables // Progress variables
private Map<String, String> cards; // local path -> url private Map<String, String> files; // local path -> url
private boolean cancel; private boolean cancel;
private final long[] times = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; private final long[] times = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
private int tptr = 0; private int tptr = 0;
@@ -91,7 +91,7 @@ public abstract class GuiDownloadService implements Runnable {
@Override @Override
public void run() { public void run() {
try { try {
cards = getNeededFiles(); files = getNeededFiles();
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -107,14 +107,14 @@ public abstract class GuiDownloadService implements Runnable {
} }
private void readyToStart() { private void readyToStart() {
if (cards.isEmpty()) { if (files.isEmpty()) {
barProgress.setDescription("All items have been downloaded."); barProgress.setDescription("All items have been downloaded.");
btnStart.setText("OK"); btnStart.setText("OK");
btnStart.setCommand(cmdClose); btnStart.setCommand(cmdClose);
} }
else { else {
barProgress.setMaximum(cards.size()); barProgress.setMaximum(files.size());
barProgress.setDescription(cards.size() == 1 ? "1 item found." : cards.size() + " items found."); barProgress.setDescription(files.size() == 1 ? "1 item found." : files.size() + " items found.");
//for(Entry<String, String> kv : cards.entrySet()) System.out.printf("Will get %s from %s%n", kv.getKey(), kv.getValue()); //for(Entry<String, String> kv : cards.entrySet()) System.out.printf("Will get %s from %s%n", kv.getKey(), kv.getValue());
btnStart.setCommand(cmdStartDownload); btnStart.setCommand(cmdStartDownload);
} }
@@ -158,7 +158,7 @@ public abstract class GuiDownloadService implements Runnable {
return tTime / Math.max(1, numNonzero); return tTime / Math.max(1, numNonzero);
} }
private void update(final int card, final File dest) { private void update(final int count, final File dest) {
FThreads.invokeInEdtLater(new Runnable() { FThreads.invokeInEdtLater(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -168,10 +168,10 @@ public abstract class GuiDownloadService implements Runnable {
final int a = getAverageTimePerObject(); final int a = getAverageTimePerObject();
if (card != cards.size()) { if (count != files.size()) {
sb.append(card + "/" + cards.size() + " - "); sb.append(count + "/" + files.size() + " - ");
long t2Go = (cards.size() - card) * a; long t2Go = (files.size() - count) * a;
if (t2Go > 3600000) { if (t2Go > 3600000) {
sb.append(String.format("%02d:", t2Go / 3600000)); sb.append(String.format("%02d:", t2Go / 3600000));
@@ -188,15 +188,16 @@ public abstract class GuiDownloadService implements Runnable {
} }
else { else {
sb.append(String.format("%d of %d items finished! Skipped " + skipped + " items. Please close!", sb.append(String.format("%d of %d items finished! Skipped " + skipped + " items. Please close!",
card, cards.size())); count, files.size()));
btnStart.setText("OK"); btnStart.setText("OK");
btnStart.setCommand(cmdClose); btnStart.setCommand(cmdClose);
btnStart.setEnabled(true); btnStart.setEnabled(true);
btnStart.requestFocusInWindow(); btnStart.requestFocusInWindow();
} }
barProgress.setValue(count);
barProgress.setDescription(sb.toString()); barProgress.setDescription(sb.toString());
System.out.println(card + "/" + cards.size() + " - " + dest); System.out.println(count + "/" + files.size() + " - " + dest);
} }
}); });
} }
@@ -222,7 +223,7 @@ public abstract class GuiDownloadService implements Runnable {
} }
int iCard = 0; int iCard = 0;
for (Entry<String, String> kv : cards.entrySet()) { for (Entry<String, String> kv : files.entrySet()) {
if (cancel) { break; } if (cancel) { break; }
String url = kv.getValue(); String url = kv.getValue();