4 * Created on 2011/05/28, 18:14:51
6 package yukihane.inqubus.gui;
8 import java.awt.Dimension;
10 import java.awt.ItemSelectable;
11 import java.awt.Point;
12 import java.awt.Toolkit;
13 import java.awt.datatransfer.DataFlavor;
14 import java.awt.datatransfer.Transferable;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.awt.event.ItemEvent;
18 import java.awt.event.ItemListener;
19 import java.awt.event.KeyEvent;
20 import java.awt.event.WindowAdapter;
21 import java.awt.event.WindowEvent;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
25 import java.io.FilenameFilter;
26 import java.io.IOException;
28 import java.nio.file.FileSystem;
29 import java.nio.file.FileSystems;
30 import java.nio.file.Path;
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.List;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37 import java.util.regex.Pattern;
38 import javax.swing.BorderFactory;
39 import javax.swing.DropMode;
40 import javax.swing.GroupLayout;
41 import javax.swing.GroupLayout.Alignment;
42 import javax.swing.JButton;
43 import javax.swing.JCheckBox;
44 import javax.swing.JFileChooser;
45 import javax.swing.JFrame;
46 import javax.swing.JLabel;
47 import javax.swing.JMenu;
48 import javax.swing.JMenuBar;
49 import javax.swing.JMenuItem;
50 import javax.swing.JOptionPane;
51 import javax.swing.JPanel;
52 import javax.swing.JScrollPane;
53 import javax.swing.JTabbedPane;
54 import javax.swing.JTable;
55 import javax.swing.JTextField;
56 import javax.swing.KeyStroke;
57 import javax.swing.LayoutStyle.ComponentPlacement;
58 import javax.swing.SwingUtilities;
59 import javax.swing.TransferHandler;
60 import javax.swing.WindowConstants;
61 import javax.swing.border.BevelBorder;
62 import org.apache.commons.configuration.ConfigurationException;
63 import org.apache.commons.lang.StringUtils;
64 import org.apache.commons.lang.builder.ToStringBuilder;
65 import saccubus.FfmpegOption;
66 import saccubus.MainFrame_AboutBox;
67 import saccubus.util.WayBackTimeParser;
68 import saccubus.worker.impl.convert.ConvertProgress;
69 import saccubus.worker.impl.download.DownloadProgress;
70 import saccubus.worker.WorkerListener;
71 import saccubus.worker.impl.convert.ConvertResult;
72 import saccubus.worker.impl.download.DownloadResult;
73 import saccubus.worker.profile.CommentProfile;
74 import saccubus.worker.profile.ConvertProfile;
75 import saccubus.worker.profile.DownloadProfile;
76 import saccubus.worker.profile.FfmpegProfile;
77 import saccubus.worker.profile.GeneralProfile;
78 import saccubus.worker.profile.LoginProfile;
79 import saccubus.worker.profile.OutputProfile;
80 import saccubus.worker.profile.ProxyProfile;
81 import saccubus.worker.profile.VideoProfile;
83 import yukihane.inqubus.Config;
84 import yukihane.inqubus.filewatch.FileWatch;
85 import yukihane.inqubus.manager.RequestProcess;
86 import yukihane.inqubus.manager.TaskKind;
87 import yukihane.inqubus.manager.TaskManage;
88 import yukihane.inqubus.manager.TaskManageListener;
89 import yukihane.inqubus.manager.TaskStatus;
90 import yukihane.inqubus.model.Target;
91 import yukihane.inqubus.model.TargetsTableModel;
97 public class MainFrame extends JFrame {
99 private static final long serialVersionUID = 1L;
100 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
101 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
102 private static final String FILE_LOCALBUTTON_TOOLTIP
103 = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
104 private static final String FILE_INPUTFIELD_TOOLTIP
105 = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
106 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
107 private static final String FILE_OUTPUTFIELD_TOOLTIP
109 private final TargetsTableModel targetModel = new TargetsTableModel();
110 private final TaskManage taskManager;
111 private final Thread videoFileWatcherThread;
112 private final FileWatch videoFileWatcher;
114 /** Creates new form MainFrame */
117 addWindowListener(new MainFrameWindowListener());
119 final Config p = Config.INSTANCE;
122 final int thDownload = p.getSystemDownloadThread();
123 final int secDownload = p.getSystemDownloadWait();
124 final int thConvert = p.getSystemConvertThread();
125 taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
127 // TODO ディレクトリ監視スレッド生成
128 final List<String> videoSearchDirs = p.getSearchVideoDirs();
129 videoSearchDirs.add(p.getVideoDir());
130 final FileSystem fs = FileSystems.getDefault();
131 final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
132 for (String s : videoSearchDirs) {
133 videoPaths.add(fs.getPath(s));
135 videoFileWatcher = new FileWatch(videoPaths);
136 this.videoFileWatcherThread = new Thread(videoFileWatcher);
137 this.videoFileWatcherThread.setDaemon(true);
139 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
140 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
141 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
142 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
143 final List<Image> images = new ArrayList<>(2);
146 setIconImages(images);
148 final JPanel pnlMain = new JPanel();
149 final JScrollPane scrDisplay = new JScrollPane();
150 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
151 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
152 final JPanel pnlButton = new JPanel();
153 final JPanel pnlInputMain = new JPanel();
154 final JLabel lblId = new JLabel();
155 final JLabel lblVideo = new JLabel();
156 cbVideoLocal = new JCheckBox();
157 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
158 fldVideo = new JTextField();
159 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
160 btnVideo.addActionListener(
161 new FileChooseAction(MainFrame.this, JFileChooser.FILES_ONLY, fldVideo));
162 final JLabel lblComment = new JLabel();
164 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
165 cbBackLog.addItemListener(new ItemListener() {
168 public void itemStateChanged(ItemEvent e) {
169 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
170 fldBackLog.setEnabled(selected);
173 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
176 public void propertyChange(PropertyChangeEvent evt) {
177 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
178 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
179 fldBackLog.setEnabled(fldEnabled);
182 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
184 cbCommentLocal = new JCheckBox();
185 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
186 cbCommentLocal.addItemListener(new ItemListener() {
189 public void itemStateChanged(ItemEvent e) {
190 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
191 cbBackLogReduce.setEnabled(!selected);
192 cbBackLog.setEnabled(!selected);
195 fldComment = new JTextField();
196 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
197 btnComment.addActionListener(
198 new FileChooseAction(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
199 final JLabel lblOutput = new JLabel();
200 cbOutputEnable = new JCheckBox();
201 fldOutput = new JTextField();
202 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
204 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
206 btnStop.addActionListener(new StopActionListener());
207 final ApplyActionListener applyListener = new ApplyActionListener();
208 btnApply.addActionListener(applyListener);
209 btnClear.addActionListener(new ActionListener() {
212 public void actionPerformed(ActionEvent e) {
217 pnlMain.setBorder(BorderFactory.createEtchedBorder());
219 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
220 scrDisplay.setViewportView(tblDisplay);
222 pnlButton.setBorder(BorderFactory.createEtchedBorder());
224 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
225 pnlButton.setLayout(gl_pnlButton);
226 gl_pnlButton.setHorizontalGroup(
227 gl_pnlButton.createParallelGroup(Alignment.LEADING)
228 .addGroup(gl_pnlButton.createSequentialGroup()
230 .addComponent(btnStart)
231 .addPreferredGap(ComponentPlacement.RELATED)
232 .addComponent(btnStop)
233 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
234 .addComponent(btnDeselect)
237 gl_pnlButton.setVerticalGroup(
238 gl_pnlButton.createParallelGroup(Alignment.LEADING)
239 .addGroup(gl_pnlButton.createSequentialGroup()
241 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
242 .addComponent(btnStart)
243 .addComponent(btnStop)
244 .addComponent(btnDeselect))
245 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
251 fldId = new IdComboBox(videoFileWatcher);
252 fldId.setToolTipText(ID_FIELD_TOOLTIP);
253 fldId.getEditorComponent().addActionListener(applyListener);
254 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
256 public void focusLost(java.awt.event.FocusEvent evt) {
257 idFieldFocusLost(evt);
261 lblVideo.setText("動画");
263 cbVideoLocal.setText("local");
264 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
266 public void itemStateChanged(java.awt.event.ItemEvent evt) {
267 useMovieLocalCheckBoxItemStateChanged(evt);
271 lblComment.setText("コメント");
273 cbCommentLocal.setText("local");
274 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
276 public void itemStateChanged(java.awt.event.ItemEvent evt) {
277 useMovieLocalCheckBoxItemStateChanged(evt);
281 lblOutput.setText("出力");
283 cbOutputEnable.setText("変換");
284 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
286 public void itemStateChanged(java.awt.event.ItemEvent evt) {
287 outputConvertCheckBoxItemStateChanged(evt);
292 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
293 pnlInputMain.setLayout(glInputMain);
294 glInputMain.setHorizontalGroup(
295 glInputMain.createParallelGroup(Alignment.LEADING)
296 .addGroup(glInputMain.createSequentialGroup()
299 .addPreferredGap(ComponentPlacement.RELATED)
300 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
301 .addPreferredGap(ComponentPlacement.UNRELATED)
302 .addComponent(cbBackLogReduce)
303 .addPreferredGap(ComponentPlacement.UNRELATED)
304 .addComponent(cbBackLog)
305 .addPreferredGap(ComponentPlacement.RELATED)
306 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
309 .addGroup(glInputMain.createSequentialGroup()
311 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
312 .addComponent(lblVideo)
313 .addComponent(lblComment)
314 .addComponent(lblOutput)
316 .addPreferredGap(ComponentPlacement.RELATED)
317 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
318 .addComponent(cbVideoLocal)
319 .addComponent(cbCommentLocal)
320 .addComponent(cbOutputEnable)
322 .addPreferredGap(ComponentPlacement.RELATED)
323 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
324 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
325 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
326 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
328 .addGroup(glInputMain.createParallelGroup()
329 .addComponent(btnVideo)
330 .addComponent(btnComment)
336 glInputMain.setVerticalGroup(
337 glInputMain.createParallelGroup(Alignment.LEADING)
338 .addGroup(glInputMain.createSequentialGroup()
340 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
341 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
343 .addComponent(cbBackLogReduce)
344 .addComponent(cbBackLog)
345 .addComponent(fldBackLog)
347 .addPreferredGap(ComponentPlacement.RELATED)
348 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
349 .addComponent(lblVideo)
350 .addComponent(cbVideoLocal)
351 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
352 .addComponent(btnVideo)
354 .addPreferredGap(ComponentPlacement.RELATED)
355 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
356 .addComponent(lblComment)
357 .addComponent(cbCommentLocal)
358 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
359 .addComponent(btnComment)
361 .addPreferredGap(ComponentPlacement.RELATED)
362 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
363 .addComponent(lblOutput)
364 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
365 .addComponent(cbOutputEnable)
371 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
372 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
373 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
374 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
377 public void actionPerformed(ActionEvent e) {
378 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
379 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
380 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
381 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
382 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
383 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
384 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
387 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
390 public void itemStateChanged(ItemEvent e) {
391 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
392 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
393 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
394 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
397 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
400 public void propertyChange(PropertyChangeEvent evt) {
401 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
402 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
403 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
404 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
405 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
410 tbpInput.add("メイン", pnlInputMain);
411 tbpInput.add("ffmpeg", pnlInputFfmpeg);
414 fldInputMessage.setEditable(false);
415 fldInputMessage.setEnabled(false);
416 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
418 final JPanel pnlInputButton = new JPanel();
419 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
420 pnlInputButton.setLayout(glInputButton);
421 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
423 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
424 .addPreferredGap(ComponentPlacement.UNRELATED)
425 .addComponent(btnClear)
426 .addPreferredGap(ComponentPlacement.UNRELATED)
427 .addComponent(btnApply)
430 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
432 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
433 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
434 .addComponent(btnClear)
435 .addComponent(btnApply)
441 final JPanel pnlInputAll = new JPanel();
442 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
443 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
444 pnlInputAll.setLayout(glInputAll);
445 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
446 .addComponent(tbpInput)
447 .addComponent(pnlInputButton)
449 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
450 .addComponent(tbpInput)
451 .addComponent(pnlInputButton)
454 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
455 pnlMain.setLayout(gl_pnlMain);
456 gl_pnlMain.setHorizontalGroup(
457 gl_pnlMain.createParallelGroup(Alignment.LEADING)
458 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
460 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
461 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
462 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
463 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
467 gl_pnlMain.setVerticalGroup(
468 gl_pnlMain.createParallelGroup(Alignment.LEADING)
469 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
471 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
472 .addPreferredGap(ComponentPlacement.RELATED)
473 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
474 .addPreferredGap(ComponentPlacement.RELATED)
475 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
481 JMenuBar menuBar = initMenuBar();
482 setJMenuBar(menuBar);
484 GroupLayout layout = new GroupLayout(getContentPane());
485 getContentPane().setLayout(layout);
486 layout.setHorizontalGroup(
487 layout.createParallelGroup(Alignment.LEADING)
488 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
490 layout.setVerticalGroup(
491 layout.createParallelGroup(Alignment.LEADING)
492 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
496 setMinimumSize(getSize());
499 * 画面のサイズや位置を前回終了時のものに設定する
501 final int windowWidth = p.getSystemWindowWidth();
502 final int windowHeight = p.getSystemWindowHeight();
503 if (windowWidth > 0 && windowHeight > 0) {
504 setSize(windowWidth, windowHeight);
507 final int windowPosX = p.getSystemWindowPosX();
508 final int windowPosY = p.getSystemWindowPosY();
509 if (windowPosX > 0 && windowPosY > 0) {
510 setLocation(windowPosX, windowPosY);
512 setLocationByPlatform(true);
515 final int colId = p.getSystemColumnId();
517 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
519 final int colStatus = p.getSystemColumnStatus();
521 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
525 pnlMain.setTransferHandler(new DownloadListTransferHandler());
526 tblDisplay.setTransferHandler(new TableTransferHandler());
529 public void startWatcher() {
530 videoFileWatcherThread.start();
533 private class GuiTaskManageListener implements TaskManageListener {
536 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
537 final String message) {
538 SwingUtilities.invokeLater(new Runnable() {
542 targetModel.setStatus(id, kind, status, percentage, message);
548 private class StopActionListener implements ActionListener {
551 public void actionPerformed(ActionEvent e) {
552 final int row = tblDisplay.getSelectedRow();
553 final Target t = targetModel.getTarget(row);
554 final boolean res = taskManager.cancel(t.getRowId());
555 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
557 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
562 private class ApplyActionListener implements ActionListener {
565 public void actionPerformed(ActionEvent e) {
567 final DownloadProfile downProf = new InqubusDownloadProfile();
568 final String id = Util.getVideoId(fldId.getText());
569 final InqubusConvertProfile convProf = new InqubusConvertProfile();
570 logger.log(Level.INFO, downProf.toString());
571 logger.log(Level.INFO, convProf.toString());
572 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
574 targetModel.addTarget(new Target(rp));
576 } catch (Throwable th) {
577 logger.log(Level.SEVERE, null, th);
578 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
583 private File searchFileMatchId(final File dir, final String id) {
584 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
589 final File[] lists = dir.listFiles(new FilenameFilter() {
591 final Pattern pattern = Pattern.compile(id + "\\D");
594 public boolean accept(File dir, String name) {
595 return pattern.matcher(name).find();
599 if (lists.length == 1) {
601 } else if (lists.length > 1) {
602 throw new UnsupportedOperationException();
609 * 動画, コメントの"local"チェックボックス更新時の処理.
611 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
612 final Config p = Config.INSTANCE;
614 final ItemSelectable source = evt.getItemSelectable();
619 if (source == cbVideoLocal) {
622 dir = new File(p.getVideoDir());
626 dir = new File(p.getCommentDir());
629 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
631 button.setEnabled(useLocal);
635 final File f = searchFileMatchId(dir, fldId.getText());
642 text = p.getVideoFileNamePattern();
646 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
648 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
649 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
650 fldOutput.setEnabled(convert);
651 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
653 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
654 final Config p = Config.INSTANCE;
655 final String id = fldId.getText();
660 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
661 final File dir = new File(p.getVideoDir());
662 final File file = searchFileMatchId(dir, id);
664 fldVideo.setText(file.getPath());
668 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
669 final File dir = new File(p.getCommentDir());
670 final File file = searchFileMatchId(dir, id);
672 fldComment.setText(file.getPath());
676 }//GEN-LAST:event_idFieldFocusLost
677 // Variables declaration - do not modify//GEN-BEGIN:variables
678 private final JTable tblDisplay;
680 private final JButton btnStart = new JButton("開始");
681 private final JButton btnStop = new JButton("停止");
682 private final JButton btnDeselect = new JButton("選択解除");
684 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
686 private final IdComboBox fldId;
687 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
688 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
689 private final JTextField fldBackLog = new JTextField();
690 private final JCheckBox cbVideoLocal;
691 private final JTextField fldVideo;
692 private final JButton btnVideo = new JButton("...");
693 private final JCheckBox cbCommentLocal;
694 private final JTextField fldComment;
695 private final JButton btnComment = new JButton("...");
696 private final JCheckBox cbOutputEnable;
697 private final JTextField fldOutput;
699 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
701 private final JTextField fldInputMessage = new JTextField();
702 private final JButton btnClear = new JButton("クリア");
703 private final JButton btnApply = new JButton("適用");
704 // End of variables declaration//GEN-END:variables
706 private void initInputPanel() {
709 tbpInput.setSelectedIndex(0);
710 fldId.requestFocus();
713 private void initMainTab() {
714 final Config p = Config.INSTANCE;
717 fldBackLog.setEnabled(false);
718 cbBackLog.setEnabled(true);
720 final boolean videoLocal = p.getVideoUseLocal();
721 cbVideoLocal.setSelected(videoLocal);
723 fldVideo.setText(p.getVideoFileNamePattern());
725 btnVideo.setEnabled(videoLocal);
727 final boolean commentLocal = p.getCommentUseLocal();
728 cbCommentLocal.setSelected(commentLocal);
730 fldComment.setText(p.getCommentFileNamePattern());
732 btnComment.setEnabled(commentLocal);
734 final boolean convert = p.getOutputEnable();
735 cbOutputEnable.setSelected(convert);
736 fldOutput.setEnabled(convert);
737 fldOutput.setText(p.getOutputFileNamePattern());
740 private void initFfmpegTab() {
741 pnlInputFfmpeg.init(Config.INSTANCE);
744 private JMenuBar initMenuBar() {
745 final JMenuBar menuBar = new JMenuBar();
747 final JMenu mnFile = new JMenu("ファイル(F)");
750 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
751 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
752 itExit.addActionListener(new ActionListener() {
755 public void actionPerformed(ActionEvent e) {
756 throw new UnsupportedOperationException("Not supported yet.");
761 final JMenu mnTool = new JMenu("ツール(T)");
764 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
766 itOption.addActionListener(new ActionListener() {
769 public void actionPerformed(ActionEvent e) {
770 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
771 dlg.setLocationRelativeTo(MainFrame.this);
773 dlg.setVisible(true);
776 mnTool.add(itOption);
778 final JMenu mnHelp = new JMenu("ヘルプ(H)");
781 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
782 itAbout.addActionListener(new ActionListener() {
785 public void actionPerformed(ActionEvent e) {
786 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
788 dlg.setLocationRelativeTo(MainFrame.this);
790 dlg.setVisible(true);
798 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
801 public void process(DownloadProgress progress) {
802 throw new UnsupportedOperationException("Not supported yet.");
806 public void cancelled() {
807 throw new UnsupportedOperationException("Not supported yet.");
811 public void done(DownloadResult result) {
812 throw new UnsupportedOperationException("Not supported yet.");
816 public void error(Throwable th) {
817 throw new UnsupportedOperationException("Not supported yet.");
821 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
824 public void process(ConvertProgress progress) {
825 throw new UnsupportedOperationException("Not supported yet.");
829 public void cancelled() {
830 throw new UnsupportedOperationException("Not supported yet.");
834 public void done(ConvertResult result) {
835 throw new UnsupportedOperationException("Not supported yet.");
839 public void error(Throwable th) {
840 throw new UnsupportedOperationException("Not supported yet.");
846 private class DownloadListTransferHandler extends TransferHandler {
848 private static final long serialVersionUID = 1L;
849 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
852 public boolean canImport(TransferHandler.TransferSupport support) {
853 Transferable transferable = support.getTransferable();
854 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
855 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
862 public boolean importData(TransferHandler.TransferSupport support) {
864 // Transferable transferable = support.getTransferable();
865 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
866 // @SuppressWarnings("unchecked")
867 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
868 // Collection<Target> targets = Target.from(data);
869 // targetModel.addTarget(targets);
870 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
871 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
872 // Matcher matcher = movieIdPattern.matcher(data);
873 // if (matcher.find()) {
874 // String movieId = matcher.group(1);
875 // Target target = Target.fromId(movieId);
876 // targetModel.addTarget(target);
883 // } catch (Exception e) {
884 // logger.log(Level.SEVERE, null, e);
887 // TODO 上記実装見直し(Locationは削除された)
892 private class TableTransferHandler extends DownloadListTransferHandler {
894 private static final long serialVersionUID = 1L;
897 public boolean canImport(TransferHandler.TransferSupport support) {
898 return super.canImport(support);
902 public boolean importData(TransferHandler.TransferSupport support) {
903 return super.importData(support);
907 private class MainFrameWindowListener extends WindowAdapter {
909 public void windowClosing(WindowEvent e) {
910 final Config p = Config.INSTANCE;
912 final Dimension size = getSize();
913 p.setSystemWindowWidth(size.width);
914 p.setSystemWindowHeight(size.height);
916 final Point pos = getLocation();
917 p.setSystemWindowPosX(pos.x);
918 p.setSystemWindowPosY(pos.y);
920 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
921 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
922 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
923 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
924 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
927 } catch (ConfigurationException ex) {
928 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
934 * ここからDownloadProfile作成用クラスの定義
937 private class InqubusDownloadProfile implements DownloadProfile {
939 private final LoginProfile loginProfile;
940 private final ProxyProfile proxyProfile;
941 private final VideoProfile videoProfile;
942 private final CommentProfile commentProfile;
943 private final GeneralProfile generalProfile;
945 private InqubusDownloadProfile() {
946 this.loginProfile = new InqubusLoginProfile();
947 this.proxyProfile = new InqubusProxyProfile();
948 this.videoProfile = new InqubusVideoProfile();
949 this.commentProfile = new InqubusCommentProfile();
950 this.generalProfile = new InqubusGeneralProfile();
954 public LoginProfile getLoginInfo() {
955 return this.loginProfile;
959 public ProxyProfile getProxyProfile() {
960 return this.proxyProfile;
964 public VideoProfile getVideoProfile() {
965 return this.videoProfile;
969 public CommentProfile getCommentProfile() {
970 return this.commentProfile;
974 public GeneralProfile getGeneralProfile() {
975 return this.generalProfile;
979 public String toString(){
980 return ToStringBuilder.reflectionToString(this);
984 private class InqubusLoginProfile implements LoginProfile {
985 private final String mail;
986 private final String password;
988 private InqubusLoginProfile(){
989 final Config p = Config.INSTANCE;
990 this.mail = p.getId();
991 this.password = p.getPassword();
995 public String getMail() {
1000 public String getPassword() {
1001 return this.password;
1005 public String toString(){
1006 return ToStringBuilder.reflectionToString(this);
1010 private class InqubusProxyProfile implements ProxyProfile {
1011 private final boolean use;
1012 private final String host;
1013 private final int port;
1015 private InqubusProxyProfile(){
1016 final Config p = Config.INSTANCE;
1017 this.use = p.getProxyUse();
1018 this.host = p.getProxyHost();
1019 final String pp = p.getProxyPort();
1020 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
1024 public boolean use() {
1029 public String getHost() {
1034 public int getPort() {
1039 public String toString(){
1040 return ToStringBuilder.reflectionToString(this);
1044 private class InqubusVideoProfile implements VideoProfile {
1045 private final boolean download;
1046 private final File dir;
1047 private final String fileName;
1048 private final File localFile;
1050 private InqubusVideoProfile(){
1051 final Config p = Config.INSTANCE;
1052 this.download = !cbVideoLocal.isSelected();
1053 if (this.download) {
1054 this.dir = new File(p.getVideoDir());
1055 this.fileName = fldVideo.getText();
1056 this.localFile = null;
1059 this.fileName = null;
1060 this.localFile = new File(fldVideo.getText());
1065 public boolean isDownload() {
1066 return this.download;
1070 public File getDir() {
1075 public String getFileName() {
1076 return this.fileName;
1080 public File getLocalFile() {
1081 return this.localFile;
1085 public String toString(){
1086 return ToStringBuilder.reflectionToString(this);
1090 private class InqubusCommentProfile implements CommentProfile {
1091 private final boolean download;
1092 private final File dir;
1093 private final String fileName;
1094 private final File localFile;
1095 private final int lengthRelatedCommentSize;
1096 private final boolean disablePerMinComment;
1097 private final int perMinCommentSize;
1098 private final long backLogPoint;
1100 private InqubusCommentProfile() {
1101 final Config p = Config.INSTANCE;
1102 this.download = !cbCommentLocal.isSelected();
1103 if (this.download) {
1104 this.dir = new File(p.getCommentDir());
1105 this.fileName = fldComment.getText();
1106 this.localFile = null;
1109 this.fileName = null;
1110 this.localFile = new File(fldComment.getText());
1113 if(cbBackLog.isSelected()) {
1115 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
1116 } catch (IOException ex) {
1117 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
1120 this.backLogPoint = -1L;
1123 this.disablePerMinComment = cbBackLogReduce.isSelected();
1124 this.lengthRelatedCommentSize
1125 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1126 this.perMinCommentSize
1127 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1131 public boolean isDownload() {
1132 return this.download;
1136 public File getDir() {
1141 public String getFileName() {
1142 return this.fileName;
1146 public File getLocalFile() {
1147 return this.localFile;
1151 public int getLengthRelatedCommentSize() {
1152 return this.lengthRelatedCommentSize;
1156 public boolean isDisablePerMinComment() {
1157 return this.disablePerMinComment;
1161 public int getPerMinCommentSize() {
1162 return this.perMinCommentSize;
1166 public long getBackLogPoint() {
1167 return this.backLogPoint;
1171 public String toString(){
1172 return ToStringBuilder.reflectionToString(this);
1176 private class InqubusGeneralProfile implements GeneralProfile {
1177 private final String replaceFrom;
1178 private final String replaceTo;
1179 private InqubusGeneralProfile() {
1180 final Config p = Config.INSTANCE;
1181 this.replaceFrom = p.getReplaceFrom();
1182 this.replaceTo = p.getReplaceTo();
1186 public String getReplaceFrom() {
1187 return this.replaceFrom;
1191 public String getReplaceTo() {
1192 return this.replaceTo;
1196 public String toString(){
1197 return ToStringBuilder.reflectionToString(this);
1202 * ここからConvertProfile作成用クラスの定義
1204 private class InqubusConvertProfile implements ConvertProfile {
1205 private final OutputProfile outputProfile;
1206 private final GeneralProfile generalProfile;
1207 private final FfmpegProfile ffmpegProfile;
1208 private final boolean convert;
1209 private final File ffmpeg;
1210 private final boolean vhookDisabled;
1211 private final boolean commentOverlay;
1212 private final File vhook;
1213 private final File tmpDir;
1214 private final File font;
1215 private final int fontIndex;
1216 private final boolean commentOpaque;
1217 private final boolean disableFontSizeArrange;
1218 private final int shadowIndex;
1219 private final boolean showConvrting;
1220 private final int maxNumOfComment;
1221 private final HideCondition ngSetting;
1223 private InqubusConvertProfile() throws IOException {
1224 final Config p = Config.INSTANCE;
1225 this.outputProfile = new InqubusOutputProfile();
1226 this.generalProfile = new InqubusGeneralProfile();
1227 this.ffmpegProfile = new InqubusFfmpegProfile();
1228 this.convert = cbOutputEnable.isSelected();
1229 this.ffmpeg = new File(p.getFfmpegPath());
1231 this.vhookDisabled = false;
1232 this.commentOverlay = p.getOutputCommentOverlay();
1233 this.vhook = new File(p.getFfmpegDllPath());
1234 this.tmpDir = new File(p.getSystemTempDir());
1235 this.font = new File(p.getFontPath());
1236 this.fontIndex = Integer.parseInt(p.getFontIndex());
1237 this.commentOpaque = p.getCommentOpaque();
1238 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1239 this.shadowIndex = p.getFontShadow();
1241 this.showConvrting = true;
1242 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1243 getCommentDisplaySizeManual());
1244 this.ngSetting = new InqubusHideCondition();
1248 public OutputProfile getOutputProfile() {
1249 return this.outputProfile;
1253 public GeneralProfile getGeneralProfile() {
1254 return this.generalProfile;
1258 public FfmpegProfile getFfmpegOption() {
1259 return this.ffmpegProfile;
1263 public boolean isConvert() {
1264 return this.convert;
1268 public File getFfmpeg() {
1273 public boolean isVhookDisabled() {
1274 return this.vhookDisabled;
1278 public boolean isCommentOverlay() {
1279 return this.commentOverlay;
1283 public File getVhook() {
1288 public File getTempDir() {
1293 public File getFont() {
1298 public int getFontIndex() {
1299 return this.fontIndex;
1303 public boolean isCommentOpaque() {
1304 return this.commentOpaque;
1308 public boolean isDisableFontSizeArrange() {
1309 return this.disableFontSizeArrange;
1313 public int getShadowIndex() {
1314 return this.shadowIndex;
1318 public boolean isShowConverting() {
1319 return this.showConvrting;
1323 public int getMaxNumOfComment() {
1324 return this.maxNumOfComment;
1328 public HideCondition getNgSetting() {
1329 return this.ngSetting;
1333 public String toString(){
1334 return ToStringBuilder.reflectionToString(this);
1338 private class InqubusOutputProfile implements OutputProfile {
1339 private final File dir;
1340 private final String fileName;
1341 private final String videoId;
1342 private final String title;
1345 private InqubusOutputProfile(){
1346 final Config p = Config.INSTANCE;
1347 this.dir = new File(p.getOutputDir());
1348 this.fileName = fldOutput.getText();
1349 // TODO この時点でのID/Titleはどうするか…
1355 public File getDir() {
1360 public String getFileName() {
1361 return this.fileName;
1365 public String getVideoId() {
1366 return this.videoId;
1370 public String getTitile() {
1375 public String toString(){
1376 return ToStringBuilder.reflectionToString(this);
1380 private class InqubusFfmpegProfile implements FfmpegProfile {
1381 private final String extOption;
1382 private final String inOption;
1383 private final String mainOption;
1384 private final String outOption;
1385 private final String avOption;
1386 private final boolean resize;
1387 private final int resizeWidth;
1388 private final int resizeHeight;
1389 private final boolean adjustRatio;
1391 private InqubusFfmpegProfile() throws IOException {
1392 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1394 final FfmpegOption ffop = FfmpegOption.load(file);
1395 this.extOption = ffop.getExtOption();
1396 this.inOption = ffop.getInOption();
1397 this.mainOption = ffop.getMainOption();
1398 this.outOption = ffop.getMainOption();
1399 this.avOption = ffop.getAvfilterOption();
1400 this.resize = ffop.isResize();
1401 this.resizeWidth = ffop.getResizeWidth();
1402 this.resizeHeight = ffop.getResizeHeight();
1403 this.adjustRatio = ffop.isAdjustRatio();
1405 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1406 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1407 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1408 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1409 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1410 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1411 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1412 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1413 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1418 public String getExtOption() {
1419 return this.extOption;
1423 public String getInOption() {
1424 return this.inOption;
1428 public String getMainOption() {
1429 return this.mainOption;
1433 public String getOutOption() {
1434 return this.outOption;
1438 public String getAvfilterOption() {
1439 return this.avOption;
1443 public boolean isResize() {
1448 public int getResizeWidth() {
1449 return this.resizeWidth;
1453 public int getResizeHeight() {
1454 return this.resizeHeight;
1458 public boolean isAdjustRatio() {
1459 return this.adjustRatio;
1463 public String toString(){
1464 return ToStringBuilder.reflectionToString(this);
1468 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1471 public String getWord() {
1477 public String getId() {
1483 public String toString(){
1484 return ToStringBuilder.reflectionToString(this);