OSDN Git Service

AbstractCommandを削除
authoryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 01:25:28 +0000 (10:25 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 22 Aug 2011 01:25:28 +0000 (10:25 +0900)
frontend/src/saccubus/converter/AbstractCommand.java [deleted file]
frontend/src/saccubus/converter/ConvertProgress.java
frontend/src/saccubus/converter/Converter.java
frontend/src/saccubus/converter/FfmpegCommand.java
frontend/src/saccubus/converter/FfmpegCommandProgress.java

diff --git a/frontend/src/saccubus/converter/AbstractCommand.java b/frontend/src/saccubus/converter/AbstractCommand.java
deleted file mode 100644 (file)
index ff62ba5..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* $Id$ */
-package saccubus.converter;
-
-import javax.swing.SwingWorker;
-import static org.apache.commons.lang.Validate.*;
-import saccubus.ConvertStopFlag;
-import saccubus.net.TextProgressListener;
-
-/**
- *
- * @author yuki
- */
-public abstract class AbstractCommand<T, V> extends SwingWorker<T, V> {
-
-    private final TextProgressListener listener;
-
-    public AbstractCommand(TextProgressListener listener) {
-        notNull(listener);
-
-        this.listener = listener;
-    }
-
-    protected void checkStop() throws InterruptedException {
-        if (Thread.interrupted()) {
-            throw new InterruptedException("中止要求を受け付けました");
-        }
-    }
-
-    protected void sendText(String text) {
-        getListener().setText(text);
-    }
-
-    /**
-     * @return the listener
-     */
-    protected TextProgressListener getListener() {
-        return listener;
-    }
-}
index 069a295..9f9e17e 100644 (file)
@@ -6,4 +6,13 @@ package saccubus.converter;
  */
 public class ConvertProgress {
 
+    private final String message;
+
+    ConvertProgress(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
 }
index 11b630b..04fbbfe 100644 (file)
@@ -5,6 +5,7 @@ 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;
@@ -33,7 +34,7 @@ import saccubus.converter.profile.ProxyProfile;
  * @author 未入力
  * @version 1.0
  */
-public abstract class Converter extends AbstractCommand<ConvertResult, ConvertProgress> implements Callable<Boolean> {
+public abstract class Converter extends SwingWorker<ConvertResult, ConvertProgress> implements Callable<Boolean> {
 
     private static final Logger logger = Logger.getLogger(Converter.class.getName());
     private final Profile profile;
@@ -49,7 +50,6 @@ public abstract class Converter extends AbstractCommand<ConvertResult, ConvertPr
      */
     public Converter(String id, Profile profile,
             TextProgressListener listener, ConvertStopFlag flag) {
-        super(listener);
         this.movieId = id;
         this.profile = profile;
     }
@@ -75,11 +75,10 @@ public abstract class Converter extends AbstractCommand<ConvertResult, ConvertPr
 //            logger.log(Level.SEVERE, null, ex);
 //        }
 //    }
-
     @Override
     protected ConvertResult doInBackground() throws Exception {
         if (!shouldRun(profile)) {
-            sendText("何もすることがありません");
+            publish(new ConvertProgress("何もすることがありません"));
             return new ConvertResult(true);
         }
 
@@ -87,7 +86,7 @@ public abstract class Converter extends AbstractCommand<ConvertResult, ConvertPr
         final FfmpegProfile ov = profile.getFfmpeg().getFfmpegOption();
 
         // TODO ログインしないで良い場合もある.
-        sendText("ログイン中");
+        publish(new ConvertProgress("ログイン中"));
 
 
 
@@ -123,7 +122,8 @@ public abstract class Converter extends AbstractCommand<ConvertResult, ConvertPr
             final String name = pattern.createFileName(movieId, true);
             final File file = new File(profile.getCommentSetting().getDir(), name);
 
-            commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentSetting().getLengthRelatedCommentSize(),
+            commentFile = client.getCommentFile(vi, file.getPath(), wbi, profile.getCommentSetting().
+                    getLengthRelatedCommentSize(),
                     profile.getCommentSetting().isDisablePerMinComment());
         } else {
             commentFile = profile.getCommentSetting().getLocalFile();
@@ -154,7 +154,7 @@ public abstract class Converter extends AbstractCommand<ConvertResult, ConvertPr
         }
 
         if (!profile.getOutputFileSetting().isConvert()) {
-            sendText("動画・コメントを保存し、変換は行いませんでした。");
+            publish(new ConvertProgress("動画・コメントを保存し、変換は行いませんでした。"));
             return new ConvertResult(true);
         }
 
@@ -271,4 +271,10 @@ public abstract class Converter extends AbstractCommand<ConvertResult, ConvertPr
         final String name = pattern.createFileName(movieId, isNotLow);
         return new File(dir, name);
     }
+
+    private void checkStop() throws InterruptedException {
+        if (Thread.interrupted()) {
+            throw new InterruptedException("中止要求を受け付けました");
+        }
+    }
 }
index ddbd716..200d206 100644 (file)
@@ -11,6 +11,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.swing.SwingWorker;
 import org.apache.commons.lang.StringUtils;
 import saccubus.ConvertStopFlag;
 import saccubus.conv.ConvertToVideoHook;
@@ -28,7 +29,8 @@ import yukihane.swf.Cws2Fws;
  *
  * @author yuki
  */
-public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCommandProgress> {
+public class FfmpegCommand extends SwingWorker<FfmpegCommandResult, FfmpegCommandProgress> {
+
     private static final Logger logger = Logger.getLogger(FfmpegCommand.class.getName());
     private final File commentMiddleFile;
     private final File tcommMiddleFile;
@@ -40,7 +42,6 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
 
     FfmpegCommand(TextProgressListener listener, ConvertStopFlag flag, File commentFile,
             File videoFile, File convertedVideoFile, ConvertProfile ffmpeg, GeneralProfile general) throws IOException {
-        super(listener);
         this.commentFile = commentFile;
         this.videoFile = videoFile;
         this.convertedVideoFile = convertedVideoFile;
@@ -52,7 +53,6 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
         TMP_CWS = File.createTempFile("cws", ".swf", tmpDir);
     }
 
-
     @Override
     protected FfmpegCommandResult doInBackground() throws Exception {
         try {
@@ -73,11 +73,11 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
     private FfmpegCommandResult exec() throws InterruptedException, IOException {
         final HideCondition ngSetting = getFfmpeg().getNgSetting();
         if (commentFile != null) {
-            sendText("コメントの中間ファイルへの変換中");
+            publish(new FfmpegCommandProgress("コメントの中間ファイルへの変換中"));
             boolean conv = ConvertToVideoHook.convert(commentFile, commentMiddleFile, ngSetting.getId(), ngSetting.
                     getWord());
             if (!conv) {
-                sendText("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?");
+                publish(new FfmpegCommandProgress("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?"));
                 return new FfmpegCommandResult(false);
             }
         }
@@ -91,14 +91,14 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
 //            }
 //        }
 //        stopFlagReturn();
-        sendText("動画の変換を開始");
+        publish(new FfmpegCommandProgress("動画の変換を開始"));
         int code;
         if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(),
                 false, tcommMiddleFile.getPath(), getFfmpeg().getFfmpegOption())) == 0) {
-            sendText("変換が正常に終了しました。");
+            publish(new FfmpegCommandProgress("変換が正常に終了しました。"));
             return new FfmpegCommandResult(true);
         } else {
-            sendText("変換エラー:" + convertedVideoFile.getPath());
+            publish(new FfmpegCommandProgress("変換エラー:" + convertedVideoFile.getPath()));
         }
         return new FfmpegCommandResult(false);
     }
@@ -138,7 +138,7 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
 
         final Info info = MediaInfo.getInfo(new File("bin", "MediaInfo"), videoFile);
         // 4:3 なら1.33, 16:9 なら1.76
-        boolean isHD = ((double)info.getWidth()/(double)info.getHeight() > 1.5);
+        boolean isHD = ((double) info.getWidth() / (double) info.getHeight() > 1.5);
         if (ov.isResize()) {
             final Size scaled = (ov.isAdjustRatio()) ? MediaInfo.adjustSize(info, ov.getResizeWidth(), ov.
                     getResizeHeight()) : new Size(info.getWidth(), info.getHeight());
@@ -149,7 +149,7 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
         List<String> avfilterArgs = getAvfilterOptions(ov.getAvfilterOption());
         if (!getFfmpeg().isVhookDisabled()) {
             String vhookArg = getVhookArg(addComment, commPath, addTcomment, tcommPath, isHD);
-            if(StringUtils.isNotBlank(vhookArg)){
+            if (StringUtils.isNotBlank(vhookArg)) {
                 avfilterArgs.add(vhookArg);
             }
         }
@@ -179,7 +179,7 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
             while ((e = ebr.readLine()) != null) {
                 String state = e;
                 if (state.startsWith("frame=")) {
-                    sendText(state);
+                    publish(new FfmpegCommandProgress(state));
                 } else if (!state.endsWith("No accelerated colorspace conversion found")) {
                     logger.log(Level.INFO, e);
                 }
@@ -253,7 +253,7 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
             sb.append("--enable-opaque-comment");
             sb.append("|");
         }
-        if(isHD){
+        if (isHD) {
             sb.append("--aspect-mode:1");
             sb.append("|");
         }
@@ -263,4 +263,10 @@ public class FfmpegCommand extends AbstractCommand<FfmpegCommandResult, FfmpegCo
     private ConvertProfile getFfmpeg() {
         return ffmpeg;
     }
+
+    protected void checkStop() throws InterruptedException {
+        if (Thread.interrupted()) {
+            throw new InterruptedException("中止要求を受け付けました");
+        }
+    }
 }
index fc530b7..c1ecd5f 100644 (file)
@@ -6,4 +6,13 @@ package saccubus.converter;
  */
 public class FfmpegCommandProgress {
 
+    private final String message;
+
+    FfmpegCommandProgress(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
 }