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.JOptionPane;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JTabbedPane;
46 import javax.swing.JTable;
47 import javax.swing.JTextField;
48 import javax.swing.KeyStroke;
49 import javax.swing.LayoutStyle.ComponentPlacement;
50 import javax.swing.SwingUtilities;
51 import javax.swing.TransferHandler;
52 import javax.swing.WindowConstants;
53 import javax.swing.border.BevelBorder;
54 import org.apache.commons.lang.StringUtils;
55 import org.apache.commons.lang.builder.ToStringBuilder;
56 import saccubus.FfmpegOption;
57 import saccubus.MainFrame_AboutBox;
58 import saccubus.OptionComboBoxModel;
59 import saccubus.util.WayBackTimeParser;
60 import saccubus.worker.impl.convert.ConvertProgress;
61 import saccubus.worker.impl.download.DownloadProgress;
62 import saccubus.worker.WorkerListener;
63 import saccubus.worker.impl.convert.ConvertResult;
64 import saccubus.worker.impl.download.DownloadResult;
65 import saccubus.worker.profile.CommentProfile;
66 import saccubus.worker.profile.ConvertProfile;
67 import saccubus.worker.profile.DownloadProfile;
68 import saccubus.worker.profile.FfmpegProfile;
69 import saccubus.worker.profile.GeneralProfile;
70 import saccubus.worker.profile.LoginProfile;
71 import saccubus.worker.profile.OutputProfile;
72 import saccubus.worker.profile.ProxyProfile;
73 import saccubus.worker.profile.VideoProfile;
75 import yukihane.inqubus.Config;
76 import yukihane.inqubus.manager.RequestProcess;
77 import yukihane.inqubus.manager.TaskKind;
78 import yukihane.inqubus.manager.TaskManage;
79 import yukihane.inqubus.manager.TaskManageListener;
80 import yukihane.inqubus.manager.TaskStatus;
81 import yukihane.inqubus.model.Target;
82 import yukihane.inqubus.model.TargetsTableModel;
88 public class MainFrame extends JFrame {
90 private static final long serialVersionUID = 1L;
91 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
92 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
93 private static final String FILE_LOCALBUTTON_TOOLTIP
94 = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
95 private static final String FILE_INPUTFIELD_TOOLTIP
96 = "ダウンロードする場合はファイル命名規則を入力します。"
97 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
98 private static final String FILE_OUTPUTFIELD_TOOLTIP
100 private final TargetsTableModel targetModel = new TargetsTableModel();
101 private final TaskManage taskManager;
103 /** Creates new form MainFrame */
105 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
106 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
107 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
108 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
109 final List<Image> images = new ArrayList<Image>(2);
112 setIconImages(images);
114 final JPanel pnlMain = new JPanel();
115 final JScrollPane scrDisplay = new JScrollPane();
116 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
117 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
118 final JPanel pnlButton = new JPanel();
119 final JTabbedPane tbpInput = new JTabbedPane();
120 final JPanel pnlInputMain = new JPanel();
121 final JLabel lblId = new JLabel();
122 fldId.setToolTipText(ID_FIELD_TOOLTIP);
123 final JLabel lblVideo = new JLabel();
124 cbVideoLocal = new JCheckBox();
125 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
126 fldVideo = new JTextField();
127 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
128 btnVideo = new JButton();
129 final JLabel lblComment = new JLabel();
131 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
132 cbBackLog.addItemListener(new ItemListener() {
135 public void itemStateChanged(ItemEvent e) {
136 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
137 fldBackLog.setEnabled(selected);
140 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
143 public void propertyChange(PropertyChangeEvent evt) {
144 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
145 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
146 fldBackLog.setEnabled(fldEnabled);
149 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
151 cbCommentLocal = new JCheckBox();
152 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
153 cbCommentLocal.addItemListener(new ItemListener() {
156 public void itemStateChanged(ItemEvent e) {
157 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
158 cbBackLogReduce.setEnabled(!selected);
159 cbBackLog.setEnabled(!selected);
162 fldComment = new JTextField();
163 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
164 btnComment = new JButton();
165 final JLabel lblOutput = new JLabel();
166 cbOutputEnable = new JCheckBox();
167 fldOutput = new JTextField();
168 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
170 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
172 btnStop.addActionListener(new StopActionListener());
173 btnApply.addActionListener(new ApplyActionListener());
175 pnlMain.setBorder(BorderFactory.createEtchedBorder());
177 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
178 scrDisplay.setViewportView(tblDisplay);
180 pnlButton.setBorder(BorderFactory.createEtchedBorder());
182 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
183 pnlButton.setLayout(gl_pnlButton);
184 gl_pnlButton.setHorizontalGroup(
185 gl_pnlButton.createParallelGroup(Alignment.LEADING)
186 .addGroup(gl_pnlButton.createSequentialGroup()
188 .addComponent(btnStart)
189 .addPreferredGap(ComponentPlacement.RELATED)
190 .addComponent(btnStop)
191 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
192 .addComponent(btnDeselect)
195 gl_pnlButton.setVerticalGroup(
196 gl_pnlButton.createParallelGroup(Alignment.LEADING)
197 .addGroup(gl_pnlButton.createSequentialGroup()
199 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
200 .addComponent(btnStart)
201 .addComponent(btnStop)
202 .addComponent(btnDeselect))
203 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
208 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
210 public void focusLost(java.awt.event.FocusEvent evt) {
211 idFieldFocusLost(evt);
215 lblVideo.setText("動画");
217 cbVideoLocal.setText("local");
218 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
220 public void itemStateChanged(java.awt.event.ItemEvent evt) {
221 useMovieLocalCheckBoxItemStateChanged(evt);
225 btnVideo.setText("...");
227 lblComment.setText("コメント");
229 cbCommentLocal.setText("local");
230 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
232 public void itemStateChanged(java.awt.event.ItemEvent evt) {
233 useMovieLocalCheckBoxItemStateChanged(evt);
237 btnComment.setText("...");
239 lblOutput.setText("出力");
241 cbOutputEnable.setText("変換");
242 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
244 public void itemStateChanged(java.awt.event.ItemEvent evt) {
245 outputConvertCheckBoxItemStateChanged(evt);
250 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
251 pnlInputMain.setLayout(glInputMain);
252 glInputMain.setHorizontalGroup(
253 glInputMain.createParallelGroup(Alignment.LEADING)
254 .addGroup(glInputMain.createSequentialGroup()
257 .addPreferredGap(ComponentPlacement.RELATED)
258 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
259 .addPreferredGap(ComponentPlacement.UNRELATED)
260 .addComponent(cbBackLogReduce)
261 .addPreferredGap(ComponentPlacement.UNRELATED)
262 .addComponent(cbBackLog)
263 .addPreferredGap(ComponentPlacement.RELATED)
264 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
267 .addGroup(glInputMain.createSequentialGroup()
269 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
270 .addGroup(glInputMain.createSequentialGroup()
271 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
272 .addComponent(lblVideo)
273 .addComponent(lblComment)
274 .addComponent(lblOutput))
275 .addPreferredGap(ComponentPlacement.RELATED)
276 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
277 .addGroup(glInputMain.createSequentialGroup()
278 .addComponent(cbVideoLocal)
279 .addPreferredGap(ComponentPlacement.RELATED)
280 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
281 .addPreferredGap(ComponentPlacement.RELATED)
282 .addComponent(btnVideo))
283 .addGroup(Alignment.TRAILING, glInputMain.createSequentialGroup()
284 .addGroup(glInputMain.createParallelGroup(Alignment.TRAILING)
285 .addGroup(Alignment.LEADING, glInputMain.createSequentialGroup()
286 .addComponent(cbOutputEnable)
287 .addPreferredGap(ComponentPlacement.RELATED)
288 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
289 .addGroup(glInputMain.createSequentialGroup()
290 .addComponent(cbCommentLocal)
291 .addPreferredGap(ComponentPlacement.RELATED)
292 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
293 .addPreferredGap(ComponentPlacement.RELATED)
294 .addComponent(btnComment))))
298 glInputMain.setVerticalGroup(
299 glInputMain.createParallelGroup(Alignment.LEADING)
300 .addGroup(glInputMain.createSequentialGroup()
302 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
303 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
305 .addComponent(cbBackLogReduce)
306 .addComponent(cbBackLog)
307 .addComponent(fldBackLog)
309 .addPreferredGap(ComponentPlacement.RELATED)
310 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
311 .addComponent(lblVideo)
312 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
313 .addComponent(btnVideo)
314 .addComponent(cbVideoLocal))
315 .addPreferredGap(ComponentPlacement.RELATED)
316 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
317 .addComponent(lblComment)
318 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
319 .addComponent(btnComment)
320 .addComponent(cbCommentLocal))
321 .addPreferredGap(ComponentPlacement.RELATED)
322 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
323 .addComponent(lblOutput)
324 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
325 .addComponent(cbOutputEnable))
330 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
331 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
332 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
333 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
336 public void actionPerformed(ActionEvent e) {
337 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
338 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
339 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
340 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
341 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
342 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
343 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
346 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
349 public void itemStateChanged(ItemEvent e) {
350 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
351 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
352 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
353 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
356 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
359 public void propertyChange(PropertyChangeEvent evt) {
360 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
361 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
362 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
363 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
364 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
369 tbpInput.add("メイン", pnlInputMain);
370 tbpInput.add("ffmpeg", pnlInputFfmpeg);
373 fldInputMessage.setEditable(false);
374 fldInputMessage.setEnabled(false);
375 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
377 final JPanel pnlInputButton = new JPanel();
378 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
379 pnlInputButton.setLayout(glInputButton);
380 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
382 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
383 .addPreferredGap(ComponentPlacement.UNRELATED)
384 .addComponent(btnApply)
387 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
389 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
390 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
391 .addComponent(btnApply)
397 final JPanel pnlInputAll = new JPanel();
398 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
399 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
400 pnlInputAll.setLayout(glInputAll);
401 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
402 .addComponent(tbpInput)
403 .addComponent(pnlInputButton)
405 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
406 .addComponent(tbpInput)
407 .addComponent(pnlInputButton)
410 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
411 pnlMain.setLayout(gl_pnlMain);
412 gl_pnlMain.setHorizontalGroup(
413 gl_pnlMain.createParallelGroup(Alignment.LEADING)
414 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
416 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
417 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
418 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
419 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
423 gl_pnlMain.setVerticalGroup(
424 gl_pnlMain.createParallelGroup(Alignment.LEADING)
425 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
427 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
428 .addPreferredGap(ComponentPlacement.RELATED)
429 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
430 .addPreferredGap(ComponentPlacement.RELATED)
431 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
437 JMenuBar menuBar = initMenuBar();
438 setJMenuBar(menuBar);
440 GroupLayout layout = new GroupLayout(getContentPane());
441 getContentPane().setLayout(layout);
442 layout.setHorizontalGroup(
443 layout.createParallelGroup(Alignment.LEADING)
444 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
446 layout.setVerticalGroup(
447 layout.createParallelGroup(Alignment.LEADING)
448 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
453 pnlMain.setTransferHandler(new DownloadListTransferHandler());
454 tblDisplay.setTransferHandler(new TableTransferHandler());
456 final Config p = Config.INSTANCE;
457 final int thDownload = p.getSystemDownloadThread();
458 final int secDownload = p.getSystemDownloadWait();
459 final int thConvert = p.getSystemConvertThread();
460 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
463 private class GuiTaskManageListener implements TaskManageListener {
466 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
467 final String message) {
468 SwingUtilities.invokeLater(new Runnable() {
472 targetModel.setStatus(id, kind, status, percentage, message);
478 private class StopActionListener implements ActionListener {
481 public void actionPerformed(ActionEvent e) {
482 final int row = tblDisplay.getSelectedRow();
483 final Target t = targetModel.getTarget(row);
484 final boolean res = taskManager.cancel(t.getRowId());
485 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
487 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
492 private class ApplyActionListener implements ActionListener {
495 public void actionPerformed(ActionEvent e) {
497 final DownloadProfile downProf = new InqubusDownloadProfile();
498 final String id = Util.getVideoId(fldId.getText());
499 final InqubusConvertProfile convProf = new InqubusConvertProfile();
500 logger.log(Level.INFO, downProf.toString());
501 logger.log(Level.INFO, convProf.toString());
502 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
504 targetModel.addTarget(new Target(rp));
506 } catch (Throwable th) {
507 logger.log(Level.SEVERE, null, th);
508 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
513 private File searchFileMatchId(final File dir, final String id) {
514 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
519 final File[] lists = dir.listFiles(new FilenameFilter() {
521 final Pattern pattern = Pattern.compile(id + "\\D");
524 public boolean accept(File dir, String name) {
525 return pattern.matcher(name).find();
529 if (lists.length == 1) {
531 } else if (lists.length > 1) {
532 throw new UnsupportedOperationException();
539 * 動画, コメントの"local"チェックボックス更新時の処理.
541 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
542 final Config p = Config.INSTANCE;
544 final ItemSelectable source = evt.getItemSelectable();
549 if (source == cbVideoLocal) {
552 dir = new File(p.getVideoDir());
556 dir = new File(p.getCommentDir());
559 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
560 btn.setEnabled(useLocal);
564 final File f = searchFileMatchId(dir, fldId.getText());
571 text = p.getVideoFileNamePattern();
575 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
577 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
578 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
579 fldOutput.setEnabled(convert);
580 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
582 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
583 final Config p = Config.INSTANCE;
584 final String id = fldId.getText();
589 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
590 final File dir = new File(p.getVideoDir());
591 final File file = searchFileMatchId(dir, id);
593 fldVideo.setText(file.getPath());
597 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
598 final File dir = new File(p.getCommentDir());
599 final File file = searchFileMatchId(dir, id);
601 fldComment.setText(file.getPath());
605 }//GEN-LAST:event_idFieldFocusLost
606 // Variables declaration - do not modify//GEN-BEGIN:variables
607 private final JTable tblDisplay;
609 private final JButton btnStart = new JButton("開始");
610 private final JButton btnStop = new JButton("停止");
611 private final JButton btnDeselect = new JButton("選択解除");
613 private final JTextField fldId = new JTextField();
614 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
615 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
616 private final JTextField fldBackLog = new JTextField();
617 private final JCheckBox cbVideoLocal;
618 private final JTextField fldVideo;
619 private final JButton btnVideo;
620 private final JCheckBox cbCommentLocal;
621 private final JTextField fldComment;
622 private final JButton btnComment;
623 private final JCheckBox cbOutputEnable;
624 private final JTextField fldOutput;
626 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
628 private final JTextField fldInputMessage = new JTextField();
629 private final JButton btnApply = new JButton("適用");
630 // End of variables declaration//GEN-END:variables
632 private void initInputPanel() {
637 private void initMainTab() {
638 final Config p = Config.INSTANCE;
641 fldBackLog.setEnabled(false);
642 cbBackLog.setEnabled(true);
644 final boolean movieLocal = p.getVideoUseLocal();
645 cbVideoLocal.setSelected(movieLocal);
646 btnVideo.setEnabled(movieLocal);
648 fldVideo.setText(p.getVideoFileNamePattern());
651 final boolean commentLocal = p.getCommentUseLocal();
652 cbCommentLocal.setSelected(commentLocal);
653 btnComment.setEnabled(commentLocal);
655 fldComment.setText(p.getCommentFileNamePattern());
658 final boolean convert = p.getOutputEnable();
659 cbOutputEnable.setSelected(convert);
660 fldOutput.setEnabled(convert);
661 fldOutput.setText(p.getOutputFileNamePattern());
664 private void initFfmpegTab() {
665 pnlInputFfmpeg.init(Config.INSTANCE);
668 private JMenuBar initMenuBar() {
669 final JMenuBar menuBar = new JMenuBar();
671 final JMenu mnFile = new JMenu("ファイル(F)");
674 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
675 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
676 itExit.addActionListener(new ActionListener() {
679 public void actionPerformed(ActionEvent e) {
680 throw new UnsupportedOperationException("Not supported yet.");
685 final JMenu mnTool = new JMenu("ツール(T)");
688 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
690 itOption.addActionListener(new ActionListener() {
693 public void actionPerformed(ActionEvent e) {
694 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
695 dlg.setLocationRelativeTo(MainFrame.this);
697 dlg.setVisible(true);
700 mnTool.add(itOption);
702 final JMenu mnHelp = new JMenu("ヘルプ(H)");
705 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
706 itAbout.addActionListener(new ActionListener() {
709 public void actionPerformed(ActionEvent e) {
710 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
712 dlg.setLocationRelativeTo(MainFrame.this);
714 dlg.setVisible(true);
722 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
725 public void process(DownloadProgress progress) {
726 throw new UnsupportedOperationException("Not supported yet.");
730 public void cancelled() {
731 throw new UnsupportedOperationException("Not supported yet.");
735 public void done(DownloadResult result) {
736 throw new UnsupportedOperationException("Not supported yet.");
740 public void error(Throwable th) {
741 throw new UnsupportedOperationException("Not supported yet.");
745 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
748 public void process(ConvertProgress progress) {
749 throw new UnsupportedOperationException("Not supported yet.");
753 public void cancelled() {
754 throw new UnsupportedOperationException("Not supported yet.");
758 public void done(ConvertResult result) {
759 throw new UnsupportedOperationException("Not supported yet.");
763 public void error(Throwable th) {
764 throw new UnsupportedOperationException("Not supported yet.");
770 private class DownloadListTransferHandler extends TransferHandler {
772 private static final long serialVersionUID = 1L;
773 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
776 public boolean canImport(TransferHandler.TransferSupport support) {
777 Transferable transferable = support.getTransferable();
778 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
779 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
786 public boolean importData(TransferHandler.TransferSupport support) {
788 // Transferable transferable = support.getTransferable();
789 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
790 // @SuppressWarnings("unchecked")
791 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
792 // Collection<Target> targets = Target.from(data);
793 // targetModel.addTarget(targets);
794 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
795 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
796 // Matcher matcher = movieIdPattern.matcher(data);
797 // if (matcher.find()) {
798 // String movieId = matcher.group(1);
799 // Target target = Target.fromId(movieId);
800 // targetModel.addTarget(target);
807 // } catch (Exception e) {
808 // logger.log(Level.SEVERE, null, e);
811 // TODO 上記実装見直し(Locationは削除された)
816 private class TableTransferHandler extends DownloadListTransferHandler {
818 private static final long serialVersionUID = 1L;
821 public boolean canImport(TransferHandler.TransferSupport support) {
822 return super.canImport(support);
826 public boolean importData(TransferHandler.TransferSupport support) {
827 return super.importData(support);
832 * ここからDownloadProfile作成用クラスの定義
835 private class InqubusDownloadProfile implements DownloadProfile {
837 private final LoginProfile loginProfile;
838 private final ProxyProfile proxyProfile;
839 private final VideoProfile videoProfile;
840 private final CommentProfile commentProfile;
841 private final GeneralProfile generalProfile;
843 private InqubusDownloadProfile() {
844 this.loginProfile = new InqubusLoginProfile();
845 this.proxyProfile = new InqubusProxyProfile();
846 this.videoProfile = new InqubusVideoProfile();
847 this.commentProfile = new InqubusCommentProfile();
848 this.generalProfile = new InqubusGeneralProfile();
852 public LoginProfile getLoginInfo() {
853 return this.loginProfile;
857 public ProxyProfile getProxyProfile() {
858 return this.proxyProfile;
862 public VideoProfile getVideoProfile() {
863 return this.videoProfile;
867 public CommentProfile getCommentProfile() {
868 return this.commentProfile;
872 public GeneralProfile getGeneralProfile() {
873 return this.generalProfile;
877 public String toString(){
878 return ToStringBuilder.reflectionToString(this);
882 private class InqubusLoginProfile implements LoginProfile {
883 private final String mail;
884 private final String password;
886 private InqubusLoginProfile(){
887 final Config p = Config.INSTANCE;
888 this.mail = p.getId();
889 this.password = p.getPassword();
893 public String getMail() {
898 public String getPassword() {
899 return this.password;
903 public String toString(){
904 return ToStringBuilder.reflectionToString(this);
908 private class InqubusProxyProfile implements ProxyProfile {
909 private final boolean use;
910 private final String host;
911 private final int port;
913 private InqubusProxyProfile(){
914 final Config p = Config.INSTANCE;
915 this.use = p.getProxyUse();
916 this.host = p.getProxyHost();
917 final String pp = p.getProxyPort();
918 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
922 public boolean use() {
927 public String getHost() {
932 public int getPort() {
937 public String toString(){
938 return ToStringBuilder.reflectionToString(this);
942 private class InqubusVideoProfile implements VideoProfile {
943 private final boolean download;
944 private final File dir;
945 private final String fileName;
946 private final File localFile;
948 private InqubusVideoProfile(){
949 final Config p = Config.INSTANCE;
950 this.download = !cbVideoLocal.isSelected();
952 this.dir = new File(p.getVideoDir());
953 this.fileName = fldVideo.getText();
954 this.localFile = null;
957 this.fileName = null;
958 this.localFile = new File(fldVideo.getText());
963 public boolean isDownload() {
964 return this.download;
968 public File getDir() {
973 public String getFileName() {
974 return this.fileName;
978 public File getLocalFile() {
979 return this.localFile;
983 public String toString(){
984 return ToStringBuilder.reflectionToString(this);
988 private class InqubusCommentProfile implements CommentProfile {
989 private final boolean download;
990 private final File dir;
991 private final String fileName;
992 private final File localFile;
993 private final int lengthRelatedCommentSize;
994 private final boolean disablePerMinComment;
995 private final int perMinCommentSize;
996 private final long backLogPoint;
998 private InqubusCommentProfile() {
999 final Config p = Config.INSTANCE;
1000 this.download = !cbCommentLocal.isSelected();
1001 if (this.download) {
1002 this.dir = new File(p.getCommentDir());
1003 this.fileName = fldComment.getText();
1004 this.localFile = null;
1007 this.fileName = null;
1008 this.localFile = new File(fldComment.getText());
1011 if(cbBackLog.isSelected()) {
1013 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
1014 } catch (IOException ex) {
1015 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
1018 this.backLogPoint = -1L;
1021 this.disablePerMinComment = cbBackLogReduce.isSelected();
1022 this.lengthRelatedCommentSize
1023 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1024 this.perMinCommentSize
1025 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1029 public boolean isDownload() {
1030 return this.download;
1034 public File getDir() {
1039 public String getFileName() {
1040 return this.fileName;
1044 public File getLocalFile() {
1045 return this.localFile;
1049 public int getLengthRelatedCommentSize() {
1050 return this.lengthRelatedCommentSize;
1054 public boolean isDisablePerMinComment() {
1055 return this.disablePerMinComment;
1059 public int getPerMinCommentSize() {
1060 return this.perMinCommentSize;
1064 public long getBackLogPoint() {
1065 return this.backLogPoint;
1069 public String toString(){
1070 return ToStringBuilder.reflectionToString(this);
1074 private class InqubusGeneralProfile implements GeneralProfile {
1075 private final String replaceFrom;
1076 private final String replaceTo;
1077 private InqubusGeneralProfile() {
1078 final Config p = Config.INSTANCE;
1079 this.replaceFrom = p.getReplaceFrom();
1080 this.replaceTo = p.getReplaceTo();
1084 public String getReplaceFrom() {
1085 return this.replaceFrom;
1089 public String getReplaceTo() {
1090 return this.replaceTo;
1094 public String toString(){
1095 return ToStringBuilder.reflectionToString(this);
1100 * ここからConvertProfile作成用クラスの定義
1102 private class InqubusConvertProfile implements ConvertProfile {
1103 private final OutputProfile outputProfile;
1104 private final GeneralProfile generalProfile;
1105 private final FfmpegProfile ffmpegProfile;
1106 private final boolean convert;
1107 private final File ffmpeg;
1108 private final boolean vhookDisabled;
1109 private final boolean commentOverlay;
1110 private final File vhook;
1111 private final File tmpDir;
1112 private final File font;
1113 private final int fontIndex;
1114 private final boolean commentOpaque;
1115 private final boolean disableFontSizeArrange;
1116 private final int shadowIndex;
1117 private final boolean showConvrting;
1118 private final int maxNumOfComment;
1119 private final HideCondition ngSetting;
1121 private InqubusConvertProfile() throws IOException {
1122 final Config p = Config.INSTANCE;
1123 this.outputProfile = new InqubusOutputProfile();
1124 this.generalProfile = new InqubusGeneralProfile();
1125 this.ffmpegProfile = new InqubusFfmpegProfile();
1126 this.convert = cbOutputEnable.isSelected();
1127 this.ffmpeg = new File(p.getFfmpegPath());
1129 this.vhookDisabled = false;
1130 this.commentOverlay = p.getOutputCommentOverlay();
1131 this.vhook = new File(p.getFfmpegDllPath());
1132 this.tmpDir = new File(p.getSystemTempDir());
1133 this.font = new File(p.getFontPath());
1134 this.fontIndex = Integer.parseInt(p.getFontIndex());
1135 this.commentOpaque = p.getCommentOpaque();
1136 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1137 this.shadowIndex = p.getFontShadow();
1139 this.showConvrting = true;
1140 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1141 getCommentDisplaySizeManual());
1142 this.ngSetting = new InqubusHideCondition();
1146 public OutputProfile getOutputProfile() {
1147 return this.outputProfile;
1151 public GeneralProfile getGeneralProfile() {
1152 return this.generalProfile;
1156 public FfmpegProfile getFfmpegOption() {
1157 return this.ffmpegProfile;
1161 public boolean isConvert() {
1162 return this.convert;
1166 public File getFfmpeg() {
1171 public boolean isVhookDisabled() {
1172 return this.vhookDisabled;
1176 public boolean isCommentOverlay() {
1177 return this.commentOverlay;
1181 public File getVhook() {
1186 public File getTempDir() {
1191 public File getFont() {
1196 public int getFontIndex() {
1197 return this.fontIndex;
1201 public boolean isCommentOpaque() {
1202 return this.commentOpaque;
1206 public boolean isDisableFontSizeArrange() {
1207 return this.disableFontSizeArrange;
1211 public int getShadowIndex() {
1212 return this.shadowIndex;
1216 public boolean isShowConverting() {
1217 return this.showConvrting;
1221 public int getMaxNumOfComment() {
1222 return this.maxNumOfComment;
1226 public HideCondition getNgSetting() {
1227 return this.ngSetting;
1231 public String toString(){
1232 return ToStringBuilder.reflectionToString(this);
1236 private class InqubusOutputProfile implements OutputProfile {
1237 private final File dir;
1238 private final String fileName;
1239 private final String videoId;
1240 private final String title;
1243 private InqubusOutputProfile(){
1244 final Config p = Config.INSTANCE;
1245 this.dir = new File(p.getOutputDir());
1246 this.fileName = fldOutput.getText();
1247 // TODO この時点でのID/Titleはどうするか…
1253 public File getDir() {
1258 public String getFileName() {
1259 return this.fileName;
1263 public String getVideoId() {
1264 return this.videoId;
1268 public String getTitile() {
1273 public String toString(){
1274 return ToStringBuilder.reflectionToString(this);
1278 private class InqubusFfmpegProfile implements FfmpegProfile {
1279 private final String extOption;
1280 private final String inOption;
1281 private final String mainOption;
1282 private final String outOption;
1283 private final String avOption;
1284 private final boolean resize;
1285 private final int resizeWidth;
1286 private final int resizeHeight;
1287 private final boolean adjustRatio;
1289 private InqubusFfmpegProfile() throws IOException {
1290 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1291 final Config p = Config.INSTANCE;
1292 final String opf = p.getFfmpegOptionFile();
1293 if (StringUtils.isNotEmpty(opf)) {
1294 final File file = new File(opf);
1295 final FfmpegOption ffop = FfmpegOption.load(file);
1296 this.extOption = ffop.getExtOption();
1297 this.inOption = ffop.getInOption();
1298 this.mainOption = ffop.getMainOption();
1299 this.outOption = ffop.getMainOption();
1300 this.avOption = ffop.getAvfilterOption();
1301 this.resize = ffop.isResize();
1302 this.resizeWidth = ffop.getResizeWidth();
1303 this.resizeHeight = ffop.getResizeHeight();
1304 this.adjustRatio = ffop.isAdjustRatio();
1307 this.extOption = p.getFfmpegExtension();
1308 this.inOption = p.getFfmpegInOption();
1309 this.mainOption = p.getFfmpegMainOption();
1310 this.outOption = p.getFfmpegOutOption();
1311 this.avOption = p.getFfmpegAvOption();
1312 this.resize = p.getFfmpegResizeEnable();
1313 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1314 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1315 this.adjustRatio = p.getFfmpegKeepAspect();
1319 public String getExtOption() {
1320 return this.extOption;
1324 public String getInOption() {
1325 return this.inOption;
1329 public String getMainOption() {
1330 return this.mainOption;
1334 public String getOutOption() {
1335 return this.outOption;
1339 public String getAvfilterOption() {
1340 return this.avOption;
1344 public boolean isResize() {
1349 public int getResizeWidth() {
1350 return this.resizeWidth;
1354 public int getResizeHeight() {
1355 return this.resizeHeight;
1359 public boolean isAdjustRatio() {
1360 return this.adjustRatio;
1364 public String toString(){
1365 return ToStringBuilder.reflectionToString(this);
1369 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1372 public String getWord() {
1378 public String getId() {
1384 public String toString(){
1385 return ToStringBuilder.reflectionToString(this);