4 * Created on 2011/05/28, 18:14:51
6 package yukihane.inqubus.gui;
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;
19 import java.io.FilenameFilter;
20 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29 import javax.swing.BorderFactory;
30 import javax.swing.DropMode;
31 import javax.swing.GroupLayout;
32 import javax.swing.GroupLayout.Alignment;
33 import javax.swing.JButton;
34 import javax.swing.JCheckBox;
35 import javax.swing.JFrame;
36 import javax.swing.JLabel;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuBar;
39 import javax.swing.JMenuItem;
40 import javax.swing.JPanel;
41 import javax.swing.JScrollPane;
42 import javax.swing.JTable;
43 import javax.swing.JTextField;
44 import javax.swing.KeyStroke;
45 import javax.swing.LayoutStyle.ComponentPlacement;
46 import javax.swing.SwingUtilities;
47 import javax.swing.TransferHandler;
48 import javax.swing.WindowConstants;
49 import org.apache.commons.lang.StringUtils;
50 import org.apache.commons.lang.builder.ToStringBuilder;
51 import saccubus.MainFrame_AboutBox;
52 import saccubus.util.WayBackTimeParser;
53 import saccubus.worker.impl.convert.ConvertProgress;
54 import saccubus.worker.impl.download.DownloadProgress;
55 import saccubus.worker.WorkerListener;
56 import saccubus.worker.impl.convert.ConvertResult;
57 import saccubus.worker.impl.download.DownloadResult;
58 import saccubus.worker.profile.CommentProfile;
59 import saccubus.worker.profile.ConvertProfile;
60 import saccubus.worker.profile.DownloadProfile;
61 import saccubus.worker.profile.FfmpegProfile;
62 import saccubus.worker.profile.GeneralProfile;
63 import saccubus.worker.profile.LoginProfile;
64 import saccubus.worker.profile.OutputProfile;
65 import saccubus.worker.profile.ProxyProfile;
66 import saccubus.worker.profile.VideoProfile;
68 import yukihane.inqubus.Config;
69 import yukihane.inqubus.manager.RequestProcess;
70 import yukihane.inqubus.manager.TaskKind;
71 import yukihane.inqubus.manager.TaskManage;
72 import yukihane.inqubus.manager.TaskManageListener;
73 import yukihane.inqubus.manager.TaskStatus;
74 import yukihane.inqubus.model.Target;
75 import yukihane.inqubus.model.TargetsTableModel;
81 public class MainFrame extends JFrame {
83 private static final long serialVersionUID = 1L;
84 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
85 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
86 private static final String FILE_LOCALBUTTON_TOOLTIP
87 = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
88 private static final String FILE_INPUTFIELD_TOOLTIP
89 = "ダウンロードする場合はファイル命名規則を入力します。"
90 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
91 private static final String FILE_OUTPUTFIELD_TOOLTIP
93 private final TargetsTableModel targetModel = new TargetsTableModel();
94 private final TaskManage taskManager;
96 /** Creates new form MainFrame */
98 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
99 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
100 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
101 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
102 final List<Image> images = new ArrayList<Image>(2);
105 setIconImages(images);
107 final JPanel pnlMain = new JPanel();
108 final JScrollPane scrDisplay = new JScrollPane();
109 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
110 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
111 final JPanel pnlButton = new JPanel();
112 final JPanel pnlInputMain = new JPanel();
113 final JLabel lblId = new JLabel();
114 fldId = new JTextField();
115 fldId.setToolTipText(ID_FIELD_TOOLTIP);
116 final JLabel lblVideo = new JLabel();
117 cbVideoLocal = new JCheckBox();
118 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
119 fldVideo = new JTextField();
120 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
121 btnVideo = new JButton();
122 final JLabel lblComment = new JLabel();
123 cbCommentLocal = new JCheckBox();
124 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
125 cbCommentLocal.addItemListener(new ItemListener() {
128 public void itemStateChanged(ItemEvent e) {
129 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
130 cbBackLogReduce.setEnabled(!selected);
131 cbBackLog.setEnabled(!selected);
133 cbBackLog.setSelected(false);
137 fldComment = new JTextField();
138 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
139 btnComment = new JButton();
140 final JLabel lblOutput = new JLabel();
141 cbOutputEnable = new JCheckBox();
142 fldOutput = new JTextField();
143 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
145 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
147 btnApply.addActionListener(new ApplyActionListener());
149 pnlMain.setBorder(BorderFactory.createEtchedBorder());
151 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
152 scrDisplay.setViewportView(tblDisplay);
154 pnlButton.setBorder(BorderFactory.createEtchedBorder());
156 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
157 pnlButton.setLayout(gl_pnlButton);
158 gl_pnlButton.setHorizontalGroup(
159 gl_pnlButton.createParallelGroup(Alignment.LEADING)
160 .addGroup(gl_pnlButton.createSequentialGroup()
162 .addComponent(btnStart)
163 .addPreferredGap(ComponentPlacement.RELATED)
164 .addComponent(btnStop)
165 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
166 .addComponent(btnDeselect)
169 gl_pnlButton.setVerticalGroup(
170 gl_pnlButton.createParallelGroup(Alignment.LEADING)
171 .addGroup(gl_pnlButton.createSequentialGroup()
173 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
174 .addComponent(btnStart)
175 .addComponent(btnStop)
176 .addComponent(btnDeselect))
177 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
180 pnlInputMain.setBorder(BorderFactory.createEtchedBorder());
184 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
186 public void focusLost(java.awt.event.FocusEvent evt) {
187 idFieldFocusLost(evt);
191 lblVideo.setText("動画");
193 cbVideoLocal.setText("local");
194 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
196 public void itemStateChanged(java.awt.event.ItemEvent evt) {
197 useMovieLocalCheckBoxItemStateChanged(evt);
201 btnVideo.setText("...");
203 lblComment.setText("コメント");
205 cbCommentLocal.setText("local");
206 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
208 public void itemStateChanged(java.awt.event.ItemEvent evt) {
209 useMovieLocalCheckBoxItemStateChanged(evt);
213 btnComment.setText("...");
215 lblOutput.setText("出力");
217 cbOutputEnable.setText("変換");
218 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
220 public void itemStateChanged(java.awt.event.ItemEvent evt) {
221 outputConvertCheckBoxItemStateChanged(evt);
226 GroupLayout gl_pnlInputMain = new GroupLayout(pnlInputMain);
227 pnlInputMain.setLayout(gl_pnlInputMain);
228 gl_pnlInputMain.setHorizontalGroup(
229 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
230 .addGroup(gl_pnlInputMain.createSequentialGroup()
232 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
233 .addGroup(gl_pnlInputMain.createSequentialGroup()
234 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
235 .addComponent(lblComment)
236 .addComponent(lblVideo)
238 .addComponent(lblOutput))
239 .addPreferredGap(ComponentPlacement.RELATED)
240 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
241 .addGroup(gl_pnlInputMain.createSequentialGroup()
242 .addComponent(cbVideoLocal)
243 .addPreferredGap(ComponentPlacement.RELATED)
244 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
245 .addPreferredGap(ComponentPlacement.RELATED)
246 .addComponent(btnVideo))
247 .addGroup(gl_pnlInputMain.createSequentialGroup()
248 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
249 .addPreferredGap(ComponentPlacement.UNRELATED)
250 .addComponent(cbBackLogReduce)
251 .addComponent(cbBackLog)
252 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
254 .addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
255 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
256 .addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
257 .addComponent(cbOutputEnable)
258 .addPreferredGap(ComponentPlacement.RELATED)
259 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
260 .addGroup(gl_pnlInputMain.createSequentialGroup()
261 .addComponent(cbCommentLocal)
262 .addPreferredGap(ComponentPlacement.RELATED)
263 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
264 .addPreferredGap(ComponentPlacement.RELATED)
265 .addComponent(btnComment))))
266 .addComponent(btnApply, Alignment.TRAILING))
269 gl_pnlInputMain.setVerticalGroup(
270 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
271 .addGroup(gl_pnlInputMain.createSequentialGroup()
273 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
274 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
276 .addComponent(cbBackLogReduce)
277 .addComponent(cbBackLog)
278 .addComponent(fldBackLog)
280 .addPreferredGap(ComponentPlacement.RELATED)
281 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
282 .addComponent(lblVideo)
283 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
284 .addComponent(btnVideo)
285 .addComponent(cbVideoLocal))
286 .addPreferredGap(ComponentPlacement.RELATED)
287 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
288 .addComponent(lblComment)
289 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
290 .addComponent(btnComment)
291 .addComponent(cbCommentLocal))
292 .addPreferredGap(ComponentPlacement.RELATED)
293 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
294 .addComponent(lblOutput)
295 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
296 .addComponent(cbOutputEnable))
297 .addPreferredGap(ComponentPlacement.UNRELATED)
298 .addComponent(btnApply)
299 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
302 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
303 pnlMain.setLayout(gl_pnlMain);
304 gl_pnlMain.setHorizontalGroup(
305 gl_pnlMain.createParallelGroup(Alignment.LEADING)
306 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
308 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
309 .addComponent(pnlInputMain, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
310 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
311 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
314 gl_pnlMain.setVerticalGroup(
315 gl_pnlMain.createParallelGroup(Alignment.LEADING)
316 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
318 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
319 .addPreferredGap(ComponentPlacement.RELATED)
320 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
321 .addPreferredGap(ComponentPlacement.RELATED)
322 .addComponent(pnlInputMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
327 JMenuBar menuBar = initMenuBar();
328 setJMenuBar(menuBar);
330 GroupLayout layout = new GroupLayout(getContentPane());
331 getContentPane().setLayout(layout);
332 layout.setHorizontalGroup(
333 layout.createParallelGroup(Alignment.LEADING)
334 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
336 layout.setVerticalGroup(
337 layout.createParallelGroup(Alignment.LEADING)
338 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
343 pnlMain.setTransferHandler(new DownloadListTransferHandler());
344 tblDisplay.setTransferHandler(new TableTransferHandler());
346 final Config p = Config.INSTANCE;
348 // TODO downloadの連続処理時待ち時間設定も必要...
349 taskManager = new TaskManage(1, 2, new GuiTaskManageListener());
352 private class GuiTaskManageListener implements TaskManageListener {
355 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
356 final String message) {
357 SwingUtilities.invokeLater(new Runnable() {
361 targetModel.setStatus(id, kind, status, percentage, message);
367 private class ApplyActionListener implements ActionListener {
370 public void actionPerformed(ActionEvent e) {
371 final DownloadProfile downProf = new InqubusDownloadProfile();
372 final String id = Util.getVideoId(fldId.getText());
373 final InqubusConvertProfile convProf = new InqubusConvertProfile();
374 logger.log(Level.INFO, downProf.toString());
375 logger.log(Level.INFO, convProf.toString());
376 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
378 targetModel.addTarget(new Target(rp));
381 /** This method is called from within the constructor to
382 * initialize the form.
383 * WARNING: Do NOT modify this code. The content of this method is
384 * always regenerated by the Form Editor.
386 @SuppressWarnings("unchecked")
387 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
388 private void initComponents() {
389 }// </editor-fold>//GEN-END:initComponents
391 private File searchFileMatchId(final File dir, final String id) {
392 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
397 final File[] lists = dir.listFiles(new FilenameFilter() {
399 final Pattern pattern = Pattern.compile(id + "\\D");
402 public boolean accept(File dir, String name) {
403 return pattern.matcher(name).find();
407 if (lists.length == 1) {
409 } else if (lists.length > 1) {
410 throw new UnsupportedOperationException();
416 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
417 final Config p = Config.INSTANCE;
419 final ItemSelectable source = evt.getItemSelectable();
424 if (source == cbVideoLocal) {
427 dir = new File(p.getVideoDir());
431 dir = new File(p.getCommentDir());
434 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
435 btn.setEnabled(useLocal);
439 final File f = searchFileMatchId(dir, fldId.getText());
446 text = p.getVideoFileNamePattern();
450 fldId.setEnabled(!(cbVideoLocal.isSelected() && cbCommentLocal.isSelected()));
452 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
454 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
455 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
456 fldOutput.setEnabled(convert);
457 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
459 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
460 final Config p = Config.INSTANCE;
461 final String id = fldId.getText();
466 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
467 final File dir = new File(p.getVideoDir());
468 final File file = searchFileMatchId(dir, id);
470 fldVideo.setText(file.getPath());
474 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
475 final File dir = new File(p.getCommentDir());
476 final File file = searchFileMatchId(dir, id);
478 fldComment.setText(file.getPath());
482 }//GEN-LAST:event_idFieldFocusLost
483 // Variables declaration - do not modify//GEN-BEGIN:variables
484 private final JTable tblDisplay;
486 private final JButton btnStart = new JButton("開始");
487 private final JButton btnStop = new JButton("停止");
488 private final JButton btnDeselect = new JButton("選択解除");
490 private final JTextField fldId;
491 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
492 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
493 private final JTextField fldBackLog = new JTextField();
494 private final JCheckBox cbVideoLocal;
495 private final JTextField fldVideo;
496 private final JButton btnVideo;
497 private final JCheckBox cbCommentLocal;
498 private final JTextField fldComment;
499 private final JButton btnComment;
500 private final JCheckBox cbOutputEnable;
501 private final JTextField fldOutput;
503 private final JButton btnApply = new JButton("適用");
504 // End of variables declaration//GEN-END:variables
506 private void initInputPanel() {
507 final Config p = Config.INSTANCE;
510 fldBackLog.setEnabled(false);
511 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
512 cbBackLog.setEnabled(true);
513 cbBackLog.addItemListener(new ItemListener() {
516 public void itemStateChanged(ItemEvent e) {
517 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
518 fldBackLog.setEnabled(selected);
521 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
523 final boolean movieLocal = p.getVideoUseLocal();
524 cbVideoLocal.setSelected(movieLocal);
525 btnVideo.setEnabled(movieLocal);
527 fldVideo.setText(p.getVideoFileNamePattern());
530 final boolean commentLocal = p.getCommentUseLocal();
531 cbCommentLocal.setSelected(commentLocal);
532 btnComment.setEnabled(commentLocal);
534 fldComment.setText(p.getCommentFileNamePattern());
537 final boolean convert = p.getOutputEnable();
538 cbOutputEnable.setSelected(convert);
539 fldOutput.setEnabled(convert);
540 fldOutput.setText(p.getOutputFileNamePattern());
544 private JMenuBar initMenuBar() {
545 final JMenuBar menuBar = new JMenuBar();
547 final JMenu mnFile = new JMenu("ファイル(F)");
550 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
551 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
552 itExit.addActionListener(new ActionListener() {
555 public void actionPerformed(ActionEvent e) {
556 throw new UnsupportedOperationException("Not supported yet.");
561 final JMenu mnTool = new JMenu("ツール(T)");
564 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
566 itOption.addActionListener(new ActionListener() {
569 public void actionPerformed(ActionEvent e) {
570 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
571 dlg.setLocationRelativeTo(MainFrame.this);
573 dlg.setVisible(true);
576 mnTool.add(itOption);
578 final JMenu mnHelp = new JMenu("ヘルプ(H)");
581 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
582 itAbout.addActionListener(new ActionListener() {
585 public void actionPerformed(ActionEvent e) {
586 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
588 dlg.setLocationRelativeTo(MainFrame.this);
590 dlg.setVisible(true);
598 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
601 public void process(DownloadProgress progress) {
602 throw new UnsupportedOperationException("Not supported yet.");
606 public void cancelled() {
607 throw new UnsupportedOperationException("Not supported yet.");
611 public void done(DownloadResult result) {
612 throw new UnsupportedOperationException("Not supported yet.");
616 public void error(Throwable th) {
617 throw new UnsupportedOperationException("Not supported yet.");
621 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
624 public void process(ConvertProgress progress) {
625 throw new UnsupportedOperationException("Not supported yet.");
629 public void cancelled() {
630 throw new UnsupportedOperationException("Not supported yet.");
634 public void done(ConvertResult result) {
635 throw new UnsupportedOperationException("Not supported yet.");
639 public void error(Throwable th) {
640 throw new UnsupportedOperationException("Not supported yet.");
646 private class DownloadListTransferHandler extends TransferHandler {
648 private static final long serialVersionUID = 1L;
649 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
652 public boolean canImport(TransferHandler.TransferSupport support) {
653 Transferable transferable = support.getTransferable();
654 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
655 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
662 public boolean importData(TransferHandler.TransferSupport support) {
664 // Transferable transferable = support.getTransferable();
665 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
666 // @SuppressWarnings("unchecked")
667 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
668 // Collection<Target> targets = Target.from(data);
669 // targetModel.addTarget(targets);
670 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
671 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
672 // Matcher matcher = movieIdPattern.matcher(data);
673 // if (matcher.find()) {
674 // String movieId = matcher.group(1);
675 // Target target = Target.fromId(movieId);
676 // targetModel.addTarget(target);
683 // } catch (Exception e) {
684 // logger.log(Level.SEVERE, null, e);
687 // TODO 上記実装見直し(Locationは削除された)
692 private class TableTransferHandler extends DownloadListTransferHandler {
694 private static final long serialVersionUID = 1L;
697 public boolean canImport(TransferHandler.TransferSupport support) {
698 return super.canImport(support);
702 public boolean importData(TransferHandler.TransferSupport support) {
703 return super.importData(support);
708 * ここからDownloadProfile作成用クラスの定義
711 private class InqubusDownloadProfile implements DownloadProfile {
713 private final LoginProfile loginProfile;
714 private final ProxyProfile proxyProfile;
715 private final VideoProfile videoProfile;
716 private final CommentProfile commentProfile;
717 private final GeneralProfile generalProfile;
719 private InqubusDownloadProfile() {
720 this.loginProfile = new InqubusLoginProfile();
721 this.proxyProfile = new InqubusProxyProfile();
722 this.videoProfile = new InqubusVideoProfile();
723 this.commentProfile = new InqubusCommentProfile();
724 this.generalProfile = new InqubusGeneralProfile();
728 public LoginProfile getLoginInfo() {
729 return this.loginProfile;
733 public ProxyProfile getProxyProfile() {
734 return this.proxyProfile;
738 public VideoProfile getVideoProfile() {
739 return this.videoProfile;
743 public CommentProfile getCommentProfile() {
744 return this.commentProfile;
748 public GeneralProfile getGeneralProfile() {
749 return this.generalProfile;
753 public String toString(){
754 return ToStringBuilder.reflectionToString(this);
758 private class InqubusLoginProfile implements LoginProfile {
759 private final String mail;
760 private final String password;
762 private InqubusLoginProfile(){
763 final Config p = Config.INSTANCE;
764 this.mail = p.getId();
765 this.password = p.getPassword();
769 public String getMail() {
774 public String getPassword() {
775 return this.password;
779 public String toString(){
780 return ToStringBuilder.reflectionToString(this);
784 private class InqubusProxyProfile implements ProxyProfile {
785 private final boolean use;
786 private final String host;
787 private final int port;
789 private InqubusProxyProfile(){
790 final Config p = Config.INSTANCE;
791 this.use = p.getProxyUse();
792 this.host = p.getProxyHost();
793 final String pp = p.getProxyPort();
794 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
798 public boolean use() {
803 public String getHost() {
808 public int getPort() {
813 public String toString(){
814 return ToStringBuilder.reflectionToString(this);
818 private class InqubusVideoProfile implements VideoProfile {
819 private final boolean download;
820 private final File dir;
821 private final String fileName;
822 private final File localFile;
824 private InqubusVideoProfile(){
825 final Config p = Config.INSTANCE;
826 this.download = !cbVideoLocal.isSelected();
828 this.dir = new File(p.getVideoDir());
829 this.fileName = fldVideo.getText();
830 this.localFile = null;
833 this.fileName = null;
834 this.localFile = new File(fldVideo.getText());
839 public boolean isDownload() {
840 return this.download;
844 public File getDir() {
849 public String getFileName() {
850 return this.fileName;
854 public File getLocalFile() {
855 return this.localFile;
859 public String toString(){
860 return ToStringBuilder.reflectionToString(this);
864 private class InqubusCommentProfile implements CommentProfile {
865 private final boolean download;
866 private final File dir;
867 private final String fileName;
868 private final File localFile;
869 private final int lengthRelatedCommentSize;
870 private final boolean disablePerMinComment;
871 private final int perMinCommentSize;
872 private final long backLogPoint;
874 private InqubusCommentProfile() {
875 final Config p = Config.INSTANCE;
876 this.download = !cbCommentLocal.isSelected();
878 this.dir = new File(p.getCommentDir());
879 this.fileName = fldComment.getText();
880 this.localFile = null;
883 this.fileName = null;
884 this.localFile = new File(fldComment.getText());
887 if(cbBackLog.isSelected()) {
889 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
890 } catch (IOException ex) {
891 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
894 this.backLogPoint = -1L;
897 this.disablePerMinComment = cbBackLogReduce.isSelected();
898 this.lengthRelatedCommentSize
899 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
900 this.perMinCommentSize
901 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
905 public boolean isDownload() {
906 return this.download;
910 public File getDir() {
915 public String getFileName() {
916 return this.fileName;
920 public File getLocalFile() {
921 return this.localFile;
925 public int getLengthRelatedCommentSize() {
926 return this.lengthRelatedCommentSize;
930 public boolean isDisablePerMinComment() {
931 return this.disablePerMinComment;
935 public int getPerMinCommentSize() {
936 return this.perMinCommentSize;
940 public long getBackLogPoint() {
941 return this.backLogPoint;
945 public String toString(){
946 return ToStringBuilder.reflectionToString(this);
950 private class InqubusGeneralProfile implements GeneralProfile {
951 private final String replaceFrom;
952 private final String replaceTo;
953 private InqubusGeneralProfile() {
954 final Config p = Config.INSTANCE;
955 this.replaceFrom = p.getReplaceFrom();
956 this.replaceTo = p.getReplaceTo();
960 public String getReplaceFrom() {
961 return this.replaceFrom;
965 public String getReplaceTo() {
966 return this.replaceTo;
970 public String toString(){
971 return ToStringBuilder.reflectionToString(this);
976 * ここからConvertProfile作成用クラスの定義
978 private class InqubusConvertProfile implements ConvertProfile {
979 private final OutputProfile outputProfile;
980 private final GeneralProfile generalProfile;
981 private final FfmpegProfile ffmpegProfile;
982 private final boolean convert;
983 private final File ffmpeg;
984 private final boolean vhookDisabled;
985 private final boolean commentOverlay;
986 private final File vhook;
987 private final File tmpDir;
988 private final File font;
989 private final int fontIndex;
990 private final boolean commentOpaque;
991 private final boolean disableFontSizeArrange;
992 private final int shadowIndex;
993 private final boolean showConvrting;
994 private final int maxNumOfComment;
995 private final HideCondition ngSetting;
997 private InqubusConvertProfile() {
998 final Config p = Config.INSTANCE;
999 this.outputProfile = new InqubusOutputProfile();
1000 this.generalProfile = new InqubusGeneralProfile();
1001 this.ffmpegProfile = new InqubusFfmpegProfile();
1002 this.convert = cbOutputEnable.isSelected();
1003 this.ffmpeg = new File(p.getFfmpegPath());
1005 this.vhookDisabled = false;
1006 this.commentOverlay = p.getOutputCommentOverlay();
1007 this.vhook = new File(p.getFfmpegDllPath());
1009 this.tmpDir = new File(".");
1010 this.font = new File(p.getFontPath());
1011 this.fontIndex = Integer.parseInt(p.getFontIndex());
1012 this.commentOpaque = p.getCommentOpaque();
1013 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1014 this.shadowIndex = p.getFontShadow();
1016 this.showConvrting = true;
1017 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1018 getCommentDisplaySizeManual());
1019 this.ngSetting = new InqubusHideCondition();
1023 public OutputProfile getOutputProfile() {
1024 return this.outputProfile;
1028 public GeneralProfile getGeneralProfile() {
1029 return this.generalProfile;
1033 public FfmpegProfile getFfmpegOption() {
1034 return this.ffmpegProfile;
1038 public boolean isConvert() {
1039 return this.convert;
1043 public File getFfmpeg() {
1048 public boolean isVhookDisabled() {
1049 return this.vhookDisabled;
1053 public boolean isCommentOverlay() {
1054 return this.commentOverlay;
1058 public File getVhook() {
1063 public File getTempDir() {
1068 public File getFont() {
1073 public int getFontIndex() {
1074 return this.fontIndex;
1078 public boolean isCommentOpaque() {
1079 return this.commentOpaque;
1083 public boolean isDisableFontSizeArrange() {
1084 return this.disableFontSizeArrange;
1088 public int getShadowIndex() {
1089 return this.shadowIndex;
1093 public boolean isShowConverting() {
1094 return this.showConvrting;
1098 public int getMaxNumOfComment() {
1099 return this.maxNumOfComment;
1103 public HideCondition getNgSetting() {
1104 return this.ngSetting;
1108 public String toString(){
1109 return ToStringBuilder.reflectionToString(this);
1113 private class InqubusOutputProfile implements OutputProfile {
1114 private final File dir;
1115 private final String fileName;
1116 private final String videoId;
1117 private final String title;
1120 private InqubusOutputProfile(){
1121 final Config p = Config.INSTANCE;
1122 this.dir = new File(p.getOutputDir());
1123 this.fileName = fldOutput.getText();
1124 // TODO この時点でのID/Titleはどうするか…
1130 public File getDir() {
1135 public String getFileName() {
1136 return this.fileName;
1140 public String getVideoId() {
1141 return this.videoId;
1145 public String getTitile() {
1150 public String toString(){
1151 return ToStringBuilder.reflectionToString(this);
1155 private class InqubusFfmpegProfile implements FfmpegProfile {
1156 private final String extOption;
1157 private final String inOption;
1158 private final String mainOption;
1159 private final String outOption;
1160 private final String avOption;
1161 private final boolean resize;
1162 private final int resizeWidth;
1163 private final int resizeHeight;
1164 private final boolean adjustRatio;
1166 private InqubusFfmpegProfile() {
1167 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1168 final Config p = Config.INSTANCE;
1169 this.extOption = p.getFfmpegExtension();
1170 this.inOption = p.getFfmpegInOption();
1171 this.mainOption = p.getFfmpegMainOption();
1172 this.outOption = p.getFfmpegOutOption();
1173 this.avOption = p.getFfmpegAvOption();
1174 this.resize = p.getFfmpegResizeEnable();
1175 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1176 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1177 this.adjustRatio = p.getFfmpegKeepAspect();
1181 public String getExtOption() {
1182 return this.extOption;
1186 public String getInOption() {
1187 return this.inOption;
1191 public String getMainOption() {
1192 return this.mainOption;
1196 public String getOutOption() {
1197 return this.outOption;
1201 public String getAvfilterOption() {
1202 return this.avOption;
1206 public boolean isResize() {
1211 public int getResizeWidth() {
1212 return this.resizeWidth;
1216 public int getResizeHeight() {
1217 return this.resizeHeight;
1221 public boolean isAdjustRatio() {
1222 return this.adjustRatio;
1226 public String toString(){
1227 return ToStringBuilder.reflectionToString(this);
1231 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1234 public String getWord() {
1240 public String getId() {
1246 public String toString(){
1247 return ToStringBuilder.reflectionToString(this);