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.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);
345 tbpInput.add("メイン", pnlInputMain);
346 tbpInput.add("ffmpeg", pnlInputFfmpeg);
349 fldInputMessage.setEditable(false);
350 fldInputMessage.setEnabled(false);
351 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
353 final JPanel pnlInputButton = new JPanel();
354 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
355 pnlInputButton.setLayout(glInputButton);
356 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
358 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
359 .addPreferredGap(ComponentPlacement.UNRELATED)
360 .addComponent(btnApply)
363 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
365 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
366 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
367 .addComponent(btnApply)
373 final JPanel pnlInputAll = new JPanel();
374 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
375 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
376 pnlInputAll.setLayout(glInputAll);
377 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
378 .addComponent(tbpInput)
379 .addComponent(pnlInputButton)
381 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
382 .addComponent(tbpInput)
383 .addComponent(pnlInputButton)
386 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
387 pnlMain.setLayout(gl_pnlMain);
388 gl_pnlMain.setHorizontalGroup(
389 gl_pnlMain.createParallelGroup(Alignment.LEADING)
390 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
392 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
393 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
394 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
395 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
399 gl_pnlMain.setVerticalGroup(
400 gl_pnlMain.createParallelGroup(Alignment.LEADING)
401 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
403 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
404 .addPreferredGap(ComponentPlacement.RELATED)
405 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
406 .addPreferredGap(ComponentPlacement.RELATED)
407 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
413 JMenuBar menuBar = initMenuBar();
414 setJMenuBar(menuBar);
416 GroupLayout layout = new GroupLayout(getContentPane());
417 getContentPane().setLayout(layout);
418 layout.setHorizontalGroup(
419 layout.createParallelGroup(Alignment.LEADING)
420 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
422 layout.setVerticalGroup(
423 layout.createParallelGroup(Alignment.LEADING)
424 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
429 pnlMain.setTransferHandler(new DownloadListTransferHandler());
430 tblDisplay.setTransferHandler(new TableTransferHandler());
432 final Config p = Config.INSTANCE;
433 final int thDownload = p.getSystemDownloadThread();
434 final int secDownload = p.getSystemDownloadWait();
435 final int thConvert = p.getSystemConvertThread();
436 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
439 private class GuiTaskManageListener implements TaskManageListener {
442 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
443 final String message) {
444 SwingUtilities.invokeLater(new Runnable() {
448 targetModel.setStatus(id, kind, status, percentage, message);
454 private class StopActionListener implements ActionListener {
457 public void actionPerformed(ActionEvent e) {
458 final int row = tblDisplay.getSelectedRow();
459 final Target t = targetModel.getTarget(row);
460 final boolean res = taskManager.cancel(t.getRowId());
461 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
463 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
468 private class ApplyActionListener implements ActionListener {
471 public void actionPerformed(ActionEvent e) {
473 final DownloadProfile downProf = new InqubusDownloadProfile();
474 final String id = Util.getVideoId(fldId.getText());
475 final InqubusConvertProfile convProf = new InqubusConvertProfile();
476 logger.log(Level.INFO, downProf.toString());
477 logger.log(Level.INFO, convProf.toString());
478 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
480 targetModel.addTarget(new Target(rp));
482 } catch (Throwable th) {
483 logger.log(Level.SEVERE, null, th);
484 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
489 private File searchFileMatchId(final File dir, final String id) {
490 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
495 final File[] lists = dir.listFiles(new FilenameFilter() {
497 final Pattern pattern = Pattern.compile(id + "\\D");
500 public boolean accept(File dir, String name) {
501 return pattern.matcher(name).find();
505 if (lists.length == 1) {
507 } else if (lists.length > 1) {
508 throw new UnsupportedOperationException();
515 * 動画, コメントの"local"チェックボックス更新時の処理.
517 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
518 final Config p = Config.INSTANCE;
520 final ItemSelectable source = evt.getItemSelectable();
525 if (source == cbVideoLocal) {
528 dir = new File(p.getVideoDir());
532 dir = new File(p.getCommentDir());
535 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
536 btn.setEnabled(useLocal);
540 final File f = searchFileMatchId(dir, fldId.getText());
547 text = p.getVideoFileNamePattern();
551 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
553 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
554 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
555 fldOutput.setEnabled(convert);
556 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
558 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
559 final Config p = Config.INSTANCE;
560 final String id = fldId.getText();
565 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
566 final File dir = new File(p.getVideoDir());
567 final File file = searchFileMatchId(dir, id);
569 fldVideo.setText(file.getPath());
573 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
574 final File dir = new File(p.getCommentDir());
575 final File file = searchFileMatchId(dir, id);
577 fldComment.setText(file.getPath());
581 }//GEN-LAST:event_idFieldFocusLost
582 // Variables declaration - do not modify//GEN-BEGIN:variables
583 private final JTable tblDisplay;
585 private final JButton btnStart = new JButton("開始");
586 private final JButton btnStop = new JButton("停止");
587 private final JButton btnDeselect = new JButton("選択解除");
589 private final JTextField fldId = new JTextField();
590 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
591 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
592 private final JTextField fldBackLog = new JTextField();
593 private final JCheckBox cbVideoLocal;
594 private final JTextField fldVideo;
595 private final JButton btnVideo;
596 private final JCheckBox cbCommentLocal;
597 private final JTextField fldComment;
598 private final JButton btnComment;
599 private final JCheckBox cbOutputEnable;
600 private final JTextField fldOutput;
602 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
604 private final JTextField fldInputMessage = new JTextField();
605 private final JButton btnApply = new JButton("適用");
606 // End of variables declaration//GEN-END:variables
608 private void initInputPanel() {
613 private void initMainTab() {
614 final Config p = Config.INSTANCE;
617 fldBackLog.setEnabled(false);
618 cbBackLog.setEnabled(true);
620 final boolean movieLocal = p.getVideoUseLocal();
621 cbVideoLocal.setSelected(movieLocal);
622 btnVideo.setEnabled(movieLocal);
624 fldVideo.setText(p.getVideoFileNamePattern());
627 final boolean commentLocal = p.getCommentUseLocal();
628 cbCommentLocal.setSelected(commentLocal);
629 btnComment.setEnabled(commentLocal);
631 fldComment.setText(p.getCommentFileNamePattern());
634 final boolean convert = p.getOutputEnable();
635 cbOutputEnable.setSelected(convert);
636 fldOutput.setEnabled(convert);
637 fldOutput.setText(p.getOutputFileNamePattern());
640 private void initFfmpegTab() {
641 pnlInputFfmpeg.init(Config.INSTANCE);
644 private JMenuBar initMenuBar() {
645 final JMenuBar menuBar = new JMenuBar();
647 final JMenu mnFile = new JMenu("ファイル(F)");
650 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
651 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
652 itExit.addActionListener(new ActionListener() {
655 public void actionPerformed(ActionEvent e) {
656 throw new UnsupportedOperationException("Not supported yet.");
661 final JMenu mnTool = new JMenu("ツール(T)");
664 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
666 itOption.addActionListener(new ActionListener() {
669 public void actionPerformed(ActionEvent e) {
670 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
671 dlg.setLocationRelativeTo(MainFrame.this);
673 dlg.setVisible(true);
676 mnTool.add(itOption);
678 final JMenu mnHelp = new JMenu("ヘルプ(H)");
681 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
682 itAbout.addActionListener(new ActionListener() {
685 public void actionPerformed(ActionEvent e) {
686 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
688 dlg.setLocationRelativeTo(MainFrame.this);
690 dlg.setVisible(true);
698 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
701 public void process(DownloadProgress progress) {
702 throw new UnsupportedOperationException("Not supported yet.");
706 public void cancelled() {
707 throw new UnsupportedOperationException("Not supported yet.");
711 public void done(DownloadResult result) {
712 throw new UnsupportedOperationException("Not supported yet.");
716 public void error(Throwable th) {
717 throw new UnsupportedOperationException("Not supported yet.");
721 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
724 public void process(ConvertProgress progress) {
725 throw new UnsupportedOperationException("Not supported yet.");
729 public void cancelled() {
730 throw new UnsupportedOperationException("Not supported yet.");
734 public void done(ConvertResult result) {
735 throw new UnsupportedOperationException("Not supported yet.");
739 public void error(Throwable th) {
740 throw new UnsupportedOperationException("Not supported yet.");
746 private class DownloadListTransferHandler extends TransferHandler {
748 private static final long serialVersionUID = 1L;
749 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
752 public boolean canImport(TransferHandler.TransferSupport support) {
753 Transferable transferable = support.getTransferable();
754 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
755 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
762 public boolean importData(TransferHandler.TransferSupport support) {
764 // Transferable transferable = support.getTransferable();
765 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
766 // @SuppressWarnings("unchecked")
767 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
768 // Collection<Target> targets = Target.from(data);
769 // targetModel.addTarget(targets);
770 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
771 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
772 // Matcher matcher = movieIdPattern.matcher(data);
773 // if (matcher.find()) {
774 // String movieId = matcher.group(1);
775 // Target target = Target.fromId(movieId);
776 // targetModel.addTarget(target);
783 // } catch (Exception e) {
784 // logger.log(Level.SEVERE, null, e);
787 // TODO 上記実装見直し(Locationは削除された)
792 private class TableTransferHandler extends DownloadListTransferHandler {
794 private static final long serialVersionUID = 1L;
797 public boolean canImport(TransferHandler.TransferSupport support) {
798 return super.canImport(support);
802 public boolean importData(TransferHandler.TransferSupport support) {
803 return super.importData(support);
808 * ここからDownloadProfile作成用クラスの定義
811 private class InqubusDownloadProfile implements DownloadProfile {
813 private final LoginProfile loginProfile;
814 private final ProxyProfile proxyProfile;
815 private final VideoProfile videoProfile;
816 private final CommentProfile commentProfile;
817 private final GeneralProfile generalProfile;
819 private InqubusDownloadProfile() {
820 this.loginProfile = new InqubusLoginProfile();
821 this.proxyProfile = new InqubusProxyProfile();
822 this.videoProfile = new InqubusVideoProfile();
823 this.commentProfile = new InqubusCommentProfile();
824 this.generalProfile = new InqubusGeneralProfile();
828 public LoginProfile getLoginInfo() {
829 return this.loginProfile;
833 public ProxyProfile getProxyProfile() {
834 return this.proxyProfile;
838 public VideoProfile getVideoProfile() {
839 return this.videoProfile;
843 public CommentProfile getCommentProfile() {
844 return this.commentProfile;
848 public GeneralProfile getGeneralProfile() {
849 return this.generalProfile;
853 public String toString(){
854 return ToStringBuilder.reflectionToString(this);
858 private class InqubusLoginProfile implements LoginProfile {
859 private final String mail;
860 private final String password;
862 private InqubusLoginProfile(){
863 final Config p = Config.INSTANCE;
864 this.mail = p.getId();
865 this.password = p.getPassword();
869 public String getMail() {
874 public String getPassword() {
875 return this.password;
879 public String toString(){
880 return ToStringBuilder.reflectionToString(this);
884 private class InqubusProxyProfile implements ProxyProfile {
885 private final boolean use;
886 private final String host;
887 private final int port;
889 private InqubusProxyProfile(){
890 final Config p = Config.INSTANCE;
891 this.use = p.getProxyUse();
892 this.host = p.getProxyHost();
893 final String pp = p.getProxyPort();
894 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
898 public boolean use() {
903 public String getHost() {
908 public int getPort() {
913 public String toString(){
914 return ToStringBuilder.reflectionToString(this);
918 private class InqubusVideoProfile implements VideoProfile {
919 private final boolean download;
920 private final File dir;
921 private final String fileName;
922 private final File localFile;
924 private InqubusVideoProfile(){
925 final Config p = Config.INSTANCE;
926 this.download = !cbVideoLocal.isSelected();
928 this.dir = new File(p.getVideoDir());
929 this.fileName = fldVideo.getText();
930 this.localFile = null;
933 this.fileName = null;
934 this.localFile = new File(fldVideo.getText());
939 public boolean isDownload() {
940 return this.download;
944 public File getDir() {
949 public String getFileName() {
950 return this.fileName;
954 public File getLocalFile() {
955 return this.localFile;
959 public String toString(){
960 return ToStringBuilder.reflectionToString(this);
964 private class InqubusCommentProfile implements CommentProfile {
965 private final boolean download;
966 private final File dir;
967 private final String fileName;
968 private final File localFile;
969 private final int lengthRelatedCommentSize;
970 private final boolean disablePerMinComment;
971 private final int perMinCommentSize;
972 private final long backLogPoint;
974 private InqubusCommentProfile() {
975 final Config p = Config.INSTANCE;
976 this.download = !cbCommentLocal.isSelected();
978 this.dir = new File(p.getCommentDir());
979 this.fileName = fldComment.getText();
980 this.localFile = null;
983 this.fileName = null;
984 this.localFile = new File(fldComment.getText());
987 if(cbBackLog.isSelected()) {
989 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
990 } catch (IOException ex) {
991 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
994 this.backLogPoint = -1L;
997 this.disablePerMinComment = cbBackLogReduce.isSelected();
998 this.lengthRelatedCommentSize
999 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1000 this.perMinCommentSize
1001 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1005 public boolean isDownload() {
1006 return this.download;
1010 public File getDir() {
1015 public String getFileName() {
1016 return this.fileName;
1020 public File getLocalFile() {
1021 return this.localFile;
1025 public int getLengthRelatedCommentSize() {
1026 return this.lengthRelatedCommentSize;
1030 public boolean isDisablePerMinComment() {
1031 return this.disablePerMinComment;
1035 public int getPerMinCommentSize() {
1036 return this.perMinCommentSize;
1040 public long getBackLogPoint() {
1041 return this.backLogPoint;
1045 public String toString(){
1046 return ToStringBuilder.reflectionToString(this);
1050 private class InqubusGeneralProfile implements GeneralProfile {
1051 private final String replaceFrom;
1052 private final String replaceTo;
1053 private InqubusGeneralProfile() {
1054 final Config p = Config.INSTANCE;
1055 this.replaceFrom = p.getReplaceFrom();
1056 this.replaceTo = p.getReplaceTo();
1060 public String getReplaceFrom() {
1061 return this.replaceFrom;
1065 public String getReplaceTo() {
1066 return this.replaceTo;
1070 public String toString(){
1071 return ToStringBuilder.reflectionToString(this);
1076 * ここからConvertProfile作成用クラスの定義
1078 private class InqubusConvertProfile implements ConvertProfile {
1079 private final OutputProfile outputProfile;
1080 private final GeneralProfile generalProfile;
1081 private final FfmpegProfile ffmpegProfile;
1082 private final boolean convert;
1083 private final File ffmpeg;
1084 private final boolean vhookDisabled;
1085 private final boolean commentOverlay;
1086 private final File vhook;
1087 private final File tmpDir;
1088 private final File font;
1089 private final int fontIndex;
1090 private final boolean commentOpaque;
1091 private final boolean disableFontSizeArrange;
1092 private final int shadowIndex;
1093 private final boolean showConvrting;
1094 private final int maxNumOfComment;
1095 private final HideCondition ngSetting;
1097 private InqubusConvertProfile() throws IOException {
1098 final Config p = Config.INSTANCE;
1099 this.outputProfile = new InqubusOutputProfile();
1100 this.generalProfile = new InqubusGeneralProfile();
1101 this.ffmpegProfile = new InqubusFfmpegProfile();
1102 this.convert = cbOutputEnable.isSelected();
1103 this.ffmpeg = new File(p.getFfmpegPath());
1105 this.vhookDisabled = false;
1106 this.commentOverlay = p.getOutputCommentOverlay();
1107 this.vhook = new File(p.getFfmpegDllPath());
1108 this.tmpDir = new File(p.getSystemTempDir());
1109 this.font = new File(p.getFontPath());
1110 this.fontIndex = Integer.parseInt(p.getFontIndex());
1111 this.commentOpaque = p.getCommentOpaque();
1112 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1113 this.shadowIndex = p.getFontShadow();
1115 this.showConvrting = true;
1116 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1117 getCommentDisplaySizeManual());
1118 this.ngSetting = new InqubusHideCondition();
1122 public OutputProfile getOutputProfile() {
1123 return this.outputProfile;
1127 public GeneralProfile getGeneralProfile() {
1128 return this.generalProfile;
1132 public FfmpegProfile getFfmpegOption() {
1133 return this.ffmpegProfile;
1137 public boolean isConvert() {
1138 return this.convert;
1142 public File getFfmpeg() {
1147 public boolean isVhookDisabled() {
1148 return this.vhookDisabled;
1152 public boolean isCommentOverlay() {
1153 return this.commentOverlay;
1157 public File getVhook() {
1162 public File getTempDir() {
1167 public File getFont() {
1172 public int getFontIndex() {
1173 return this.fontIndex;
1177 public boolean isCommentOpaque() {
1178 return this.commentOpaque;
1182 public boolean isDisableFontSizeArrange() {
1183 return this.disableFontSizeArrange;
1187 public int getShadowIndex() {
1188 return this.shadowIndex;
1192 public boolean isShowConverting() {
1193 return this.showConvrting;
1197 public int getMaxNumOfComment() {
1198 return this.maxNumOfComment;
1202 public HideCondition getNgSetting() {
1203 return this.ngSetting;
1207 public String toString(){
1208 return ToStringBuilder.reflectionToString(this);
1212 private class InqubusOutputProfile implements OutputProfile {
1213 private final File dir;
1214 private final String fileName;
1215 private final String videoId;
1216 private final String title;
1219 private InqubusOutputProfile(){
1220 final Config p = Config.INSTANCE;
1221 this.dir = new File(p.getOutputDir());
1222 this.fileName = fldOutput.getText();
1223 // TODO この時点でのID/Titleはどうするか…
1229 public File getDir() {
1234 public String getFileName() {
1235 return this.fileName;
1239 public String getVideoId() {
1240 return this.videoId;
1244 public String getTitile() {
1249 public String toString(){
1250 return ToStringBuilder.reflectionToString(this);
1254 private class InqubusFfmpegProfile implements FfmpegProfile {
1255 private final String extOption;
1256 private final String inOption;
1257 private final String mainOption;
1258 private final String outOption;
1259 private final String avOption;
1260 private final boolean resize;
1261 private final int resizeWidth;
1262 private final int resizeHeight;
1263 private final boolean adjustRatio;
1265 private InqubusFfmpegProfile() throws IOException {
1266 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1267 final Config p = Config.INSTANCE;
1268 final String opf = p.getFfmpegOptionFile();
1269 if (StringUtils.isNotEmpty(opf)) {
1270 final File file = new File(opf);
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();
1283 this.extOption = p.getFfmpegExtension();
1284 this.inOption = p.getFfmpegInOption();
1285 this.mainOption = p.getFfmpegMainOption();
1286 this.outOption = p.getFfmpegOutOption();
1287 this.avOption = p.getFfmpegAvOption();
1288 this.resize = p.getFfmpegResizeEnable();
1289 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1290 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1291 this.adjustRatio = p.getFfmpegKeepAspect();
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);