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 cmbVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
159 btnVideo.addActionListener(
160 new FileChooseAction(MainFrame.this, JFileChooser.FILES_ONLY, fldVideo));
161 final JLabel lblComment = new JLabel();
163 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
164 cbBackLog.addItemListener(new ItemListener() {
167 public void itemStateChanged(ItemEvent e) {
168 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
169 fldBackLog.setEnabled(selected);
172 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
175 public void propertyChange(PropertyChangeEvent evt) {
176 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
177 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
178 fldBackLog.setEnabled(fldEnabled);
181 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
183 cbCommentLocal = new JCheckBox();
184 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
185 cbCommentLocal.addItemListener(new ItemListener() {
188 public void itemStateChanged(ItemEvent e) {
189 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
190 cbBackLogReduce.setEnabled(!selected);
191 cbBackLog.setEnabled(!selected);
194 cmbComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
195 btnComment.addActionListener(
196 new FileChooseAction(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
197 final JLabel lblOutput = new JLabel();
198 cbOutputEnable = new JCheckBox();
199 fldOutput = new JTextField();
200 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
202 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
204 btnStop.addActionListener(new StopActionListener());
205 final ApplyActionListener applyListener = new ApplyActionListener();
206 btnApply.addActionListener(applyListener);
207 btnClear.addActionListener(new ActionListener() {
210 public void actionPerformed(ActionEvent e) {
215 pnlMain.setBorder(BorderFactory.createEtchedBorder());
217 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
218 scrDisplay.setViewportView(tblDisplay);
220 pnlButton.setBorder(BorderFactory.createEtchedBorder());
222 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
223 pnlButton.setLayout(gl_pnlButton);
224 gl_pnlButton.setHorizontalGroup(
225 gl_pnlButton.createParallelGroup(Alignment.LEADING)
226 .addGroup(gl_pnlButton.createSequentialGroup()
228 .addPreferredGap(ComponentPlacement.RELATED)
229 .addComponent(btnStop)
230 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
233 gl_pnlButton.setVerticalGroup(
234 gl_pnlButton.createParallelGroup(Alignment.LEADING)
235 .addGroup(gl_pnlButton.createSequentialGroup()
237 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
238 .addComponent(btnStop)
240 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
247 fldId = new IdComboBox(videoFileWatcher);
248 fldId.setToolTipText(ID_FIELD_TOOLTIP);
249 fldId.getEditorComponent().addActionListener(applyListener);
250 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
252 public void focusLost(java.awt.event.FocusEvent evt) {
253 idFieldFocusLost(evt);
257 lblVideo.setText("動画");
259 cbVideoLocal.setText("local");
260 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
262 public void itemStateChanged(java.awt.event.ItemEvent evt) {
263 useMovieLocalCheckBoxItemStateChanged(evt);
267 lblComment.setText("コメント");
269 cbCommentLocal.setText("local");
270 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
272 public void itemStateChanged(java.awt.event.ItemEvent evt) {
273 useMovieLocalCheckBoxItemStateChanged(evt);
277 lblOutput.setText("出力");
279 cbOutputEnable.setText("変換");
280 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
282 public void itemStateChanged(java.awt.event.ItemEvent evt) {
283 outputConvertCheckBoxItemStateChanged(evt);
288 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
289 pnlInputMain.setLayout(glInputMain);
290 glInputMain.setHorizontalGroup(
291 glInputMain.createParallelGroup(Alignment.LEADING)
292 .addGroup(glInputMain.createSequentialGroup()
295 .addPreferredGap(ComponentPlacement.RELATED)
296 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
297 .addPreferredGap(ComponentPlacement.UNRELATED)
298 .addComponent(cbBackLogReduce)
299 .addPreferredGap(ComponentPlacement.UNRELATED)
300 .addComponent(cbBackLog)
301 .addPreferredGap(ComponentPlacement.RELATED)
302 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
305 .addGroup(glInputMain.createSequentialGroup()
307 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
308 .addComponent(lblVideo)
309 .addComponent(lblComment)
310 .addComponent(lblOutput)
312 .addPreferredGap(ComponentPlacement.RELATED)
313 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
314 .addComponent(cbVideoLocal)
315 .addComponent(cbCommentLocal)
316 .addComponent(cbOutputEnable)
318 .addPreferredGap(ComponentPlacement.RELATED)
319 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
320 .addComponent(cmbVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
321 .addComponent(cmbComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
322 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
324 .addGroup(glInputMain.createParallelGroup()
325 .addComponent(btnVideo)
326 .addComponent(btnComment)
332 glInputMain.setVerticalGroup(
333 glInputMain.createParallelGroup(Alignment.LEADING)
334 .addGroup(glInputMain.createSequentialGroup()
336 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
337 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
339 .addComponent(cbBackLogReduce)
340 .addComponent(cbBackLog)
341 .addComponent(fldBackLog)
343 .addPreferredGap(ComponentPlacement.RELATED)
344 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
345 .addComponent(lblVideo)
346 .addComponent(cbVideoLocal)
347 .addComponent(cmbVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
348 .addComponent(btnVideo)
350 .addPreferredGap(ComponentPlacement.RELATED)
351 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
352 .addComponent(lblComment)
353 .addComponent(cbCommentLocal)
354 .addComponent(cmbComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
355 .addComponent(btnComment)
357 .addPreferredGap(ComponentPlacement.RELATED)
358 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
359 .addComponent(lblOutput)
360 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
361 .addComponent(cbOutputEnable)
367 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
368 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
369 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
370 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
373 public void actionPerformed(ActionEvent e) {
374 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
375 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
376 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
377 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
378 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
379 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
380 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
383 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
386 public void itemStateChanged(ItemEvent e) {
387 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
388 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
389 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
390 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
393 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
396 public void propertyChange(PropertyChangeEvent evt) {
397 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
398 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
399 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
400 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
401 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
406 tbpInput.add("メイン", pnlInputMain);
407 tbpInput.add("ffmpeg", pnlInputFfmpeg);
410 fldInputMessage.setEditable(false);
411 fldInputMessage.setEnabled(false);
412 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
414 final JPanel pnlInputButton = new JPanel();
415 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
416 pnlInputButton.setLayout(glInputButton);
417 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
419 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
420 .addPreferredGap(ComponentPlacement.UNRELATED)
421 .addComponent(btnClear)
422 .addPreferredGap(ComponentPlacement.UNRELATED)
423 .addComponent(btnApply)
426 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
428 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
429 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
430 .addComponent(btnClear)
431 .addComponent(btnApply)
437 final JPanel pnlInputAll = new JPanel();
438 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
439 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
440 pnlInputAll.setLayout(glInputAll);
441 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
442 .addComponent(tbpInput)
443 .addComponent(pnlInputButton)
445 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
446 .addComponent(tbpInput)
447 .addComponent(pnlInputButton)
450 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
451 pnlMain.setLayout(gl_pnlMain);
452 gl_pnlMain.setHorizontalGroup(
453 gl_pnlMain.createParallelGroup(Alignment.LEADING)
454 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
456 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
457 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
458 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
459 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
463 gl_pnlMain.setVerticalGroup(
464 gl_pnlMain.createParallelGroup(Alignment.LEADING)
465 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
467 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
468 .addPreferredGap(ComponentPlacement.RELATED)
469 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
470 .addPreferredGap(ComponentPlacement.RELATED)
471 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
477 JMenuBar menuBar = initMenuBar();
478 setJMenuBar(menuBar);
480 GroupLayout layout = new GroupLayout(getContentPane());
481 getContentPane().setLayout(layout);
482 layout.setHorizontalGroup(
483 layout.createParallelGroup(Alignment.LEADING)
484 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
486 layout.setVerticalGroup(
487 layout.createParallelGroup(Alignment.LEADING)
488 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
492 setMinimumSize(getSize());
495 * 画面のサイズや位置を前回終了時のものに設定する
497 final int windowWidth = p.getSystemWindowWidth();
498 final int windowHeight = p.getSystemWindowHeight();
499 if (windowWidth > 0 && windowHeight > 0) {
500 setSize(windowWidth, windowHeight);
503 // TODO 最大化した状態で終了した場合の考慮
504 final int windowPosX = p.getSystemWindowPosX();
505 final int windowPosY = p.getSystemWindowPosY();
506 if (windowPosX > 1024 && windowPosY > 1024) {
507 setLocation(windowPosX, windowPosY);
509 setLocationByPlatform(true);
512 final int colId = p.getSystemColumnId();
514 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
516 final int colStatus = p.getSystemColumnStatus();
518 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
522 pnlMain.setTransferHandler(new DownloadListTransferHandler());
523 tblDisplay.setTransferHandler(new TableTransferHandler());
526 public void startWatcher() {
527 videoFileWatcherThread.start();
530 private class GuiTaskManageListener implements TaskManageListener {
533 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
534 final String message) {
535 SwingUtilities.invokeLater(new Runnable() {
539 targetModel.setStatus(id, kind, status, percentage, message);
545 private class StopActionListener implements ActionListener {
548 public void actionPerformed(ActionEvent e) {
549 final int row = tblDisplay.getSelectedRow();
550 final Target t = targetModel.getTarget(row);
551 final boolean res = taskManager.cancel(t.getRowId());
552 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
554 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
559 private class ApplyActionListener implements ActionListener {
562 public void actionPerformed(ActionEvent e) {
564 final DownloadProfile downProf = new InqubusDownloadProfile();
565 final String id = Util.getVideoId(fldId.getText());
566 final InqubusConvertProfile convProf = new InqubusConvertProfile();
567 logger.log(Level.INFO, downProf.toString());
568 logger.log(Level.INFO, convProf.toString());
569 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
571 targetModel.addTarget(new Target(rp));
573 } catch (Throwable th) {
574 logger.log(Level.SEVERE, null, th);
575 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
580 private File searchFileMatchId(final File dir, final String id) {
581 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
586 final File[] lists = dir.listFiles(new FilenameFilter() {
588 final Pattern pattern = Pattern.compile(id + "\\D");
591 public boolean accept(File dir, String name) {
592 return pattern.matcher(name).find();
596 if (lists.length == 1) {
598 } else if (lists.length > 1) {
599 throw new UnsupportedOperationException();
606 * 動画, コメントの"local"チェックボックス更新時の処理.
608 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
609 final Config p = Config.INSTANCE;
611 final ItemSelectable source = evt.getItemSelectable();
616 if (source == cbVideoLocal) {
619 dir = new File(p.getVideoDir());
623 dir = new File(p.getCommentDir());
626 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
628 button.setEnabled(useLocal);
632 final File f = searchFileMatchId(dir, fldId.getText());
639 text = p.getVideoFileNamePattern();
643 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
645 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
646 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
647 fldOutput.setEnabled(convert);
648 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
650 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
651 final Config p = Config.INSTANCE;
652 final String id = fldId.getText();
657 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
658 final File dir = new File(p.getVideoDir());
659 final File file = searchFileMatchId(dir, id);
661 fldVideo.setText(file.getPath());
665 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
666 final File dir = new File(p.getCommentDir());
667 final File file = searchFileMatchId(dir, id);
669 fldComment.setText(file.getPath());
673 }//GEN-LAST:event_idFieldFocusLost
674 // Variables declaration - do not modify//GEN-BEGIN:variables
675 private final JTable tblDisplay;
677 private final JButton btnStop = new JButton("停止");
679 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
681 private final IdComboBox fldId;
682 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
683 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
684 private final JTextField fldBackLog = new JTextField();
685 private final JCheckBox cbVideoLocal;
686 private final FileComboBox cmbVideo = new FileComboBox();
687 private final JTextField fldVideo = cmbVideo.getEditorComponent();
688 private final JButton btnVideo = new JButton("...");
689 private final JCheckBox cbCommentLocal;
690 private final FileComboBox cmbComment = new FileComboBox();
691 private final JTextField fldComment = cmbComment.getEditorComponent();
692 private final JButton btnComment = new JButton("...");
693 private final JCheckBox cbOutputEnable;
694 private final JTextField fldOutput;
696 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
698 private final JTextField fldInputMessage = new JTextField();
699 private final JButton btnClear = new JButton("クリア");
700 private final JButton btnApply = new JButton("適用");
701 // End of variables declaration//GEN-END:variables
703 private void initInputPanel() {
706 tbpInput.setSelectedIndex(0);
707 fldId.requestFocus();
710 private void initMainTab() {
711 final Config p = Config.INSTANCE;
714 fldBackLog.setEnabled(false);
715 cbBackLog.setEnabled(true);
717 final boolean videoLocal = p.getVideoUseLocal();
718 cbVideoLocal.setSelected(videoLocal);
720 fldVideo.setText(p.getVideoFileNamePattern());
722 btnVideo.setEnabled(videoLocal);
724 final boolean commentLocal = p.getCommentUseLocal();
725 cbCommentLocal.setSelected(commentLocal);
727 fldComment.setText(p.getCommentFileNamePattern());
729 btnComment.setEnabled(commentLocal);
731 final boolean convert = p.getOutputEnable();
732 cbOutputEnable.setSelected(convert);
733 fldOutput.setEnabled(convert);
734 fldOutput.setText(p.getOutputFileNamePattern());
737 private void initFfmpegTab() {
738 pnlInputFfmpeg.init(Config.INSTANCE);
741 private JMenuBar initMenuBar() {
742 final JMenuBar menuBar = new JMenuBar();
744 final JMenu mnFile = new JMenu("ファイル(F)");
747 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
748 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
749 itExit.addActionListener(new ActionListener() {
752 public void actionPerformed(ActionEvent e) {
753 throw new UnsupportedOperationException("Not supported yet.");
758 final JMenu mnTool = new JMenu("ツール(T)");
761 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
763 itOption.addActionListener(new ActionListener() {
766 public void actionPerformed(ActionEvent e) {
767 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
768 dlg.setLocationRelativeTo(MainFrame.this);
770 dlg.setVisible(true);
773 mnTool.add(itOption);
775 final JMenu mnHelp = new JMenu("ヘルプ(H)");
778 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
779 itAbout.addActionListener(new ActionListener() {
782 public void actionPerformed(ActionEvent e) {
783 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
785 dlg.setLocationRelativeTo(MainFrame.this);
787 dlg.setVisible(true);
795 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
798 public void process(DownloadProgress progress) {
799 throw new UnsupportedOperationException("Not supported yet.");
803 public void cancelled() {
804 throw new UnsupportedOperationException("Not supported yet.");
808 public void done(DownloadResult result) {
809 throw new UnsupportedOperationException("Not supported yet.");
813 public void error(Throwable th) {
814 throw new UnsupportedOperationException("Not supported yet.");
818 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
821 public void process(ConvertProgress progress) {
822 throw new UnsupportedOperationException("Not supported yet.");
826 public void cancelled() {
827 throw new UnsupportedOperationException("Not supported yet.");
831 public void done(ConvertResult result) {
832 throw new UnsupportedOperationException("Not supported yet.");
836 public void error(Throwable th) {
837 throw new UnsupportedOperationException("Not supported yet.");
843 private class DownloadListTransferHandler extends TransferHandler {
845 private static final long serialVersionUID = 1L;
846 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
849 public boolean canImport(TransferHandler.TransferSupport support) {
850 Transferable transferable = support.getTransferable();
851 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
852 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
859 public boolean importData(TransferHandler.TransferSupport support) {
861 // Transferable transferable = support.getTransferable();
862 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
863 // @SuppressWarnings("unchecked")
864 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
865 // Collection<Target> targets = Target.from(data);
866 // targetModel.addTarget(targets);
867 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
868 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
869 // Matcher matcher = movieIdPattern.matcher(data);
870 // if (matcher.find()) {
871 // String movieId = matcher.group(1);
872 // Target target = Target.fromId(movieId);
873 // targetModel.addTarget(target);
880 // } catch (Exception e) {
881 // logger.log(Level.SEVERE, null, e);
884 // TODO 上記実装見直し(Locationは削除された)
889 private class TableTransferHandler extends DownloadListTransferHandler {
891 private static final long serialVersionUID = 1L;
894 public boolean canImport(TransferHandler.TransferSupport support) {
895 return super.canImport(support);
899 public boolean importData(TransferHandler.TransferSupport support) {
900 return super.importData(support);
904 private class MainFrameWindowListener extends WindowAdapter {
906 public void windowClosing(WindowEvent e) {
907 final Config p = Config.INSTANCE;
909 final Dimension size = getSize();
910 p.setSystemWindowWidth(size.width);
911 p.setSystemWindowHeight(size.height);
913 final Point pos = getLocation();
914 p.setSystemWindowPosX(pos.x);
915 p.setSystemWindowPosY(pos.y);
917 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
918 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
919 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
920 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
921 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
924 } catch (ConfigurationException ex) {
925 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
931 * ここからDownloadProfile作成用クラスの定義
934 private class InqubusDownloadProfile implements DownloadProfile {
936 private final LoginProfile loginProfile;
937 private final ProxyProfile proxyProfile;
938 private final VideoProfile videoProfile;
939 private final CommentProfile commentProfile;
940 private final GeneralProfile generalProfile;
942 private InqubusDownloadProfile() {
943 this.loginProfile = new InqubusLoginProfile();
944 this.proxyProfile = new InqubusProxyProfile();
945 this.videoProfile = new InqubusVideoProfile();
946 this.commentProfile = new InqubusCommentProfile();
947 this.generalProfile = new InqubusGeneralProfile();
951 public LoginProfile getLoginInfo() {
952 return this.loginProfile;
956 public ProxyProfile getProxyProfile() {
957 return this.proxyProfile;
961 public VideoProfile getVideoProfile() {
962 return this.videoProfile;
966 public CommentProfile getCommentProfile() {
967 return this.commentProfile;
971 public GeneralProfile getGeneralProfile() {
972 return this.generalProfile;
976 public String toString(){
977 return ToStringBuilder.reflectionToString(this);
981 private class InqubusLoginProfile implements LoginProfile {
982 private final String mail;
983 private final String password;
985 private InqubusLoginProfile(){
986 final Config p = Config.INSTANCE;
987 this.mail = p.getId();
988 this.password = p.getPassword();
992 public String getMail() {
997 public String getPassword() {
998 return this.password;
1002 public String toString(){
1003 return ToStringBuilder.reflectionToString(this);
1007 private class InqubusProxyProfile implements ProxyProfile {
1008 private final boolean use;
1009 private final String host;
1010 private final int port;
1012 private InqubusProxyProfile(){
1013 final Config p = Config.INSTANCE;
1014 this.use = p.getProxyUse();
1015 this.host = p.getProxyHost();
1016 final String pp = p.getProxyPort();
1017 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
1021 public boolean use() {
1026 public String getHost() {
1031 public int getPort() {
1036 public String toString(){
1037 return ToStringBuilder.reflectionToString(this);
1041 private class InqubusVideoProfile implements VideoProfile {
1042 private final boolean download;
1043 private final File dir;
1044 private final String fileName;
1045 private final File localFile;
1047 private InqubusVideoProfile(){
1048 final Config p = Config.INSTANCE;
1049 this.download = !cbVideoLocal.isSelected();
1050 if (this.download) {
1051 this.dir = new File(p.getVideoDir());
1052 this.fileName = fldVideo.getText();
1053 this.localFile = null;
1056 this.fileName = null;
1057 this.localFile = new File(fldVideo.getText());
1062 public boolean isDownload() {
1063 return this.download;
1067 public File getDir() {
1072 public String getFileName() {
1073 return this.fileName;
1077 public File getLocalFile() {
1078 return this.localFile;
1082 public String toString(){
1083 return ToStringBuilder.reflectionToString(this);
1087 private class InqubusCommentProfile implements CommentProfile {
1088 private final boolean download;
1089 private final File dir;
1090 private final String fileName;
1091 private final File localFile;
1092 private final int lengthRelatedCommentSize;
1093 private final boolean disablePerMinComment;
1094 private final int perMinCommentSize;
1095 private final long backLogPoint;
1097 private InqubusCommentProfile() {
1098 final Config p = Config.INSTANCE;
1099 this.download = !cbCommentLocal.isSelected();
1100 if (this.download) {
1101 this.dir = new File(p.getCommentDir());
1102 this.fileName = fldComment.getText();
1103 this.localFile = null;
1106 this.fileName = null;
1107 this.localFile = new File(fldComment.getText());
1110 if(cbBackLog.isSelected()) {
1112 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
1113 } catch (IOException ex) {
1114 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
1117 this.backLogPoint = -1L;
1120 this.disablePerMinComment = cbBackLogReduce.isSelected();
1121 this.lengthRelatedCommentSize
1122 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1123 this.perMinCommentSize
1124 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1128 public boolean isDownload() {
1129 return this.download;
1133 public File getDir() {
1138 public String getFileName() {
1139 return this.fileName;
1143 public File getLocalFile() {
1144 return this.localFile;
1148 public int getLengthRelatedCommentSize() {
1149 return this.lengthRelatedCommentSize;
1153 public boolean isDisablePerMinComment() {
1154 return this.disablePerMinComment;
1158 public int getPerMinCommentSize() {
1159 return this.perMinCommentSize;
1163 public long getBackLogPoint() {
1164 return this.backLogPoint;
1168 public String toString(){
1169 return ToStringBuilder.reflectionToString(this);
1173 private class InqubusGeneralProfile implements GeneralProfile {
1174 private final String replaceFrom;
1175 private final String replaceTo;
1176 private InqubusGeneralProfile() {
1177 final Config p = Config.INSTANCE;
1178 this.replaceFrom = p.getReplaceFrom();
1179 this.replaceTo = p.getReplaceTo();
1183 public String getReplaceFrom() {
1184 return this.replaceFrom;
1188 public String getReplaceTo() {
1189 return this.replaceTo;
1193 public String toString(){
1194 return ToStringBuilder.reflectionToString(this);
1199 * ここからConvertProfile作成用クラスの定義
1201 private class InqubusConvertProfile implements ConvertProfile {
1202 private final OutputProfile outputProfile;
1203 private final GeneralProfile generalProfile;
1204 private final FfmpegProfile ffmpegProfile;
1205 private final boolean convert;
1206 private final File ffmpeg;
1207 private final boolean vhookDisabled;
1208 private final boolean commentOverlay;
1209 private final File vhook;
1210 private final File tmpDir;
1211 private final File font;
1212 private final int fontIndex;
1213 private final boolean commentOpaque;
1214 private final boolean disableFontSizeArrange;
1215 private final int shadowIndex;
1216 private final boolean showConvrting;
1217 private final int maxNumOfComment;
1218 private final HideCondition ngSetting;
1220 private InqubusConvertProfile() throws IOException {
1221 final Config p = Config.INSTANCE;
1222 this.outputProfile = new InqubusOutputProfile();
1223 this.generalProfile = new InqubusGeneralProfile();
1224 this.ffmpegProfile = new InqubusFfmpegProfile();
1225 this.convert = cbOutputEnable.isSelected();
1226 this.ffmpeg = new File(p.getFfmpegPath());
1228 this.vhookDisabled = false;
1229 this.commentOverlay = p.getOutputCommentOverlay();
1230 this.vhook = new File(p.getFfmpegDllPath());
1231 this.tmpDir = new File(p.getSystemTempDir());
1232 this.font = new File(p.getFontPath());
1233 this.fontIndex = Integer.parseInt(p.getFontIndex());
1234 this.commentOpaque = p.getCommentOpaque();
1235 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1236 this.shadowIndex = p.getFontShadow();
1238 this.showConvrting = true;
1239 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1240 getCommentDisplaySizeManual());
1241 this.ngSetting = new InqubusHideCondition();
1245 public OutputProfile getOutputProfile() {
1246 return this.outputProfile;
1250 public GeneralProfile getGeneralProfile() {
1251 return this.generalProfile;
1255 public FfmpegProfile getFfmpegOption() {
1256 return this.ffmpegProfile;
1260 public boolean isConvert() {
1261 return this.convert;
1265 public File getFfmpeg() {
1270 public boolean isVhookDisabled() {
1271 return this.vhookDisabled;
1275 public boolean isCommentOverlay() {
1276 return this.commentOverlay;
1280 public File getVhook() {
1285 public File getTempDir() {
1290 public File getFont() {
1295 public int getFontIndex() {
1296 return this.fontIndex;
1300 public boolean isCommentOpaque() {
1301 return this.commentOpaque;
1305 public boolean isDisableFontSizeArrange() {
1306 return this.disableFontSizeArrange;
1310 public int getShadowIndex() {
1311 return this.shadowIndex;
1315 public boolean isShowConverting() {
1316 return this.showConvrting;
1320 public int getMaxNumOfComment() {
1321 return this.maxNumOfComment;
1325 public HideCondition getNgSetting() {
1326 return this.ngSetting;
1330 public String toString(){
1331 return ToStringBuilder.reflectionToString(this);
1335 private class InqubusOutputProfile implements OutputProfile {
1336 private final File dir;
1337 private final String fileName;
1338 private final String videoId;
1339 private final String title;
1342 private InqubusOutputProfile(){
1343 final Config p = Config.INSTANCE;
1344 this.dir = new File(p.getOutputDir());
1345 this.fileName = fldOutput.getText();
1346 // TODO この時点でのID/Titleはどうするか…
1352 public File getDir() {
1357 public String getFileName() {
1358 return this.fileName;
1362 public String getVideoId() {
1363 return this.videoId;
1367 public String getTitile() {
1372 public String toString(){
1373 return ToStringBuilder.reflectionToString(this);
1377 private class InqubusFfmpegProfile implements FfmpegProfile {
1378 private final String extOption;
1379 private final String inOption;
1380 private final String mainOption;
1381 private final String outOption;
1382 private final String avOption;
1383 private final boolean resize;
1384 private final int resizeWidth;
1385 private final int resizeHeight;
1386 private final boolean adjustRatio;
1388 private InqubusFfmpegProfile() throws IOException {
1389 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1391 final FfmpegOption ffop = FfmpegOption.load(file);
1392 this.extOption = ffop.getExtOption();
1393 this.inOption = ffop.getInOption();
1394 this.mainOption = ffop.getMainOption();
1395 this.outOption = ffop.getMainOption();
1396 this.avOption = ffop.getAvfilterOption();
1397 this.resize = ffop.isResize();
1398 this.resizeWidth = ffop.getResizeWidth();
1399 this.resizeHeight = ffop.getResizeHeight();
1400 this.adjustRatio = ffop.isAdjustRatio();
1402 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1403 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1404 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1405 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1406 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1407 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1408 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1409 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1410 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1415 public String getExtOption() {
1416 return this.extOption;
1420 public String getInOption() {
1421 return this.inOption;
1425 public String getMainOption() {
1426 return this.mainOption;
1430 public String getOutOption() {
1431 return this.outOption;
1435 public String getAvfilterOption() {
1436 return this.avOption;
1440 public boolean isResize() {
1445 public int getResizeWidth() {
1446 return this.resizeWidth;
1450 public int getResizeHeight() {
1451 return this.resizeHeight;
1455 public boolean isAdjustRatio() {
1456 return this.adjustRatio;
1460 public String toString(){
1461 return ToStringBuilder.reflectionToString(this);
1465 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1468 public String getWord() {
1474 public String getId() {
1480 public String toString(){
1481 return ToStringBuilder.reflectionToString(this);