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