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.Image;
9 import java.awt.ItemSelectable;
10 import java.awt.Toolkit;
11 import java.awt.datatransfer.DataFlavor;
12 import java.awt.datatransfer.Transferable;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.awt.event.ItemEvent;
16 import java.awt.event.ItemListener;
17 import java.awt.event.KeyEvent;
18 import java.io.File;
19 import java.io.FilenameFilter;
20 import java.net.URL;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28 import javax.swing.BorderFactory;
29 import javax.swing.DropMode;
30 import javax.swing.GroupLayout;
31 import javax.swing.GroupLayout.Alignment;
32 import javax.swing.JButton;
33 import javax.swing.JCheckBox;
34 import javax.swing.JFrame;
35 import javax.swing.JLabel;
36 import javax.swing.JMenu;
37 import javax.swing.JMenuBar;
38 import javax.swing.JMenuItem;
39 import javax.swing.JPanel;
40 import javax.swing.JScrollPane;
41 import javax.swing.JTable;
42 import javax.swing.JTextField;
43 import javax.swing.KeyStroke;
44 import javax.swing.LayoutStyle.ComponentPlacement;
45 import javax.swing.TransferHandler;
46 import javax.swing.WindowConstants;
47 import org.apache.commons.lang.StringUtils;
48 import saccubus.MainFrame_AboutBox;
49 import saccubus.worker.Download;
50 import saccubus.worker.profile.CommentProfile;
51 import saccubus.worker.profile.DownloadProfile;
52 import saccubus.worker.profile.GeneralProfile;
53 import saccubus.worker.profile.LoginProfile;
54 import saccubus.worker.profile.ProxyProfile;
55 import saccubus.worker.profile.VideoProfile;
56 import yukihane.Util;
57 import yukihane.inqubus.Config;
58 import yukihane.inqubus.model.Target;
59 import yukihane.inqubus.model.TargetsTableModel;
60
61 /**
62  *
63  * @author yuki
64  */
65 public class MainFrame extends JFrame {
66
67     private static final long serialVersionUID = 1L;
68     private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
69     private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
70     private static final String FILE_LOCALBUTTON_TOOLTIP
71             = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
72     private static final String FILE_INPUTFIELD_TOOLTIP
73             = "ダウンロードする場合はファイル命名規則を入力します。"
74             + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
75     private static final String FILE_OUTPUTFIELD_TOOLTIP
76             = "ファイル命名規則入力します。";
77     private final TargetsTableModel targetModel = new TargetsTableModel();
78
79     /** Creates new form MainFrame */
80     public MainFrame() {
81         final URL url = MainFrame_AboutBox.class.getResource("icon.png");
82         final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
83         final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
84         final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
85         final List<Image> images = new ArrayList<Image>(2);
86         images.add(icon1);
87         images.add(icon2);
88         setIconImages(images);
89
90         final JPanel pnlMain = new JPanel();
91         final JScrollPane scrDisplay = new JScrollPane();
92         tblDisplay = new JTable();
93         final JPanel pnlButton = new JPanel();
94         btnStart = new JButton();
95         btnStop = new JButton();
96         btnDeselect = new JButton();
97         final JPanel pnlInputMain = new JPanel();
98         final JLabel lblId = new JLabel();
99         fldId = new JTextField();
100         fldId.setToolTipText(ID_FIELD_TOOLTIP);
101         final JLabel lblVideo = new JLabel();
102         cbVideoLocal = new JCheckBox();
103         cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
104         fldVideo = new JTextField();
105         fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
106         btnVideo = new JButton();
107         final JLabel lblComment = new JLabel();
108         cbCommentLocal = new JCheckBox();
109         cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
110         cbCommentLocal.addItemListener(new ItemListener() {
111
112             @Override
113             public void itemStateChanged(ItemEvent e) {
114                 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
115                 cbBackLogReduce.setEnabled(!selected);
116                 cbBackLog.setEnabled(!selected);
117                 if(selected) {
118                     cbBackLog.setSelected(false);
119                 }
120             }
121         });
122         fldComment = new JTextField();
123         fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
124         btnComment = new JButton();
125         final JLabel lblOutput = new JLabel();
126         cbOutputEnable = new JCheckBox();
127         fldOutput = new JTextField();
128         fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
129
130         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
131
132         btnApply.addActionListener(new ApplyActionListener());
133
134         pnlMain.setBorder(BorderFactory.createEtchedBorder());
135
136         tblDisplay.setModel(targetModel);
137         tblDisplay.setDropMode(DropMode.INSERT_ROWS);
138         scrDisplay.setViewportView(tblDisplay);
139
140         pnlButton.setBorder(BorderFactory.createEtchedBorder());
141
142         btnStart.setText("開始");
143
144         btnStop.setText("停止");
145
146         btnDeselect.setText("選択解除");
147
148         GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
149         pnlButton.setLayout(gl_pnlButton);
150         gl_pnlButton.setHorizontalGroup(
151             gl_pnlButton.createParallelGroup(Alignment.LEADING)
152             .addGroup(gl_pnlButton.createSequentialGroup()
153                 .addContainerGap()
154                 .addComponent(btnStart)
155                 .addPreferredGap(ComponentPlacement.RELATED)
156                 .addComponent(btnStop)
157                 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
158                 .addComponent(btnDeselect)
159                 .addContainerGap())
160         );
161         gl_pnlButton.setVerticalGroup(
162             gl_pnlButton.createParallelGroup(Alignment.LEADING)
163             .addGroup(gl_pnlButton.createSequentialGroup()
164                 .addContainerGap()
165                 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
166                     .addComponent(btnStart)
167                     .addComponent(btnStop)
168                     .addComponent(btnDeselect))
169                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170         );
171
172         pnlInputMain.setBorder(BorderFactory.createEtchedBorder());
173
174         lblId.setText("ID");
175
176         fldId.addFocusListener(new java.awt.event.FocusAdapter() {
177
178             public void focusLost(java.awt.event.FocusEvent evt) {
179                 idFieldFocusLost(evt);
180             }
181         });
182
183         lblVideo.setText("動画");
184
185         cbVideoLocal.setText("local");
186         cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
187
188             public void itemStateChanged(java.awt.event.ItemEvent evt) {
189                 useMovieLocalCheckBoxItemStateChanged(evt);
190             }
191         });
192
193         btnVideo.setText("...");
194
195         lblComment.setText("コメント");
196
197         cbCommentLocal.setText("local");
198         cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
199
200             public void itemStateChanged(java.awt.event.ItemEvent evt) {
201                 useMovieLocalCheckBoxItemStateChanged(evt);
202             }
203         });
204
205         btnComment.setText("...");
206
207         lblOutput.setText("出力");
208
209         cbOutputEnable.setText("変換");
210         cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
211
212             public void itemStateChanged(java.awt.event.ItemEvent evt) {
213                 outputConvertCheckBoxItemStateChanged(evt);
214             }
215         });
216
217
218         GroupLayout gl_pnlInputMain = new GroupLayout(pnlInputMain);
219         pnlInputMain.setLayout(gl_pnlInputMain);
220         gl_pnlInputMain.setHorizontalGroup(
221             gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
222             .addGroup(gl_pnlInputMain.createSequentialGroup()
223                 .addContainerGap()
224                 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
225                     .addGroup(gl_pnlInputMain.createSequentialGroup()
226                         .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
227                             .addComponent(lblComment)
228                             .addComponent(lblVideo)
229                             .addComponent(lblId)
230                             .addComponent(lblOutput))
231                         .addPreferredGap(ComponentPlacement.RELATED)
232                         .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
233                             .addGroup(gl_pnlInputMain.createSequentialGroup()
234                                 .addComponent(cbVideoLocal)
235                                 .addPreferredGap(ComponentPlacement.RELATED)
236                                 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
237                                 .addPreferredGap(ComponentPlacement.RELATED)
238                                 .addComponent(btnVideo))
239                             .addGroup(gl_pnlInputMain.createSequentialGroup()
240                                 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
241                                 .addPreferredGap(ComponentPlacement.UNRELATED)
242                                 .addComponent(cbBackLogReduce)
243                                 .addComponent(cbBackLog)
244                                 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
245                             )
246                             .addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
247                                 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
248                                     .addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
249                                         .addComponent(cbOutputEnable)
250                                         .addPreferredGap(ComponentPlacement.RELATED)
251                                         .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
252                                     .addGroup(gl_pnlInputMain.createSequentialGroup()
253                                         .addComponent(cbCommentLocal)
254                                         .addPreferredGap(ComponentPlacement.RELATED)
255                                         .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
256                                 .addPreferredGap(ComponentPlacement.RELATED)
257                                 .addComponent(btnComment))))
258                     .addComponent(btnApply, Alignment.TRAILING))
259                 .addContainerGap())
260         );
261         gl_pnlInputMain.setVerticalGroup(
262             gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
263             .addGroup(gl_pnlInputMain.createSequentialGroup()
264                 .addContainerGap()
265                 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
266                     .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
267                     .addComponent(lblId)
268                     .addComponent(cbBackLogReduce)
269                     .addComponent(cbBackLog)
270                     .addComponent(fldBackLog)
271                 )
272                 .addPreferredGap(ComponentPlacement.RELATED)
273                 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
274                     .addComponent(lblVideo)
275                     .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
276                     .addComponent(btnVideo)
277                     .addComponent(cbVideoLocal))
278                 .addPreferredGap(ComponentPlacement.RELATED)
279                 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
280                     .addComponent(lblComment)
281                     .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
282                     .addComponent(btnComment)
283                     .addComponent(cbCommentLocal))
284                 .addPreferredGap(ComponentPlacement.RELATED)
285                 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
286                     .addComponent(lblOutput)
287                     .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
288                     .addComponent(cbOutputEnable))
289                 .addPreferredGap(ComponentPlacement.UNRELATED)
290                 .addComponent(btnApply)
291                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
292         );
293
294         GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
295         pnlMain.setLayout(gl_pnlMain);
296         gl_pnlMain.setHorizontalGroup(
297             gl_pnlMain.createParallelGroup(Alignment.LEADING)
298             .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
299                 .addContainerGap()
300                 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
301                     .addComponent(pnlInputMain, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
302                     .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
303                     .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
304                 .addContainerGap())
305         );
306         gl_pnlMain.setVerticalGroup(
307             gl_pnlMain.createParallelGroup(Alignment.LEADING)
308             .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
309                 .addContainerGap()
310                 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
311                 .addPreferredGap(ComponentPlacement.RELATED)
312                 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
313                 .addPreferredGap(ComponentPlacement.RELATED)
314                 .addComponent(pnlInputMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
315                 .addGap(24, 24, 24))
316         );
317
318
319         JMenuBar menuBar = initMenuBar();
320         setJMenuBar(menuBar);
321
322         GroupLayout layout = new GroupLayout(getContentPane());
323         getContentPane().setLayout(layout);
324         layout.setHorizontalGroup(
325             layout.createParallelGroup(Alignment.LEADING)
326             .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
327         );
328         layout.setVerticalGroup(
329             layout.createParallelGroup(Alignment.LEADING)
330             .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
331         );
332
333         pack();
334         initInputPanel();
335         pnlMain.setTransferHandler(new DownloadListTransferHandler());
336         tblDisplay.setTransferHandler(new TableTransferHandler());
337     }
338
339     private class ApplyActionListener implements ActionListener {
340
341         @Override
342         public void actionPerformed(ActionEvent e) {
343             final DownloadProfile prof = new InqubusDownloadProfile();
344             final String id = Util.getVideoId(fldId.getText());
345
346             new Download(prof, id).execute();
347         }
348     }
349     /** This method is called from within the constructor to
350      * initialize the form.
351      * WARNING: Do NOT modify this code. The content of this method is
352      * always regenerated by the Form Editor.
353      */
354     @SuppressWarnings("unchecked")
355     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
356     private void initComponents() {
357     }// </editor-fold>//GEN-END:initComponents
358
359     private File searchFileMatchId(final File dir, final String id) throws UnsupportedOperationException {
360         // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
361         if (id.isEmpty()) {
362             return null;
363         }
364
365         final File[] lists = dir.listFiles(new FilenameFilter() {
366
367             final Pattern pattern = Pattern.compile(id + "\\D");
368
369             @Override
370             public boolean accept(File dir, String name) {
371                 return pattern.matcher(name).find();
372             }
373         });
374
375         if (lists.length == 1) {
376             return lists[0];
377         } else if (lists.length > 1) {
378             throw new UnsupportedOperationException();
379         } else {
380             return null;
381         }
382     }
383
384     private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
385         final Config p = Config.INSTANCE;
386
387         final ItemSelectable source = evt.getItemSelectable();
388
389         JButton btn;
390         JTextField field;
391         File dir;
392         if (source == cbVideoLocal) {
393             btn = btnVideo;
394             field = fldVideo;
395             dir = new File(p.getVideoDir());
396         } else {
397             btn = btnComment;
398             field = fldComment;
399             dir = new File(p.getCommentDir());
400         }
401
402         final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
403         btn.setEnabled(useLocal);
404
405         String text;
406         if (useLocal) {
407             final File f = searchFileMatchId(dir, fldId.getText());
408             if (f != null) {
409                 text = f.getPath();
410             } else {
411                 text = "";
412             }
413         } else {
414             text = p.getVideoFileNamePattern();
415         }
416         field.setText(text);
417
418         fldId.setEnabled(!(cbVideoLocal.isSelected() && cbCommentLocal.isSelected()));
419
420     }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
421
422     private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
423         final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
424         fldOutput.setEnabled(convert);
425     }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
426
427     private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
428         final Config p = Config.INSTANCE;
429         final String id = fldId.getText();
430         if (id.isEmpty()) {
431             return;
432         }
433
434         if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
435             final File dir = new File(p.getVideoDir());
436             final File file = searchFileMatchId(dir, id);
437             if (file != null) {
438                 fldVideo.setText(file.getPath());
439             }
440         }
441
442         if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
443             final File dir = new File(p.getCommentDir());
444             final File file = searchFileMatchId(dir, id);
445             if (file != null) {
446                 fldComment.setText(file.getPath());
447             }
448         }
449
450     }//GEN-LAST:event_idFieldFocusLost
451     // Variables declaration - do not modify//GEN-BEGIN:variables
452     private final JTable tblDisplay;
453     // ボタン領域
454     private final JButton btnStart;
455     private final JButton btnStop;
456     private final JButton btnDeselect;
457     //入力領域 - 標準
458     private final JTextField fldId;
459     private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
460     private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
461     private final JTextField fldBackLog = new JTextField();
462     private final JCheckBox cbVideoLocal;
463     private final JTextField fldVideo;
464     private final JButton btnVideo;
465     private final JCheckBox cbCommentLocal;
466     private final JTextField fldComment;
467     private final JButton btnComment;
468     private final JCheckBox cbOutputEnable;
469     private final JTextField fldOutput;
470     // 適用
471     private final JButton btnApply = new JButton("適用");
472     // End of variables declaration//GEN-END:variables
473
474     private void initInputPanel() {
475         final Config p = Config.INSTANCE;
476
477         fldId.setText("");
478         fldBackLog.setEnabled(false);
479         fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
480         cbBackLog.setEnabled(true);
481         cbBackLog.addItemListener(new ItemListener() {
482
483             @Override
484             public void itemStateChanged(ItemEvent e) {
485                 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
486                 fldBackLog.setEnabled(selected);
487             }
488         });
489         cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
490
491         final boolean movieLocal = p.getVideoUseLocal();
492         cbVideoLocal.setSelected(movieLocal);
493         btnVideo.setEnabled(movieLocal);
494         if (!movieLocal) {
495             fldVideo.setText(p.getVideoFileNamePattern());
496         }
497
498         final boolean commentLocal = p.getCommentUseLocal();
499         cbCommentLocal.setSelected(commentLocal);
500         btnComment.setEnabled(commentLocal);
501         if (!commentLocal) {
502             fldComment.setText(p.getCommentFileNamePattern());
503         }
504
505         final boolean convert = p.getOutputEnable();
506         cbOutputEnable.setSelected(convert);
507         fldOutput.setEnabled(convert);
508         fldOutput.setText(p.getOutputFileNamePattern());
509
510     }
511
512     private JMenuBar initMenuBar() {
513         final JMenuBar menuBar = new JMenuBar();
514
515         final JMenu mnFile = new JMenu("ファイル(F)");
516         menuBar.add(mnFile);
517
518         final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
519         itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
520         itExit.addActionListener(new ActionListener() {
521
522             @Override
523             public void actionPerformed(ActionEvent e) {
524                 throw new UnsupportedOperationException("Not supported yet.");
525             }
526         });
527         mnFile.add(itExit);
528
529         final JMenu mnTool = new JMenu("ツール(T)");
530         menuBar.add(mnTool);
531
532         final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
533         // TODO ショートカットキー
534         itOption.addActionListener(new ActionListener() {
535
536             @Override
537             public void actionPerformed(ActionEvent e) {
538                 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
539                 dlg.setLocationRelativeTo(MainFrame.this);
540                 dlg.setModal(true);
541                 dlg.setVisible(true);
542             }
543         });
544         mnTool.add(itOption);
545
546         final JMenu mnHelp = new JMenu("ヘルプ(H)");
547         menuBar.add(mnHelp);
548
549         final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
550         itAbout.addActionListener(new ActionListener() {
551
552             @Override
553             public void actionPerformed(ActionEvent e) {
554                 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
555                 dlg.pack();
556                 dlg.setLocationRelativeTo(MainFrame.this);
557                 dlg.setModal(true);
558                 dlg.setVisible(true);
559             }
560         });
561         mnHelp.add(itAbout);
562
563         return menuBar;
564     }
565
566     private class DownloadListTransferHandler extends TransferHandler {
567
568         private static final long serialVersionUID = 1L;
569         private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
570
571         @Override
572         public boolean canImport(TransferHandler.TransferSupport support) {
573             Transferable transferable = support.getTransferable();
574             if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
575                     || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
576                 return true;
577             }
578             return false;
579         }
580
581         @Override
582         public boolean importData(TransferHandler.TransferSupport support) {
583             try {
584                 Transferable transferable = support.getTransferable();
585                 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
586                     @SuppressWarnings("unchecked")
587                     final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
588                     Collection<Target> targets = Target.from(data);
589                     targetModel.addTarget(targets);
590                 } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
591                     String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
592                     Matcher matcher = movieIdPattern.matcher(data);
593                     if (matcher.find()) {
594                         String movieId = matcher.group(1);
595                         Target target = Target.fromId(movieId);
596                         targetModel.addTarget(target);
597                     } else {
598                         return false;
599                     }
600
601                 }
602                 return false;
603             } catch (Exception e) {
604                 logger.log(Level.SEVERE, null, e);
605                 return false;
606             }
607         }
608     }
609
610     private class TableTransferHandler extends DownloadListTransferHandler {
611
612         private static final long serialVersionUID = 1L;
613
614         @Override
615         public boolean canImport(TransferHandler.TransferSupport support) {
616             return super.canImport(support);
617         }
618
619         @Override
620         public boolean importData(TransferHandler.TransferSupport support) {
621             return super.importData(support);
622         }
623     }
624
625
626     private class InqubusDownloadProfile implements DownloadProfile {
627
628         private final LoginProfile loginProfile;
629         private final ProxyProfile proxyProfile;
630         private final VideoProfile videoProfile;
631         private final CommentProfile commentProfile;
632         private final GeneralProfile generalProfile;
633
634         private InqubusDownloadProfile() {
635             this.loginProfile = new InqubusLoginProfile();
636             this.proxyProfile = new InqubusProxyProfile();
637             this.videoProfile = new InqubusVideoProfile();
638             this.commentProfile = new InqubusCommentProfile();
639             this.generalProfile = new InqubusGeneralProfile();
640         }
641
642         @Override
643         public LoginProfile getLoginInfo() {
644             return this.loginProfile;
645         }
646
647         @Override
648         public ProxyProfile getProxyProfile() {
649             return this.proxyProfile;
650         }
651
652         @Override
653         public VideoProfile getVideoProfile() {
654             return this.videoProfile;
655         }
656
657         @Override
658         public CommentProfile getCommentProfile() {
659             return this.commentProfile;
660         }
661
662         @Override
663         public GeneralProfile getGeneralProfile() {
664             return this.generalProfile;
665         }
666     }
667
668     private class InqubusLoginProfile implements LoginProfile {
669         private final String mail;
670         private final String password;
671
672         private InqubusLoginProfile(){
673             final Config p = Config.INSTANCE;
674             this.mail = p.getId();
675             this.password = p.getPassword();
676         }
677
678         @Override
679         public String getMail() {
680             return this.mail;
681         }
682
683         @Override
684         public String getPassword() {
685             return this.password;
686         }
687     }
688
689     private class InqubusProxyProfile implements ProxyProfile {
690         private final boolean use;
691         private final String host;
692         private final int port;
693
694         private InqubusProxyProfile(){
695             final Config p = Config.INSTANCE;
696             this.use = p.getProxyUse();
697             this.host = p.getProxyHost();
698             final String pp = p.getProxyPort();
699             this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
700         }
701
702         @Override
703         public boolean use() {
704             return this.use;
705         }
706
707         @Override
708         public String getHost() {
709             return this.host;
710         }
711
712         @Override
713         public int getPort() {
714             return this.port;
715         }
716     }
717
718     private class InqubusVideoProfile implements VideoProfile {
719         private final boolean download;
720         private final File dir;
721         private final String fileName;
722         private final File localFile;
723
724         private InqubusVideoProfile(){
725             this.download = !cbVideoLocal.isSelected();
726             if (this.download) {
727                 this.dir = new File(fldVideo.getText());
728                 // TODO ディレクトリとファイル名の入力欄を分ける
729                 this.fileName = "{id}_{title}";
730                 this.localFile = null;
731             } else {
732                 this.dir = null;
733                 this.fileName = null;
734                 this.localFile = new File(fldVideo.getText());
735             }
736         }
737
738         @Override
739         public boolean isDownload() {
740             return this.download;
741         }
742
743         @Override
744         public File getDir() {
745             return this.dir;
746         }
747
748         @Override
749         public String getFileName() {
750             return this.fileName;
751         }
752
753         @Override
754         public File getLocalFile() {
755             return this.localFile;
756         }
757     }
758
759     private class InqubusCommentProfile implements CommentProfile {
760
761         @Override
762         public int getLengthRelatedCommentSize() {
763             throw new UnsupportedOperationException("Not supported yet.");
764         }
765
766         @Override
767         public boolean isDisablePerMinComment() {
768             throw new UnsupportedOperationException("Not supported yet.");
769         }
770
771         @Override
772         public int getPerMinCommentSize() {
773             throw new UnsupportedOperationException("Not supported yet.");
774         }
775
776         @Override
777         public long getBackLogPoint() {
778             throw new UnsupportedOperationException("Not supported yet.");
779         }
780
781         @Override
782         public boolean isDownload() {
783             throw new UnsupportedOperationException("Not supported yet.");
784         }
785
786         @Override
787         public File getDir() {
788             throw new UnsupportedOperationException("Not supported yet.");
789         }
790
791         @Override
792         public String getFileName() {
793             throw new UnsupportedOperationException("Not supported yet.");
794         }
795
796         @Override
797         public File getLocalFile() {
798             throw new UnsupportedOperationException("Not supported yet.");
799         }
800
801     }
802
803     private class InqubusGeneralProfile implements GeneralProfile {
804 //        private final String replaceFrom;
805         private InqubusGeneralProfile() {
806             final Config p = Config.INSTANCE;
807             // TODO 置換文字設定コンフィグが無い
808 //            this.replaceFrom = p.get
809         }
810
811         @Override
812         public String getReplaceFrom() {
813 //            return this.replaceFrom;
814             throw new UnsupportedOperationException("Not supported yet.");
815         }
816
817         @Override
818         public String getReplaceTo() {
819             throw new UnsupportedOperationException("Not supported yet.");
820         }
821
822     }
823 }