OSDN Git Service

worker listenerのインタフェース名変更
authoryukihane <yukihane.feather@gmail.com>
Sat, 27 Aug 2011 04:56:41 +0000 (13:56 +0900)
committeryukihane <yukihane.feather@gmail.com>
Sat, 27 Aug 2011 04:56:41 +0000 (13:56 +0900)
frontend/src/saccubus/worker/Convert.java
frontend/src/saccubus/worker/Download.java
frontend/src/saccubus/worker/Worker.java [new file with mode: 0644]
frontend/src/yukihane/inqubus/gui/MainFrame.java
frontend/src/yukihane/inqubus/manager/Request.java

index f87102e..c01cff6 100644 (file)
@@ -50,7 +50,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
      * @param output 変換後出力動画.
      * @throws IOException 変換失敗.
      */
-    public Convert(ConvertProfile profile, File video, File comment, SaccubusListener<ConvertProgress> listener) {
+    public Convert(ConvertProfile profile, File video, File comment, WorkerListener<ConvertProgress> listener) {
         super(listener);
         this.profile = profile;
         this.videoFile = video;
index c2044fe..9480486 100644 (file)
@@ -49,7 +49,7 @@ public class Download extends Worker<DownloadResult, DownloadProgress> {
      * @param listener
      * @param flag
      */
-    public Download(DownloadProfile profile, String videoId, SaccubusListener<DownloadProgress> listener) {
+    public Download(DownloadProfile profile, String videoId, WorkerListener<DownloadProgress> listener) {
         // TODO listener登録
         super(listener);
         this.videoId = videoId;
diff --git a/frontend/src/saccubus/worker/Worker.java b/frontend/src/saccubus/worker/Worker.java
new file mode 100644 (file)
index 0000000..7ff7250
--- /dev/null
@@ -0,0 +1,35 @@
+package saccubus.worker;
+
+import java.util.concurrent.Callable;
+
+/**
+ * 途中経過を報告できるCallableです.
+ *
+ * @author yuki
+ */
+public abstract class Worker<T, V> implements Callable<T> {
+    private static int serialNumber = 0;
+
+    private final int id;
+    private final WorkerListener<V> listener;
+
+    public Worker(WorkerListener<V> listener) {
+        this.id = ++serialNumber;
+        this.listener = listener;
+    }
+
+    public final int getId() {
+        return id;
+    }
+
+    protected final void publish(V value) {
+        if (listener != null) {
+            listener.process(value);
+        }
+    }
+
+    public interface WorkerListener<V> {
+
+        void process(V progress);
+    }
+}
index e3a2dd1..6d2144b 100644 (file)
@@ -51,7 +51,7 @@ import saccubus.MainFrame_AboutBox;
 import saccubus.util.WayBackTimeParser;
 import saccubus.worker.ConvertProgress;
 import saccubus.worker.DownloadProgress;
-import saccubus.worker.Worker.SaccubusListener;
+import saccubus.worker.Worker.WorkerListener;
 import saccubus.worker.profile.CommentProfile;
 import saccubus.worker.profile.DownloadProfile;
 import saccubus.worker.profile.GeneralProfile;
@@ -578,7 +578,7 @@ public class MainFrame extends JFrame {
         return menuBar;
     }
 
-    private class DownloadProgressListener implements SaccubusListener<DownloadProgress> {
+    private class DownloadProgressListener implements WorkerListener<DownloadProgress> {
 
         @Override
         public void process(DownloadProgress progress) {
@@ -586,7 +586,7 @@ public class MainFrame extends JFrame {
         }
     }
 
-    private class ConvertProgressListener implements SaccubusListener<ConvertProgress> {
+    private class ConvertProgressListener implements WorkerListener<ConvertProgress> {
 
         @Override
         public void process(ConvertProgress progress) {
index fd26eba..5abb30f 100644 (file)
@@ -3,7 +3,7 @@ package yukihane.inqubus.manager;
 import java.io.File;
 import saccubus.worker.ConvertProgress;
 import saccubus.worker.DownloadProgress;
-import saccubus.worker.Worker.SaccubusListener;
+import saccubus.worker.Worker.WorkerListener;
 import saccubus.worker.profile.ConvertProfile;
 import saccubus.worker.profile.DownloadProfile;
 
@@ -17,12 +17,12 @@ public class Request {
     private final int rowId;
     private final DownloadProfile downloadProfile;
     private final String videoId;
-    private final SaccubusListener<DownloadProgress> downloadProgressListener;
+    private final WorkerListener<DownloadProgress> downloadProgressListener;
     private final ConvertProfile convertProfile;
-    private final SaccubusListener<ConvertProgress> convertProgressListener;
+    private final WorkerListener<ConvertProgress> convertProgressListener;
 
-    public Request(DownloadProfile download, String videoId, SaccubusListener<DownloadProgress> downListener,
-            ConvertProfile convert, SaccubusListener<ConvertProgress> convListener) {
+    public Request(DownloadProfile download, String videoId, WorkerListener<DownloadProgress> downListener,
+            ConvertProfile convert, WorkerListener<ConvertProgress> convListener) {
         this.rowId = ++serialId;
         this.downloadProfile = download;
         this.videoId = videoId;
@@ -47,11 +47,11 @@ public class Request {
         return rowId;
     }
 
-    SaccubusListener<DownloadProgress> getDownloadProgressListener() {
+    WorkerListener<DownloadProgress> getDownloadProgressListener() {
         return downloadProgressListener;
     }
 
-    SaccubusListener<ConvertProgress> getConvertProgressListener() {
+    WorkerListener<ConvertProgress> getConvertProgressListener() {
         return convertProgressListener;
     }
 }