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 .addPreferredGap(ComponentPlacement.RELATED)
231 .addComponent(btnStop)
232 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
235 gl_pnlButton.setVerticalGroup(
236 gl_pnlButton.createParallelGroup(Alignment.LEADING)
237 .addGroup(gl_pnlButton.createSequentialGroup()
239 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
240 .addComponent(btnStop)
242 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
249 fldId = new IdComboBox(videoFileWatcher);
250 fldId.setToolTipText(ID_FIELD_TOOLTIP);
251 fldId.getEditorComponent().addActionListener(applyListener);
252 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
254 public void focusLost(java.awt.event.FocusEvent evt) {
255 idFieldFocusLost(evt);
259 lblVideo.setText("動画");
261 cbVideoLocal.setText("local");
262 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
264 public void itemStateChanged(java.awt.event.ItemEvent evt) {
265 useMovieLocalCheckBoxItemStateChanged(evt);
269 lblComment.setText("コメント");
271 cbCommentLocal.setText("local");
272 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
274 public void itemStateChanged(java.awt.event.ItemEvent evt) {
275 useMovieLocalCheckBoxItemStateChanged(evt);
279 lblOutput.setText("出力");
281 cbOutputEnable.setText("変換");
282 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
284 public void itemStateChanged(java.awt.event.ItemEvent evt) {
285 outputConvertCheckBoxItemStateChanged(evt);
290 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
291 pnlInputMain.setLayout(glInputMain);
292 glInputMain.setHorizontalGroup(
293 glInputMain.createParallelGroup(Alignment.LEADING)
294 .addGroup(glInputMain.createSequentialGroup()
297 .addPreferredGap(ComponentPlacement.RELATED)
298 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
299 .addPreferredGap(ComponentPlacement.UNRELATED)
300 .addComponent(cbBackLogReduce)
301 .addPreferredGap(ComponentPlacement.UNRELATED)
302 .addComponent(cbBackLog)
303 .addPreferredGap(ComponentPlacement.RELATED)
304 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
307 .addGroup(glInputMain.createSequentialGroup()
309 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
310 .addComponent(lblVideo)
311 .addComponent(lblComment)
312 .addComponent(lblOutput)
314 .addPreferredGap(ComponentPlacement.RELATED)
315 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
316 .addComponent(cbVideoLocal)
317 .addComponent(cbCommentLocal)
318 .addComponent(cbOutputEnable)
320 .addPreferredGap(ComponentPlacement.RELATED)
321 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
322 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
323 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
324 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
326 .addGroup(glInputMain.createParallelGroup()
327 .addComponent(btnVideo)
328 .addComponent(btnComment)
334 glInputMain.setVerticalGroup(
335 glInputMain.createParallelGroup(Alignment.LEADING)
336 .addGroup(glInputMain.createSequentialGroup()
338 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
339 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
341 .addComponent(cbBackLogReduce)
342 .addComponent(cbBackLog)
343 .addComponent(fldBackLog)
345 .addPreferredGap(ComponentPlacement.RELATED)
346 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
347 .addComponent(lblVideo)
348 .addComponent(cbVideoLocal)
349 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
350 .addComponent(btnVideo)
352 .addPreferredGap(ComponentPlacement.RELATED)
353 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
354 .addComponent(lblComment)
355 .addComponent(cbCommentLocal)
356 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
357 .addComponent(btnComment)
359 .addPreferredGap(ComponentPlacement.RELATED)
360 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
361 .addComponent(lblOutput)
362 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
363 .addComponent(cbOutputEnable)
369 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
370 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
371 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
372 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
375 public void actionPerformed(ActionEvent e) {
376 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
377 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
378 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
379 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
380 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
381 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
382 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
385 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
388 public void itemStateChanged(ItemEvent e) {
389 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
390 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
391 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
392 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
395 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
398 public void propertyChange(PropertyChangeEvent evt) {
399 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
400 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
401 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
402 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
403 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
408 tbpInput.add("メイン", pnlInputMain);
409 tbpInput.add("ffmpeg", pnlInputFfmpeg);
412 fldInputMessage.setEditable(false);
413 fldInputMessage.setEnabled(false);
414 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
416 final JPanel pnlInputButton = new JPanel();
417 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
418 pnlInputButton.setLayout(glInputButton);
419 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
421 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
422 .addPreferredGap(ComponentPlacement.UNRELATED)
423 .addComponent(btnClear)
424 .addPreferredGap(ComponentPlacement.UNRELATED)
425 .addComponent(btnApply)
428 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
430 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
431 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
432 .addComponent(btnClear)
433 .addComponent(btnApply)
439 final JPanel pnlInputAll = new JPanel();
440 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
441 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
442 pnlInputAll.setLayout(glInputAll);
443 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
444 .addComponent(tbpInput)
445 .addComponent(pnlInputButton)
447 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
448 .addComponent(tbpInput)
449 .addComponent(pnlInputButton)
452 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
453 pnlMain.setLayout(gl_pnlMain);
454 gl_pnlMain.setHorizontalGroup(
455 gl_pnlMain.createParallelGroup(Alignment.LEADING)
456 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
458 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
459 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
460 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
461 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
465 gl_pnlMain.setVerticalGroup(
466 gl_pnlMain.createParallelGroup(Alignment.LEADING)
467 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
469 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
470 .addPreferredGap(ComponentPlacement.RELATED)
471 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
472 .addPreferredGap(ComponentPlacement.RELATED)
473 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
479 JMenuBar menuBar = initMenuBar();
480 setJMenuBar(menuBar);
482 GroupLayout layout = new GroupLayout(getContentPane());
483 getContentPane().setLayout(layout);
484 layout.setHorizontalGroup(
485 layout.createParallelGroup(Alignment.LEADING)
486 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
488 layout.setVerticalGroup(
489 layout.createParallelGroup(Alignment.LEADING)
490 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
494 setMinimumSize(getSize());
497 * 画面のサイズや位置を前回終了時のものに設定する
499 final int windowWidth = p.getSystemWindowWidth();
500 final int windowHeight = p.getSystemWindowHeight();
501 if (windowWidth > 0 && windowHeight > 0) {
502 setSize(windowWidth, windowHeight);
505 // TODO 最大化した状態で終了した場合の考慮
506 final int windowPosX = p.getSystemWindowPosX();
507 final int windowPosY = p.getSystemWindowPosY();
508 if (windowPosX > 1024 && windowPosY > 1024) {
509 setLocation(windowPosX, windowPosY);
511 setLocationByPlatform(true);
514 final int colId = p.getSystemColumnId();
516 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
518 final int colStatus = p.getSystemColumnStatus();
520 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
524 pnlMain.setTransferHandler(new DownloadListTransferHandler());
525 tblDisplay.setTransferHandler(new TableTransferHandler());
528 public void startWatcher() {
529 videoFileWatcherThread.start();
532 private class GuiTaskManageListener implements TaskManageListener {
535 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
536 final String message) {
537 SwingUtilities.invokeLater(new Runnable() {
541 targetModel.setStatus(id, kind, status, percentage, message);
547 private class StopActionListener implements ActionListener {
550 public void actionPerformed(ActionEvent e) {
551 final int row = tblDisplay.getSelectedRow();
552 final Target t = targetModel.getTarget(row);
553 final boolean res = taskManager.cancel(t.getRowId());
554 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
556 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
561 private class ApplyActionListener implements ActionListener {
564 public void actionPerformed(ActionEvent e) {
566 final DownloadProfile downProf = new InqubusDownloadProfile();
567 final String id = Util.getVideoId(fldId.getText());
568 final InqubusConvertProfile convProf = new InqubusConvertProfile();
569 logger.log(Level.INFO, downProf.toString());
570 logger.log(Level.INFO, convProf.toString());
571 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
573 targetModel.addTarget(new Target(rp));
575 } catch (Throwable th) {
576 logger.log(Level.SEVERE, null, th);
577 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
582 private File searchFileMatchId(final File dir, final String id) {
583 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
588 final File[] lists = dir.listFiles(new FilenameFilter() {
590 final Pattern pattern = Pattern.compile(id + "\\D");
593 public boolean accept(File dir, String name) {
594 return pattern.matcher(name).find();
598 if (lists.length == 1) {
600 } else if (lists.length > 1) {
601 throw new UnsupportedOperationException();
608 * 動画, コメントの"local"チェックボックス更新時の処理.
610 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
611 final Config p = Config.INSTANCE;
613 final ItemSelectable source = evt.getItemSelectable();
618 if (source == cbVideoLocal) {
621 dir = new File(p.getVideoDir());
625 dir = new File(p.getCommentDir());
628 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
630 button.setEnabled(useLocal);
634 final File f = searchFileMatchId(dir, fldId.getText());
641 text = p.getVideoFileNamePattern();
645 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
647 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
648 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
649 fldOutput.setEnabled(convert);
650 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
652 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
653 final Config p = Config.INSTANCE;
654 final String id = fldId.getText();
659 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
660 final File dir = new File(p.getVideoDir());
661 final File file = searchFileMatchId(dir, id);
663 fldVideo.setText(file.getPath());
667 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
668 final File dir = new File(p.getCommentDir());
669 final File file = searchFileMatchId(dir, id);
671 fldComment.setText(file.getPath());
675 }//GEN-LAST:event_idFieldFocusLost
676 // Variables declaration - do not modify//GEN-BEGIN:variables
677 private final JTable tblDisplay;
679 private final JButton btnStop = new JButton("停止");
681 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
683 private final IdComboBox fldId;
684 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
685 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
686 private final JTextField fldBackLog = new JTextField();
687 private final JCheckBox cbVideoLocal;
688 private final JTextField fldVideo;
689 private final JButton btnVideo = new JButton("...");
690 private final JCheckBox cbCommentLocal;
691 private final JTextField fldComment;
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);