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 = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
95 private static final String FILE_INPUTFIELD_TOOLTIP
96 = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
97 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
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<>(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 final JLabel lblComment = new JLabel();
130 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
131 cbBackLog.addItemListener(new ItemListener() {
134 public void itemStateChanged(ItemEvent e) {
135 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
136 fldBackLog.setEnabled(selected);
139 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
142 public void propertyChange(PropertyChangeEvent evt) {
143 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
144 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
145 fldBackLog.setEnabled(fldEnabled);
148 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
150 cbCommentLocal = new JCheckBox();
151 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
152 cbCommentLocal.addItemListener(new ItemListener() {
155 public void itemStateChanged(ItemEvent e) {
156 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
157 cbBackLogReduce.setEnabled(!selected);
158 cbBackLog.setEnabled(!selected);
161 fldComment = new JTextField();
162 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
163 final JLabel lblOutput = new JLabel();
164 cbOutputEnable = new JCheckBox();
165 fldOutput = new JTextField();
166 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
168 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
170 btnStop.addActionListener(new StopActionListener());
171 final ApplyActionListener applyListener = new ApplyActionListener();
172 btnApply.addActionListener(applyListener);
174 pnlMain.setBorder(BorderFactory.createEtchedBorder());
176 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
177 scrDisplay.setViewportView(tblDisplay);
179 pnlButton.setBorder(BorderFactory.createEtchedBorder());
181 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
182 pnlButton.setLayout(gl_pnlButton);
183 gl_pnlButton.setHorizontalGroup(
184 gl_pnlButton.createParallelGroup(Alignment.LEADING)
185 .addGroup(gl_pnlButton.createSequentialGroup()
187 .addComponent(btnStart)
188 .addPreferredGap(ComponentPlacement.RELATED)
189 .addComponent(btnStop)
190 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
191 .addComponent(btnDeselect)
194 gl_pnlButton.setVerticalGroup(
195 gl_pnlButton.createParallelGroup(Alignment.LEADING)
196 .addGroup(gl_pnlButton.createSequentialGroup()
198 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
199 .addComponent(btnStart)
200 .addComponent(btnStop)
201 .addComponent(btnDeselect))
202 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
207 fldId.addActionListener(applyListener);
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 lblComment.setText("コメント");
227 cbCommentLocal.setText("local");
228 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
230 public void itemStateChanged(java.awt.event.ItemEvent evt) {
231 useMovieLocalCheckBoxItemStateChanged(evt);
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 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
247 pnlInputMain.setLayout(glInputMain);
248 glInputMain.setHorizontalGroup(
249 glInputMain.createParallelGroup(Alignment.LEADING)
250 .addGroup(glInputMain.createSequentialGroup()
253 .addPreferredGap(ComponentPlacement.RELATED)
254 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
255 .addPreferredGap(ComponentPlacement.UNRELATED)
256 .addComponent(cbBackLogReduce)
257 .addPreferredGap(ComponentPlacement.UNRELATED)
258 .addComponent(cbBackLog)
259 .addPreferredGap(ComponentPlacement.RELATED)
260 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
263 .addGroup(glInputMain.createSequentialGroup()
265 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
266 .addComponent(lblVideo)
267 .addComponent(lblComment)
268 .addComponent(lblOutput)
270 .addPreferredGap(ComponentPlacement.RELATED)
271 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
272 .addComponent(cbVideoLocal)
273 .addComponent(cbCommentLocal)
274 .addComponent(cbOutputEnable)
276 .addPreferredGap(ComponentPlacement.RELATED)
277 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
278 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
279 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
280 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
286 glInputMain.setVerticalGroup(
287 glInputMain.createParallelGroup(Alignment.LEADING)
288 .addGroup(glInputMain.createSequentialGroup()
290 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
291 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
293 .addComponent(cbBackLogReduce)
294 .addComponent(cbBackLog)
295 .addComponent(fldBackLog)
297 .addPreferredGap(ComponentPlacement.RELATED)
298 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
299 .addComponent(lblVideo)
300 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
301 .addComponent(cbVideoLocal))
302 .addPreferredGap(ComponentPlacement.RELATED)
303 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
304 .addComponent(lblComment)
305 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
306 .addComponent(cbCommentLocal))
307 .addPreferredGap(ComponentPlacement.RELATED)
308 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
309 .addComponent(lblOutput)
310 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
311 .addComponent(cbOutputEnable)
317 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
318 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
319 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
320 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
323 public void actionPerformed(ActionEvent e) {
324 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
325 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
326 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
327 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
328 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
329 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
330 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
333 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
336 public void itemStateChanged(ItemEvent e) {
337 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
338 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
339 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
340 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
343 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
346 public void propertyChange(PropertyChangeEvent evt) {
347 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
348 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
349 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
350 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
351 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
356 tbpInput.add("メイン", pnlInputMain);
357 tbpInput.add("ffmpeg", pnlInputFfmpeg);
360 fldInputMessage.setEditable(false);
361 fldInputMessage.setEnabled(false);
362 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
364 final JPanel pnlInputButton = new JPanel();
365 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
366 pnlInputButton.setLayout(glInputButton);
367 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
369 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
370 .addPreferredGap(ComponentPlacement.UNRELATED)
371 .addComponent(btnApply)
374 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
376 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
377 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
378 .addComponent(btnApply)
384 final JPanel pnlInputAll = new JPanel();
385 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
386 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
387 pnlInputAll.setLayout(glInputAll);
388 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
389 .addComponent(tbpInput)
390 .addComponent(pnlInputButton)
392 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
393 .addComponent(tbpInput)
394 .addComponent(pnlInputButton)
397 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
398 pnlMain.setLayout(gl_pnlMain);
399 gl_pnlMain.setHorizontalGroup(
400 gl_pnlMain.createParallelGroup(Alignment.LEADING)
401 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
403 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
404 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
405 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
406 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
410 gl_pnlMain.setVerticalGroup(
411 gl_pnlMain.createParallelGroup(Alignment.LEADING)
412 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
414 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
415 .addPreferredGap(ComponentPlacement.RELATED)
416 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
417 .addPreferredGap(ComponentPlacement.RELATED)
418 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
424 JMenuBar menuBar = initMenuBar();
425 setJMenuBar(menuBar);
427 GroupLayout layout = new GroupLayout(getContentPane());
428 getContentPane().setLayout(layout);
429 layout.setHorizontalGroup(
430 layout.createParallelGroup(Alignment.LEADING)
431 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
433 layout.setVerticalGroup(
434 layout.createParallelGroup(Alignment.LEADING)
435 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
440 pnlMain.setTransferHandler(new DownloadListTransferHandler());
441 tblDisplay.setTransferHandler(new TableTransferHandler());
443 final Config p = Config.INSTANCE;
444 final int thDownload = p.getSystemDownloadThread();
445 final int secDownload = p.getSystemDownloadWait();
446 final int thConvert = p.getSystemConvertThread();
447 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
450 private class GuiTaskManageListener implements TaskManageListener {
453 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
454 final String message) {
455 SwingUtilities.invokeLater(new Runnable() {
459 targetModel.setStatus(id, kind, status, percentage, message);
465 private class StopActionListener implements ActionListener {
468 public void actionPerformed(ActionEvent e) {
469 final int row = tblDisplay.getSelectedRow();
470 final Target t = targetModel.getTarget(row);
471 final boolean res = taskManager.cancel(t.getRowId());
472 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
474 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
479 private class ApplyActionListener implements ActionListener {
482 public void actionPerformed(ActionEvent e) {
484 final DownloadProfile downProf = new InqubusDownloadProfile();
485 final String id = Util.getVideoId(fldId.getText());
486 final InqubusConvertProfile convProf = new InqubusConvertProfile();
487 logger.log(Level.INFO, downProf.toString());
488 logger.log(Level.INFO, convProf.toString());
489 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
491 targetModel.addTarget(new Target(rp));
493 } catch (Throwable th) {
494 logger.log(Level.SEVERE, null, th);
495 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
500 private File searchFileMatchId(final File dir, final String id) {
501 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
506 final File[] lists = dir.listFiles(new FilenameFilter() {
508 final Pattern pattern = Pattern.compile(id + "\\D");
511 public boolean accept(File dir, String name) {
512 return pattern.matcher(name).find();
516 if (lists.length == 1) {
518 } else if (lists.length > 1) {
519 throw new UnsupportedOperationException();
526 * 動画, コメントの"local"チェックボックス更新時の処理.
528 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
529 final Config p = Config.INSTANCE;
531 final ItemSelectable source = evt.getItemSelectable();
535 if (source == cbVideoLocal) {
537 dir = new File(p.getVideoDir());
540 dir = new File(p.getCommentDir());
543 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
547 final File f = searchFileMatchId(dir, fldId.getText());
554 text = p.getVideoFileNamePattern();
558 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
560 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
561 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
562 fldOutput.setEnabled(convert);
563 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
565 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
566 final Config p = Config.INSTANCE;
567 final String id = fldId.getText();
572 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
573 final File dir = new File(p.getVideoDir());
574 final File file = searchFileMatchId(dir, id);
576 fldVideo.setText(file.getPath());
580 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
581 final File dir = new File(p.getCommentDir());
582 final File file = searchFileMatchId(dir, id);
584 fldComment.setText(file.getPath());
588 }//GEN-LAST:event_idFieldFocusLost
589 // Variables declaration - do not modify//GEN-BEGIN:variables
590 private final JTable tblDisplay;
592 private final JButton btnStart = new JButton("開始");
593 private final JButton btnStop = new JButton("停止");
594 private final JButton btnDeselect = new JButton("選択解除");
596 private final JTextField fldId = new JTextField();
597 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
598 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
599 private final JTextField fldBackLog = new JTextField();
600 private final JCheckBox cbVideoLocal;
601 private final JTextField fldVideo;
602 private final JCheckBox cbCommentLocal;
603 private final JTextField fldComment;
604 private final JCheckBox cbOutputEnable;
605 private final JTextField fldOutput;
607 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
609 private final JTextField fldInputMessage = new JTextField();
610 private final JButton btnApply = new JButton("適用");
611 // End of variables declaration//GEN-END:variables
613 private void initInputPanel() {
618 private void initMainTab() {
619 final Config p = Config.INSTANCE;
622 fldBackLog.setEnabled(false);
623 cbBackLog.setEnabled(true);
625 final boolean movieLocal = p.getVideoUseLocal();
626 cbVideoLocal.setSelected(movieLocal);
628 fldVideo.setText(p.getVideoFileNamePattern());
631 final boolean commentLocal = p.getCommentUseLocal();
632 cbCommentLocal.setSelected(commentLocal);
634 fldComment.setText(p.getCommentFileNamePattern());
637 final boolean convert = p.getOutputEnable();
638 cbOutputEnable.setSelected(convert);
639 fldOutput.setEnabled(convert);
640 fldOutput.setText(p.getOutputFileNamePattern());
643 private void initFfmpegTab() {
644 pnlInputFfmpeg.init(Config.INSTANCE);
647 private JMenuBar initMenuBar() {
648 final JMenuBar menuBar = new JMenuBar();
650 final JMenu mnFile = new JMenu("ファイル(F)");
653 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
654 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
655 itExit.addActionListener(new ActionListener() {
658 public void actionPerformed(ActionEvent e) {
659 throw new UnsupportedOperationException("Not supported yet.");
664 final JMenu mnTool = new JMenu("ツール(T)");
667 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
669 itOption.addActionListener(new ActionListener() {
672 public void actionPerformed(ActionEvent e) {
673 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
674 dlg.setLocationRelativeTo(MainFrame.this);
676 dlg.setVisible(true);
679 mnTool.add(itOption);
681 final JMenu mnHelp = new JMenu("ヘルプ(H)");
684 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
685 itAbout.addActionListener(new ActionListener() {
688 public void actionPerformed(ActionEvent e) {
689 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
691 dlg.setLocationRelativeTo(MainFrame.this);
693 dlg.setVisible(true);
701 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
704 public void process(DownloadProgress progress) {
705 throw new UnsupportedOperationException("Not supported yet.");
709 public void cancelled() {
710 throw new UnsupportedOperationException("Not supported yet.");
714 public void done(DownloadResult result) {
715 throw new UnsupportedOperationException("Not supported yet.");
719 public void error(Throwable th) {
720 throw new UnsupportedOperationException("Not supported yet.");
724 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
727 public void process(ConvertProgress progress) {
728 throw new UnsupportedOperationException("Not supported yet.");
732 public void cancelled() {
733 throw new UnsupportedOperationException("Not supported yet.");
737 public void done(ConvertResult result) {
738 throw new UnsupportedOperationException("Not supported yet.");
742 public void error(Throwable th) {
743 throw new UnsupportedOperationException("Not supported yet.");
749 private class DownloadListTransferHandler extends TransferHandler {
751 private static final long serialVersionUID = 1L;
752 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
755 public boolean canImport(TransferHandler.TransferSupport support) {
756 Transferable transferable = support.getTransferable();
757 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
758 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
765 public boolean importData(TransferHandler.TransferSupport support) {
767 // Transferable transferable = support.getTransferable();
768 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
769 // @SuppressWarnings("unchecked")
770 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
771 // Collection<Target> targets = Target.from(data);
772 // targetModel.addTarget(targets);
773 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
774 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
775 // Matcher matcher = movieIdPattern.matcher(data);
776 // if (matcher.find()) {
777 // String movieId = matcher.group(1);
778 // Target target = Target.fromId(movieId);
779 // targetModel.addTarget(target);
786 // } catch (Exception e) {
787 // logger.log(Level.SEVERE, null, e);
790 // TODO 上記実装見直し(Locationは削除された)
795 private class TableTransferHandler extends DownloadListTransferHandler {
797 private static final long serialVersionUID = 1L;
800 public boolean canImport(TransferHandler.TransferSupport support) {
801 return super.canImport(support);
805 public boolean importData(TransferHandler.TransferSupport support) {
806 return super.importData(support);
811 * ここからDownloadProfile作成用クラスの定義
814 private class InqubusDownloadProfile implements DownloadProfile {
816 private final LoginProfile loginProfile;
817 private final ProxyProfile proxyProfile;
818 private final VideoProfile videoProfile;
819 private final CommentProfile commentProfile;
820 private final GeneralProfile generalProfile;
822 private InqubusDownloadProfile() {
823 this.loginProfile = new InqubusLoginProfile();
824 this.proxyProfile = new InqubusProxyProfile();
825 this.videoProfile = new InqubusVideoProfile();
826 this.commentProfile = new InqubusCommentProfile();
827 this.generalProfile = new InqubusGeneralProfile();
831 public LoginProfile getLoginInfo() {
832 return this.loginProfile;
836 public ProxyProfile getProxyProfile() {
837 return this.proxyProfile;
841 public VideoProfile getVideoProfile() {
842 return this.videoProfile;
846 public CommentProfile getCommentProfile() {
847 return this.commentProfile;
851 public GeneralProfile getGeneralProfile() {
852 return this.generalProfile;
856 public String toString(){
857 return ToStringBuilder.reflectionToString(this);
861 private class InqubusLoginProfile implements LoginProfile {
862 private final String mail;
863 private final String password;
865 private InqubusLoginProfile(){
866 final Config p = Config.INSTANCE;
867 this.mail = p.getId();
868 this.password = p.getPassword();
872 public String getMail() {
877 public String getPassword() {
878 return this.password;
882 public String toString(){
883 return ToStringBuilder.reflectionToString(this);
887 private class InqubusProxyProfile implements ProxyProfile {
888 private final boolean use;
889 private final String host;
890 private final int port;
892 private InqubusProxyProfile(){
893 final Config p = Config.INSTANCE;
894 this.use = p.getProxyUse();
895 this.host = p.getProxyHost();
896 final String pp = p.getProxyPort();
897 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
901 public boolean use() {
906 public String getHost() {
911 public int getPort() {
916 public String toString(){
917 return ToStringBuilder.reflectionToString(this);
921 private class InqubusVideoProfile implements VideoProfile {
922 private final boolean download;
923 private final File dir;
924 private final String fileName;
925 private final File localFile;
927 private InqubusVideoProfile(){
928 final Config p = Config.INSTANCE;
929 this.download = !cbVideoLocal.isSelected();
931 this.dir = new File(p.getVideoDir());
932 this.fileName = fldVideo.getText();
933 this.localFile = null;
936 this.fileName = null;
937 this.localFile = new File(fldVideo.getText());
942 public boolean isDownload() {
943 return this.download;
947 public File getDir() {
952 public String getFileName() {
953 return this.fileName;
957 public File getLocalFile() {
958 return this.localFile;
962 public String toString(){
963 return ToStringBuilder.reflectionToString(this);
967 private class InqubusCommentProfile implements CommentProfile {
968 private final boolean download;
969 private final File dir;
970 private final String fileName;
971 private final File localFile;
972 private final int lengthRelatedCommentSize;
973 private final boolean disablePerMinComment;
974 private final int perMinCommentSize;
975 private final long backLogPoint;
977 private InqubusCommentProfile() {
978 final Config p = Config.INSTANCE;
979 this.download = !cbCommentLocal.isSelected();
981 this.dir = new File(p.getCommentDir());
982 this.fileName = fldComment.getText();
983 this.localFile = null;
986 this.fileName = null;
987 this.localFile = new File(fldComment.getText());
990 if(cbBackLog.isSelected()) {
992 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
993 } catch (IOException ex) {
994 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
997 this.backLogPoint = -1L;
1000 this.disablePerMinComment = cbBackLogReduce.isSelected();
1001 this.lengthRelatedCommentSize
1002 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1003 this.perMinCommentSize
1004 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1008 public boolean isDownload() {
1009 return this.download;
1013 public File getDir() {
1018 public String getFileName() {
1019 return this.fileName;
1023 public File getLocalFile() {
1024 return this.localFile;
1028 public int getLengthRelatedCommentSize() {
1029 return this.lengthRelatedCommentSize;
1033 public boolean isDisablePerMinComment() {
1034 return this.disablePerMinComment;
1038 public int getPerMinCommentSize() {
1039 return this.perMinCommentSize;
1043 public long getBackLogPoint() {
1044 return this.backLogPoint;
1048 public String toString(){
1049 return ToStringBuilder.reflectionToString(this);
1053 private class InqubusGeneralProfile implements GeneralProfile {
1054 private final String replaceFrom;
1055 private final String replaceTo;
1056 private InqubusGeneralProfile() {
1057 final Config p = Config.INSTANCE;
1058 this.replaceFrom = p.getReplaceFrom();
1059 this.replaceTo = p.getReplaceTo();
1063 public String getReplaceFrom() {
1064 return this.replaceFrom;
1068 public String getReplaceTo() {
1069 return this.replaceTo;
1073 public String toString(){
1074 return ToStringBuilder.reflectionToString(this);
1079 * ここからConvertProfile作成用クラスの定義
1081 private class InqubusConvertProfile implements ConvertProfile {
1082 private final OutputProfile outputProfile;
1083 private final GeneralProfile generalProfile;
1084 private final FfmpegProfile ffmpegProfile;
1085 private final boolean convert;
1086 private final File ffmpeg;
1087 private final boolean vhookDisabled;
1088 private final boolean commentOverlay;
1089 private final File vhook;
1090 private final File tmpDir;
1091 private final File font;
1092 private final int fontIndex;
1093 private final boolean commentOpaque;
1094 private final boolean disableFontSizeArrange;
1095 private final int shadowIndex;
1096 private final boolean showConvrting;
1097 private final int maxNumOfComment;
1098 private final HideCondition ngSetting;
1100 private InqubusConvertProfile() throws IOException {
1101 final Config p = Config.INSTANCE;
1102 this.outputProfile = new InqubusOutputProfile();
1103 this.generalProfile = new InqubusGeneralProfile();
1104 this.ffmpegProfile = new InqubusFfmpegProfile();
1105 this.convert = cbOutputEnable.isSelected();
1106 this.ffmpeg = new File(p.getFfmpegPath());
1108 this.vhookDisabled = false;
1109 this.commentOverlay = p.getOutputCommentOverlay();
1110 this.vhook = new File(p.getFfmpegDllPath());
1111 this.tmpDir = new File(p.getSystemTempDir());
1112 this.font = new File(p.getFontPath());
1113 this.fontIndex = Integer.parseInt(p.getFontIndex());
1114 this.commentOpaque = p.getCommentOpaque();
1115 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1116 this.shadowIndex = p.getFontShadow();
1118 this.showConvrting = true;
1119 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1120 getCommentDisplaySizeManual());
1121 this.ngSetting = new InqubusHideCondition();
1125 public OutputProfile getOutputProfile() {
1126 return this.outputProfile;
1130 public GeneralProfile getGeneralProfile() {
1131 return this.generalProfile;
1135 public FfmpegProfile getFfmpegOption() {
1136 return this.ffmpegProfile;
1140 public boolean isConvert() {
1141 return this.convert;
1145 public File getFfmpeg() {
1150 public boolean isVhookDisabled() {
1151 return this.vhookDisabled;
1155 public boolean isCommentOverlay() {
1156 return this.commentOverlay;
1160 public File getVhook() {
1165 public File getTempDir() {
1170 public File getFont() {
1175 public int getFontIndex() {
1176 return this.fontIndex;
1180 public boolean isCommentOpaque() {
1181 return this.commentOpaque;
1185 public boolean isDisableFontSizeArrange() {
1186 return this.disableFontSizeArrange;
1190 public int getShadowIndex() {
1191 return this.shadowIndex;
1195 public boolean isShowConverting() {
1196 return this.showConvrting;
1200 public int getMaxNumOfComment() {
1201 return this.maxNumOfComment;
1205 public HideCondition getNgSetting() {
1206 return this.ngSetting;
1210 public String toString(){
1211 return ToStringBuilder.reflectionToString(this);
1215 private class InqubusOutputProfile implements OutputProfile {
1216 private final File dir;
1217 private final String fileName;
1218 private final String videoId;
1219 private final String title;
1222 private InqubusOutputProfile(){
1223 final Config p = Config.INSTANCE;
1224 this.dir = new File(p.getOutputDir());
1225 this.fileName = fldOutput.getText();
1226 // TODO この時点でのID/Titleはどうするか…
1232 public File getDir() {
1237 public String getFileName() {
1238 return this.fileName;
1242 public String getVideoId() {
1243 return this.videoId;
1247 public String getTitile() {
1252 public String toString(){
1253 return ToStringBuilder.reflectionToString(this);
1257 private class InqubusFfmpegProfile implements FfmpegProfile {
1258 private final String extOption;
1259 private final String inOption;
1260 private final String mainOption;
1261 private final String outOption;
1262 private final String avOption;
1263 private final boolean resize;
1264 private final int resizeWidth;
1265 private final int resizeHeight;
1266 private final boolean adjustRatio;
1268 private InqubusFfmpegProfile() throws IOException {
1269 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1271 final FfmpegOption ffop = FfmpegOption.load(file);
1272 this.extOption = ffop.getExtOption();
1273 this.inOption = ffop.getInOption();
1274 this.mainOption = ffop.getMainOption();
1275 this.outOption = ffop.getMainOption();
1276 this.avOption = ffop.getAvfilterOption();
1277 this.resize = ffop.isResize();
1278 this.resizeWidth = ffop.getResizeWidth();
1279 this.resizeHeight = ffop.getResizeHeight();
1280 this.adjustRatio = ffop.isAdjustRatio();
1282 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1283 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1284 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1285 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1286 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1287 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1288 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1289 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1290 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1295 public String getExtOption() {
1296 return this.extOption;
1300 public String getInOption() {
1301 return this.inOption;
1305 public String getMainOption() {
1306 return this.mainOption;
1310 public String getOutOption() {
1311 return this.outOption;
1315 public String getAvfilterOption() {
1316 return this.avOption;
1320 public boolean isResize() {
1325 public int getResizeWidth() {
1326 return this.resizeWidth;
1330 public int getResizeHeight() {
1331 return this.resizeHeight;
1335 public boolean isAdjustRatio() {
1336 return this.adjustRatio;
1340 public String toString(){
1341 return ToStringBuilder.reflectionToString(this);
1345 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1348 public String getWord() {
1354 public String getId() {
1360 public String toString(){
1361 return ToStringBuilder.reflectionToString(this);