diff options
author | Jonathan Bauer | 2015-07-14 17:24:41 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-07-14 17:24:41 +0200 |
commit | 0e36207bf778ea53ef4f5ab0a3dd1f9266d35c5b (patch) | |
tree | 83b5ae218770b6462766a39fae412e613a33ae2e /dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java | |
parent | [client] fix wrong setting of tokens in Session (diff) | |
download | tutor-module-0e36207bf778ea53ef4f5ab0a3dd1f9266d35c5b.tar.gz tutor-module-0e36207bf778ea53ef4f5ab0a3dd1f9266d35c5b.tar.xz tutor-module-0e36207bf778ea53ef4f5ab0a3dd1f9266d35c5b.zip |
[client] removed old swing stuff from util/*
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java | 51 |
1 files changed, 12 insertions, 39 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java index aebaf732..a2cfcba7 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java @@ -1,11 +1,9 @@ package org.openslx.dozmod.filetransfer; import java.io.File; +import java.io.IOException; import java.io.RandomAccessFile; -import javax.swing.JOptionPane; -import javax.swing.SwingWorker; - import org.apache.log4j.Logger; import org.openslx.filetransfer.DataReceivedCallback; import org.openslx.filetransfer.Downloader; @@ -18,7 +16,7 @@ import org.openslx.filetransfer.WantRangeCallback; * @author www.codejava.net * */ -public class DownloadTask extends SwingWorker<Void, Void> { +public class DownloadTask implements Runnable { /** * Logger instance for this class. @@ -86,11 +84,9 @@ public class DownloadTask extends SwingWorker<Void, Void> { final long now = System.currentTimeMillis(); if (lastUpdate + UPDATE_INTERVAL_MS < now) { final int percentCompleted = (int) ((totalBytesRead * 100) / fileSize); - setProgress(percentCompleted); lastBytes = (lastBytes * 2 + currentBytes) / 3; final double speed = lastBytes / UPDATE_INTERVAL_SECONDS; - firePropertyChange("speed", 0, speed / BYTES_PER_MIB); - firePropertyChange("bytesread", 0, totalBytesRead); + LOGGER.debug(percentCompleted + "% complete (speed: " + speed/BYTES_PER_MIB + ", total: " + totalBytesRead + ")"); lastUpdate = now; currentBytes = 0; } @@ -103,10 +99,10 @@ public class DownloadTask extends SwingWorker<Void, Void> { * Executed in background thread */ @Override - protected Void doInBackground() throws Exception { + public void run() { + boolean ret = false; // show filesize in the GUI - firePropertyChange("filesize", 0, fileSize); Downloader download = null; RandomAccessFile file = null; @@ -115,16 +111,16 @@ public class DownloadTask extends SwingWorker<Void, Void> { try { file = new RandomAccessFile(new File(saveDir), "rw"); } catch (Exception e2) { - JOptionPane.showMessageDialog(null, "Could not open destination file:\n" + saveDir + "\n" - + e2.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); - e2.printStackTrace(); - setProgress(0); - return null; + LOGGER.error("Could not open for writing: ", e2); + return; } Callbacks cb = new Callbacks(file); ret = download.download(cb, cb); + } catch (IOException e) { + LOGGER.error("Could not open connection: ", e); + return; } finally { if (file != null) { try { @@ -139,33 +135,10 @@ public class DownloadTask extends SwingWorker<Void, Void> { // if the download succeeded, set the progress to 100% manually again here to make // sure the GUI knows about it. if (ret) { - setProgress(100); - firePropertyChange("bytesread", 0, fileSize); - firePropertyChange("success", false, true); + LOGGER.debug("successul download."); success = true; } - return null; + return; } - - /** - * Executed in Swing's event dispatching thread - */ - @Override - protected void done() { - if (isCancelled()) - return; - if (success) { - LOGGER.info("Datei erfolgreich heruntergeladen."); - String vmxResult = ""; - JOptionPane.showMessageDialog(null, "Datei erfolgreich heruntergeladen. " + vmxResult, "Message", - JOptionPane.INFORMATION_MESSAGE); - } else { - LOGGER.error("Datei wurde unvollständig heruntergeladen."); - JOptionPane.showMessageDialog(null, - "Datei wurde unvollständig heruntergeladen. Bitte wiederholen.", "Message", - JOptionPane.INFORMATION_MESSAGE); - } - } - } |