OSDN Git Service

カスタムJTable
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
index 71f9a25..4fd93b2 100644 (file)
@@ -17,6 +17,7 @@ import java.awt.event.ItemListener;
 import java.awt.event.KeyEvent;
 import java.io.File;
 import java.io.FilenameFilter;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -42,19 +43,34 @@ import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.KeyStroke;
 import javax.swing.LayoutStyle.ComponentPlacement;
+import javax.swing.SwingUtilities;
 import javax.swing.TransferHandler;
 import javax.swing.WindowConstants;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ToStringBuilder;
 import saccubus.MainFrame_AboutBox;
-import saccubus.worker.Download;
+import saccubus.util.WayBackTimeParser;
+import saccubus.worker.impl.convert.ConvertProgress;
+import saccubus.worker.impl.download.DownloadProgress;
+import saccubus.worker.WorkerListener;
+import saccubus.worker.impl.convert.ConvertResult;
+import saccubus.worker.impl.download.DownloadResult;
 import saccubus.worker.profile.CommentProfile;
+import saccubus.worker.profile.ConvertProfile;
 import saccubus.worker.profile.DownloadProfile;
+import saccubus.worker.profile.FfmpegProfile;
 import saccubus.worker.profile.GeneralProfile;
 import saccubus.worker.profile.LoginProfile;
+import saccubus.worker.profile.OutputProfile;
 import saccubus.worker.profile.ProxyProfile;
 import saccubus.worker.profile.VideoProfile;
 import yukihane.Util;
 import yukihane.inqubus.Config;
+import yukihane.inqubus.manager.RequestProcess;
+import yukihane.inqubus.manager.TaskKind;
+import yukihane.inqubus.manager.TaskManage;
+import yukihane.inqubus.manager.TaskManageListener;
+import yukihane.inqubus.manager.TaskStatus;
 import yukihane.inqubus.model.Target;
 import yukihane.inqubus.model.TargetsTableModel;
 
@@ -75,6 +91,7 @@ public class MainFrame extends JFrame {
     private static final String FILE_OUTPUTFIELD_TOOLTIP
             = "ファイル命名規則入力します。";
     private final TargetsTableModel targetModel = new TargetsTableModel();
+    private final TaskManage taskManager;
 
     /** Creates new form MainFrame */
     public MainFrame() {
@@ -89,7 +106,7 @@ public class MainFrame extends JFrame {
 
         final JPanel pnlMain = new JPanel();
         final JScrollPane scrDisplay = new JScrollPane();
-        tblDisplay = new JTable();
+        tblDisplay = new MainTable();
         final JPanel pnlButton = new JPanel();
         btnStart = new JButton();
         btnStop = new JButton();
@@ -334,16 +351,39 @@ public class MainFrame extends JFrame {
         initInputPanel();
         pnlMain.setTransferHandler(new DownloadListTransferHandler());
         tblDisplay.setTransferHandler(new TableTransferHandler());
+
+        final Config p = Config.INSTANCE;
+        // TODO コンフィグからスレッド数
+        taskManager = new TaskManage(1, 1, new GuiTaskManageListener());
+    }
+
+    private class GuiTaskManageListener implements TaskManageListener {
+
+        @Override
+        public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
+                final String message) {
+            SwingUtilities.invokeLater(new Runnable() {
+
+                @Override
+                public void run() {
+                    targetModel.setStatus(id, kind, status, percentage, message);
+                }
+            });
+        }
     }
 
     private class ApplyActionListener implements ActionListener {
 
         @Override
         public void actionPerformed(ActionEvent e) {
-            final DownloadProfile prof = new InqubusDownloadProfile();
+            final DownloadProfile downProf = new InqubusDownloadProfile();
             final String id = Util.getVideoId(fldId.getText());
-
-            new Download(prof, id).execute();
+            final InqubusConvertProfile convProf = new InqubusConvertProfile();
+            logger.log(Level.INFO, downProf.toString());
+            logger.log(Level.INFO, convProf.toString());
+            final RequestProcess rp = new RequestProcess(downProf, id, convProf);
+            taskManager.add(rp);
+            targetModel.addTarget(new Target(rp));
         }
     }
     /** This method is called from within the constructor to
@@ -356,7 +396,7 @@ public class MainFrame extends JFrame {
     private void initComponents() {
     }// </editor-fold>//GEN-END:initComponents
 
-    private File searchFileMatchId(final File dir, final String id) throws UnsupportedOperationException {
+    private File searchFileMatchId(final File dir, final String id) {
         // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
         if (id.isEmpty()) {
             return null;
@@ -563,6 +603,54 @@ public class MainFrame extends JFrame {
         return menuBar;
     }
 
+    private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
+
+        @Override
+        public void process(DownloadProgress progress) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void cancelled() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void done(DownloadResult result) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void error(Throwable th) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+    }
+
+    private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
+
+        @Override
+        public void process(ConvertProgress progress) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void cancelled() {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void done(ConvertResult result) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void error(Throwable th) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+    }
+
+
+
     private class DownloadListTransferHandler extends TransferHandler {
 
         private static final long serialVersionUID = 1L;
@@ -580,30 +668,32 @@ public class MainFrame extends JFrame {
 
         @Override
         public boolean importData(TransferHandler.TransferSupport support) {
-            try {
-                Transferable transferable = support.getTransferable();
-                if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
-                    @SuppressWarnings("unchecked")
-                    final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
-                    Collection<Target> targets = Target.from(data);
-                    targetModel.addTarget(targets);
-                } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
-                    String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
-                    Matcher matcher = movieIdPattern.matcher(data);
-                    if (matcher.find()) {
-                        String movieId = matcher.group(1);
-                        Target target = Target.fromId(movieId);
-                        targetModel.addTarget(target);
-                    } else {
-                        return false;
-                    }
-
-                }
-                return false;
-            } catch (Exception e) {
-                logger.log(Level.SEVERE, null, e);
-                return false;
-            }
+//            try {
+//                Transferable transferable = support.getTransferable();
+//                if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
+//                    @SuppressWarnings("unchecked")
+//                    final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
+//                    Collection<Target> targets = Target.from(data);
+//                    targetModel.addTarget(targets);
+//                } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+//                    String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
+//                    Matcher matcher = movieIdPattern.matcher(data);
+//                    if (matcher.find()) {
+//                        String movieId = matcher.group(1);
+//                        Target target = Target.fromId(movieId);
+//                        targetModel.addTarget(target);
+//                    } else {
+//                        return false;
+//                    }
+//
+//                }
+//                return false;
+//            } catch (Exception e) {
+//                logger.log(Level.SEVERE, null, e);
+//                return false;
+//            }
+            // TODO 上記実装見直し(Locationは削除された)
+            return false;
         }
     }
 
@@ -622,6 +712,9 @@ public class MainFrame extends JFrame {
         }
     }
 
+    /*
+     * ここからDownloadProfile作成用クラスの定義
+     */
 
     private class InqubusDownloadProfile implements DownloadProfile {
 
@@ -663,6 +756,11 @@ public class MainFrame extends JFrame {
         public GeneralProfile getGeneralProfile() {
             return this.generalProfile;
         }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
     }
 
     private class InqubusLoginProfile implements LoginProfile {
@@ -684,6 +782,11 @@ public class MainFrame extends JFrame {
         public String getPassword() {
             return this.password;
         }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
     }
 
     private class InqubusProxyProfile implements ProxyProfile {
@@ -713,6 +816,11 @@ public class MainFrame extends JFrame {
         public int getPort() {
             return this.port;
         }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
     }
 
     private class InqubusVideoProfile implements VideoProfile {
@@ -722,11 +830,11 @@ public class MainFrame extends JFrame {
         private final File localFile;
 
         private InqubusVideoProfile(){
+            final Config p = Config.INSTANCE;
             this.download = !cbVideoLocal.isSelected();
             if (this.download) {
-                this.dir = new File(fldVideo.getText());
-                // TODO ディレクトリとファイル名の入力欄を分ける
-                this.fileName = "{id}_{title}";
+                this.dir = new File(p.getVideoDir());
+                this.fileName = fldVideo.getText();
                 this.localFile = null;
             } else {
                 this.dir = null;
@@ -754,70 +862,397 @@ public class MainFrame extends JFrame {
         public File getLocalFile() {
             return this.localFile;
         }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
     }
 
     private class InqubusCommentProfile implements CommentProfile {
+        private final boolean download;
+        private final File dir;
+        private final String fileName;
+        private final File localFile;
+        private final int lengthRelatedCommentSize;
+        private final boolean disablePerMinComment;
+        private final int perMinCommentSize;
+        private final long backLogPoint;
+
+        private InqubusCommentProfile() {
+            final Config p = Config.INSTANCE;
+            this.download = !cbVideoLocal.isSelected();
+            if (this.download) {
+                this.dir = new File(p.getVideoDir());
+                this.fileName = fldVideo.getText();
+                this.localFile = null;
+            } else {
+                this.dir = null;
+                this.fileName = null;
+                this.localFile = new File(fldVideo.getText());
+            }
+
+            if(cbBackLog.isSelected()) {
+                try {
+                    this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
+                } catch (IOException ex) {
+                    throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
+                }
+            } else {
+                this.backLogPoint = -1L;
+            }
+
+            this.disablePerMinComment = cbBackLogReduce.isSelected();
+            this.lengthRelatedCommentSize
+                    = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
+            this.perMinCommentSize
+                    = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
+        }
+
+        @Override
+        public boolean isDownload() {
+            return this.download;
+        }
+
+        @Override
+        public File getDir() {
+            return this.dir;
+        }
+
+        @Override
+        public String getFileName() {
+            return this.fileName;
+        }
+
+        @Override
+        public File getLocalFile() {
+            return this.localFile;
+        }
 
         @Override
         public int getLengthRelatedCommentSize() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            return this.lengthRelatedCommentSize;
         }
 
         @Override
         public boolean isDisablePerMinComment() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            return this.disablePerMinComment;
         }
 
         @Override
         public int getPerMinCommentSize() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            return this.perMinCommentSize;
         }
 
         @Override
         public long getBackLogPoint() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            return this.backLogPoint;
         }
 
         @Override
-        public boolean isDownload() {
-            throw new UnsupportedOperationException("Not supported yet.");
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+
+    private class InqubusGeneralProfile implements GeneralProfile {
+        private final String replaceFrom;
+        private final String replaceTo;
+        private InqubusGeneralProfile() {
+            final Config p = Config.INSTANCE;
+            this.replaceFrom = p.getReplaceFrom();
+            this.replaceTo = p.getReplaceTo();
+        }
+
+        @Override
+        public String getReplaceFrom() {
+            return this.replaceFrom;
+        }
+
+        @Override
+        public String getReplaceTo() {
+            return this.replaceTo;
+        }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+
+    /*
+     * ここからConvertProfile作成用クラスの定義
+     */
+    private class InqubusConvertProfile implements ConvertProfile {
+        private final OutputProfile outputProfile;
+        private final GeneralProfile generalProfile;
+        private final FfmpegProfile ffmpegProfile;
+        private final boolean convert;
+        private final File ffmpeg;
+        private final boolean vhookDisabled;
+        private final boolean commentOverlay;
+        private final File vhook;
+        private final File tmpDir;
+        private final File font;
+        private final int fontIndex;
+        private final boolean commentOpaque;
+        private final boolean disableFontSizeArrange;
+        private final int shadowIndex;
+        private final boolean showConvrting;
+        private final int maxNumOfComment;
+        private final HideCondition ngSetting;
+
+        private InqubusConvertProfile() {
+            final Config p = Config.INSTANCE;
+            this.outputProfile = new InqubusOutputProfile();
+            this.generalProfile = new InqubusGeneralProfile();
+            this.ffmpegProfile = new InqubusFfmpegProfile();
+            this.convert = cbOutputEnable.isSelected();
+            this.ffmpeg = new File(p.getFfmpegPath());
+            // TODO コンフィグに設定なし
+            this.vhookDisabled = false;
+            this.commentOverlay = p.getOutputCommentOverlay();
+            this.vhook = new File(p.getFfmpegDllPath());
+            // TODO コンフィグに設定なし
+            this.tmpDir = new File(".");
+            this.font = new File(p.getFontPath());
+            this.fontIndex = Integer.parseInt(p.getFontIndex());
+            this.commentOpaque = p.getCommentOpaque();
+            this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
+            this.shadowIndex = p.getFontShadow();
+            // TODO コンフィグに設定なし
+            this.showConvrting = true;
+            this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
+                    getCommentDisplaySizeManual());
+            this.ngSetting = new InqubusHideCondition();
+        }
+
+        @Override
+        public OutputProfile getOutputProfile() {
+            return this.outputProfile;
+        }
+
+        @Override
+        public GeneralProfile getGeneralProfile() {
+            return this.generalProfile;
+        }
+
+        @Override
+        public FfmpegProfile getFfmpegOption() {
+            return this.ffmpegProfile;
+        }
+
+        @Override
+        public boolean isConvert() {
+            return this.convert;
+        }
+
+        @Override
+        public File getFfmpeg() {
+            return this.ffmpeg;
+        }
+
+        @Override
+        public boolean isVhookDisabled() {
+            return this.vhookDisabled;
+        }
+
+        @Override
+        public boolean isCommentOverlay() {
+            return this.commentOverlay;
+        }
+
+        @Override
+        public File getVhook() {
+            return this.vhook;
+        }
+
+        @Override
+        public File getTempDir() {
+            return this.tmpDir;
+        }
+
+        @Override
+        public File getFont() {
+            return this.font;
+        }
+
+        @Override
+        public int getFontIndex() {
+            return this.fontIndex;
+        }
+
+        @Override
+        public boolean isCommentOpaque() {
+            return this.commentOpaque;
+        }
+
+        @Override
+        public boolean isDisableFontSizeArrange() {
+            return this.disableFontSizeArrange;
+        }
+
+        @Override
+        public int getShadowIndex() {
+            return this.shadowIndex;
+        }
+
+        @Override
+        public boolean isShowConverting() {
+            return this.showConvrting;
+        }
+
+        @Override
+        public int getMaxNumOfComment() {
+            return this.maxNumOfComment;
+        }
+
+        @Override
+        public HideCondition getNgSetting() {
+            return this.ngSetting;
+        }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+
+    private class InqubusOutputProfile implements OutputProfile {
+        private final File dir;
+        private final String fileName;
+        private final String videoId;
+        private final String title;
+
+
+        private InqubusOutputProfile(){
+            final Config p = Config.INSTANCE;
+            this.dir = new File(p.getOutputDir());
+            this.fileName = fldOutput.getText();
+            // TODO この時点でのID/Titleはどうするか…
+            this.videoId = "";
+            this.title = "";
         }
 
         @Override
         public File getDir() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            return this.dir;
         }
 
         @Override
         public String getFileName() {
-            throw new UnsupportedOperationException("Not supported yet.");
+            return this.fileName;
         }
 
         @Override
-        public File getLocalFile() {
-            throw new UnsupportedOperationException("Not supported yet.");
+        public String getVideoId() {
+            return this.videoId;
+        }
+
+        @Override
+        public String getTitile() {
+            return this.title;
         }
 
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
     }
 
-    private class InqubusGeneralProfile implements GeneralProfile {
-//        private final String replaceFrom;
-        private InqubusGeneralProfile() {
+    private class InqubusFfmpegProfile implements FfmpegProfile {
+        private final String extOption;
+        private final String inOption;
+        private final String mainOption;
+        private final String outOption;
+        private final String avOption;
+        private final boolean resize;
+        private final int resizeWidth;
+        private final int resizeHeight;
+        private final boolean adjustRatio;
+
+        private InqubusFfmpegProfile() {
+            // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
             final Config p = Config.INSTANCE;
-            // TODO 置換文字設定コンフィグが無い
-//            this.replaceFrom = p.get
+            this.extOption = p.getFfmpegExtension();
+            this.inOption = p.getFfmpegInOption();
+            this.mainOption = p.getFfmpegMainOption();
+            this.outOption = p.getFfmpegOutOption();
+            this.avOption = p.getFfmpegAvOption();
+            this.resize = p.getFfmpegResizeEnable();
+            this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
+            this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
+            this.adjustRatio = p.getFfmpegKeepAspect();
         }
 
         @Override
-        public String getReplaceFrom() {
-//            return this.replaceFrom;
-            throw new UnsupportedOperationException("Not supported yet.");
+        public String getExtOption() {
+            return this.extOption;
         }
 
         @Override
-        public String getReplaceTo() {
-            throw new UnsupportedOperationException("Not supported yet.");
+        public String getInOption() {
+            return this.inOption;
+        }
+
+        @Override
+        public String getMainOption() {
+            return this.mainOption;
         }
 
+        @Override
+        public String getOutOption() {
+            return this.outOption;
+        }
+
+        @Override
+        public String getAvfilterOption() {
+            return this.avOption;
+        }
+
+        @Override
+        public boolean isResize() {
+            return this.resize;
+        }
+
+        @Override
+        public int getResizeWidth() {
+            return this.resizeWidth;
+        }
+
+        @Override
+        public int getResizeHeight() {
+            return this.resizeHeight;
+        }
+
+        @Override
+        public boolean isAdjustRatio() {
+            return this.adjustRatio;
+        }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+
+    private class InqubusHideCondition implements ConvertProfile.HideCondition{
+
+        @Override
+        public String getWord() {
+            // TODO
+            return "";
+        }
+
+        @Override
+        public String getId() {
+            // TODO
+            return "";
+        }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
     }
 }