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;
18 import java.beans.PropertyChangeEvent;
19 import java.beans.PropertyChangeListener;
21 import java.io.FilenameFilter;
22 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.regex.Matcher;
30 import java.util.regex.Pattern;
31 import javax.swing.BorderFactory;
32 import javax.swing.DropMode;
33 import javax.swing.GroupLayout;
34 import javax.swing.GroupLayout.Alignment;
35 import javax.swing.JButton;
36 import javax.swing.JCheckBox;
37 import javax.swing.JFrame;
38 import javax.swing.JLabel;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuBar;
41 import javax.swing.JMenuItem;
42 import javax.swing.JPanel;
43 import javax.swing.JScrollPane;
44 import javax.swing.JTable;
45 import javax.swing.JTextField;
46 import javax.swing.KeyStroke;
47 import javax.swing.LayoutStyle.ComponentPlacement;
48 import javax.swing.SwingUtilities;
49 import javax.swing.TransferHandler;
50 import javax.swing.WindowConstants;
51 import org.apache.commons.lang.StringUtils;
52 import org.apache.commons.lang.builder.ToStringBuilder;
53 import saccubus.MainFrame_AboutBox;
54 import saccubus.util.WayBackTimeParser;
55 import saccubus.worker.impl.convert.ConvertProgress;
56 import saccubus.worker.impl.download.DownloadProgress;
57 import saccubus.worker.WorkerListener;
58 import saccubus.worker.impl.convert.ConvertResult;
59 import saccubus.worker.impl.download.DownloadResult;
60 import saccubus.worker.profile.CommentProfile;
61 import saccubus.worker.profile.ConvertProfile;
62 import saccubus.worker.profile.DownloadProfile;
63 import saccubus.worker.profile.FfmpegProfile;
64 import saccubus.worker.profile.GeneralProfile;
65 import saccubus.worker.profile.LoginProfile;
66 import saccubus.worker.profile.OutputProfile;
67 import saccubus.worker.profile.ProxyProfile;
68 import saccubus.worker.profile.VideoProfile;
70 import yukihane.inqubus.Config;
71 import yukihane.inqubus.manager.RequestProcess;
72 import yukihane.inqubus.manager.TaskKind;
73 import yukihane.inqubus.manager.TaskManage;
74 import yukihane.inqubus.manager.TaskManageListener;
75 import yukihane.inqubus.manager.TaskStatus;
76 import yukihane.inqubus.model.Target;
77 import yukihane.inqubus.model.TargetsTableModel;
83 public class MainFrame extends JFrame {
85 private static final long serialVersionUID = 1L;
86 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
87 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
88 private static final String FILE_LOCALBUTTON_TOOLTIP
89 = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
90 private static final String FILE_INPUTFIELD_TOOLTIP
91 = "ダウンロードする場合はファイル命名規則を入力します。"
92 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
93 private static final String FILE_OUTPUTFIELD_TOOLTIP
95 private final TargetsTableModel targetModel = new TargetsTableModel();
96 private final TaskManage taskManager;
98 /** Creates new form MainFrame */
100 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
101 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
102 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
103 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
104 final List<Image> images = new ArrayList<Image>(2);
107 setIconImages(images);
109 final JPanel pnlMain = new JPanel();
110 final JScrollPane scrDisplay = new JScrollPane();
111 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
112 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
113 final JPanel pnlButton = new JPanel();
114 final JPanel pnlInputMain = new JPanel();
115 final JLabel lblId = new JLabel();
116 fldId.setToolTipText(ID_FIELD_TOOLTIP);
117 final JLabel lblVideo = new JLabel();
118 cbVideoLocal = new JCheckBox();
119 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
120 fldVideo = new JTextField();
121 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
122 btnVideo = new JButton();
123 final JLabel lblComment = new JLabel();
125 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
126 cbBackLog.addItemListener(new ItemListener() {
129 public void itemStateChanged(ItemEvent e) {
130 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
131 fldBackLog.setEnabled(selected);
134 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
137 public void propertyChange(PropertyChangeEvent evt) {
138 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
139 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
140 fldBackLog.setEnabled(fldEnabled);
143 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
145 cbCommentLocal = new JCheckBox();
146 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
147 cbCommentLocal.addItemListener(new ItemListener() {
150 public void itemStateChanged(ItemEvent e) {
151 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
152 cbBackLogReduce.setEnabled(!selected);
153 cbBackLog.setEnabled(!selected);
156 fldComment = new JTextField();
157 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
158 btnComment = new JButton();
159 final JLabel lblOutput = new JLabel();
160 cbOutputEnable = new JCheckBox();
161 fldOutput = new JTextField();
162 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
164 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
166 btnStop.addActionListener(new StopActionListener());
167 btnApply.addActionListener(new ApplyActionListener());
169 pnlMain.setBorder(BorderFactory.createEtchedBorder());
171 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
172 scrDisplay.setViewportView(tblDisplay);
174 pnlButton.setBorder(BorderFactory.createEtchedBorder());
176 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
177 pnlButton.setLayout(gl_pnlButton);
178 gl_pnlButton.setHorizontalGroup(
179 gl_pnlButton.createParallelGroup(Alignment.LEADING)
180 .addGroup(gl_pnlButton.createSequentialGroup()
182 .addComponent(btnStart)
183 .addPreferredGap(ComponentPlacement.RELATED)
184 .addComponent(btnStop)
185 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
186 .addComponent(btnDeselect)
189 gl_pnlButton.setVerticalGroup(
190 gl_pnlButton.createParallelGroup(Alignment.LEADING)
191 .addGroup(gl_pnlButton.createSequentialGroup()
193 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
194 .addComponent(btnStart)
195 .addComponent(btnStop)
196 .addComponent(btnDeselect))
197 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
200 pnlInputMain.setBorder(BorderFactory.createEtchedBorder());
204 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
206 public void focusLost(java.awt.event.FocusEvent evt) {
207 idFieldFocusLost(evt);
211 lblVideo.setText("動画");
213 cbVideoLocal.setText("local");
214 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
216 public void itemStateChanged(java.awt.event.ItemEvent evt) {
217 useMovieLocalCheckBoxItemStateChanged(evt);
221 btnVideo.setText("...");
223 lblComment.setText("コメント");
225 cbCommentLocal.setText("local");
226 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
228 public void itemStateChanged(java.awt.event.ItemEvent evt) {
229 useMovieLocalCheckBoxItemStateChanged(evt);
233 btnComment.setText("...");
235 lblOutput.setText("出力");
237 cbOutputEnable.setText("変換");
238 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
240 public void itemStateChanged(java.awt.event.ItemEvent evt) {
241 outputConvertCheckBoxItemStateChanged(evt);
246 GroupLayout gl_pnlInputMain = new GroupLayout(pnlInputMain);
247 pnlInputMain.setLayout(gl_pnlInputMain);
248 gl_pnlInputMain.setHorizontalGroup(
249 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
250 .addGroup(gl_pnlInputMain.createSequentialGroup()
252 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
253 .addGroup(gl_pnlInputMain.createSequentialGroup()
254 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
255 .addComponent(lblComment)
256 .addComponent(lblVideo)
258 .addComponent(lblOutput))
259 .addPreferredGap(ComponentPlacement.RELATED)
260 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
261 .addGroup(gl_pnlInputMain.createSequentialGroup()
262 .addComponent(cbVideoLocal)
263 .addPreferredGap(ComponentPlacement.RELATED)
264 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
265 .addPreferredGap(ComponentPlacement.RELATED)
266 .addComponent(btnVideo))
267 .addGroup(gl_pnlInputMain.createSequentialGroup()
268 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
269 .addPreferredGap(ComponentPlacement.UNRELATED)
270 .addComponent(cbBackLogReduce)
271 .addComponent(cbBackLog)
272 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
274 .addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
275 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
276 .addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
277 .addComponent(cbOutputEnable)
278 .addPreferredGap(ComponentPlacement.RELATED)
279 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
280 .addGroup(gl_pnlInputMain.createSequentialGroup()
281 .addComponent(cbCommentLocal)
282 .addPreferredGap(ComponentPlacement.RELATED)
283 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
284 .addPreferredGap(ComponentPlacement.RELATED)
285 .addComponent(btnComment))))
286 .addComponent(btnApply, Alignment.TRAILING))
289 gl_pnlInputMain.setVerticalGroup(
290 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
291 .addGroup(gl_pnlInputMain.createSequentialGroup()
293 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
294 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
296 .addComponent(cbBackLogReduce)
297 .addComponent(cbBackLog)
298 .addComponent(fldBackLog)
300 .addPreferredGap(ComponentPlacement.RELATED)
301 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
302 .addComponent(lblVideo)
303 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
304 .addComponent(btnVideo)
305 .addComponent(cbVideoLocal))
306 .addPreferredGap(ComponentPlacement.RELATED)
307 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
308 .addComponent(lblComment)
309 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
310 .addComponent(btnComment)
311 .addComponent(cbCommentLocal))
312 .addPreferredGap(ComponentPlacement.RELATED)
313 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
314 .addComponent(lblOutput)
315 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
316 .addComponent(cbOutputEnable))
317 .addPreferredGap(ComponentPlacement.UNRELATED)
318 .addComponent(btnApply)
319 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
322 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
323 pnlMain.setLayout(gl_pnlMain);
324 gl_pnlMain.setHorizontalGroup(
325 gl_pnlMain.createParallelGroup(Alignment.LEADING)
326 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
328 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
329 .addComponent(pnlInputMain, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
330 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
331 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
334 gl_pnlMain.setVerticalGroup(
335 gl_pnlMain.createParallelGroup(Alignment.LEADING)
336 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
338 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
339 .addPreferredGap(ComponentPlacement.RELATED)
340 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
341 .addPreferredGap(ComponentPlacement.RELATED)
342 .addComponent(pnlInputMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
347 JMenuBar menuBar = initMenuBar();
348 setJMenuBar(menuBar);
350 GroupLayout layout = new GroupLayout(getContentPane());
351 getContentPane().setLayout(layout);
352 layout.setHorizontalGroup(
353 layout.createParallelGroup(Alignment.LEADING)
354 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
356 layout.setVerticalGroup(
357 layout.createParallelGroup(Alignment.LEADING)
358 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
363 pnlMain.setTransferHandler(new DownloadListTransferHandler());
364 tblDisplay.setTransferHandler(new TableTransferHandler());
366 final Config p = Config.INSTANCE;
368 // TODO downloadの連続処理時待ち時間設定も必要...
369 final int thDownload = p.getSystemDownloadThread();
370 final int secDownload = p.getSystemDownloadWait();
371 final int thConvert = p.getSystemConvertThread();
372 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
375 private class GuiTaskManageListener implements TaskManageListener {
378 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
379 final String message) {
380 SwingUtilities.invokeLater(new Runnable() {
384 targetModel.setStatus(id, kind, status, percentage, message);
390 private class StopActionListener implements ActionListener {
393 public void actionPerformed(ActionEvent e) {
394 // FIXME 待機中に停止しても「状態」の表示が変わらない。
395 final int row = tblDisplay.getSelectedRow();
396 final Target t = targetModel.getTarget(row);
397 final boolean res = taskManager.cancel(t.getRowId());
398 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
402 private class ApplyActionListener implements ActionListener {
405 public void actionPerformed(ActionEvent e) {
406 final DownloadProfile downProf = new InqubusDownloadProfile();
407 final String id = Util.getVideoId(fldId.getText());
408 final InqubusConvertProfile convProf = new InqubusConvertProfile();
409 logger.log(Level.INFO, downProf.toString());
410 logger.log(Level.INFO, convProf.toString());
411 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
413 targetModel.addTarget(new Target(rp));
416 /** This method is called from within the constructor to
417 * initialize the form.
418 * WARNING: Do NOT modify this code. The content of this method is
419 * always regenerated by the Form Editor.
421 @SuppressWarnings("unchecked")
422 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
423 private void initComponents() {
424 }// </editor-fold>//GEN-END:initComponents
426 private File searchFileMatchId(final File dir, final String id) {
427 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
432 final File[] lists = dir.listFiles(new FilenameFilter() {
434 final Pattern pattern = Pattern.compile(id + "\\D");
437 public boolean accept(File dir, String name) {
438 return pattern.matcher(name).find();
442 if (lists.length == 1) {
444 } else if (lists.length > 1) {
445 throw new UnsupportedOperationException();
452 * 動画, コメントの"local"チェックボックス更新時の処理.
454 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
455 final Config p = Config.INSTANCE;
457 final ItemSelectable source = evt.getItemSelectable();
462 if (source == cbVideoLocal) {
465 dir = new File(p.getVideoDir());
469 dir = new File(p.getCommentDir());
472 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
473 btn.setEnabled(useLocal);
477 final File f = searchFileMatchId(dir, fldId.getText());
484 text = p.getVideoFileNamePattern();
488 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
490 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
491 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
492 fldOutput.setEnabled(convert);
493 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
495 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
496 final Config p = Config.INSTANCE;
497 final String id = fldId.getText();
502 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
503 final File dir = new File(p.getVideoDir());
504 final File file = searchFileMatchId(dir, id);
506 fldVideo.setText(file.getPath());
510 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
511 final File dir = new File(p.getCommentDir());
512 final File file = searchFileMatchId(dir, id);
514 fldComment.setText(file.getPath());
518 }//GEN-LAST:event_idFieldFocusLost
519 // Variables declaration - do not modify//GEN-BEGIN:variables
520 private final JTable tblDisplay;
522 private final JButton btnStart = new JButton("開始");
523 private final JButton btnStop = new JButton("停止");
524 private final JButton btnDeselect = new JButton("選択解除");
526 private final JTextField fldId = new JTextField();
527 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
528 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
529 private final JTextField fldBackLog = new JTextField();
530 private final JCheckBox cbVideoLocal;
531 private final JTextField fldVideo;
532 private final JButton btnVideo;
533 private final JCheckBox cbCommentLocal;
534 private final JTextField fldComment;
535 private final JButton btnComment;
536 private final JCheckBox cbOutputEnable;
537 private final JTextField fldOutput;
539 private final JButton btnApply = new JButton("適用");
540 // End of variables declaration//GEN-END:variables
542 private void initInputPanel() {
543 final Config p = Config.INSTANCE;
546 fldBackLog.setEnabled(false);
547 cbBackLog.setEnabled(true);
549 final boolean movieLocal = p.getVideoUseLocal();
550 cbVideoLocal.setSelected(movieLocal);
551 btnVideo.setEnabled(movieLocal);
553 fldVideo.setText(p.getVideoFileNamePattern());
556 final boolean commentLocal = p.getCommentUseLocal();
557 cbCommentLocal.setSelected(commentLocal);
558 btnComment.setEnabled(commentLocal);
560 fldComment.setText(p.getCommentFileNamePattern());
563 final boolean convert = p.getOutputEnable();
564 cbOutputEnable.setSelected(convert);
565 fldOutput.setEnabled(convert);
566 fldOutput.setText(p.getOutputFileNamePattern());
570 private JMenuBar initMenuBar() {
571 final JMenuBar menuBar = new JMenuBar();
573 final JMenu mnFile = new JMenu("ファイル(F)");
576 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
577 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
578 itExit.addActionListener(new ActionListener() {
581 public void actionPerformed(ActionEvent e) {
582 throw new UnsupportedOperationException("Not supported yet.");
587 final JMenu mnTool = new JMenu("ツール(T)");
590 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
592 itOption.addActionListener(new ActionListener() {
595 public void actionPerformed(ActionEvent e) {
596 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
597 dlg.setLocationRelativeTo(MainFrame.this);
599 dlg.setVisible(true);
602 mnTool.add(itOption);
604 final JMenu mnHelp = new JMenu("ヘルプ(H)");
607 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
608 itAbout.addActionListener(new ActionListener() {
611 public void actionPerformed(ActionEvent e) {
612 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
614 dlg.setLocationRelativeTo(MainFrame.this);
616 dlg.setVisible(true);
624 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
627 public void process(DownloadProgress progress) {
628 throw new UnsupportedOperationException("Not supported yet.");
632 public void cancelled() {
633 throw new UnsupportedOperationException("Not supported yet.");
637 public void done(DownloadResult result) {
638 throw new UnsupportedOperationException("Not supported yet.");
642 public void error(Throwable th) {
643 throw new UnsupportedOperationException("Not supported yet.");
647 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
650 public void process(ConvertProgress progress) {
651 throw new UnsupportedOperationException("Not supported yet.");
655 public void cancelled() {
656 throw new UnsupportedOperationException("Not supported yet.");
660 public void done(ConvertResult result) {
661 throw new UnsupportedOperationException("Not supported yet.");
665 public void error(Throwable th) {
666 throw new UnsupportedOperationException("Not supported yet.");
672 private class DownloadListTransferHandler extends TransferHandler {
674 private static final long serialVersionUID = 1L;
675 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
678 public boolean canImport(TransferHandler.TransferSupport support) {
679 Transferable transferable = support.getTransferable();
680 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
681 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
688 public boolean importData(TransferHandler.TransferSupport support) {
690 // Transferable transferable = support.getTransferable();
691 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
692 // @SuppressWarnings("unchecked")
693 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
694 // Collection<Target> targets = Target.from(data);
695 // targetModel.addTarget(targets);
696 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
697 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
698 // Matcher matcher = movieIdPattern.matcher(data);
699 // if (matcher.find()) {
700 // String movieId = matcher.group(1);
701 // Target target = Target.fromId(movieId);
702 // targetModel.addTarget(target);
709 // } catch (Exception e) {
710 // logger.log(Level.SEVERE, null, e);
713 // TODO 上記実装見直し(Locationは削除された)
718 private class TableTransferHandler extends DownloadListTransferHandler {
720 private static final long serialVersionUID = 1L;
723 public boolean canImport(TransferHandler.TransferSupport support) {
724 return super.canImport(support);
728 public boolean importData(TransferHandler.TransferSupport support) {
729 return super.importData(support);
734 * ここからDownloadProfile作成用クラスの定義
737 private class InqubusDownloadProfile implements DownloadProfile {
739 private final LoginProfile loginProfile;
740 private final ProxyProfile proxyProfile;
741 private final VideoProfile videoProfile;
742 private final CommentProfile commentProfile;
743 private final GeneralProfile generalProfile;
745 private InqubusDownloadProfile() {
746 this.loginProfile = new InqubusLoginProfile();
747 this.proxyProfile = new InqubusProxyProfile();
748 this.videoProfile = new InqubusVideoProfile();
749 this.commentProfile = new InqubusCommentProfile();
750 this.generalProfile = new InqubusGeneralProfile();
754 public LoginProfile getLoginInfo() {
755 return this.loginProfile;
759 public ProxyProfile getProxyProfile() {
760 return this.proxyProfile;
764 public VideoProfile getVideoProfile() {
765 return this.videoProfile;
769 public CommentProfile getCommentProfile() {
770 return this.commentProfile;
774 public GeneralProfile getGeneralProfile() {
775 return this.generalProfile;
779 public String toString(){
780 return ToStringBuilder.reflectionToString(this);
784 private class InqubusLoginProfile implements LoginProfile {
785 private final String mail;
786 private final String password;
788 private InqubusLoginProfile(){
789 final Config p = Config.INSTANCE;
790 this.mail = p.getId();
791 this.password = p.getPassword();
795 public String getMail() {
800 public String getPassword() {
801 return this.password;
805 public String toString(){
806 return ToStringBuilder.reflectionToString(this);
810 private class InqubusProxyProfile implements ProxyProfile {
811 private final boolean use;
812 private final String host;
813 private final int port;
815 private InqubusProxyProfile(){
816 final Config p = Config.INSTANCE;
817 this.use = p.getProxyUse();
818 this.host = p.getProxyHost();
819 final String pp = p.getProxyPort();
820 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
824 public boolean use() {
829 public String getHost() {
834 public int getPort() {
839 public String toString(){
840 return ToStringBuilder.reflectionToString(this);
844 private class InqubusVideoProfile implements VideoProfile {
845 private final boolean download;
846 private final File dir;
847 private final String fileName;
848 private final File localFile;
850 private InqubusVideoProfile(){
851 final Config p = Config.INSTANCE;
852 this.download = !cbVideoLocal.isSelected();
854 this.dir = new File(p.getVideoDir());
855 this.fileName = fldVideo.getText();
856 this.localFile = null;
859 this.fileName = null;
860 this.localFile = new File(fldVideo.getText());
865 public boolean isDownload() {
866 return this.download;
870 public File getDir() {
875 public String getFileName() {
876 return this.fileName;
880 public File getLocalFile() {
881 return this.localFile;
885 public String toString(){
886 return ToStringBuilder.reflectionToString(this);
890 private class InqubusCommentProfile implements CommentProfile {
891 private final boolean download;
892 private final File dir;
893 private final String fileName;
894 private final File localFile;
895 private final int lengthRelatedCommentSize;
896 private final boolean disablePerMinComment;
897 private final int perMinCommentSize;
898 private final long backLogPoint;
900 private InqubusCommentProfile() {
901 final Config p = Config.INSTANCE;
902 this.download = !cbCommentLocal.isSelected();
904 this.dir = new File(p.getCommentDir());
905 this.fileName = fldComment.getText();
906 this.localFile = null;
909 this.fileName = null;
910 this.localFile = new File(fldComment.getText());
913 if(cbBackLog.isSelected()) {
915 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
916 } catch (IOException ex) {
917 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
920 this.backLogPoint = -1L;
923 this.disablePerMinComment = cbBackLogReduce.isSelected();
924 this.lengthRelatedCommentSize
925 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
926 this.perMinCommentSize
927 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
931 public boolean isDownload() {
932 return this.download;
936 public File getDir() {
941 public String getFileName() {
942 return this.fileName;
946 public File getLocalFile() {
947 return this.localFile;
951 public int getLengthRelatedCommentSize() {
952 return this.lengthRelatedCommentSize;
956 public boolean isDisablePerMinComment() {
957 return this.disablePerMinComment;
961 public int getPerMinCommentSize() {
962 return this.perMinCommentSize;
966 public long getBackLogPoint() {
967 return this.backLogPoint;
971 public String toString(){
972 return ToStringBuilder.reflectionToString(this);
976 private class InqubusGeneralProfile implements GeneralProfile {
977 private final String replaceFrom;
978 private final String replaceTo;
979 private InqubusGeneralProfile() {
980 final Config p = Config.INSTANCE;
981 this.replaceFrom = p.getReplaceFrom();
982 this.replaceTo = p.getReplaceTo();
986 public String getReplaceFrom() {
987 return this.replaceFrom;
991 public String getReplaceTo() {
992 return this.replaceTo;
996 public String toString(){
997 return ToStringBuilder.reflectionToString(this);
1002 * ここからConvertProfile作成用クラスの定義
1004 private class InqubusConvertProfile implements ConvertProfile {
1005 private final OutputProfile outputProfile;
1006 private final GeneralProfile generalProfile;
1007 private final FfmpegProfile ffmpegProfile;
1008 private final boolean convert;
1009 private final File ffmpeg;
1010 private final boolean vhookDisabled;
1011 private final boolean commentOverlay;
1012 private final File vhook;
1013 private final File tmpDir;
1014 private final File font;
1015 private final int fontIndex;
1016 private final boolean commentOpaque;
1017 private final boolean disableFontSizeArrange;
1018 private final int shadowIndex;
1019 private final boolean showConvrting;
1020 private final int maxNumOfComment;
1021 private final HideCondition ngSetting;
1023 private InqubusConvertProfile() {
1024 final Config p = Config.INSTANCE;
1025 this.outputProfile = new InqubusOutputProfile();
1026 this.generalProfile = new InqubusGeneralProfile();
1027 this.ffmpegProfile = new InqubusFfmpegProfile();
1028 this.convert = cbOutputEnable.isSelected();
1029 this.ffmpeg = new File(p.getFfmpegPath());
1031 this.vhookDisabled = false;
1032 this.commentOverlay = p.getOutputCommentOverlay();
1033 this.vhook = new File(p.getFfmpegDllPath());
1035 this.tmpDir = new File(".");
1036 this.font = new File(p.getFontPath());
1037 this.fontIndex = Integer.parseInt(p.getFontIndex());
1038 this.commentOpaque = p.getCommentOpaque();
1039 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1040 this.shadowIndex = p.getFontShadow();
1042 this.showConvrting = true;
1043 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1044 getCommentDisplaySizeManual());
1045 this.ngSetting = new InqubusHideCondition();
1049 public OutputProfile getOutputProfile() {
1050 return this.outputProfile;
1054 public GeneralProfile getGeneralProfile() {
1055 return this.generalProfile;
1059 public FfmpegProfile getFfmpegOption() {
1060 return this.ffmpegProfile;
1064 public boolean isConvert() {
1065 return this.convert;
1069 public File getFfmpeg() {
1074 public boolean isVhookDisabled() {
1075 return this.vhookDisabled;
1079 public boolean isCommentOverlay() {
1080 return this.commentOverlay;
1084 public File getVhook() {
1089 public File getTempDir() {
1094 public File getFont() {
1099 public int getFontIndex() {
1100 return this.fontIndex;
1104 public boolean isCommentOpaque() {
1105 return this.commentOpaque;
1109 public boolean isDisableFontSizeArrange() {
1110 return this.disableFontSizeArrange;
1114 public int getShadowIndex() {
1115 return this.shadowIndex;
1119 public boolean isShowConverting() {
1120 return this.showConvrting;
1124 public int getMaxNumOfComment() {
1125 return this.maxNumOfComment;
1129 public HideCondition getNgSetting() {
1130 return this.ngSetting;
1134 public String toString(){
1135 return ToStringBuilder.reflectionToString(this);
1139 private class InqubusOutputProfile implements OutputProfile {
1140 private final File dir;
1141 private final String fileName;
1142 private final String videoId;
1143 private final String title;
1146 private InqubusOutputProfile(){
1147 final Config p = Config.INSTANCE;
1148 this.dir = new File(p.getOutputDir());
1149 this.fileName = fldOutput.getText();
1150 // TODO この時点でのID/Titleはどうするか…
1156 public File getDir() {
1161 public String getFileName() {
1162 return this.fileName;
1166 public String getVideoId() {
1167 return this.videoId;
1171 public String getTitile() {
1176 public String toString(){
1177 return ToStringBuilder.reflectionToString(this);
1181 private class InqubusFfmpegProfile implements FfmpegProfile {
1182 private final String extOption;
1183 private final String inOption;
1184 private final String mainOption;
1185 private final String outOption;
1186 private final String avOption;
1187 private final boolean resize;
1188 private final int resizeWidth;
1189 private final int resizeHeight;
1190 private final boolean adjustRatio;
1192 private InqubusFfmpegProfile() {
1193 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1194 final Config p = Config.INSTANCE;
1195 this.extOption = p.getFfmpegExtension();
1196 this.inOption = p.getFfmpegInOption();
1197 this.mainOption = p.getFfmpegMainOption();
1198 this.outOption = p.getFfmpegOutOption();
1199 this.avOption = p.getFfmpegAvOption();
1200 this.resize = p.getFfmpegResizeEnable();
1201 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1202 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1203 this.adjustRatio = p.getFfmpegKeepAspect();
1207 public String getExtOption() {
1208 return this.extOption;
1212 public String getInOption() {
1213 return this.inOption;
1217 public String getMainOption() {
1218 return this.mainOption;
1222 public String getOutOption() {
1223 return this.outOption;
1227 public String getAvfilterOption() {
1228 return this.avOption;
1232 public boolean isResize() {
1237 public int getResizeWidth() {
1238 return this.resizeWidth;
1242 public int getResizeHeight() {
1243 return this.resizeHeight;
1247 public boolean isAdjustRatio() {
1248 return this.adjustRatio;
1252 public String toString(){
1253 return ToStringBuilder.reflectionToString(this);
1257 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1260 public String getWord() {
1266 public String getId() {
1272 public String toString(){
1273 return ToStringBuilder.reflectionToString(this);