OSDN Git Service

終了時に画面サイズ, 表示位置を記憶し次回起動時に再現する
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
1 /*
2  * MainFrame.java
3  *
4  * Created on 2011/05/28, 18:14:51
5  */
6 package yukihane.inqubus.gui;
7
8 import java.awt.Dimension;
9 import java.awt.Image;
10 import java.awt.ItemSelectable;
11 import java.awt.Point;
12 import java.awt.Toolkit;
13 import java.awt.datatransfer.DataFlavor;
14 import java.awt.datatransfer.Transferable;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.awt.event.ItemEvent;
18 import java.awt.event.ItemListener;
19 import java.awt.event.KeyEvent;
20 import java.awt.event.WindowAdapter;
21 import java.awt.event.WindowEvent;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.io.File;
25 import java.io.FilenameFilter;
26 import java.io.IOException;
27 import java.net.URL;
28 import java.nio.file.FileSystem;
29 import java.nio.file.FileSystems;
30 import java.nio.file.Path;
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Set;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37 import java.util.regex.Pattern;
38 import javax.swing.BorderFactory;
39 import javax.swing.DropMode;
40 import javax.swing.GroupLayout;
41 import javax.swing.GroupLayout.Alignment;
42 import javax.swing.JButton;
43 import javax.swing.JCheckBox;
44 import javax.swing.JFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuBar;
48 import javax.swing.JMenuItem;
49 import javax.swing.JOptionPane;
50 import javax.swing.JPanel;
51 import javax.swing.JScrollPane;
52 import javax.swing.JTabbedPane;
53 import javax.swing.JTable;
54 import javax.swing.JTextField;
55 import javax.swing.KeyStroke;
56 import javax.swing.LayoutStyle.ComponentPlacement;
57 import javax.swing.SwingUtilities;
58 import javax.swing.TransferHandler;
59 import javax.swing.WindowConstants;
60 import javax.swing.border.BevelBorder;
61 import org.apache.commons.configuration.ConfigurationException;
62 import org.apache.commons.lang.StringUtils;
63 import org.apache.commons.lang.builder.ToStringBuilder;
64 import saccubus.FfmpegOption;
65 import saccubus.MainFrame_AboutBox;
66 import saccubus.util.WayBackTimeParser;
67 import saccubus.worker.impl.convert.ConvertProgress;
68 import saccubus.worker.impl.download.DownloadProgress;
69 import saccubus.worker.WorkerListener;
70 import saccubus.worker.impl.convert.ConvertResult;
71 import saccubus.worker.impl.download.DownloadResult;
72 import saccubus.worker.profile.CommentProfile;
73 import saccubus.worker.profile.ConvertProfile;
74 import saccubus.worker.profile.DownloadProfile;
75 import saccubus.worker.profile.FfmpegProfile;
76 import saccubus.worker.profile.GeneralProfile;
77 import saccubus.worker.profile.LoginProfile;
78 import saccubus.worker.profile.OutputProfile;
79 import saccubus.worker.profile.ProxyProfile;
80 import saccubus.worker.profile.VideoProfile;
81 import yukihane.Util;
82 import yukihane.inqubus.Config;
83 import yukihane.inqubus.filewatch.FileWatch;
84 import yukihane.inqubus.manager.RequestProcess;
85 import yukihane.inqubus.manager.TaskKind;
86 import yukihane.inqubus.manager.TaskManage;
87 import yukihane.inqubus.manager.TaskManageListener;
88 import yukihane.inqubus.manager.TaskStatus;
89 import yukihane.inqubus.model.Target;
90 import yukihane.inqubus.model.TargetsTableModel;
91
92 /**
93  *
94  * @author yuki
95  */
96 public class MainFrame extends JFrame {
97
98     private static final long serialVersionUID = 1L;
99     private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
100     private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
101     private static final String FILE_LOCALBUTTON_TOOLTIP
102             = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
103     private static final String FILE_INPUTFIELD_TOOLTIP
104             = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
105             + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
106     private static final String FILE_OUTPUTFIELD_TOOLTIP
107             = "ファイル命名規則入力します。";
108     private final TargetsTableModel targetModel = new TargetsTableModel();
109     private final TaskManage taskManager;
110     private final Thread videoFileWatcherThread;
111     private final FileWatch videoFileWatcher;
112
113     /** Creates new form MainFrame */
114     public MainFrame() {
115         super();
116         addWindowListener(new MainFrameWindowListener());
117
118         final Config p = Config.INSTANCE;
119
120         // ワーカスレッド生成
121         final int thDownload = p.getSystemDownloadThread();
122         final int secDownload = p.getSystemDownloadWait();
123         final int thConvert = p.getSystemConvertThread();
124         taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
125
126         // TODO ディレクトリ監視スレッド生成
127         final List<String> videoSearchDirs = p.getSearchVideoDirs();
128         videoSearchDirs.add(p.getVideoDir());
129         final FileSystem fs = FileSystems.getDefault();
130         final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
131         for (String s : videoSearchDirs) {
132             videoPaths.add(fs.getPath(s));
133         }
134         videoFileWatcher = new FileWatch(videoPaths);
135         this.videoFileWatcherThread = new Thread(videoFileWatcher);
136         this.videoFileWatcherThread.setDaemon(true);
137
138         final URL url = MainFrame_AboutBox.class.getResource("icon.png");
139         final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
140         final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
141         final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
142         final List<Image> images = new ArrayList<>(2);
143         images.add(icon1);
144         images.add(icon2);
145         setIconImages(images);
146
147         final JPanel pnlMain = new JPanel();
148         final JScrollPane scrDisplay = new JScrollPane();
149         tblDisplay = new JTable(targetModel, new TargetsColumnModel());
150         tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
151         final JPanel pnlButton = new JPanel();
152         final JTabbedPane tbpInput = new JTabbedPane();
153         final JPanel pnlInputMain = new JPanel();
154         final JLabel lblId = new JLabel();
155         final JLabel lblVideo = new JLabel();
156         cbVideoLocal = new JCheckBox();
157         cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
158         fldVideo = new JTextField();
159         fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
160         final JLabel lblComment = new JLabel();
161
162         fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
163         cbBackLog.addItemListener(new ItemListener() {
164
165             @Override
166             public void itemStateChanged(ItemEvent e) {
167                 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
168                 fldBackLog.setEnabled(selected);
169             }
170         });
171         cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
172
173             @Override
174             public void propertyChange(PropertyChangeEvent evt) {
175                 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
176                 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
177                 fldBackLog.setEnabled(fldEnabled);
178             }
179         });
180         cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
181
182         cbCommentLocal = new JCheckBox();
183         cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
184         cbCommentLocal.addItemListener(new ItemListener() {
185
186             @Override
187             public void itemStateChanged(ItemEvent e) {
188                 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
189                 cbBackLogReduce.setEnabled(!selected);
190                 cbBackLog.setEnabled(!selected);
191             }
192         });
193         fldComment = new JTextField();
194         fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
195         final JLabel lblOutput = new JLabel();
196         cbOutputEnable = new JCheckBox();
197         fldOutput = new JTextField();
198         fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
199
200         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
201
202         btnStop.addActionListener(new StopActionListener());
203         final ApplyActionListener applyListener = new ApplyActionListener();
204         btnApply.addActionListener(applyListener);
205
206         pnlMain.setBorder(BorderFactory.createEtchedBorder());
207
208         tblDisplay.setDropMode(DropMode.INSERT_ROWS);
209         scrDisplay.setViewportView(tblDisplay);
210
211         pnlButton.setBorder(BorderFactory.createEtchedBorder());
212
213         GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
214         pnlButton.setLayout(gl_pnlButton);
215         gl_pnlButton.setHorizontalGroup(
216             gl_pnlButton.createParallelGroup(Alignment.LEADING)
217             .addGroup(gl_pnlButton.createSequentialGroup()
218                 .addContainerGap()
219                 .addComponent(btnStart)
220                 .addPreferredGap(ComponentPlacement.RELATED)
221                 .addComponent(btnStop)
222                 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
223                 .addComponent(btnDeselect)
224                 .addContainerGap())
225         );
226         gl_pnlButton.setVerticalGroup(
227             gl_pnlButton.createParallelGroup(Alignment.LEADING)
228             .addGroup(gl_pnlButton.createSequentialGroup()
229                 .addContainerGap()
230                 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
231                     .addComponent(btnStart)
232                     .addComponent(btnStop)
233                     .addComponent(btnDeselect))
234                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
235         );
236
237         lblId.setText("ID");
238
239
240         fldId = new IdComboBox(videoFileWatcher);
241         fldId.setToolTipText(ID_FIELD_TOOLTIP);
242         fldId.getEditorComponent().addActionListener(applyListener);
243         fldId.addFocusListener(new java.awt.event.FocusAdapter() {
244
245             public void focusLost(java.awt.event.FocusEvent evt) {
246                 idFieldFocusLost(evt);
247             }
248         });
249
250         lblVideo.setText("動画");
251
252         cbVideoLocal.setText("local");
253         cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
254
255             public void itemStateChanged(java.awt.event.ItemEvent evt) {
256                 useMovieLocalCheckBoxItemStateChanged(evt);
257             }
258         });
259
260         lblComment.setText("コメント");
261
262         cbCommentLocal.setText("local");
263         cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
264
265             public void itemStateChanged(java.awt.event.ItemEvent evt) {
266                 useMovieLocalCheckBoxItemStateChanged(evt);
267             }
268         });
269
270         lblOutput.setText("出力");
271
272         cbOutputEnable.setText("変換");
273         cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
274
275             public void itemStateChanged(java.awt.event.ItemEvent evt) {
276                 outputConvertCheckBoxItemStateChanged(evt);
277             }
278         });
279
280
281         final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
282         pnlInputMain.setLayout(glInputMain);
283         glInputMain.setHorizontalGroup(
284             glInputMain.createParallelGroup(Alignment.LEADING)
285             .addGroup(glInputMain.createSequentialGroup()
286                 .addContainerGap()
287                 .addComponent(lblId)
288                 .addPreferredGap(ComponentPlacement.RELATED)
289                 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
290                 .addPreferredGap(ComponentPlacement.UNRELATED)
291                 .addComponent(cbBackLogReduce)
292                 .addPreferredGap(ComponentPlacement.UNRELATED)
293                 .addComponent(cbBackLog)
294                 .addPreferredGap(ComponentPlacement.RELATED)
295                 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
296                 .addContainerGap()
297             )
298             .addGroup(glInputMain.createSequentialGroup()
299                 .addContainerGap()
300                 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
301                     .addComponent(lblVideo)
302                     .addComponent(lblComment)
303                     .addComponent(lblOutput)
304                 )
305                 .addPreferredGap(ComponentPlacement.RELATED)
306                 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
307                     .addComponent(cbVideoLocal)
308                     .addComponent(cbCommentLocal)
309                     .addComponent(cbOutputEnable)
310                 )
311                 .addPreferredGap(ComponentPlacement.RELATED)
312                 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
313                     .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
314                     .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
315                     .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
316                 )
317                 .addContainerGap()
318             )
319         );
320
321         glInputMain.setVerticalGroup(
322             glInputMain.createParallelGroup(Alignment.LEADING)
323             .addGroup(glInputMain.createSequentialGroup()
324                 .addContainerGap()
325                 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
326                     .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
327                     .addComponent(lblId)
328                     .addComponent(cbBackLogReduce)
329                     .addComponent(cbBackLog)
330                     .addComponent(fldBackLog)
331                 )
332                 .addPreferredGap(ComponentPlacement.RELATED)
333                 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
334                     .addComponent(lblVideo)
335                     .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
336                     .addComponent(cbVideoLocal))
337                 .addPreferredGap(ComponentPlacement.RELATED)
338                 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
339                     .addComponent(lblComment)
340                     .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
341                     .addComponent(cbCommentLocal))
342                 .addPreferredGap(ComponentPlacement.RELATED)
343                 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
344                     .addComponent(lblOutput)
345                     .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
346                     .addComponent(cbOutputEnable)
347                 )
348             )
349         );
350
351         // ffmpeg入力パネル
352         pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
353         pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
354         pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
355         pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
356
357             @Override
358             public void actionPerformed(ActionEvent e) {
359                 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
360                 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
361                 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
362                 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
363                 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
364                 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
365                 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
366             }
367         });
368         pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
369
370             @Override
371             public void itemStateChanged(ItemEvent e) {
372                 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
373                 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
374                 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
375                 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
376             }
377         });
378         pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
379
380             @Override
381             public void propertyChange(PropertyChangeEvent evt) {
382                 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
383                 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
384                 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
385                 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
386                 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
387             }
388         });
389
390
391         tbpInput.add("メイン", pnlInputMain);
392         tbpInput.add("ffmpeg", pnlInputFfmpeg);
393
394         // 入力部のボタンやメッセージ表示部
395         fldInputMessage.setEditable(false);
396         fldInputMessage.setEnabled(false);
397         fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
398
399         final JPanel pnlInputButton = new JPanel();
400         final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
401         pnlInputButton.setLayout(glInputButton);
402         glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
403             .addContainerGap()
404             .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
405             .addPreferredGap(ComponentPlacement.UNRELATED)
406             .addComponent(btnApply)
407             .addContainerGap()
408         );
409         glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
410             .addContainerGap()
411             .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
412                 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
413                 .addComponent(btnApply)
414             )
415             .addContainerGap()
416         );
417
418         // 画面下半分の入力部分
419         final JPanel pnlInputAll = new JPanel();
420         pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
421         final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
422         pnlInputAll.setLayout(glInputAll);
423         glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
424             .addComponent(tbpInput)
425             .addComponent(pnlInputButton)
426         );
427         glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
428             .addComponent(tbpInput)
429             .addComponent(pnlInputButton)
430         );
431
432         GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
433         pnlMain.setLayout(gl_pnlMain);
434         gl_pnlMain.setHorizontalGroup(
435             gl_pnlMain.createParallelGroup(Alignment.LEADING)
436             .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
437                 .addContainerGap()
438                 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
439                     .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
440                     .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
441                     .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
442                 )
443                 .addContainerGap())
444         );
445         gl_pnlMain.setVerticalGroup(
446             gl_pnlMain.createParallelGroup(Alignment.LEADING)
447             .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
448                 .addContainerGap()
449                 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
450                 .addPreferredGap(ComponentPlacement.RELATED)
451                 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
452                 .addPreferredGap(ComponentPlacement.RELATED)
453                 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
454                 .addContainerGap()
455             )
456         );
457
458
459         JMenuBar menuBar = initMenuBar();
460         setJMenuBar(menuBar);
461
462         GroupLayout layout = new GroupLayout(getContentPane());
463         getContentPane().setLayout(layout);
464         layout.setHorizontalGroup(
465             layout.createParallelGroup(Alignment.LEADING)
466             .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
467         );
468         layout.setVerticalGroup(
469             layout.createParallelGroup(Alignment.LEADING)
470             .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
471         );
472
473         pack();
474
475         /*
476          * 画面のサイズや位置を前回終了時のものに設定する
477          */
478         final int windowWidth = p.getSystemWindowWidth();
479         final int windowHeight = p.getSystemWindowHeight();
480         if (windowWidth > 0 && windowHeight > 0) {
481             setSize(windowWidth, windowHeight);
482         }
483
484         final int windowPosX = p.getSystemWindowPosX();
485         final int windowPosY = p.getSystemWindowPosY();
486         if (windowPosX > 0 && windowPosY > 0) {
487             setLocation(windowPosX, windowPosY);
488         } else {
489             setLocationByPlatform(true);
490         }
491
492         final int colId = p.getSystemColumnId();
493         if(colId > 0) {
494             tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
495         }
496         final int colStatus = p.getSystemColumnStatus();
497         if(colStatus > 0) {
498             tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
499         }
500
501         initInputPanel();
502         pnlMain.setTransferHandler(new DownloadListTransferHandler());
503         tblDisplay.setTransferHandler(new TableTransferHandler());
504     }
505
506     public void startWatcher() {
507         videoFileWatcherThread.start();
508     }
509
510     private class GuiTaskManageListener implements TaskManageListener {
511
512         @Override
513         public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
514                 final String message) {
515             SwingUtilities.invokeLater(new Runnable() {
516
517                 @Override
518                 public void run() {
519                     targetModel.setStatus(id, kind, status, percentage, message);
520                 }
521             });
522         }
523     }
524
525     private class StopActionListener implements ActionListener {
526
527         @Override
528         public void actionPerformed(ActionEvent e) {
529             final int row = tblDisplay.getSelectedRow();
530             final Target t = targetModel.getTarget(row);
531             final boolean res = taskManager.cancel(t.getRowId());
532             logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
533             if (res) {
534                 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
535             }
536         }
537     }
538
539     private class ApplyActionListener implements ActionListener {
540
541         @Override
542         public void actionPerformed(ActionEvent e) {
543             try {
544                 final DownloadProfile downProf = new InqubusDownloadProfile();
545                 final String id = Util.getVideoId(fldId.getText());
546                 final InqubusConvertProfile convProf = new InqubusConvertProfile();
547                 logger.log(Level.INFO, downProf.toString());
548                 logger.log(Level.INFO, convProf.toString());
549                 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
550                 taskManager.add(rp);
551                 targetModel.addTarget(new Target(rp));
552                 initInputPanel();
553             } catch (Throwable th) {
554                 logger.log(Level.SEVERE, null, th);
555                 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
556             }
557         }
558     }
559
560     private File searchFileMatchId(final File dir, final String id) {
561         // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
562         if (id.isEmpty()) {
563             return null;
564         }
565
566         final File[] lists = dir.listFiles(new FilenameFilter() {
567
568             final Pattern pattern = Pattern.compile(id + "\\D");
569
570             @Override
571             public boolean accept(File dir, String name) {
572                 return pattern.matcher(name).find();
573             }
574         });
575
576         if (lists.length == 1) {
577             return lists[0];
578         } else if (lists.length > 1) {
579             throw new UnsupportedOperationException();
580         } else {
581             return null;
582         }
583     }
584
585     /**
586      * 動画, コメントの"local"チェックボックス更新時の処理.
587      */
588     private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
589         final Config p = Config.INSTANCE;
590
591         final ItemSelectable source = evt.getItemSelectable();
592
593         JTextField field;
594         File dir;
595         if (source == cbVideoLocal) {
596             field = fldVideo;
597             dir = new File(p.getVideoDir());
598         } else {
599             field = fldComment;
600             dir = new File(p.getCommentDir());
601         }
602
603         final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
604
605         String text;
606         if (useLocal) {
607             final File f = searchFileMatchId(dir, fldId.getText());
608             if (f != null) {
609                 text = f.getPath();
610             } else {
611                 text = "";
612             }
613         } else {
614             text = p.getVideoFileNamePattern();
615         }
616         field.setText(text);
617
618     }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
619
620     private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
621         final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
622         fldOutput.setEnabled(convert);
623     }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
624
625     private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
626         final Config p = Config.INSTANCE;
627         final String id = fldId.getText();
628         if (id.isEmpty()) {
629             return;
630         }
631
632         if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
633             final File dir = new File(p.getVideoDir());
634             final File file = searchFileMatchId(dir, id);
635             if (file != null) {
636                 fldVideo.setText(file.getPath());
637             }
638         }
639
640         if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
641             final File dir = new File(p.getCommentDir());
642             final File file = searchFileMatchId(dir, id);
643             if (file != null) {
644                 fldComment.setText(file.getPath());
645             }
646         }
647
648     }//GEN-LAST:event_idFieldFocusLost
649     // Variables declaration - do not modify//GEN-BEGIN:variables
650     private final JTable tblDisplay;
651     // ボタン領域
652     private final JButton btnStart = new JButton("開始");
653     private final JButton btnStop = new JButton("停止");
654     private final JButton btnDeselect = new JButton("選択解除");
655     // 入力領域 - メイン
656     private final IdComboBox fldId;
657     private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
658     private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
659     private final JTextField fldBackLog = new JTextField();
660     private final JCheckBox cbVideoLocal;
661     private final JTextField fldVideo;
662     private final JCheckBox cbCommentLocal;
663     private final JTextField fldComment;
664     private final JCheckBox cbOutputEnable;
665     private final JTextField fldOutput;
666     // 入力領域 - ffmpeg
667     private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
668     // 適用
669     private final JTextField fldInputMessage = new JTextField();
670     private final JButton btnApply = new JButton("適用");
671     // End of variables declaration//GEN-END:variables
672
673     private void initInputPanel() {
674         initMainTab();
675         initFfmpegTab();
676     }
677
678     private void initMainTab() {
679         final Config p = Config.INSTANCE;
680
681         fldId.setText("");
682         fldBackLog.setEnabled(false);
683         cbBackLog.setEnabled(true);
684
685         final boolean movieLocal = p.getVideoUseLocal();
686         cbVideoLocal.setSelected(movieLocal);
687         if (!movieLocal) {
688             fldVideo.setText(p.getVideoFileNamePattern());
689         }
690
691         final boolean commentLocal = p.getCommentUseLocal();
692         cbCommentLocal.setSelected(commentLocal);
693         if (!commentLocal) {
694             fldComment.setText(p.getCommentFileNamePattern());
695         }
696
697         final boolean convert = p.getOutputEnable();
698         cbOutputEnable.setSelected(convert);
699         fldOutput.setEnabled(convert);
700         fldOutput.setText(p.getOutputFileNamePattern());
701     }
702
703     private void initFfmpegTab() {
704         pnlInputFfmpeg.init(Config.INSTANCE);
705     }
706
707     private JMenuBar initMenuBar() {
708         final JMenuBar menuBar = new JMenuBar();
709
710         final JMenu mnFile = new JMenu("ファイル(F)");
711         menuBar.add(mnFile);
712
713         final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
714         itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
715         itExit.addActionListener(new ActionListener() {
716
717             @Override
718             public void actionPerformed(ActionEvent e) {
719                 throw new UnsupportedOperationException("Not supported yet.");
720             }
721         });
722         mnFile.add(itExit);
723
724         final JMenu mnTool = new JMenu("ツール(T)");
725         menuBar.add(mnTool);
726
727         final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
728         // TODO ショートカットキー
729         itOption.addActionListener(new ActionListener() {
730
731             @Override
732             public void actionPerformed(ActionEvent e) {
733                 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
734                 dlg.setLocationRelativeTo(MainFrame.this);
735                 dlg.setModal(true);
736                 dlg.setVisible(true);
737             }
738         });
739         mnTool.add(itOption);
740
741         final JMenu mnHelp = new JMenu("ヘルプ(H)");
742         menuBar.add(mnHelp);
743
744         final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
745         itAbout.addActionListener(new ActionListener() {
746
747             @Override
748             public void actionPerformed(ActionEvent e) {
749                 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
750                 dlg.pack();
751                 dlg.setLocationRelativeTo(MainFrame.this);
752                 dlg.setModal(true);
753                 dlg.setVisible(true);
754             }
755         });
756         mnHelp.add(itAbout);
757
758         return menuBar;
759     }
760
761     private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
762
763         @Override
764         public void process(DownloadProgress progress) {
765             throw new UnsupportedOperationException("Not supported yet.");
766         }
767
768         @Override
769         public void cancelled() {
770             throw new UnsupportedOperationException("Not supported yet.");
771         }
772
773         @Override
774         public void done(DownloadResult result) {
775             throw new UnsupportedOperationException("Not supported yet.");
776         }
777
778         @Override
779         public void error(Throwable th) {
780             throw new UnsupportedOperationException("Not supported yet.");
781         }
782     }
783
784     private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
785
786         @Override
787         public void process(ConvertProgress progress) {
788             throw new UnsupportedOperationException("Not supported yet.");
789         }
790
791         @Override
792         public void cancelled() {
793             throw new UnsupportedOperationException("Not supported yet.");
794         }
795
796         @Override
797         public void done(ConvertResult result) {
798             throw new UnsupportedOperationException("Not supported yet.");
799         }
800
801         @Override
802         public void error(Throwable th) {
803             throw new UnsupportedOperationException("Not supported yet.");
804         }
805     }
806
807
808
809     private class DownloadListTransferHandler extends TransferHandler {
810
811         private static final long serialVersionUID = 1L;
812         private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
813
814         @Override
815         public boolean canImport(TransferHandler.TransferSupport support) {
816             Transferable transferable = support.getTransferable();
817             if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
818                     || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
819                 return true;
820             }
821             return false;
822         }
823
824         @Override
825         public boolean importData(TransferHandler.TransferSupport support) {
826 //            try {
827 //                Transferable transferable = support.getTransferable();
828 //                if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
829 //                    @SuppressWarnings("unchecked")
830 //                    final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
831 //                    Collection<Target> targets = Target.from(data);
832 //                    targetModel.addTarget(targets);
833 //                } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
834 //                    String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
835 //                    Matcher matcher = movieIdPattern.matcher(data);
836 //                    if (matcher.find()) {
837 //                        String movieId = matcher.group(1);
838 //                        Target target = Target.fromId(movieId);
839 //                        targetModel.addTarget(target);
840 //                    } else {
841 //                        return false;
842 //                    }
843 //
844 //                }
845 //                return false;
846 //            } catch (Exception e) {
847 //                logger.log(Level.SEVERE, null, e);
848 //                return false;
849 //            }
850             // TODO 上記実装見直し(Locationは削除された)
851             return false;
852         }
853     }
854
855     private class TableTransferHandler extends DownloadListTransferHandler {
856
857         private static final long serialVersionUID = 1L;
858
859         @Override
860         public boolean canImport(TransferHandler.TransferSupport support) {
861             return super.canImport(support);
862         }
863
864         @Override
865         public boolean importData(TransferHandler.TransferSupport support) {
866             return super.importData(support);
867         }
868     }
869
870     private class MainFrameWindowListener extends WindowAdapter {
871         @Override
872         public void windowClosing(WindowEvent e) {
873             final Config p = Config.INSTANCE;
874
875             final Dimension size = getSize();
876             p.setSystemWindowWidth(size.width);
877             p.setSystemWindowHeight(size.height);
878
879             final Point pos = getLocation();
880             p.setSystemWindowPosX(pos.x);
881             p.setSystemWindowPosY(pos.y);
882
883             p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
884             p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
885             p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
886             p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
887             p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
888             try {
889                 p.save();
890             } catch (ConfigurationException ex) {
891                 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
892             }
893         }
894     }
895
896     /*
897      * ここからDownloadProfile作成用クラスの定義
898      */
899
900     private class InqubusDownloadProfile implements DownloadProfile {
901
902         private final LoginProfile loginProfile;
903         private final ProxyProfile proxyProfile;
904         private final VideoProfile videoProfile;
905         private final CommentProfile commentProfile;
906         private final GeneralProfile generalProfile;
907
908         private InqubusDownloadProfile() {
909             this.loginProfile = new InqubusLoginProfile();
910             this.proxyProfile = new InqubusProxyProfile();
911             this.videoProfile = new InqubusVideoProfile();
912             this.commentProfile = new InqubusCommentProfile();
913             this.generalProfile = new InqubusGeneralProfile();
914         }
915
916         @Override
917         public LoginProfile getLoginInfo() {
918             return this.loginProfile;
919         }
920
921         @Override
922         public ProxyProfile getProxyProfile() {
923             return this.proxyProfile;
924         }
925
926         @Override
927         public VideoProfile getVideoProfile() {
928             return this.videoProfile;
929         }
930
931         @Override
932         public CommentProfile getCommentProfile() {
933             return this.commentProfile;
934         }
935
936         @Override
937         public GeneralProfile getGeneralProfile() {
938             return this.generalProfile;
939         }
940
941         @Override
942         public String toString(){
943             return ToStringBuilder.reflectionToString(this);
944         }
945     }
946
947     private class InqubusLoginProfile implements LoginProfile {
948         private final String mail;
949         private final String password;
950
951         private InqubusLoginProfile(){
952             final Config p = Config.INSTANCE;
953             this.mail = p.getId();
954             this.password = p.getPassword();
955         }
956
957         @Override
958         public String getMail() {
959             return this.mail;
960         }
961
962         @Override
963         public String getPassword() {
964             return this.password;
965         }
966
967         @Override
968         public String toString(){
969             return ToStringBuilder.reflectionToString(this);
970         }
971     }
972
973     private class InqubusProxyProfile implements ProxyProfile {
974         private final boolean use;
975         private final String host;
976         private final int port;
977
978         private InqubusProxyProfile(){
979             final Config p = Config.INSTANCE;
980             this.use = p.getProxyUse();
981             this.host = p.getProxyHost();
982             final String pp = p.getProxyPort();
983             this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
984         }
985
986         @Override
987         public boolean use() {
988             return this.use;
989         }
990
991         @Override
992         public String getHost() {
993             return this.host;
994         }
995
996         @Override
997         public int getPort() {
998             return this.port;
999         }
1000
1001         @Override
1002         public String toString(){
1003             return ToStringBuilder.reflectionToString(this);
1004         }
1005     }
1006
1007     private class InqubusVideoProfile implements VideoProfile {
1008         private final boolean download;
1009         private final File dir;
1010         private final String fileName;
1011         private final File localFile;
1012
1013         private InqubusVideoProfile(){
1014             final Config p = Config.INSTANCE;
1015             this.download = !cbVideoLocal.isSelected();
1016             if (this.download) {
1017                 this.dir = new File(p.getVideoDir());
1018                 this.fileName = fldVideo.getText();
1019                 this.localFile = null;
1020             } else {
1021                 this.dir = null;
1022                 this.fileName = null;
1023                 this.localFile = new File(fldVideo.getText());
1024             }
1025         }
1026
1027         @Override
1028         public boolean isDownload() {
1029             return this.download;
1030         }
1031
1032         @Override
1033         public File getDir() {
1034             return this.dir;
1035         }
1036
1037         @Override
1038         public String getFileName() {
1039             return this.fileName;
1040         }
1041
1042         @Override
1043         public File getLocalFile() {
1044             return this.localFile;
1045         }
1046
1047         @Override
1048         public String toString(){
1049             return ToStringBuilder.reflectionToString(this);
1050         }
1051     }
1052
1053     private class InqubusCommentProfile implements CommentProfile {
1054         private final boolean download;
1055         private final File dir;
1056         private final String fileName;
1057         private final File localFile;
1058         private final int lengthRelatedCommentSize;
1059         private final boolean disablePerMinComment;
1060         private final int perMinCommentSize;
1061         private final long backLogPoint;
1062
1063         private InqubusCommentProfile() {
1064             final Config p = Config.INSTANCE;
1065             this.download = !cbCommentLocal.isSelected();
1066             if (this.download) {
1067                 this.dir = new File(p.getCommentDir());
1068                 this.fileName = fldComment.getText();
1069                 this.localFile = null;
1070             } else {
1071                 this.dir = null;
1072                 this.fileName = null;
1073                 this.localFile = new File(fldComment.getText());
1074             }
1075
1076             if(cbBackLog.isSelected()) {
1077                 try {
1078                     this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
1079                 } catch (IOException ex) {
1080                     throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
1081                 }
1082             } else {
1083                 this.backLogPoint = -1L;
1084             }
1085
1086             this.disablePerMinComment = cbBackLogReduce.isSelected();
1087             this.lengthRelatedCommentSize
1088                     = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1089             this.perMinCommentSize
1090                     = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1091         }
1092
1093         @Override
1094         public boolean isDownload() {
1095             return this.download;
1096         }
1097
1098         @Override
1099         public File getDir() {
1100             return this.dir;
1101         }
1102
1103         @Override
1104         public String getFileName() {
1105             return this.fileName;
1106         }
1107
1108         @Override
1109         public File getLocalFile() {
1110             return this.localFile;
1111         }
1112
1113         @Override
1114         public int getLengthRelatedCommentSize() {
1115             return this.lengthRelatedCommentSize;
1116         }
1117
1118         @Override
1119         public boolean isDisablePerMinComment() {
1120             return this.disablePerMinComment;
1121         }
1122
1123         @Override
1124         public int getPerMinCommentSize() {
1125             return this.perMinCommentSize;
1126         }
1127
1128         @Override
1129         public long getBackLogPoint() {
1130             return this.backLogPoint;
1131         }
1132
1133         @Override
1134         public String toString(){
1135             return ToStringBuilder.reflectionToString(this);
1136         }
1137     }
1138
1139     private class InqubusGeneralProfile implements GeneralProfile {
1140         private final String replaceFrom;
1141         private final String replaceTo;
1142         private InqubusGeneralProfile() {
1143             final Config p = Config.INSTANCE;
1144             this.replaceFrom = p.getReplaceFrom();
1145             this.replaceTo = p.getReplaceTo();
1146         }
1147
1148         @Override
1149         public String getReplaceFrom() {
1150             return this.replaceFrom;
1151         }
1152
1153         @Override
1154         public String getReplaceTo() {
1155             return this.replaceTo;
1156         }
1157
1158         @Override
1159         public String toString(){
1160             return ToStringBuilder.reflectionToString(this);
1161         }
1162     }
1163
1164     /*
1165      * ここからConvertProfile作成用クラスの定義
1166      */
1167     private class InqubusConvertProfile implements ConvertProfile {
1168         private final OutputProfile outputProfile;
1169         private final GeneralProfile generalProfile;
1170         private final FfmpegProfile ffmpegProfile;
1171         private final boolean convert;
1172         private final File ffmpeg;
1173         private final boolean vhookDisabled;
1174         private final boolean commentOverlay;
1175         private final File vhook;
1176         private final File tmpDir;
1177         private final File font;
1178         private final int fontIndex;
1179         private final boolean commentOpaque;
1180         private final boolean disableFontSizeArrange;
1181         private final int shadowIndex;
1182         private final boolean showConvrting;
1183         private final int maxNumOfComment;
1184         private final HideCondition ngSetting;
1185
1186         private InqubusConvertProfile() throws IOException {
1187             final Config p = Config.INSTANCE;
1188             this.outputProfile = new InqubusOutputProfile();
1189             this.generalProfile = new InqubusGeneralProfile();
1190             this.ffmpegProfile = new InqubusFfmpegProfile();
1191             this.convert = cbOutputEnable.isSelected();
1192             this.ffmpeg = new File(p.getFfmpegPath());
1193             // TODO コンフィグに設定なし
1194             this.vhookDisabled = false;
1195             this.commentOverlay = p.getOutputCommentOverlay();
1196             this.vhook = new File(p.getFfmpegDllPath());
1197             this.tmpDir = new File(p.getSystemTempDir());
1198             this.font = new File(p.getFontPath());
1199             this.fontIndex = Integer.parseInt(p.getFontIndex());
1200             this.commentOpaque = p.getCommentOpaque();
1201             this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1202             this.shadowIndex = p.getFontShadow();
1203             // TODO コンフィグに設定なし
1204             this.showConvrting = true;
1205             this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1206                     getCommentDisplaySizeManual());
1207             this.ngSetting = new InqubusHideCondition();
1208         }
1209
1210         @Override
1211         public OutputProfile getOutputProfile() {
1212             return this.outputProfile;
1213         }
1214
1215         @Override
1216         public GeneralProfile getGeneralProfile() {
1217             return this.generalProfile;
1218         }
1219
1220         @Override
1221         public FfmpegProfile getFfmpegOption() {
1222             return this.ffmpegProfile;
1223         }
1224
1225         @Override
1226         public boolean isConvert() {
1227             return this.convert;
1228         }
1229
1230         @Override
1231         public File getFfmpeg() {
1232             return this.ffmpeg;
1233         }
1234
1235         @Override
1236         public boolean isVhookDisabled() {
1237             return this.vhookDisabled;
1238         }
1239
1240         @Override
1241         public boolean isCommentOverlay() {
1242             return this.commentOverlay;
1243         }
1244
1245         @Override
1246         public File getVhook() {
1247             return this.vhook;
1248         }
1249
1250         @Override
1251         public File getTempDir() {
1252             return this.tmpDir;
1253         }
1254
1255         @Override
1256         public File getFont() {
1257             return this.font;
1258         }
1259
1260         @Override
1261         public int getFontIndex() {
1262             return this.fontIndex;
1263         }
1264
1265         @Override
1266         public boolean isCommentOpaque() {
1267             return this.commentOpaque;
1268         }
1269
1270         @Override
1271         public boolean isDisableFontSizeArrange() {
1272             return this.disableFontSizeArrange;
1273         }
1274
1275         @Override
1276         public int getShadowIndex() {
1277             return this.shadowIndex;
1278         }
1279
1280         @Override
1281         public boolean isShowConverting() {
1282             return this.showConvrting;
1283         }
1284
1285         @Override
1286         public int getMaxNumOfComment() {
1287             return this.maxNumOfComment;
1288         }
1289
1290         @Override
1291         public HideCondition getNgSetting() {
1292             return this.ngSetting;
1293         }
1294
1295         @Override
1296         public String toString(){
1297             return ToStringBuilder.reflectionToString(this);
1298         }
1299     }
1300
1301     private class InqubusOutputProfile implements OutputProfile {
1302         private final File dir;
1303         private final String fileName;
1304         private final String videoId;
1305         private final String title;
1306
1307
1308         private InqubusOutputProfile(){
1309             final Config p = Config.INSTANCE;
1310             this.dir = new File(p.getOutputDir());
1311             this.fileName = fldOutput.getText();
1312             // TODO この時点でのID/Titleはどうするか…
1313             this.videoId = "";
1314             this.title = "";
1315         }
1316
1317         @Override
1318         public File getDir() {
1319             return this.dir;
1320         }
1321
1322         @Override
1323         public String getFileName() {
1324             return this.fileName;
1325         }
1326
1327         @Override
1328         public String getVideoId() {
1329             return this.videoId;
1330         }
1331
1332         @Override
1333         public String getTitile() {
1334             return this.title;
1335         }
1336
1337         @Override
1338         public String toString(){
1339             return ToStringBuilder.reflectionToString(this);
1340         }
1341     }
1342
1343     private class InqubusFfmpegProfile implements FfmpegProfile {
1344         private final String extOption;
1345         private final String inOption;
1346         private final String mainOption;
1347         private final String outOption;
1348         private final String avOption;
1349         private final boolean resize;
1350         private final int resizeWidth;
1351         private final int resizeHeight;
1352         private final boolean adjustRatio;
1353
1354         private InqubusFfmpegProfile() throws IOException {
1355             final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1356             if (file != null) {
1357                 final FfmpegOption ffop = FfmpegOption.load(file);
1358                 this.extOption = ffop.getExtOption();
1359                 this.inOption = ffop.getInOption();
1360                 this.mainOption = ffop.getMainOption();
1361                 this.outOption = ffop.getMainOption();
1362                 this.avOption = ffop.getAvfilterOption();
1363                 this.resize = ffop.isResize();
1364                 this.resizeWidth = ffop.getResizeWidth();
1365                 this.resizeHeight = ffop.getResizeHeight();
1366                 this.adjustRatio = ffop.isAdjustRatio();
1367             } else {
1368                 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1369                 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1370                 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1371                 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1372                 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1373                 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1374                 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1375                 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1376                 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1377             }
1378         }
1379
1380         @Override
1381         public String getExtOption() {
1382             return this.extOption;
1383         }
1384
1385         @Override
1386         public String getInOption() {
1387             return this.inOption;
1388         }
1389
1390         @Override
1391         public String getMainOption() {
1392             return this.mainOption;
1393         }
1394
1395         @Override
1396         public String getOutOption() {
1397             return this.outOption;
1398         }
1399
1400         @Override
1401         public String getAvfilterOption() {
1402             return this.avOption;
1403         }
1404
1405         @Override
1406         public boolean isResize() {
1407             return this.resize;
1408         }
1409
1410         @Override
1411         public int getResizeWidth() {
1412             return this.resizeWidth;
1413         }
1414
1415         @Override
1416         public int getResizeHeight() {
1417             return this.resizeHeight;
1418         }
1419
1420         @Override
1421         public boolean isAdjustRatio() {
1422             return this.adjustRatio;
1423         }
1424
1425         @Override
1426         public String toString(){
1427             return ToStringBuilder.reflectionToString(this);
1428         }
1429     }
1430
1431     private class InqubusHideCondition implements ConvertProfile.HideCondition{
1432
1433         @Override
1434         public String getWord() {
1435             // TODO
1436             return "";
1437         }
1438
1439         @Override
1440         public String getId() {
1441             // TODO
1442             return "";
1443         }
1444
1445         @Override
1446         public String toString(){
1447             return ToStringBuilder.reflectionToString(this);
1448         }
1449     }
1450 }