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.JFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuBar;
48 import javax.swing.JMenuItem;
49 import javax.swing.JOptionPane;
50 import javax.swing.JPanel;
51 import javax.swing.JScrollPane;
52 import javax.swing.JTabbedPane;
53 import javax.swing.JTable;
54 import javax.swing.JTextField;
55 import javax.swing.KeyStroke;
56 import javax.swing.LayoutStyle.ComponentPlacement;
57 import javax.swing.SwingUtilities;
58 import javax.swing.TransferHandler;
59 import javax.swing.WindowConstants;
60 import javax.swing.border.BevelBorder;
61 import org.apache.commons.configuration.ConfigurationException;
62 import org.apache.commons.lang.StringUtils;
63 import org.apache.commons.lang.builder.ToStringBuilder;
64 import saccubus.FfmpegOption;
65 import saccubus.MainFrame_AboutBox;
66 import saccubus.util.WayBackTimeParser;
67 import saccubus.worker.impl.convert.ConvertProgress;
68 import saccubus.worker.impl.download.DownloadProgress;
69 import saccubus.worker.WorkerListener;
70 import saccubus.worker.impl.convert.ConvertResult;
71 import saccubus.worker.impl.download.DownloadResult;
72 import saccubus.worker.profile.CommentProfile;
73 import saccubus.worker.profile.ConvertProfile;
74 import saccubus.worker.profile.DownloadProfile;
75 import saccubus.worker.profile.FfmpegProfile;
76 import saccubus.worker.profile.GeneralProfile;
77 import saccubus.worker.profile.LoginProfile;
78 import saccubus.worker.profile.OutputProfile;
79 import saccubus.worker.profile.ProxyProfile;
80 import saccubus.worker.profile.VideoProfile;
82 import yukihane.inqubus.Config;
83 import yukihane.inqubus.filewatch.FileWatch;
84 import yukihane.inqubus.manager.RequestProcess;
85 import yukihane.inqubus.manager.TaskKind;
86 import yukihane.inqubus.manager.TaskManage;
87 import yukihane.inqubus.manager.TaskManageListener;
88 import yukihane.inqubus.manager.TaskStatus;
89 import yukihane.inqubus.model.Target;
90 import yukihane.inqubus.model.TargetsTableModel;
96 public class MainFrame extends JFrame {
98 private static final long serialVersionUID = 1L;
99 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
100 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
101 private static final String FILE_LOCALBUTTON_TOOLTIP
102 = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
103 private static final String FILE_INPUTFIELD_TOOLTIP
104 = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
105 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
106 private static final String FILE_OUTPUTFIELD_TOOLTIP
108 private final TargetsTableModel targetModel = new TargetsTableModel();
109 private final TaskManage taskManager;
110 private final Thread videoFileWatcherThread;
111 private final FileWatch videoFileWatcher;
113 /** Creates new form MainFrame */
116 addWindowListener(new MainFrameWindowListener());
118 final Config p = Config.INSTANCE;
121 final int thDownload = p.getSystemDownloadThread();
122 final int secDownload = p.getSystemDownloadWait();
123 final int thConvert = p.getSystemConvertThread();
124 taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
126 // TODO ディレクトリ監視スレッド生成
127 final List<String> videoSearchDirs = p.getSearchVideoDirs();
128 videoSearchDirs.add(p.getVideoDir());
129 final FileSystem fs = FileSystems.getDefault();
130 final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
131 for (String s : videoSearchDirs) {
132 videoPaths.add(fs.getPath(s));
134 videoFileWatcher = new FileWatch(videoPaths);
135 this.videoFileWatcherThread = new Thread(videoFileWatcher);
136 this.videoFileWatcherThread.setDaemon(true);
138 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
139 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
140 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
141 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
142 final List<Image> images = new ArrayList<>(2);
145 setIconImages(images);
147 final JPanel pnlMain = new JPanel();
148 final JScrollPane scrDisplay = new JScrollPane();
149 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
150 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
151 final JPanel pnlButton = new JPanel();
152 final JTabbedPane tbpInput = new JTabbedPane();
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 final JLabel lblComment = new JLabel();
162 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
163 cbBackLog.addItemListener(new ItemListener() {
166 public void itemStateChanged(ItemEvent e) {
167 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
168 fldBackLog.setEnabled(selected);
171 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
174 public void propertyChange(PropertyChangeEvent evt) {
175 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
176 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
177 fldBackLog.setEnabled(fldEnabled);
180 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
182 cbCommentLocal = new JCheckBox();
183 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
184 cbCommentLocal.addItemListener(new ItemListener() {
187 public void itemStateChanged(ItemEvent e) {
188 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
189 cbBackLogReduce.setEnabled(!selected);
190 cbBackLog.setEnabled(!selected);
193 fldComment = new JTextField();
194 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
195 final JLabel lblOutput = new JLabel();
196 cbOutputEnable = new JCheckBox();
197 fldOutput = new JTextField();
198 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
200 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
202 btnStop.addActionListener(new StopActionListener());
203 final ApplyActionListener applyListener = new ApplyActionListener();
204 btnApply.addActionListener(applyListener);
206 pnlMain.setBorder(BorderFactory.createEtchedBorder());
208 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
209 scrDisplay.setViewportView(tblDisplay);
211 pnlButton.setBorder(BorderFactory.createEtchedBorder());
213 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
214 pnlButton.setLayout(gl_pnlButton);
215 gl_pnlButton.setHorizontalGroup(
216 gl_pnlButton.createParallelGroup(Alignment.LEADING)
217 .addGroup(gl_pnlButton.createSequentialGroup()
219 .addComponent(btnStart)
220 .addPreferredGap(ComponentPlacement.RELATED)
221 .addComponent(btnStop)
222 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
223 .addComponent(btnDeselect)
226 gl_pnlButton.setVerticalGroup(
227 gl_pnlButton.createParallelGroup(Alignment.LEADING)
228 .addGroup(gl_pnlButton.createSequentialGroup()
230 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
231 .addComponent(btnStart)
232 .addComponent(btnStop)
233 .addComponent(btnDeselect))
234 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
240 fldId = new IdComboBox(videoFileWatcher);
241 fldId.setToolTipText(ID_FIELD_TOOLTIP);
242 fldId.getEditorComponent().addActionListener(applyListener);
243 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
245 public void focusLost(java.awt.event.FocusEvent evt) {
246 idFieldFocusLost(evt);
250 lblVideo.setText("動画");
252 cbVideoLocal.setText("local");
253 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
255 public void itemStateChanged(java.awt.event.ItemEvent evt) {
256 useMovieLocalCheckBoxItemStateChanged(evt);
260 lblComment.setText("コメント");
262 cbCommentLocal.setText("local");
263 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
265 public void itemStateChanged(java.awt.event.ItemEvent evt) {
266 useMovieLocalCheckBoxItemStateChanged(evt);
270 lblOutput.setText("出力");
272 cbOutputEnable.setText("変換");
273 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
275 public void itemStateChanged(java.awt.event.ItemEvent evt) {
276 outputConvertCheckBoxItemStateChanged(evt);
281 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
282 pnlInputMain.setLayout(glInputMain);
283 glInputMain.setHorizontalGroup(
284 glInputMain.createParallelGroup(Alignment.LEADING)
285 .addGroup(glInputMain.createSequentialGroup()
288 .addPreferredGap(ComponentPlacement.RELATED)
289 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
290 .addPreferredGap(ComponentPlacement.UNRELATED)
291 .addComponent(cbBackLogReduce)
292 .addPreferredGap(ComponentPlacement.UNRELATED)
293 .addComponent(cbBackLog)
294 .addPreferredGap(ComponentPlacement.RELATED)
295 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
298 .addGroup(glInputMain.createSequentialGroup()
300 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
301 .addComponent(lblVideo)
302 .addComponent(lblComment)
303 .addComponent(lblOutput)
305 .addPreferredGap(ComponentPlacement.RELATED)
306 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
307 .addComponent(cbVideoLocal)
308 .addComponent(cbCommentLocal)
309 .addComponent(cbOutputEnable)
311 .addPreferredGap(ComponentPlacement.RELATED)
312 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
313 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
314 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
315 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
321 glInputMain.setVerticalGroup(
322 glInputMain.createParallelGroup(Alignment.LEADING)
323 .addGroup(glInputMain.createSequentialGroup()
325 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
326 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
328 .addComponent(cbBackLogReduce)
329 .addComponent(cbBackLog)
330 .addComponent(fldBackLog)
332 .addPreferredGap(ComponentPlacement.RELATED)
333 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
334 .addComponent(lblVideo)
335 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
336 .addComponent(cbVideoLocal))
337 .addPreferredGap(ComponentPlacement.RELATED)
338 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
339 .addComponent(lblComment)
340 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
341 .addComponent(cbCommentLocal))
342 .addPreferredGap(ComponentPlacement.RELATED)
343 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
344 .addComponent(lblOutput)
345 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
346 .addComponent(cbOutputEnable)
352 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
353 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
354 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
355 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
358 public void actionPerformed(ActionEvent e) {
359 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
360 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
361 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
362 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
363 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
364 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
365 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
368 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
371 public void itemStateChanged(ItemEvent e) {
372 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
373 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
374 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
375 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
378 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
381 public void propertyChange(PropertyChangeEvent evt) {
382 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
383 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
384 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
385 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
386 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
391 tbpInput.add("メイン", pnlInputMain);
392 tbpInput.add("ffmpeg", pnlInputFfmpeg);
395 fldInputMessage.setEditable(false);
396 fldInputMessage.setEnabled(false);
397 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
399 final JPanel pnlInputButton = new JPanel();
400 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
401 pnlInputButton.setLayout(glInputButton);
402 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
404 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
405 .addPreferredGap(ComponentPlacement.UNRELATED)
406 .addComponent(btnApply)
409 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
411 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
412 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
413 .addComponent(btnApply)
419 final JPanel pnlInputAll = new JPanel();
420 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
421 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
422 pnlInputAll.setLayout(glInputAll);
423 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
424 .addComponent(tbpInput)
425 .addComponent(pnlInputButton)
427 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
428 .addComponent(tbpInput)
429 .addComponent(pnlInputButton)
432 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
433 pnlMain.setLayout(gl_pnlMain);
434 gl_pnlMain.setHorizontalGroup(
435 gl_pnlMain.createParallelGroup(Alignment.LEADING)
436 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
438 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
439 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
440 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
441 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
445 gl_pnlMain.setVerticalGroup(
446 gl_pnlMain.createParallelGroup(Alignment.LEADING)
447 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
449 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
450 .addPreferredGap(ComponentPlacement.RELATED)
451 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
452 .addPreferredGap(ComponentPlacement.RELATED)
453 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
459 JMenuBar menuBar = initMenuBar();
460 setJMenuBar(menuBar);
462 GroupLayout layout = new GroupLayout(getContentPane());
463 getContentPane().setLayout(layout);
464 layout.setHorizontalGroup(
465 layout.createParallelGroup(Alignment.LEADING)
466 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
468 layout.setVerticalGroup(
469 layout.createParallelGroup(Alignment.LEADING)
470 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
476 * 画面のサイズや位置を前回終了時のものに設定する
478 final int windowWidth = p.getSystemWindowWidth();
479 final int windowHeight = p.getSystemWindowHeight();
480 if (windowWidth > 0 && windowHeight > 0) {
481 setSize(windowWidth, windowHeight);
484 final int windowPosX = p.getSystemWindowPosX();
485 final int windowPosY = p.getSystemWindowPosY();
486 if (windowPosX > 0 && windowPosY > 0) {
487 setLocation(windowPosX, windowPosY);
489 setLocationByPlatform(true);
492 final int colId = p.getSystemColumnId();
494 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
496 final int colStatus = p.getSystemColumnStatus();
498 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
502 pnlMain.setTransferHandler(new DownloadListTransferHandler());
503 tblDisplay.setTransferHandler(new TableTransferHandler());
506 public void startWatcher() {
507 videoFileWatcherThread.start();
510 private class GuiTaskManageListener implements TaskManageListener {
513 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
514 final String message) {
515 SwingUtilities.invokeLater(new Runnable() {
519 targetModel.setStatus(id, kind, status, percentage, message);
525 private class StopActionListener implements ActionListener {
528 public void actionPerformed(ActionEvent e) {
529 final int row = tblDisplay.getSelectedRow();
530 final Target t = targetModel.getTarget(row);
531 final boolean res = taskManager.cancel(t.getRowId());
532 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
534 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
539 private class ApplyActionListener implements ActionListener {
542 public void actionPerformed(ActionEvent e) {
544 final DownloadProfile downProf = new InqubusDownloadProfile();
545 final String id = Util.getVideoId(fldId.getText());
546 final InqubusConvertProfile convProf = new InqubusConvertProfile();
547 logger.log(Level.INFO, downProf.toString());
548 logger.log(Level.INFO, convProf.toString());
549 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
551 targetModel.addTarget(new Target(rp));
553 } catch (Throwable th) {
554 logger.log(Level.SEVERE, null, th);
555 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
560 private File searchFileMatchId(final File dir, final String id) {
561 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
566 final File[] lists = dir.listFiles(new FilenameFilter() {
568 final Pattern pattern = Pattern.compile(id + "\\D");
571 public boolean accept(File dir, String name) {
572 return pattern.matcher(name).find();
576 if (lists.length == 1) {
578 } else if (lists.length > 1) {
579 throw new UnsupportedOperationException();
586 * 動画, コメントの"local"チェックボックス更新時の処理.
588 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
589 final Config p = Config.INSTANCE;
591 final ItemSelectable source = evt.getItemSelectable();
595 if (source == cbVideoLocal) {
597 dir = new File(p.getVideoDir());
600 dir = new File(p.getCommentDir());
603 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
607 final File f = searchFileMatchId(dir, fldId.getText());
614 text = p.getVideoFileNamePattern();
618 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
620 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
621 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
622 fldOutput.setEnabled(convert);
623 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
625 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
626 final Config p = Config.INSTANCE;
627 final String id = fldId.getText();
632 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
633 final File dir = new File(p.getVideoDir());
634 final File file = searchFileMatchId(dir, id);
636 fldVideo.setText(file.getPath());
640 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
641 final File dir = new File(p.getCommentDir());
642 final File file = searchFileMatchId(dir, id);
644 fldComment.setText(file.getPath());
648 }//GEN-LAST:event_idFieldFocusLost
649 // Variables declaration - do not modify//GEN-BEGIN:variables
650 private final JTable tblDisplay;
652 private final JButton btnStart = new JButton("開始");
653 private final JButton btnStop = new JButton("停止");
654 private final JButton btnDeselect = new JButton("選択解除");
656 private final IdComboBox fldId;
657 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
658 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
659 private final JTextField fldBackLog = new JTextField();
660 private final JCheckBox cbVideoLocal;
661 private final JTextField fldVideo;
662 private final JCheckBox cbCommentLocal;
663 private final JTextField fldComment;
664 private final JCheckBox cbOutputEnable;
665 private final JTextField fldOutput;
667 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
669 private final JTextField fldInputMessage = new JTextField();
670 private final JButton btnApply = new JButton("適用");
671 // End of variables declaration//GEN-END:variables
673 private void initInputPanel() {
678 private void initMainTab() {
679 final Config p = Config.INSTANCE;
682 fldBackLog.setEnabled(false);
683 cbBackLog.setEnabled(true);
685 final boolean movieLocal = p.getVideoUseLocal();
686 cbVideoLocal.setSelected(movieLocal);
688 fldVideo.setText(p.getVideoFileNamePattern());
691 final boolean commentLocal = p.getCommentUseLocal();
692 cbCommentLocal.setSelected(commentLocal);
694 fldComment.setText(p.getCommentFileNamePattern());
697 final boolean convert = p.getOutputEnable();
698 cbOutputEnable.setSelected(convert);
699 fldOutput.setEnabled(convert);
700 fldOutput.setText(p.getOutputFileNamePattern());
703 private void initFfmpegTab() {
704 pnlInputFfmpeg.init(Config.INSTANCE);
707 private JMenuBar initMenuBar() {
708 final JMenuBar menuBar = new JMenuBar();
710 final JMenu mnFile = new JMenu("ファイル(F)");
713 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
714 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
715 itExit.addActionListener(new ActionListener() {
718 public void actionPerformed(ActionEvent e) {
719 throw new UnsupportedOperationException("Not supported yet.");
724 final JMenu mnTool = new JMenu("ツール(T)");
727 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
729 itOption.addActionListener(new ActionListener() {
732 public void actionPerformed(ActionEvent e) {
733 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
734 dlg.setLocationRelativeTo(MainFrame.this);
736 dlg.setVisible(true);
739 mnTool.add(itOption);
741 final JMenu mnHelp = new JMenu("ヘルプ(H)");
744 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
745 itAbout.addActionListener(new ActionListener() {
748 public void actionPerformed(ActionEvent e) {
749 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
751 dlg.setLocationRelativeTo(MainFrame.this);
753 dlg.setVisible(true);
761 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
764 public void process(DownloadProgress progress) {
765 throw new UnsupportedOperationException("Not supported yet.");
769 public void cancelled() {
770 throw new UnsupportedOperationException("Not supported yet.");
774 public void done(DownloadResult result) {
775 throw new UnsupportedOperationException("Not supported yet.");
779 public void error(Throwable th) {
780 throw new UnsupportedOperationException("Not supported yet.");
784 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
787 public void process(ConvertProgress progress) {
788 throw new UnsupportedOperationException("Not supported yet.");
792 public void cancelled() {
793 throw new UnsupportedOperationException("Not supported yet.");
797 public void done(ConvertResult result) {
798 throw new UnsupportedOperationException("Not supported yet.");
802 public void error(Throwable th) {
803 throw new UnsupportedOperationException("Not supported yet.");
809 private class DownloadListTransferHandler extends TransferHandler {
811 private static final long serialVersionUID = 1L;
812 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
815 public boolean canImport(TransferHandler.TransferSupport support) {
816 Transferable transferable = support.getTransferable();
817 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
818 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
825 public boolean importData(TransferHandler.TransferSupport support) {
827 // Transferable transferable = support.getTransferable();
828 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
829 // @SuppressWarnings("unchecked")
830 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
831 // Collection<Target> targets = Target.from(data);
832 // targetModel.addTarget(targets);
833 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
834 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
835 // Matcher matcher = movieIdPattern.matcher(data);
836 // if (matcher.find()) {
837 // String movieId = matcher.group(1);
838 // Target target = Target.fromId(movieId);
839 // targetModel.addTarget(target);
846 // } catch (Exception e) {
847 // logger.log(Level.SEVERE, null, e);
850 // TODO 上記実装見直し(Locationは削除された)
855 private class TableTransferHandler extends DownloadListTransferHandler {
857 private static final long serialVersionUID = 1L;
860 public boolean canImport(TransferHandler.TransferSupport support) {
861 return super.canImport(support);
865 public boolean importData(TransferHandler.TransferSupport support) {
866 return super.importData(support);
870 private class MainFrameWindowListener extends WindowAdapter {
872 public void windowClosing(WindowEvent e) {
873 final Config p = Config.INSTANCE;
875 final Dimension size = getSize();
876 p.setSystemWindowWidth(size.width);
877 p.setSystemWindowHeight(size.height);
879 final Point pos = getLocation();
880 p.setSystemWindowPosX(pos.x);
881 p.setSystemWindowPosY(pos.y);
883 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
884 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
885 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
886 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
887 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
890 } catch (ConfigurationException ex) {
891 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
897 * ここからDownloadProfile作成用クラスの定義
900 private class InqubusDownloadProfile implements DownloadProfile {
902 private final LoginProfile loginProfile;
903 private final ProxyProfile proxyProfile;
904 private final VideoProfile videoProfile;
905 private final CommentProfile commentProfile;
906 private final GeneralProfile generalProfile;
908 private InqubusDownloadProfile() {
909 this.loginProfile = new InqubusLoginProfile();
910 this.proxyProfile = new InqubusProxyProfile();
911 this.videoProfile = new InqubusVideoProfile();
912 this.commentProfile = new InqubusCommentProfile();
913 this.generalProfile = new InqubusGeneralProfile();
917 public LoginProfile getLoginInfo() {
918 return this.loginProfile;
922 public ProxyProfile getProxyProfile() {
923 return this.proxyProfile;
927 public VideoProfile getVideoProfile() {
928 return this.videoProfile;
932 public CommentProfile getCommentProfile() {
933 return this.commentProfile;
937 public GeneralProfile getGeneralProfile() {
938 return this.generalProfile;
942 public String toString(){
943 return ToStringBuilder.reflectionToString(this);
947 private class InqubusLoginProfile implements LoginProfile {
948 private final String mail;
949 private final String password;
951 private InqubusLoginProfile(){
952 final Config p = Config.INSTANCE;
953 this.mail = p.getId();
954 this.password = p.getPassword();
958 public String getMail() {
963 public String getPassword() {
964 return this.password;
968 public String toString(){
969 return ToStringBuilder.reflectionToString(this);
973 private class InqubusProxyProfile implements ProxyProfile {
974 private final boolean use;
975 private final String host;
976 private final int port;
978 private InqubusProxyProfile(){
979 final Config p = Config.INSTANCE;
980 this.use = p.getProxyUse();
981 this.host = p.getProxyHost();
982 final String pp = p.getProxyPort();
983 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
987 public boolean use() {
992 public String getHost() {
997 public int getPort() {
1002 public String toString(){
1003 return ToStringBuilder.reflectionToString(this);
1007 private class InqubusVideoProfile implements VideoProfile {
1008 private final boolean download;
1009 private final File dir;
1010 private final String fileName;
1011 private final File localFile;
1013 private InqubusVideoProfile(){
1014 final Config p = Config.INSTANCE;
1015 this.download = !cbVideoLocal.isSelected();
1016 if (this.download) {
1017 this.dir = new File(p.getVideoDir());
1018 this.fileName = fldVideo.getText();
1019 this.localFile = null;
1022 this.fileName = null;
1023 this.localFile = new File(fldVideo.getText());
1028 public boolean isDownload() {
1029 return this.download;
1033 public File getDir() {
1038 public String getFileName() {
1039 return this.fileName;
1043 public File getLocalFile() {
1044 return this.localFile;
1048 public String toString(){
1049 return ToStringBuilder.reflectionToString(this);
1053 private class InqubusCommentProfile implements CommentProfile {
1054 private final boolean download;
1055 private final File dir;
1056 private final String fileName;
1057 private final File localFile;
1058 private final int lengthRelatedCommentSize;
1059 private final boolean disablePerMinComment;
1060 private final int perMinCommentSize;
1061 private final long backLogPoint;
1063 private InqubusCommentProfile() {
1064 final Config p = Config.INSTANCE;
1065 this.download = !cbCommentLocal.isSelected();
1066 if (this.download) {
1067 this.dir = new File(p.getCommentDir());
1068 this.fileName = fldComment.getText();
1069 this.localFile = null;
1072 this.fileName = null;
1073 this.localFile = new File(fldComment.getText());
1076 if(cbBackLog.isSelected()) {
1078 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
1079 } catch (IOException ex) {
1080 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
1083 this.backLogPoint = -1L;
1086 this.disablePerMinComment = cbBackLogReduce.isSelected();
1087 this.lengthRelatedCommentSize
1088 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1089 this.perMinCommentSize
1090 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1094 public boolean isDownload() {
1095 return this.download;
1099 public File getDir() {
1104 public String getFileName() {
1105 return this.fileName;
1109 public File getLocalFile() {
1110 return this.localFile;
1114 public int getLengthRelatedCommentSize() {
1115 return this.lengthRelatedCommentSize;
1119 public boolean isDisablePerMinComment() {
1120 return this.disablePerMinComment;
1124 public int getPerMinCommentSize() {
1125 return this.perMinCommentSize;
1129 public long getBackLogPoint() {
1130 return this.backLogPoint;
1134 public String toString(){
1135 return ToStringBuilder.reflectionToString(this);
1139 private class InqubusGeneralProfile implements GeneralProfile {
1140 private final String replaceFrom;
1141 private final String replaceTo;
1142 private InqubusGeneralProfile() {
1143 final Config p = Config.INSTANCE;
1144 this.replaceFrom = p.getReplaceFrom();
1145 this.replaceTo = p.getReplaceTo();
1149 public String getReplaceFrom() {
1150 return this.replaceFrom;
1154 public String getReplaceTo() {
1155 return this.replaceTo;
1159 public String toString(){
1160 return ToStringBuilder.reflectionToString(this);
1165 * ここからConvertProfile作成用クラスの定義
1167 private class InqubusConvertProfile implements ConvertProfile {
1168 private final OutputProfile outputProfile;
1169 private final GeneralProfile generalProfile;
1170 private final FfmpegProfile ffmpegProfile;
1171 private final boolean convert;
1172 private final File ffmpeg;
1173 private final boolean vhookDisabled;
1174 private final boolean commentOverlay;
1175 private final File vhook;
1176 private final File tmpDir;
1177 private final File font;
1178 private final int fontIndex;
1179 private final boolean commentOpaque;
1180 private final boolean disableFontSizeArrange;
1181 private final int shadowIndex;
1182 private final boolean showConvrting;
1183 private final int maxNumOfComment;
1184 private final HideCondition ngSetting;
1186 private InqubusConvertProfile() throws IOException {
1187 final Config p = Config.INSTANCE;
1188 this.outputProfile = new InqubusOutputProfile();
1189 this.generalProfile = new InqubusGeneralProfile();
1190 this.ffmpegProfile = new InqubusFfmpegProfile();
1191 this.convert = cbOutputEnable.isSelected();
1192 this.ffmpeg = new File(p.getFfmpegPath());
1194 this.vhookDisabled = false;
1195 this.commentOverlay = p.getOutputCommentOverlay();
1196 this.vhook = new File(p.getFfmpegDllPath());
1197 this.tmpDir = new File(p.getSystemTempDir());
1198 this.font = new File(p.getFontPath());
1199 this.fontIndex = Integer.parseInt(p.getFontIndex());
1200 this.commentOpaque = p.getCommentOpaque();
1201 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1202 this.shadowIndex = p.getFontShadow();
1204 this.showConvrting = true;
1205 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1206 getCommentDisplaySizeManual());
1207 this.ngSetting = new InqubusHideCondition();
1211 public OutputProfile getOutputProfile() {
1212 return this.outputProfile;
1216 public GeneralProfile getGeneralProfile() {
1217 return this.generalProfile;
1221 public FfmpegProfile getFfmpegOption() {
1222 return this.ffmpegProfile;
1226 public boolean isConvert() {
1227 return this.convert;
1231 public File getFfmpeg() {
1236 public boolean isVhookDisabled() {
1237 return this.vhookDisabled;
1241 public boolean isCommentOverlay() {
1242 return this.commentOverlay;
1246 public File getVhook() {
1251 public File getTempDir() {
1256 public File getFont() {
1261 public int getFontIndex() {
1262 return this.fontIndex;
1266 public boolean isCommentOpaque() {
1267 return this.commentOpaque;
1271 public boolean isDisableFontSizeArrange() {
1272 return this.disableFontSizeArrange;
1276 public int getShadowIndex() {
1277 return this.shadowIndex;
1281 public boolean isShowConverting() {
1282 return this.showConvrting;
1286 public int getMaxNumOfComment() {
1287 return this.maxNumOfComment;
1291 public HideCondition getNgSetting() {
1292 return this.ngSetting;
1296 public String toString(){
1297 return ToStringBuilder.reflectionToString(this);
1301 private class InqubusOutputProfile implements OutputProfile {
1302 private final File dir;
1303 private final String fileName;
1304 private final String videoId;
1305 private final String title;
1308 private InqubusOutputProfile(){
1309 final Config p = Config.INSTANCE;
1310 this.dir = new File(p.getOutputDir());
1311 this.fileName = fldOutput.getText();
1312 // TODO この時点でのID/Titleはどうするか…
1318 public File getDir() {
1323 public String getFileName() {
1324 return this.fileName;
1328 public String getVideoId() {
1329 return this.videoId;
1333 public String getTitile() {
1338 public String toString(){
1339 return ToStringBuilder.reflectionToString(this);
1343 private class InqubusFfmpegProfile implements FfmpegProfile {
1344 private final String extOption;
1345 private final String inOption;
1346 private final String mainOption;
1347 private final String outOption;
1348 private final String avOption;
1349 private final boolean resize;
1350 private final int resizeWidth;
1351 private final int resizeHeight;
1352 private final boolean adjustRatio;
1354 private InqubusFfmpegProfile() throws IOException {
1355 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1357 final FfmpegOption ffop = FfmpegOption.load(file);
1358 this.extOption = ffop.getExtOption();
1359 this.inOption = ffop.getInOption();
1360 this.mainOption = ffop.getMainOption();
1361 this.outOption = ffop.getMainOption();
1362 this.avOption = ffop.getAvfilterOption();
1363 this.resize = ffop.isResize();
1364 this.resizeWidth = ffop.getResizeWidth();
1365 this.resizeHeight = ffop.getResizeHeight();
1366 this.adjustRatio = ffop.isAdjustRatio();
1368 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1369 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1370 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1371 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1372 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1373 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1374 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1375 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1376 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1381 public String getExtOption() {
1382 return this.extOption;
1386 public String getInOption() {
1387 return this.inOption;
1391 public String getMainOption() {
1392 return this.mainOption;
1396 public String getOutOption() {
1397 return this.outOption;
1401 public String getAvfilterOption() {
1402 return this.avOption;
1406 public boolean isResize() {
1411 public int getResizeWidth() {
1412 return this.resizeWidth;
1416 public int getResizeHeight() {
1417 return this.resizeHeight;
1421 public boolean isAdjustRatio() {
1422 return this.adjustRatio;
1426 public String toString(){
1427 return ToStringBuilder.reflectionToString(this);
1431 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1434 public String getWord() {
1440 public String getId() {
1446 public String toString(){
1447 return ToStringBuilder.reflectionToString(this);