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.setToolTipText(ID_FIELD_TOOLTIP);
115 final JLabel lblVideo = new JLabel();
116 cbVideoLocal = new JCheckBox();
117 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
118 fldVideo = new JTextField();
119 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
120 btnVideo = new JButton();
121 final JLabel lblComment = new JLabel();
122 cbCommentLocal = new JCheckBox();
123 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
124 cbCommentLocal.addItemListener(new ItemListener() {
127 public void itemStateChanged(ItemEvent e) {
128 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
129 cbBackLogReduce.setEnabled(!selected);
130 cbBackLog.setEnabled(!selected);
132 cbBackLog.setSelected(false);
136 fldComment = new JTextField();
137 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
138 btnComment = new JButton();
139 final JLabel lblOutput = new JLabel();
140 cbOutputEnable = new JCheckBox();
141 fldOutput = new JTextField();
142 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
144 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
146 btnStop.addActionListener(new StopActionListener());
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 final int thDownload = p.getSystemDownloadThread();
350 final int secDownload = p.getSystemDownloadWait();
351 final int thConvert = p.getSystemConvertThread();
352 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
355 private class GuiTaskManageListener implements TaskManageListener {
358 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
359 final String message) {
360 SwingUtilities.invokeLater(new Runnable() {
364 targetModel.setStatus(id, kind, status, percentage, message);
370 private class StopActionListener implements ActionListener {
373 public void actionPerformed(ActionEvent e) {
374 // FIXME 待機中に停止しても「状態」の表示が変わらない。
375 final int row = tblDisplay.getSelectedRow();
376 final Target t = targetModel.getTarget(row);
377 final boolean res = taskManager.cancel(t.getRowId());
378 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
382 private class ApplyActionListener implements ActionListener {
385 public void actionPerformed(ActionEvent e) {
386 final DownloadProfile downProf = new InqubusDownloadProfile();
387 final String id = Util.getVideoId(fldId.getText());
388 final InqubusConvertProfile convProf = new InqubusConvertProfile();
389 logger.log(Level.INFO, downProf.toString());
390 logger.log(Level.INFO, convProf.toString());
391 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
393 targetModel.addTarget(new Target(rp));
396 /** This method is called from within the constructor to
397 * initialize the form.
398 * WARNING: Do NOT modify this code. The content of this method is
399 * always regenerated by the Form Editor.
401 @SuppressWarnings("unchecked")
402 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
403 private void initComponents() {
404 }// </editor-fold>//GEN-END:initComponents
406 private File searchFileMatchId(final File dir, final String id) {
407 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
412 final File[] lists = dir.listFiles(new FilenameFilter() {
414 final Pattern pattern = Pattern.compile(id + "\\D");
417 public boolean accept(File dir, String name) {
418 return pattern.matcher(name).find();
422 if (lists.length == 1) {
424 } else if (lists.length > 1) {
425 throw new UnsupportedOperationException();
432 * 動画, コメントの"local"チェックボックス更新時の処理.
434 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
435 final Config p = Config.INSTANCE;
437 final ItemSelectable source = evt.getItemSelectable();
442 if (source == cbVideoLocal) {
445 dir = new File(p.getVideoDir());
449 dir = new File(p.getCommentDir());
452 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
453 btn.setEnabled(useLocal);
457 final File f = searchFileMatchId(dir, fldId.getText());
464 text = p.getVideoFileNamePattern();
468 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
470 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
471 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
472 fldOutput.setEnabled(convert);
473 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
475 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
476 final Config p = Config.INSTANCE;
477 final String id = fldId.getText();
482 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
483 final File dir = new File(p.getVideoDir());
484 final File file = searchFileMatchId(dir, id);
486 fldVideo.setText(file.getPath());
490 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
491 final File dir = new File(p.getCommentDir());
492 final File file = searchFileMatchId(dir, id);
494 fldComment.setText(file.getPath());
498 }//GEN-LAST:event_idFieldFocusLost
499 // Variables declaration - do not modify//GEN-BEGIN:variables
500 private final JTable tblDisplay;
502 private final JButton btnStart = new JButton("開始");
503 private final JButton btnStop = new JButton("停止");
504 private final JButton btnDeselect = new JButton("選択解除");
506 private final JTextField fldId = new JTextField();
507 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
508 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
509 private final JTextField fldBackLog = new JTextField();
510 private final JCheckBox cbVideoLocal;
511 private final JTextField fldVideo;
512 private final JButton btnVideo;
513 private final JCheckBox cbCommentLocal;
514 private final JTextField fldComment;
515 private final JButton btnComment;
516 private final JCheckBox cbOutputEnable;
517 private final JTextField fldOutput;
519 private final JButton btnApply = new JButton("適用");
520 // End of variables declaration//GEN-END:variables
522 private void initInputPanel() {
523 final Config p = Config.INSTANCE;
526 fldBackLog.setEnabled(false);
527 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
528 cbBackLog.setEnabled(true);
529 cbBackLog.addItemListener(new ItemListener() {
532 public void itemStateChanged(ItemEvent e) {
533 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
534 fldBackLog.setEnabled(selected);
537 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
539 final boolean movieLocal = p.getVideoUseLocal();
540 cbVideoLocal.setSelected(movieLocal);
541 btnVideo.setEnabled(movieLocal);
543 fldVideo.setText(p.getVideoFileNamePattern());
546 final boolean commentLocal = p.getCommentUseLocal();
547 cbCommentLocal.setSelected(commentLocal);
548 btnComment.setEnabled(commentLocal);
550 fldComment.setText(p.getCommentFileNamePattern());
553 final boolean convert = p.getOutputEnable();
554 cbOutputEnable.setSelected(convert);
555 fldOutput.setEnabled(convert);
556 fldOutput.setText(p.getOutputFileNamePattern());
560 private JMenuBar initMenuBar() {
561 final JMenuBar menuBar = new JMenuBar();
563 final JMenu mnFile = new JMenu("ファイル(F)");
566 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
567 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
568 itExit.addActionListener(new ActionListener() {
571 public void actionPerformed(ActionEvent e) {
572 throw new UnsupportedOperationException("Not supported yet.");
577 final JMenu mnTool = new JMenu("ツール(T)");
580 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
582 itOption.addActionListener(new ActionListener() {
585 public void actionPerformed(ActionEvent e) {
586 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
587 dlg.setLocationRelativeTo(MainFrame.this);
589 dlg.setVisible(true);
592 mnTool.add(itOption);
594 final JMenu mnHelp = new JMenu("ヘルプ(H)");
597 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
598 itAbout.addActionListener(new ActionListener() {
601 public void actionPerformed(ActionEvent e) {
602 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
604 dlg.setLocationRelativeTo(MainFrame.this);
606 dlg.setVisible(true);
614 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
617 public void process(DownloadProgress progress) {
618 throw new UnsupportedOperationException("Not supported yet.");
622 public void cancelled() {
623 throw new UnsupportedOperationException("Not supported yet.");
627 public void done(DownloadResult result) {
628 throw new UnsupportedOperationException("Not supported yet.");
632 public void error(Throwable th) {
633 throw new UnsupportedOperationException("Not supported yet.");
637 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
640 public void process(ConvertProgress progress) {
641 throw new UnsupportedOperationException("Not supported yet.");
645 public void cancelled() {
646 throw new UnsupportedOperationException("Not supported yet.");
650 public void done(ConvertResult result) {
651 throw new UnsupportedOperationException("Not supported yet.");
655 public void error(Throwable th) {
656 throw new UnsupportedOperationException("Not supported yet.");
662 private class DownloadListTransferHandler extends TransferHandler {
664 private static final long serialVersionUID = 1L;
665 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
668 public boolean canImport(TransferHandler.TransferSupport support) {
669 Transferable transferable = support.getTransferable();
670 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
671 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
678 public boolean importData(TransferHandler.TransferSupport support) {
680 // Transferable transferable = support.getTransferable();
681 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
682 // @SuppressWarnings("unchecked")
683 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
684 // Collection<Target> targets = Target.from(data);
685 // targetModel.addTarget(targets);
686 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
687 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
688 // Matcher matcher = movieIdPattern.matcher(data);
689 // if (matcher.find()) {
690 // String movieId = matcher.group(1);
691 // Target target = Target.fromId(movieId);
692 // targetModel.addTarget(target);
699 // } catch (Exception e) {
700 // logger.log(Level.SEVERE, null, e);
703 // TODO 上記実装見直し(Locationは削除された)
708 private class TableTransferHandler extends DownloadListTransferHandler {
710 private static final long serialVersionUID = 1L;
713 public boolean canImport(TransferHandler.TransferSupport support) {
714 return super.canImport(support);
718 public boolean importData(TransferHandler.TransferSupport support) {
719 return super.importData(support);
724 * ここからDownloadProfile作成用クラスの定義
727 private class InqubusDownloadProfile implements DownloadProfile {
729 private final LoginProfile loginProfile;
730 private final ProxyProfile proxyProfile;
731 private final VideoProfile videoProfile;
732 private final CommentProfile commentProfile;
733 private final GeneralProfile generalProfile;
735 private InqubusDownloadProfile() {
736 this.loginProfile = new InqubusLoginProfile();
737 this.proxyProfile = new InqubusProxyProfile();
738 this.videoProfile = new InqubusVideoProfile();
739 this.commentProfile = new InqubusCommentProfile();
740 this.generalProfile = new InqubusGeneralProfile();
744 public LoginProfile getLoginInfo() {
745 return this.loginProfile;
749 public ProxyProfile getProxyProfile() {
750 return this.proxyProfile;
754 public VideoProfile getVideoProfile() {
755 return this.videoProfile;
759 public CommentProfile getCommentProfile() {
760 return this.commentProfile;
764 public GeneralProfile getGeneralProfile() {
765 return this.generalProfile;
769 public String toString(){
770 return ToStringBuilder.reflectionToString(this);
774 private class InqubusLoginProfile implements LoginProfile {
775 private final String mail;
776 private final String password;
778 private InqubusLoginProfile(){
779 final Config p = Config.INSTANCE;
780 this.mail = p.getId();
781 this.password = p.getPassword();
785 public String getMail() {
790 public String getPassword() {
791 return this.password;
795 public String toString(){
796 return ToStringBuilder.reflectionToString(this);
800 private class InqubusProxyProfile implements ProxyProfile {
801 private final boolean use;
802 private final String host;
803 private final int port;
805 private InqubusProxyProfile(){
806 final Config p = Config.INSTANCE;
807 this.use = p.getProxyUse();
808 this.host = p.getProxyHost();
809 final String pp = p.getProxyPort();
810 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
814 public boolean use() {
819 public String getHost() {
824 public int getPort() {
829 public String toString(){
830 return ToStringBuilder.reflectionToString(this);
834 private class InqubusVideoProfile implements VideoProfile {
835 private final boolean download;
836 private final File dir;
837 private final String fileName;
838 private final File localFile;
840 private InqubusVideoProfile(){
841 final Config p = Config.INSTANCE;
842 this.download = !cbVideoLocal.isSelected();
844 this.dir = new File(p.getVideoDir());
845 this.fileName = fldVideo.getText();
846 this.localFile = null;
849 this.fileName = null;
850 this.localFile = new File(fldVideo.getText());
855 public boolean isDownload() {
856 return this.download;
860 public File getDir() {
865 public String getFileName() {
866 return this.fileName;
870 public File getLocalFile() {
871 return this.localFile;
875 public String toString(){
876 return ToStringBuilder.reflectionToString(this);
880 private class InqubusCommentProfile implements CommentProfile {
881 private final boolean download;
882 private final File dir;
883 private final String fileName;
884 private final File localFile;
885 private final int lengthRelatedCommentSize;
886 private final boolean disablePerMinComment;
887 private final int perMinCommentSize;
888 private final long backLogPoint;
890 private InqubusCommentProfile() {
891 final Config p = Config.INSTANCE;
892 this.download = !cbCommentLocal.isSelected();
894 this.dir = new File(p.getCommentDir());
895 this.fileName = fldComment.getText();
896 this.localFile = null;
899 this.fileName = null;
900 this.localFile = new File(fldComment.getText());
903 if(cbBackLog.isSelected()) {
905 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
906 } catch (IOException ex) {
907 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
910 this.backLogPoint = -1L;
913 this.disablePerMinComment = cbBackLogReduce.isSelected();
914 this.lengthRelatedCommentSize
915 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
916 this.perMinCommentSize
917 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
921 public boolean isDownload() {
922 return this.download;
926 public File getDir() {
931 public String getFileName() {
932 return this.fileName;
936 public File getLocalFile() {
937 return this.localFile;
941 public int getLengthRelatedCommentSize() {
942 return this.lengthRelatedCommentSize;
946 public boolean isDisablePerMinComment() {
947 return this.disablePerMinComment;
951 public int getPerMinCommentSize() {
952 return this.perMinCommentSize;
956 public long getBackLogPoint() {
957 return this.backLogPoint;
961 public String toString(){
962 return ToStringBuilder.reflectionToString(this);
966 private class InqubusGeneralProfile implements GeneralProfile {
967 private final String replaceFrom;
968 private final String replaceTo;
969 private InqubusGeneralProfile() {
970 final Config p = Config.INSTANCE;
971 this.replaceFrom = p.getReplaceFrom();
972 this.replaceTo = p.getReplaceTo();
976 public String getReplaceFrom() {
977 return this.replaceFrom;
981 public String getReplaceTo() {
982 return this.replaceTo;
986 public String toString(){
987 return ToStringBuilder.reflectionToString(this);
992 * ここからConvertProfile作成用クラスの定義
994 private class InqubusConvertProfile implements ConvertProfile {
995 private final OutputProfile outputProfile;
996 private final GeneralProfile generalProfile;
997 private final FfmpegProfile ffmpegProfile;
998 private final boolean convert;
999 private final File ffmpeg;
1000 private final boolean vhookDisabled;
1001 private final boolean commentOverlay;
1002 private final File vhook;
1003 private final File tmpDir;
1004 private final File font;
1005 private final int fontIndex;
1006 private final boolean commentOpaque;
1007 private final boolean disableFontSizeArrange;
1008 private final int shadowIndex;
1009 private final boolean showConvrting;
1010 private final int maxNumOfComment;
1011 private final HideCondition ngSetting;
1013 private InqubusConvertProfile() {
1014 final Config p = Config.INSTANCE;
1015 this.outputProfile = new InqubusOutputProfile();
1016 this.generalProfile = new InqubusGeneralProfile();
1017 this.ffmpegProfile = new InqubusFfmpegProfile();
1018 this.convert = cbOutputEnable.isSelected();
1019 this.ffmpeg = new File(p.getFfmpegPath());
1021 this.vhookDisabled = false;
1022 this.commentOverlay = p.getOutputCommentOverlay();
1023 this.vhook = new File(p.getFfmpegDllPath());
1025 this.tmpDir = new File(".");
1026 this.font = new File(p.getFontPath());
1027 this.fontIndex = Integer.parseInt(p.getFontIndex());
1028 this.commentOpaque = p.getCommentOpaque();
1029 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1030 this.shadowIndex = p.getFontShadow();
1032 this.showConvrting = true;
1033 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1034 getCommentDisplaySizeManual());
1035 this.ngSetting = new InqubusHideCondition();
1039 public OutputProfile getOutputProfile() {
1040 return this.outputProfile;
1044 public GeneralProfile getGeneralProfile() {
1045 return this.generalProfile;
1049 public FfmpegProfile getFfmpegOption() {
1050 return this.ffmpegProfile;
1054 public boolean isConvert() {
1055 return this.convert;
1059 public File getFfmpeg() {
1064 public boolean isVhookDisabled() {
1065 return this.vhookDisabled;
1069 public boolean isCommentOverlay() {
1070 return this.commentOverlay;
1074 public File getVhook() {
1079 public File getTempDir() {
1084 public File getFont() {
1089 public int getFontIndex() {
1090 return this.fontIndex;
1094 public boolean isCommentOpaque() {
1095 return this.commentOpaque;
1099 public boolean isDisableFontSizeArrange() {
1100 return this.disableFontSizeArrange;
1104 public int getShadowIndex() {
1105 return this.shadowIndex;
1109 public boolean isShowConverting() {
1110 return this.showConvrting;
1114 public int getMaxNumOfComment() {
1115 return this.maxNumOfComment;
1119 public HideCondition getNgSetting() {
1120 return this.ngSetting;
1124 public String toString(){
1125 return ToStringBuilder.reflectionToString(this);
1129 private class InqubusOutputProfile implements OutputProfile {
1130 private final File dir;
1131 private final String fileName;
1132 private final String videoId;
1133 private final String title;
1136 private InqubusOutputProfile(){
1137 final Config p = Config.INSTANCE;
1138 this.dir = new File(p.getOutputDir());
1139 this.fileName = fldOutput.getText();
1140 // TODO この時点でのID/Titleはどうするか…
1146 public File getDir() {
1151 public String getFileName() {
1152 return this.fileName;
1156 public String getVideoId() {
1157 return this.videoId;
1161 public String getTitile() {
1166 public String toString(){
1167 return ToStringBuilder.reflectionToString(this);
1171 private class InqubusFfmpegProfile implements FfmpegProfile {
1172 private final String extOption;
1173 private final String inOption;
1174 private final String mainOption;
1175 private final String outOption;
1176 private final String avOption;
1177 private final boolean resize;
1178 private final int resizeWidth;
1179 private final int resizeHeight;
1180 private final boolean adjustRatio;
1182 private InqubusFfmpegProfile() {
1183 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1184 final Config p = Config.INSTANCE;
1185 this.extOption = p.getFfmpegExtension();
1186 this.inOption = p.getFfmpegInOption();
1187 this.mainOption = p.getFfmpegMainOption();
1188 this.outOption = p.getFfmpegOutOption();
1189 this.avOption = p.getFfmpegAvOption();
1190 this.resize = p.getFfmpegResizeEnable();
1191 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1192 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1193 this.adjustRatio = p.getFfmpegKeepAspect();
1197 public String getExtOption() {
1198 return this.extOption;
1202 public String getInOption() {
1203 return this.inOption;
1207 public String getMainOption() {
1208 return this.mainOption;
1212 public String getOutOption() {
1213 return this.outOption;
1217 public String getAvfilterOption() {
1218 return this.avOption;
1222 public boolean isResize() {
1227 public int getResizeWidth() {
1228 return this.resizeWidth;
1232 public int getResizeHeight() {
1233 return this.resizeHeight;
1237 public boolean isAdjustRatio() {
1238 return this.adjustRatio;
1242 public String toString(){
1243 return ToStringBuilder.reflectionToString(this);
1247 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1250 public String getWord() {
1256 public String getId() {
1262 public String toString(){
1263 return ToStringBuilder.reflectionToString(this);