OSDN Git Service

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