OSDN Git Service

進捗報告実装
authoryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 07:46:01 +0000 (16:46 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 07:48:43 +0000 (16:48 +0900)
frontend/src/saccubus/worker/impl/PercentageReportable.java [new file with mode: 0644]
frontend/src/saccubus/worker/impl/convert/Convert.java
frontend/src/saccubus/worker/impl/convert/ConvertProgress.java
frontend/src/saccubus/worker/impl/download/Download.java
frontend/src/saccubus/worker/impl/download/DownloadProgress.java
frontend/src/yukihane/inqubus/manager/TaskManage.java

diff --git a/frontend/src/saccubus/worker/impl/PercentageReportable.java b/frontend/src/saccubus/worker/impl/PercentageReportable.java
new file mode 100644 (file)
index 0000000..24960ae
--- /dev/null
@@ -0,0 +1,9 @@
+package saccubus.worker.impl;
+
+/**
+ *
+ * @author yuki
+ */
+public interface PercentageReportable {
+    double getPercentage();
+}
index 3f581f3..3aca88f 100644 (file)
@@ -52,7 +52,8 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
      * @param output 変換後出力動画.
      * @throws IOException 変換失敗.
      */
-    public Convert(ConvertProfile profile, File video, File comment, WorkerListener<ConvertResult, ConvertProgress> listener) {
+    public Convert(ConvertProfile profile, File video, File comment,
+            WorkerListener<ConvertResult, ConvertProgress> listener) {
         super(listener);
         this.profile = profile;
         this.videoFile = video;
@@ -84,18 +85,18 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
             if (profile.isCommentOverlay()) {
                 transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir());
                 final HideCondition hide = profile.getNgSetting();
-                publish(new ConvertProgress(PROCESS, "コメントの中間ファイルへの変換中"));
+                publish(new ConvertProgress(PROCESS, 0.0, "コメントの中間ファイルへの変換中"));
                 ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.getWord());
             }
 
             checkStop();
-            publish(new ConvertProgress(PROCESS, "動画の変換を開始"));
+            publish(new ConvertProgress(PROCESS, 0.0, "動画の変換を開始"));
 
             final int code = convert(transformedComment, outputFile);
             if (code != 0) {
                 throw new IOException("ffmpeg実行失敗: " + outputFile.getPath());
             }
-            publish(new ConvertProgress(PROCESS, "変換が正常に終了しました。"));
+            publish(new ConvertProgress(PROCESS, 100.0, "変換が正常に終了しました。"));
             return new ConvertResult(true, outputFile.getName());
         } finally {
             if (transformedComment != null && transformedComment.exists()) {
@@ -191,7 +192,8 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
             String msg;
             while ((msg = ebr.readLine()) != null) {
                 if (msg.startsWith("frame=")) {
-                    publish(new ConvertProgress(PROCESS, msg));
+                    // TODO パーセンテージ計算、出力
+                    publish(new ConvertProgress(PROCESS, 0.0, msg));
                 } else if (!msg.endsWith("No accelerated colorspace conversion found")) {
                     logger.log(Level.INFO, msg);
                 }
index 44b9527..79df46c 100644 (file)
@@ -1,18 +1,22 @@
 package saccubus.worker.impl.convert;
 
 import org.apache.commons.lang.builder.ToStringBuilder;
+import saccubus.worker.impl.MessageReportable;
+import saccubus.worker.impl.PercentageReportable;
 
 /**
  *
  * @author yuki
  */
-public class ConvertProgress {
+public class ConvertProgress implements PercentageReportable, MessageReportable {
 
     private final ConvertStatus status;
+    private final double percentage;
     private final String message;
 
-    ConvertProgress(ConvertStatus status, String message) {
+    ConvertProgress(ConvertStatus status, double percentage, String message) {
         this.status = status;
+        this.percentage = percentage;
         this.message = message;
     }
 
@@ -25,6 +29,11 @@ public class ConvertProgress {
     }
 
     @Override
+    public double getPercentage() {
+        return percentage;
+    }
+
+    @Override
     public String toString() {
         return ToStringBuilder.reflectionToString(this);
     }
index 51810e1..eb5b166 100644 (file)
@@ -80,7 +80,7 @@ public class Download extends Worker<DownloadResult, DownloadProgress> {
     @Override
     public DownloadResult work() throws Exception {
 
-        publish(new DownloadProgress(PROCESS, "ログイン中"));
+        publish(new DownloadProgress(PROCESS, 0.0, "ログイン中"));
 
         NicoHttpClient client = null;
         nicobrowser.VideoInfo vi = null;
@@ -132,7 +132,7 @@ public class Download extends Worker<DownloadResult, DownloadProgress> {
                 @Override
                 public void progress(long fileSize, long downloadSize) {
                     final double vol = (double) downloadSize / (double) fileSize * 100.0;
-                    publish(new DownloadProgress(PROCESS, String.format("ダウンロード%.2f%%", vol)));
+                    publish(new DownloadProgress(PROCESS, vol, String.format("ダウンロード%.2f%%", vol)));
                 }
             });
 
index 62a265d..1ef07f8 100644 (file)
@@ -1,18 +1,22 @@
 package saccubus.worker.impl.download;
 
 import org.apache.commons.lang.builder.ToStringBuilder;
+import saccubus.worker.impl.MessageReportable;
+import saccubus.worker.impl.PercentageReportable;
 
 /**
  *
  * @author yuki
  */
-public class DownloadProgress {
+public class DownloadProgress implements PercentageReportable, MessageReportable {
 
     private final DownloadStatus status;
+    private final double percentage;
     private final String message;
 
-    DownloadProgress(DownloadStatus status, String message) {
+    DownloadProgress(DownloadStatus status, double percentage, String message) {
         this.status = status;
+        this.percentage = percentage;
         this.message = message;
     }
 
@@ -25,6 +29,11 @@ public class DownloadProgress {
     }
 
     @Override
+    public double getPercentage() {
+        return percentage;
+    }
+
+    @Override
     public String toString() {
         return ToStringBuilder.reflectionToString(this);
     }
index 47d4f10..ab37bbe 100644 (file)
@@ -8,6 +8,8 @@ import java.util.concurrent.Future;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import saccubus.worker.WorkerListener;
+import saccubus.worker.impl.MessageReportable;
+import saccubus.worker.impl.PercentageReportable;
 import saccubus.worker.impl.convert.Convert;
 import saccubus.worker.impl.convert.ConvertProgress;
 import saccubus.worker.impl.convert.ConvertResult;
@@ -22,6 +24,7 @@ import saccubus.worker.profile.DownloadProfile;
  * @author yuki
  */
 public class TaskManage {
+
     private static final Logger logger = Logger.getLogger(TaskManage.class.getName());
     private final ExecutorService downloadExecutorService;
     private final ExecutorService convertExecutorService;
@@ -94,7 +97,7 @@ public class TaskManage {
         }
     }
 
-    abstract class TaskManageInnerListener<T, V> implements WorkerListener<T, V> {
+    abstract class TaskManageInnerListener<T, V extends PercentageReportable & MessageReportable> implements WorkerListener<T, V> {
 
         private final int rowId;
 
@@ -122,8 +125,7 @@ public class TaskManage {
         @Override
         public void process(V progress) {
             logger.log(Level.FINEST, "process: {0}", progress);
-            // TOOD
-            notify(TaskStatus.DOING, 0.0, "");
+            notify(TaskStatus.DOING, progress.getPercentage(), progress.getMessage());
         }
 
         @Override