OSDN Git Service

カスタムJTable
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
index 3b05f30..4fd93b2 100644 (file)
@@ -43,23 +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.util.WayBackTimeParser;
-import saccubus.worker.ConvertProgress;
-import saccubus.worker.DownloadProgress;
-import saccubus.worker.SaccubusCallable.SaccubusListener;
+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;
 
@@ -80,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() {
@@ -94,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();
@@ -339,17 +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());
-            logger.log(Level.INFO, prof.toString());
-            // TODO 処理開始
-//            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
@@ -569,20 +603,50 @@ public class MainFrame extends JFrame {
         return menuBar;
     }
 
-    private class DownloadProgressListener implements SaccubusListener<DownloadProgress> {
+    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 SaccubusListener<ConvertProgress> {
+    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.");
+        }
     }
 
 
@@ -604,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;
         }
     }
 
@@ -646,6 +712,9 @@ public class MainFrame extends JFrame {
         }
     }
 
+    /*
+     * ここからDownloadProfile作成用クラスの定義
+     */
 
     private class InqubusDownloadProfile implements DownloadProfile {
 
@@ -910,4 +979,280 @@ public class MainFrame extends JFrame {
             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() {
+            return this.dir;
+        }
+
+        @Override
+        public String getFileName() {
+            return this.fileName;
+        }
+
+        @Override
+        public String getVideoId() {
+            return this.videoId;
+        }
+
+        @Override
+        public String getTitile() {
+            return this.title;
+        }
+
+        @Override
+        public String toString(){
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+
+    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;
+            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 getExtOption() {
+            return this.extOption;
+        }
+
+        @Override
+        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);
+        }
+    }
 }