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 | |
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/*
3 files changed, 16 insertions, 56 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); - } - } - } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java index acedba09..e8c44130 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java @@ -7,14 +7,12 @@ import java.net.URL; import java.net.URLConnection; import java.sql.Date; -import javax.swing.JOptionPane; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.openslx.bwlp.thrift.iface.SessionData; - import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.SessionData; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -218,18 +216,12 @@ public class News { tmpDate = new Date(Long.parseLong(dateNode.getNodeValue().trim()) * 1000); } catch (NumberFormatException nfe) { LOGGER.error("Date format is invalid, see trace: ", nfe); - JOptionPane.showMessageDialog(null, - "Zeitstempel aus der XML is invalid!", - "Fehler", JOptionPane.ERROR_MESSAGE); - // TODO: set current date. } // Date creation worked, save it if (tmpDate != null) date = tmpDate; } } else { - JOptionPane.showMessageDialog(null, - "Invalides XML! Kein 'news' Wurzelelement. News wird leer gelassen.", - "Fehler", JOptionPane.ERROR_MESSAGE); + LOGGER.error("No valid news in the response!"); return; } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java index 224ad865..4c477f3d 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java @@ -7,8 +7,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import javax.swing.JOptionPane; - import org.apache.log4j.Logger; public class OpenLinks { @@ -39,7 +37,7 @@ public class OpenLinks { // temp map Map<String, URI> tmpUris = new HashMap<String, URI>(); for (String key : links.keySet()) { - URI tmp; + URI tmp; try { tmp = new URI(links.get(key)); } catch (URISyntaxException e) { @@ -71,10 +69,7 @@ public class OpenLinks { try { desktop.browse(uris.get(key)); } catch (Exception e) { - e.printStackTrace(); - JOptionPane.showMessageDialog(null, - e.getCause() + "\n" + e.getStackTrace(), - "Debug-Message", JOptionPane.ERROR_MESSAGE); + LOGGER.debug("Got exception in openWebpage: ", e); } } }// end openWebpage |