OSDN Git Service

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