OSDN Git Service

WorkerをSwingWorker風に
authoryukihane <yukihane.feather@gmail.com>
Sat, 27 Aug 2011 12:51:23 +0000 (21:51 +0900)
committeryukihane <yukihane.feather@gmail.com>
Sat, 27 Aug 2011 12:51:23 +0000 (21:51 +0900)
frontend/src/saccubus/worker/Worker.java
frontend/src/saccubus/worker/convert/Convert.java
frontend/src/saccubus/worker/download/Download.java

index d3c5e28..463814a 100644 (file)
@@ -18,6 +18,22 @@ public abstract class Worker<T, V> implements Callable<T> {
         this.listener = listener;
     }
 
+    @Override
+    public final T call() throws Exception {
+        try {
+            final T result = doInBackground();
+            // TODO
+            publish(null);
+            return result;
+        } catch (Throwable th) {
+            // TODO
+            publish(null);
+            throw th;
+        }
+    }
+
+    protected abstract T doInBackground() throws Exception;
+
     public final int getId() {
         return id;
     }
index 5d32b57..c1f962d 100644 (file)
@@ -14,7 +14,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import javax.swing.SwingWorker;
 import saccubus.conv.ConvertToVideoHook;
 import saccubus.worker.Worker;
 import saccubus.worker.WorkerListener;
@@ -60,7 +59,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
     }
 
     @Override
-    public ConvertResult call() throws Exception {
+    protected ConvertResult doInBackground() throws Exception {
         if (!profile.isConvert()) {
             return new ConvertResult(true, "");
         }
index e369fff..3f332b1 100644 (file)
@@ -3,9 +3,7 @@ package saccubus.worker.download;
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.util.concurrent.Callable;
 import java.util.logging.Logger;
-import javax.swing.SwingWorker;
 import nicobrowser.GetFlvResult;
 import nicobrowser.NamePattern;
 import nicobrowser.NicoHttpClient;
@@ -17,7 +15,6 @@ import saccubus.worker.Worker;
 import saccubus.worker.WorkerListener;
 import saccubus.worker.profile.CommentProfile;
 import saccubus.worker.profile.GeneralProfile;
-import saccubus.worker.profile.OutputProfile;
 import saccubus.worker.profile.DownloadProfile;
 import saccubus.worker.profile.ProxyProfile;
 
@@ -79,7 +76,7 @@ public class Download extends Worker<DownloadResult, DownloadProgress> {
 //        }
 //    }
     @Override
-    public DownloadResult call() throws Exception {
+    public DownloadResult doInBackground() throws Exception {
 
         publish(new DownloadProgress("ログイン中"));