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