OSDN Git Service

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