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 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 btnApply.addActionListener(new ApplyActionListener());
173 pnlMain.setBorder(BorderFactory.createEtchedBorder());
175 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
176 scrDisplay.setViewportView(tblDisplay);
178 pnlButton.setBorder(BorderFactory.createEtchedBorder());
180 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
181 pnlButton.setLayout(gl_pnlButton);
182 gl_pnlButton.setHorizontalGroup(
183 gl_pnlButton.createParallelGroup(Alignment.LEADING)
184 .addGroup(gl_pnlButton.createSequentialGroup()
186 .addComponent(btnStart)
187 .addPreferredGap(ComponentPlacement.RELATED)
188 .addComponent(btnStop)
189 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
190 .addComponent(btnDeselect)
193 gl_pnlButton.setVerticalGroup(
194 gl_pnlButton.createParallelGroup(Alignment.LEADING)
195 .addGroup(gl_pnlButton.createSequentialGroup()
197 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
198 .addComponent(btnStart)
199 .addComponent(btnStop)
200 .addComponent(btnDeselect))
201 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
206 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
208 public void focusLost(java.awt.event.FocusEvent evt) {
209 idFieldFocusLost(evt);
213 lblVideo.setText("動画");
215 cbVideoLocal.setText("local");
216 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
218 public void itemStateChanged(java.awt.event.ItemEvent evt) {
219 useMovieLocalCheckBoxItemStateChanged(evt);
223 lblComment.setText("コメント");
225 cbCommentLocal.setText("local");
226 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
228 public void itemStateChanged(java.awt.event.ItemEvent evt) {
229 useMovieLocalCheckBoxItemStateChanged(evt);
233 lblOutput.setText("出力");
235 cbOutputEnable.setText("変換");
236 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
238 public void itemStateChanged(java.awt.event.ItemEvent evt) {
239 outputConvertCheckBoxItemStateChanged(evt);
244 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
245 pnlInputMain.setLayout(glInputMain);
246 glInputMain.setHorizontalGroup(
247 glInputMain.createParallelGroup(Alignment.LEADING)
248 .addGroup(glInputMain.createSequentialGroup()
251 .addPreferredGap(ComponentPlacement.RELATED)
252 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
253 .addPreferredGap(ComponentPlacement.UNRELATED)
254 .addComponent(cbBackLogReduce)
255 .addPreferredGap(ComponentPlacement.UNRELATED)
256 .addComponent(cbBackLog)
257 .addPreferredGap(ComponentPlacement.RELATED)
258 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
261 .addGroup(glInputMain.createSequentialGroup()
263 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
264 .addComponent(lblVideo)
265 .addComponent(lblComment)
266 .addComponent(lblOutput)
268 .addPreferredGap(ComponentPlacement.RELATED)
269 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
270 .addComponent(cbVideoLocal)
271 .addComponent(cbCommentLocal)
272 .addComponent(cbOutputEnable)
274 .addPreferredGap(ComponentPlacement.RELATED)
275 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
276 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
277 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
278 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
284 glInputMain.setVerticalGroup(
285 glInputMain.createParallelGroup(Alignment.LEADING)
286 .addGroup(glInputMain.createSequentialGroup()
288 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
289 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
291 .addComponent(cbBackLogReduce)
292 .addComponent(cbBackLog)
293 .addComponent(fldBackLog)
295 .addPreferredGap(ComponentPlacement.RELATED)
296 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
297 .addComponent(lblVideo)
298 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
299 .addComponent(cbVideoLocal))
300 .addPreferredGap(ComponentPlacement.RELATED)
301 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
302 .addComponent(lblComment)
303 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
304 .addComponent(cbCommentLocal))
305 .addPreferredGap(ComponentPlacement.RELATED)
306 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
307 .addComponent(lblOutput)
308 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
309 .addComponent(cbOutputEnable)
315 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
316 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
317 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
318 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
321 public void actionPerformed(ActionEvent e) {
322 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
323 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
324 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
325 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
326 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
327 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
328 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
331 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
334 public void itemStateChanged(ItemEvent e) {
335 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
336 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
337 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
338 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
341 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
344 public void propertyChange(PropertyChangeEvent evt) {
345 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
346 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
347 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
348 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
349 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
354 tbpInput.add("メイン", pnlInputMain);
355 tbpInput.add("ffmpeg", pnlInputFfmpeg);
358 fldInputMessage.setEditable(false);
359 fldInputMessage.setEnabled(false);
360 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
362 final JPanel pnlInputButton = new JPanel();
363 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
364 pnlInputButton.setLayout(glInputButton);
365 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
367 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
368 .addPreferredGap(ComponentPlacement.UNRELATED)
369 .addComponent(btnApply)
372 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
374 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
375 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
376 .addComponent(btnApply)
382 final JPanel pnlInputAll = new JPanel();
383 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
384 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
385 pnlInputAll.setLayout(glInputAll);
386 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
387 .addComponent(tbpInput)
388 .addComponent(pnlInputButton)
390 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
391 .addComponent(tbpInput)
392 .addComponent(pnlInputButton)
395 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
396 pnlMain.setLayout(gl_pnlMain);
397 gl_pnlMain.setHorizontalGroup(
398 gl_pnlMain.createParallelGroup(Alignment.LEADING)
399 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
401 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
402 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
403 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
404 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
408 gl_pnlMain.setVerticalGroup(
409 gl_pnlMain.createParallelGroup(Alignment.LEADING)
410 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
412 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
413 .addPreferredGap(ComponentPlacement.RELATED)
414 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
415 .addPreferredGap(ComponentPlacement.RELATED)
416 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
422 JMenuBar menuBar = initMenuBar();
423 setJMenuBar(menuBar);
425 GroupLayout layout = new GroupLayout(getContentPane());
426 getContentPane().setLayout(layout);
427 layout.setHorizontalGroup(
428 layout.createParallelGroup(Alignment.LEADING)
429 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
431 layout.setVerticalGroup(
432 layout.createParallelGroup(Alignment.LEADING)
433 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
438 pnlMain.setTransferHandler(new DownloadListTransferHandler());
439 tblDisplay.setTransferHandler(new TableTransferHandler());
441 final Config p = Config.INSTANCE;
442 final int thDownload = p.getSystemDownloadThread();
443 final int secDownload = p.getSystemDownloadWait();
444 final int thConvert = p.getSystemConvertThread();
445 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
448 private class GuiTaskManageListener implements TaskManageListener {
451 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
452 final String message) {
453 SwingUtilities.invokeLater(new Runnable() {
457 targetModel.setStatus(id, kind, status, percentage, message);
463 private class StopActionListener implements ActionListener {
466 public void actionPerformed(ActionEvent e) {
467 final int row = tblDisplay.getSelectedRow();
468 final Target t = targetModel.getTarget(row);
469 final boolean res = taskManager.cancel(t.getRowId());
470 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
472 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
477 private class ApplyActionListener implements ActionListener {
480 public void actionPerformed(ActionEvent e) {
482 final DownloadProfile downProf = new InqubusDownloadProfile();
483 final String id = Util.getVideoId(fldId.getText());
484 final InqubusConvertProfile convProf = new InqubusConvertProfile();
485 logger.log(Level.INFO, downProf.toString());
486 logger.log(Level.INFO, convProf.toString());
487 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
489 targetModel.addTarget(new Target(rp));
491 } catch (Throwable th) {
492 logger.log(Level.SEVERE, null, th);
493 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
498 private File searchFileMatchId(final File dir, final String id) {
499 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
504 final File[] lists = dir.listFiles(new FilenameFilter() {
506 final Pattern pattern = Pattern.compile(id + "\\D");
509 public boolean accept(File dir, String name) {
510 return pattern.matcher(name).find();
514 if (lists.length == 1) {
516 } else if (lists.length > 1) {
517 throw new UnsupportedOperationException();
524 * 動画, コメントの"local"チェックボックス更新時の処理.
526 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
527 final Config p = Config.INSTANCE;
529 final ItemSelectable source = evt.getItemSelectable();
533 if (source == cbVideoLocal) {
535 dir = new File(p.getVideoDir());
538 dir = new File(p.getCommentDir());
541 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
545 final File f = searchFileMatchId(dir, fldId.getText());
552 text = p.getVideoFileNamePattern();
556 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
558 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
559 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
560 fldOutput.setEnabled(convert);
561 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
563 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
564 final Config p = Config.INSTANCE;
565 final String id = fldId.getText();
570 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
571 final File dir = new File(p.getVideoDir());
572 final File file = searchFileMatchId(dir, id);
574 fldVideo.setText(file.getPath());
578 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
579 final File dir = new File(p.getCommentDir());
580 final File file = searchFileMatchId(dir, id);
582 fldComment.setText(file.getPath());
586 }//GEN-LAST:event_idFieldFocusLost
587 // Variables declaration - do not modify//GEN-BEGIN:variables
588 private final JTable tblDisplay;
590 private final JButton btnStart = new JButton("開始");
591 private final JButton btnStop = new JButton("停止");
592 private final JButton btnDeselect = new JButton("選択解除");
594 private final JTextField fldId = new JTextField();
595 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
596 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
597 private final JTextField fldBackLog = new JTextField();
598 private final JCheckBox cbVideoLocal;
599 private final JTextField fldVideo;
600 private final JCheckBox cbCommentLocal;
601 private final JTextField fldComment;
602 private final JCheckBox cbOutputEnable;
603 private final JTextField fldOutput;
605 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
607 private final JTextField fldInputMessage = new JTextField();
608 private final JButton btnApply = new JButton("適用");
609 // End of variables declaration//GEN-END:variables
611 private void initInputPanel() {
616 private void initMainTab() {
617 final Config p = Config.INSTANCE;
620 fldBackLog.setEnabled(false);
621 cbBackLog.setEnabled(true);
623 final boolean movieLocal = p.getVideoUseLocal();
624 cbVideoLocal.setSelected(movieLocal);
626 fldVideo.setText(p.getVideoFileNamePattern());
629 final boolean commentLocal = p.getCommentUseLocal();
630 cbCommentLocal.setSelected(commentLocal);
632 fldComment.setText(p.getCommentFileNamePattern());
635 final boolean convert = p.getOutputEnable();
636 cbOutputEnable.setSelected(convert);
637 fldOutput.setEnabled(convert);
638 fldOutput.setText(p.getOutputFileNamePattern());
641 private void initFfmpegTab() {
642 pnlInputFfmpeg.init(Config.INSTANCE);
645 private JMenuBar initMenuBar() {
646 final JMenuBar menuBar = new JMenuBar();
648 final JMenu mnFile = new JMenu("ファイル(F)");
651 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
652 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
653 itExit.addActionListener(new ActionListener() {
656 public void actionPerformed(ActionEvent e) {
657 throw new UnsupportedOperationException("Not supported yet.");
662 final JMenu mnTool = new JMenu("ツール(T)");
665 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
667 itOption.addActionListener(new ActionListener() {
670 public void actionPerformed(ActionEvent e) {
671 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
672 dlg.setLocationRelativeTo(MainFrame.this);
674 dlg.setVisible(true);
677 mnTool.add(itOption);
679 final JMenu mnHelp = new JMenu("ヘルプ(H)");
682 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
683 itAbout.addActionListener(new ActionListener() {
686 public void actionPerformed(ActionEvent e) {
687 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
689 dlg.setLocationRelativeTo(MainFrame.this);
691 dlg.setVisible(true);
699 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
702 public void process(DownloadProgress progress) {
703 throw new UnsupportedOperationException("Not supported yet.");
707 public void cancelled() {
708 throw new UnsupportedOperationException("Not supported yet.");
712 public void done(DownloadResult result) {
713 throw new UnsupportedOperationException("Not supported yet.");
717 public void error(Throwable th) {
718 throw new UnsupportedOperationException("Not supported yet.");
722 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
725 public void process(ConvertProgress progress) {
726 throw new UnsupportedOperationException("Not supported yet.");
730 public void cancelled() {
731 throw new UnsupportedOperationException("Not supported yet.");
735 public void done(ConvertResult result) {
736 throw new UnsupportedOperationException("Not supported yet.");
740 public void error(Throwable th) {
741 throw new UnsupportedOperationException("Not supported yet.");
747 private class DownloadListTransferHandler extends TransferHandler {
749 private static final long serialVersionUID = 1L;
750 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
753 public boolean canImport(TransferHandler.TransferSupport support) {
754 Transferable transferable = support.getTransferable();
755 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
756 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
763 public boolean importData(TransferHandler.TransferSupport support) {
765 // Transferable transferable = support.getTransferable();
766 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
767 // @SuppressWarnings("unchecked")
768 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
769 // Collection<Target> targets = Target.from(data);
770 // targetModel.addTarget(targets);
771 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
772 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
773 // Matcher matcher = movieIdPattern.matcher(data);
774 // if (matcher.find()) {
775 // String movieId = matcher.group(1);
776 // Target target = Target.fromId(movieId);
777 // targetModel.addTarget(target);
784 // } catch (Exception e) {
785 // logger.log(Level.SEVERE, null, e);
788 // TODO 上記実装見直し(Locationは削除された)
793 private class TableTransferHandler extends DownloadListTransferHandler {
795 private static final long serialVersionUID = 1L;
798 public boolean canImport(TransferHandler.TransferSupport support) {
799 return super.canImport(support);
803 public boolean importData(TransferHandler.TransferSupport support) {
804 return super.importData(support);
809 * ここからDownloadProfile作成用クラスの定義
812 private class InqubusDownloadProfile implements DownloadProfile {
814 private final LoginProfile loginProfile;
815 private final ProxyProfile proxyProfile;
816 private final VideoProfile videoProfile;
817 private final CommentProfile commentProfile;
818 private final GeneralProfile generalProfile;
820 private InqubusDownloadProfile() {
821 this.loginProfile = new InqubusLoginProfile();
822 this.proxyProfile = new InqubusProxyProfile();
823 this.videoProfile = new InqubusVideoProfile();
824 this.commentProfile = new InqubusCommentProfile();
825 this.generalProfile = new InqubusGeneralProfile();
829 public LoginProfile getLoginInfo() {
830 return this.loginProfile;
834 public ProxyProfile getProxyProfile() {
835 return this.proxyProfile;
839 public VideoProfile getVideoProfile() {
840 return this.videoProfile;
844 public CommentProfile getCommentProfile() {
845 return this.commentProfile;
849 public GeneralProfile getGeneralProfile() {
850 return this.generalProfile;
854 public String toString(){
855 return ToStringBuilder.reflectionToString(this);
859 private class InqubusLoginProfile implements LoginProfile {
860 private final String mail;
861 private final String password;
863 private InqubusLoginProfile(){
864 final Config p = Config.INSTANCE;
865 this.mail = p.getId();
866 this.password = p.getPassword();
870 public String getMail() {
875 public String getPassword() {
876 return this.password;
880 public String toString(){
881 return ToStringBuilder.reflectionToString(this);
885 private class InqubusProxyProfile implements ProxyProfile {
886 private final boolean use;
887 private final String host;
888 private final int port;
890 private InqubusProxyProfile(){
891 final Config p = Config.INSTANCE;
892 this.use = p.getProxyUse();
893 this.host = p.getProxyHost();
894 final String pp = p.getProxyPort();
895 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
899 public boolean use() {
904 public String getHost() {
909 public int getPort() {
914 public String toString(){
915 return ToStringBuilder.reflectionToString(this);
919 private class InqubusVideoProfile implements VideoProfile {
920 private final boolean download;
921 private final File dir;
922 private final String fileName;
923 private final File localFile;
925 private InqubusVideoProfile(){
926 final Config p = Config.INSTANCE;
927 this.download = !cbVideoLocal.isSelected();
929 this.dir = new File(p.getVideoDir());
930 this.fileName = fldVideo.getText();
931 this.localFile = null;
934 this.fileName = null;
935 this.localFile = new File(fldVideo.getText());
940 public boolean isDownload() {
941 return this.download;
945 public File getDir() {
950 public String getFileName() {
951 return this.fileName;
955 public File getLocalFile() {
956 return this.localFile;
960 public String toString(){
961 return ToStringBuilder.reflectionToString(this);
965 private class InqubusCommentProfile implements CommentProfile {
966 private final boolean download;
967 private final File dir;
968 private final String fileName;
969 private final File localFile;
970 private final int lengthRelatedCommentSize;
971 private final boolean disablePerMinComment;
972 private final int perMinCommentSize;
973 private final long backLogPoint;
975 private InqubusCommentProfile() {
976 final Config p = Config.INSTANCE;
977 this.download = !cbCommentLocal.isSelected();
979 this.dir = new File(p.getCommentDir());
980 this.fileName = fldComment.getText();
981 this.localFile = null;
984 this.fileName = null;
985 this.localFile = new File(fldComment.getText());
988 if(cbBackLog.isSelected()) {
990 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
991 } catch (IOException ex) {
992 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
995 this.backLogPoint = -1L;
998 this.disablePerMinComment = cbBackLogReduce.isSelected();
999 this.lengthRelatedCommentSize
1000 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1001 this.perMinCommentSize
1002 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1006 public boolean isDownload() {
1007 return this.download;
1011 public File getDir() {
1016 public String getFileName() {
1017 return this.fileName;
1021 public File getLocalFile() {
1022 return this.localFile;
1026 public int getLengthRelatedCommentSize() {
1027 return this.lengthRelatedCommentSize;
1031 public boolean isDisablePerMinComment() {
1032 return this.disablePerMinComment;
1036 public int getPerMinCommentSize() {
1037 return this.perMinCommentSize;
1041 public long getBackLogPoint() {
1042 return this.backLogPoint;
1046 public String toString(){
1047 return ToStringBuilder.reflectionToString(this);
1051 private class InqubusGeneralProfile implements GeneralProfile {
1052 private final String replaceFrom;
1053 private final String replaceTo;
1054 private InqubusGeneralProfile() {
1055 final Config p = Config.INSTANCE;
1056 this.replaceFrom = p.getReplaceFrom();
1057 this.replaceTo = p.getReplaceTo();
1061 public String getReplaceFrom() {
1062 return this.replaceFrom;
1066 public String getReplaceTo() {
1067 return this.replaceTo;
1071 public String toString(){
1072 return ToStringBuilder.reflectionToString(this);
1077 * ここからConvertProfile作成用クラスの定義
1079 private class InqubusConvertProfile implements ConvertProfile {
1080 private final OutputProfile outputProfile;
1081 private final GeneralProfile generalProfile;
1082 private final FfmpegProfile ffmpegProfile;
1083 private final boolean convert;
1084 private final File ffmpeg;
1085 private final boolean vhookDisabled;
1086 private final boolean commentOverlay;
1087 private final File vhook;
1088 private final File tmpDir;
1089 private final File font;
1090 private final int fontIndex;
1091 private final boolean commentOpaque;
1092 private final boolean disableFontSizeArrange;
1093 private final int shadowIndex;
1094 private final boolean showConvrting;
1095 private final int maxNumOfComment;
1096 private final HideCondition ngSetting;
1098 private InqubusConvertProfile() throws IOException {
1099 final Config p = Config.INSTANCE;
1100 this.outputProfile = new InqubusOutputProfile();
1101 this.generalProfile = new InqubusGeneralProfile();
1102 this.ffmpegProfile = new InqubusFfmpegProfile();
1103 this.convert = cbOutputEnable.isSelected();
1104 this.ffmpeg = new File(p.getFfmpegPath());
1106 this.vhookDisabled = false;
1107 this.commentOverlay = p.getOutputCommentOverlay();
1108 this.vhook = new File(p.getFfmpegDllPath());
1109 this.tmpDir = new File(p.getSystemTempDir());
1110 this.font = new File(p.getFontPath());
1111 this.fontIndex = Integer.parseInt(p.getFontIndex());
1112 this.commentOpaque = p.getCommentOpaque();
1113 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1114 this.shadowIndex = p.getFontShadow();
1116 this.showConvrting = true;
1117 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1118 getCommentDisplaySizeManual());
1119 this.ngSetting = new InqubusHideCondition();
1123 public OutputProfile getOutputProfile() {
1124 return this.outputProfile;
1128 public GeneralProfile getGeneralProfile() {
1129 return this.generalProfile;
1133 public FfmpegProfile getFfmpegOption() {
1134 return this.ffmpegProfile;
1138 public boolean isConvert() {
1139 return this.convert;
1143 public File getFfmpeg() {
1148 public boolean isVhookDisabled() {
1149 return this.vhookDisabled;
1153 public boolean isCommentOverlay() {
1154 return this.commentOverlay;
1158 public File getVhook() {
1163 public File getTempDir() {
1168 public File getFont() {
1173 public int getFontIndex() {
1174 return this.fontIndex;
1178 public boolean isCommentOpaque() {
1179 return this.commentOpaque;
1183 public boolean isDisableFontSizeArrange() {
1184 return this.disableFontSizeArrange;
1188 public int getShadowIndex() {
1189 return this.shadowIndex;
1193 public boolean isShowConverting() {
1194 return this.showConvrting;
1198 public int getMaxNumOfComment() {
1199 return this.maxNumOfComment;
1203 public HideCondition getNgSetting() {
1204 return this.ngSetting;
1208 public String toString(){
1209 return ToStringBuilder.reflectionToString(this);
1213 private class InqubusOutputProfile implements OutputProfile {
1214 private final File dir;
1215 private final String fileName;
1216 private final String videoId;
1217 private final String title;
1220 private InqubusOutputProfile(){
1221 final Config p = Config.INSTANCE;
1222 this.dir = new File(p.getOutputDir());
1223 this.fileName = fldOutput.getText();
1224 // TODO この時点でのID/Titleはどうするか…
1230 public File getDir() {
1235 public String getFileName() {
1236 return this.fileName;
1240 public String getVideoId() {
1241 return this.videoId;
1245 public String getTitile() {
1250 public String toString(){
1251 return ToStringBuilder.reflectionToString(this);
1255 private class InqubusFfmpegProfile implements FfmpegProfile {
1256 private final String extOption;
1257 private final String inOption;
1258 private final String mainOption;
1259 private final String outOption;
1260 private final String avOption;
1261 private final boolean resize;
1262 private final int resizeWidth;
1263 private final int resizeHeight;
1264 private final boolean adjustRatio;
1266 private InqubusFfmpegProfile() throws IOException {
1267 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1269 final FfmpegOption ffop = FfmpegOption.load(file);
1270 this.extOption = ffop.getExtOption();
1271 this.inOption = ffop.getInOption();
1272 this.mainOption = ffop.getMainOption();
1273 this.outOption = ffop.getMainOption();
1274 this.avOption = ffop.getAvfilterOption();
1275 this.resize = ffop.isResize();
1276 this.resizeWidth = ffop.getResizeWidth();
1277 this.resizeHeight = ffop.getResizeHeight();
1278 this.adjustRatio = ffop.isAdjustRatio();
1280 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1281 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1282 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1283 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1284 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1285 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1286 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1287 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1288 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1293 public String getExtOption() {
1294 return this.extOption;
1298 public String getInOption() {
1299 return this.inOption;
1303 public String getMainOption() {
1304 return this.mainOption;
1308 public String getOutOption() {
1309 return this.outOption;
1313 public String getAvfilterOption() {
1314 return this.avOption;
1318 public boolean isResize() {
1323 public int getResizeWidth() {
1324 return this.resizeWidth;
1328 public int getResizeHeight() {
1329 return this.resizeHeight;
1333 public boolean isAdjustRatio() {
1334 return this.adjustRatio;
1338 public String toString(){
1339 return ToStringBuilder.reflectionToString(this);
1343 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1346 public String getWord() {
1352 public String getId() {
1358 public String toString(){
1359 return ToStringBuilder.reflectionToString(this);