OSDN Git Service

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