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.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.awt.event.ItemEvent;
16 import java.awt.event.ItemListener;
17 import java.awt.event.KeyEvent;
18 import java.awt.event.MouseEvent;
19 import java.awt.event.WindowAdapter;
20 import java.awt.event.WindowEvent;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
24 import java.io.IOException;
26 import java.nio.file.FileSystem;
27 import java.nio.file.FileSystems;
28 import java.nio.file.Path;
29 import java.util.ArrayList;
30 import java.util.HashSet;
31 import java.util.List;
33 import java.util.SortedSet;
34 import javax.swing.BorderFactory;
35 import javax.swing.DefaultComboBoxModel;
36 import javax.swing.DropMode;
37 import javax.swing.GroupLayout;
38 import javax.swing.GroupLayout.Alignment;
39 import javax.swing.JButton;
40 import javax.swing.JCheckBox;
41 import javax.swing.JFileChooser;
42 import javax.swing.JFrame;
43 import javax.swing.JLabel;
44 import javax.swing.JMenu;
45 import javax.swing.JMenuBar;
46 import javax.swing.JMenuItem;
47 import javax.swing.JOptionPane;
48 import javax.swing.JPanel;
49 import javax.swing.JScrollPane;
50 import javax.swing.JTabbedPane;
51 import javax.swing.JTable;
52 import javax.swing.JTextField;
53 import javax.swing.KeyStroke;
54 import javax.swing.LayoutStyle.ComponentPlacement;
55 import javax.swing.SwingUtilities;
56 import javax.swing.WindowConstants;
57 import javax.swing.border.BevelBorder;
58 import javax.swing.table.TableModel;
59 import org.apache.commons.configuration.ConfigurationException;
60 import org.apache.commons.lang.builder.ToStringBuilder;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
63 import saccubus.MainFrame_AboutBox;
64 import saccubus.util.WayBackTimeParser;
65 import saccubus.worker.profile.CommentProfile;
66 import saccubus.worker.profile.DownloadProfile;
67 import saccubus.worker.profile.FfmpegProfile;
68 import saccubus.worker.profile.GeneralProfile;
69 import saccubus.worker.profile.LoginProfile;
70 import saccubus.worker.profile.OutputProfile;
71 import saccubus.worker.profile.ProxyProfile;
72 import saccubus.worker.profile.VideoProfile;
74 import yukihane.inqubus.config.Config;
75 import yukihane.inqubus.config.ConfigCommentProfile;
76 import yukihane.inqubus.config.ConfigConvertProfile;
77 import yukihane.inqubus.config.ConfigFfmpegProfile;
78 import yukihane.inqubus.config.ConfigGeneralProfile;
79 import yukihane.inqubus.config.ConfigLoginProfile;
80 import yukihane.inqubus.config.ConfigOutputProfile;
81 import yukihane.inqubus.config.ConfigProxyProfile;
82 import yukihane.inqubus.filewatch.FileWatch;
83 import yukihane.inqubus.filewatch.FileWatchUtil;
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;
91 import yukihane.inqubus.thumbnail.Repository;
92 import yukihane.inqubus.thumbnail.Thumbnail;
98 public class MainFrame extends JFrame {
100 private static final long serialVersionUID = 1L;
101 private static final Logger logger = LoggerFactory.getLogger(MainFrame.class);
102 private final Repository thumbRepository = new Repository();
103 private final TargetsTableModel targetModel = new TargetsTableModel();
104 private final TaskManage taskManager;
105 private final Thread videoFileWatcherThread;
106 private final FileWatch videoFileWatcher;
107 private final Thread commentFileWatcherThread;
108 private final FileWatch commentFileWatcher;
111 /** Creates new form MainFrame */
114 addWindowListener(new MainFrameWindowListener());
115 setTitle(MainFrame_AboutBox.VERSION);
117 final Config p = Config.INSTANCE;
120 final int thDownload = p.getSystemDownloadThread();
121 final int secDownload = p.getSystemDownloadWait();
122 final int thConvert = p.getSystemConvertThread();
123 taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
126 final FileSystem fs = FileSystems.getDefault();
128 final List<String> videoSearchDirs = p.getSearchVideoDirs();
129 videoSearchDirs.add(p.getVideoDir());
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 List<String> commentSearchDirs = p.getSearchCommentDirs();
139 commentSearchDirs.add(p.getCommentDir());
140 final Set<Path> commentPaths = new HashSet<>(commentSearchDirs.size());
141 for(String s : commentSearchDirs) {
142 commentPaths.add(fs.getPath(s));
144 commentFileWatcher = new FileWatch(commentPaths);
145 this.commentFileWatcherThread = new Thread(commentFileWatcher);
146 this.commentFileWatcherThread.setDaemon(true);
148 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
149 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
150 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
151 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
152 final List<Image> images = new ArrayList<>(2);
155 setIconImages(images);
157 final JPanel pnlMain = new JPanel();
158 final JScrollPane scrDisplay = new JScrollPane();
159 tblDisplay = new JTable(targetModel, new TargetsColumnModel()) {
160 private static final long serialVersionUID = 1L;
163 public String getToolTipText(MouseEvent e) {
164 int row = convertRowIndexToModel(rowAtPoint(e.getPoint()));
165 TableModel m = getModel();
166 final String videoId = (String) m.getValueAt(row, 0);
168 final Thumbnail thumbnail = thumbRepository.getThumnail(videoId);
169 if (thumbnail == null) {
170 return videoId + ": 動画情報未取得";
173 final URL imageUrl = thumbnail.getImageFile().toURI().toURL();
175 return "<html>" + videoId + ": " + thumbnail.getTitle()
176 + " (" + thumbnail.getLength() + ")" + "<br/>"
177 + "<img src=\"" + imageUrl + "\"/>"
179 } catch (Throwable ex) {
180 logger.warn(null, ex);
181 return videoId + ": 情報取得できません";
185 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
186 final JPanel pnlButton = new JPanel();
187 final JPanel pnlInputMain = new JPanel();
188 final JLabel lblId = new JLabel();
189 final JLabel lblVideo = new JLabel();
190 cbVideoLocal = new JCheckBox();
191 btnVideo.addActionListener(
192 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldVideo));
193 fldVideo.setTransferHandler(new ContentTransferHandler(fldVideo.getTransferHandler(), cbVideoLocal));
194 final JLabel lblComment = new JLabel();
196 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
197 cbBackLog.addItemListener(new ItemListener() {
200 public void itemStateChanged(ItemEvent e) {
201 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
202 fldBackLog.setEnabled(selected);
205 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
208 public void propertyChange(PropertyChangeEvent evt) {
209 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
210 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
211 fldBackLog.setEnabled(fldEnabled);
214 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
216 cbCommentLocal = new JCheckBox();
217 cbOwnerComment = new JCheckBox();
219 btnComment.addActionListener(
220 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
221 fldComment.setTransferHandler(new ContentTransferHandler(fldComment.getTransferHandler(), cbCommentLocal));
223 final JLabel lblOutput = new JLabel();
224 cbOutputEnable = new JCheckBox();
225 fldOutput = new JTextField();
227 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
229 btnStop.addActionListener(new StopActionListener());
230 final ApplyActionListener applyListener = new ApplyActionListener();
231 btnApply.addActionListener(applyListener);
232 btnClear.addActionListener(new ActionListener() {
235 public void actionPerformed(ActionEvent e) {
240 pnlMain.setBorder(BorderFactory.createEtchedBorder());
242 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
243 scrDisplay.setViewportView(tblDisplay);
245 pnlButton.setBorder(BorderFactory.createEtchedBorder());
247 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
248 pnlButton.setLayout(gl_pnlButton);
249 gl_pnlButton.setHorizontalGroup(
250 gl_pnlButton.createParallelGroup(Alignment.LEADING)
251 .addGroup(gl_pnlButton.createSequentialGroup()
253 .addPreferredGap(ComponentPlacement.RELATED)
254 .addComponent(btnStop)
255 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
258 gl_pnlButton.setVerticalGroup(
259 gl_pnlButton.createParallelGroup(Alignment.LEADING)
260 .addGroup(gl_pnlButton.createSequentialGroup()
262 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
263 .addComponent(btnStop)
265 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
272 cmbId = new IdComboBox(videoFileWatcher);
273 cmbId.getEditorComponent().addActionListener(applyListener);
274 cmbId.getEditorComponent().addFocusListener(new java.awt.event.FocusAdapter() {
277 public void focusLost(java.awt.event.FocusEvent evt) {
278 idFieldFocusLost(evt);
282 lblVideo.setText("動画");
284 cbVideoLocal.setText("local");
285 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
288 public void itemStateChanged(java.awt.event.ItemEvent evt) {
289 useMovieLocalCheckBoxItemStateChanged(evt);
293 lblComment.setText("コメント");
295 cbCommentLocal.setText("local");
296 cbCommentLocal.addItemListener(new ItemListener() {
299 public void itemStateChanged(ItemEvent e) {
300 useMovieLocalCheckBoxItemStateChanged(e);
301 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
302 cbBackLogReduce.setEnabled(!selected);
303 cbBackLog.setEnabled(!selected);
304 cbOwnerComment.setEnabled(!selected);
308 cbOwnerComment.setText("投コメのみ");
310 lblOutput.setText("出力");
312 cbOutputEnable.setText("変換");
313 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
316 public void itemStateChanged(java.awt.event.ItemEvent evt) {
317 outputConvertCheckBoxItemStateChanged(evt);
322 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
323 pnlInputMain.setLayout(glInputMain);
324 glInputMain.setHorizontalGroup(
325 glInputMain.createParallelGroup(Alignment.LEADING)
326 .addGroup(glInputMain.createSequentialGroup()
329 .addPreferredGap(ComponentPlacement.RELATED)
330 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
333 .addGroup(glInputMain.createSequentialGroup()
335 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
336 .addComponent(lblVideo)
337 .addComponent(lblComment)
338 .addComponent(lblOutput)
340 .addPreferredGap(ComponentPlacement.RELATED)
341 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
342 .addComponent(cbVideoLocal)
343 .addComponent(cbCommentLocal)
344 .addComponent(cbOutputEnable)
346 .addPreferredGap(ComponentPlacement.RELATED)
347 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
348 .addComponent(cmbVideo, 300, 300, Short.MAX_VALUE)
349 .addComponent(cmbComment, 300, 300, Short.MAX_VALUE)
350 .addComponent(fldOutput, 300, 300, Short.MAX_VALUE)
352 .addGroup(glInputMain.createParallelGroup()
353 .addComponent(btnVideo)
354 .addComponent(btnComment)
358 .addGroup(glInputMain.createSequentialGroup()
360 .addComponent(cbOwnerComment)
361 .addPreferredGap(ComponentPlacement.UNRELATED)
362 .addComponent(cbBackLogReduce)
363 .addPreferredGap(ComponentPlacement.UNRELATED)
364 .addComponent(cbBackLog)
365 .addPreferredGap(ComponentPlacement.RELATED)
366 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
370 glInputMain.setVerticalGroup(
371 glInputMain.createParallelGroup(Alignment.LEADING)
372 .addGroup(glInputMain.createSequentialGroup()
374 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
375 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
378 .addPreferredGap(ComponentPlacement.RELATED)
379 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
380 .addComponent(lblVideo)
381 .addComponent(cbVideoLocal)
382 .addComponent(cmbVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
383 .addComponent(btnVideo)
385 .addPreferredGap(ComponentPlacement.RELATED)
386 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
387 .addComponent(lblComment)
388 .addComponent(cbCommentLocal)
389 .addComponent(cmbComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
390 .addComponent(btnComment)
392 .addPreferredGap(ComponentPlacement.RELATED)
393 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
394 .addComponent(cbOwnerComment)
395 .addComponent(cbBackLogReduce)
396 .addComponent(cbBackLog)
397 .addComponent(fldBackLog)
399 .addPreferredGap(ComponentPlacement.RELATED)
400 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
401 .addComponent(lblOutput)
402 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
403 .addComponent(cbOutputEnable)
409 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
410 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
411 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
412 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
415 public void actionPerformed(ActionEvent e) {
416 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
417 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
418 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
419 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
420 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
421 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
422 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
425 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
428 public void itemStateChanged(ItemEvent e) {
429 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
430 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
431 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
432 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
435 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
438 public void propertyChange(PropertyChangeEvent evt) {
439 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
440 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
441 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
442 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
443 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
448 tbpInput.add("メイン", pnlInputMain);
449 tbpInput.add("ffmpeg", pnlInputFfmpeg);
452 fldInputMessage.setEditable(false);
453 fldInputMessage.setEnabled(false);
454 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
456 final JPanel pnlInputButton = new JPanel();
457 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
458 pnlInputButton.setLayout(glInputButton);
459 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
461 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
462 .addPreferredGap(ComponentPlacement.UNRELATED)
463 .addComponent(btnClear)
464 .addPreferredGap(ComponentPlacement.UNRELATED)
465 .addComponent(btnApply)
468 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
470 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
471 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
472 .addComponent(btnClear)
473 .addComponent(btnApply)
479 final JPanel pnlInputAll = new JPanel();
480 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
481 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
482 pnlInputAll.setLayout(glInputAll);
483 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
484 .addComponent(tbpInput)
485 .addComponent(pnlInputButton)
487 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
488 .addComponent(tbpInput)
489 .addComponent(pnlInputButton)
492 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
493 pnlMain.setLayout(gl_pnlMain);
494 gl_pnlMain.setHorizontalGroup(
495 gl_pnlMain.createParallelGroup(Alignment.LEADING)
496 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
498 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
499 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
500 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
501 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
505 gl_pnlMain.setVerticalGroup(
506 gl_pnlMain.createParallelGroup(Alignment.LEADING)
507 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
509 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
510 .addPreferredGap(ComponentPlacement.RELATED)
511 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
512 .addPreferredGap(ComponentPlacement.RELATED)
513 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
519 JMenuBar menuBar = initMenuBar();
520 setJMenuBar(menuBar);
522 GroupLayout layout = new GroupLayout(getContentPane());
523 getContentPane().setLayout(layout);
524 layout.setHorizontalGroup(
525 layout.createParallelGroup(Alignment.LEADING)
526 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
528 layout.setVerticalGroup(
529 layout.createParallelGroup(Alignment.LEADING)
530 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
534 setMinimumSize(getSize());
537 * 画面のサイズや位置を前回終了時のものに設定する
539 final int windowWidth = p.getSystemWindowWidth();
540 final int windowHeight = p.getSystemWindowHeight();
541 if (windowWidth > 0 && windowHeight > 0) {
542 setSize(windowWidth, windowHeight);
545 final int windowPosX = p.getSystemWindowPosX();
546 final int windowPosY = p.getSystemWindowPosY();
547 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
548 if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
549 && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
550 setLocation(windowPosX, windowPosY);
552 setLocationByPlatform(true);
555 final int colId = p.getSystemColumnId();
557 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
559 final int colStatus = p.getSystemColumnStatus();
561 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
567 public void startWatcher() {
568 videoFileWatcherThread.start();
569 commentFileWatcherThread.start();
572 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
574 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
575 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
576 combo.setModel(model);
578 combo.setModel(new DefaultComboBoxModel<String>());
579 combo.getEditorComponent().setText(pattern);
583 private class GuiTaskManageListener implements TaskManageListener {
586 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
587 final String message) {
588 SwingUtilities.invokeLater(new Runnable() {
592 targetModel.setStatus(id, kind, status, percentage, message);
598 private class StopActionListener implements ActionListener {
601 public void actionPerformed(ActionEvent e) {
602 final int row = tblDisplay.getSelectedRow();
603 final Target t = targetModel.getTarget(row);
604 final boolean res = taskManager.cancel(t.getRowId());
605 logger.debug("停止: {} {}", t.getVideoId(), res);
607 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
612 private class ApplyActionListener implements ActionListener {
615 public void actionPerformed(ActionEvent e) {
617 final DownloadProfile downProf = new InqubusDownloadProfile();
618 final String id = Util.getVideoId(cmbId.getText());
619 final InqubusConvertProfile convProf = new InqubusConvertProfile();
620 logger.debug(downProf.toString());
621 logger.debug(convProf.toString());
623 final File tempDir = new File(Config.INSTANCE.getSystemTempDir());
624 thumbRepository.request(downProf.getProxyProfile(), tempDir, id);
626 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
628 targetModel.addTarget(new Target(rp));
630 } catch (Throwable th) {
631 logger.error(null, th);
632 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
638 * 動画, コメントの"local"チェックボックス更新時の処理.
640 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
641 final Config p = Config.INSTANCE;
643 final ItemSelectable source = evt.getItemSelectable();
649 if (source == cbVideoLocal) {
652 allFiles = videoFileWatcher.getFiles();
653 pattern = p.getVideoFileNamePattern();
657 allFiles = commentFileWatcher.getFiles();
658 pattern = p.getCommentFileNamePattern();
661 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
663 button.setEnabled(useLocal);
664 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
668 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
669 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
670 fldOutput.setEnabled(convert);
671 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
673 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
674 final Config p = Config.INSTANCE;
675 final String id = cmbId.getText();
677 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
678 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
679 }//GEN-LAST:event_idFieldFocusLost
680 // Variables declaration - do not modify//GEN-BEGIN:variables
681 private final JTable tblDisplay;
683 private final JButton btnStop = new JButton("停止");
685 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
687 private final IdComboBox cmbId;
688 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
689 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
690 private final JTextField fldBackLog = new JTextField();
691 private final JCheckBox cbVideoLocal;
692 private final FileComboBox cmbVideo = new FileComboBox();
693 private final JTextField fldVideo = cmbVideo.getEditorComponent();
694 private final JButton btnVideo = new JButton("...");
695 private final JCheckBox cbCommentLocal;
696 private final FileComboBox cmbComment = new FileComboBox();
697 private final JTextField fldComment = cmbComment.getEditorComponent();
698 private final JButton btnComment = new JButton("...");
699 private final JCheckBox cbOwnerComment;
700 private final JCheckBox cbOutputEnable;
701 private final JTextField fldOutput;
703 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
705 private final JTextField fldInputMessage = new JTextField();
706 private final JButton btnClear = new JButton("クリア");
707 private final JButton btnApply = new JButton("適用");
708 // End of variables declaration//GEN-END:variables
710 private void initInputPanel() {
713 tbpInput.setSelectedIndex(0);
714 cmbId.requestFocus();
717 private void initMainTab() {
718 final Config p = Config.INSTANCE;
721 cbBackLogReduce.setSelected(p.getCommentMinDisabled());
722 cbBackLog.setEnabled(true);
723 cbBackLog.setSelected(false);
724 fldBackLog.setEnabled(false);
725 fldBackLog.setText("");
727 final boolean videoLocal = p.getVideoUseLocal();
728 cbVideoLocal.setSelected(videoLocal);
730 fldVideo.setText(p.getVideoFileNamePattern());
732 btnVideo.setEnabled(videoLocal);
734 final boolean commentLocal = p.getCommentUseLocal();
735 cbCommentLocal.setSelected(commentLocal);
737 fldComment.setText(p.getCommentFileNamePattern());
739 btnComment.setEnabled(commentLocal);
741 final boolean convert = p.getOutputEnable();
742 cbOutputEnable.setSelected(convert);
743 fldOutput.setEnabled(convert);
744 fldOutput.setText(p.getOutputFileNamePattern());
747 private void initFfmpegTab() {
748 pnlInputFfmpeg.init(Config.INSTANCE);
751 private JMenuBar initMenuBar() {
752 final JMenuBar menuBar = new JMenuBar();
754 final JMenu mnFile = new JMenu("ファイル(F)");
757 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
758 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
759 final ActionListener exitActionListener = new ActionListener() {
762 public void actionPerformed(ActionEvent e) {
763 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
766 itExit.addActionListener(exitActionListener);
769 final JMenu mnTool = new JMenu("ツール(T)");
772 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
773 itOption.addActionListener(new ActionListener() {
776 public void actionPerformed(ActionEvent e) {
777 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
778 dlg.setLocationRelativeTo(MainFrame.this);
780 dlg.setVisible(true);
783 mnTool.add(itOption);
785 final JMenu mnHelp = new JMenu("ヘルプ(H)");
788 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
789 itAbout.addActionListener(new ActionListener() {
792 public void actionPerformed(ActionEvent e) {
793 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
795 dlg.setLocationRelativeTo(MainFrame.this);
797 dlg.setVisible(true);
805 private class MainFrameWindowListener extends WindowAdapter {
807 public void windowClosing(WindowEvent e) {
808 final Config p = Config.INSTANCE;
810 // 保存するのは最大化していない場合だけ
811 if (JFrame.NORMAL == getExtendedState()) {
812 final Dimension size = getSize();
813 p.setSystemWindowWidth(size.width);
814 p.setSystemWindowHeight(size.height);
816 final Point pos = getLocation();
817 p.setSystemWindowPosX(pos.x);
818 p.setSystemWindowPosY(pos.y);
821 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
822 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
823 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
824 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
825 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
828 } catch (ConfigurationException ex) {
829 logger.error("コンフィグ保存失敗", ex);
835 * ここからDownloadProfile作成用クラスの定義
837 private class InqubusDownloadProfile implements DownloadProfile {
839 private final LoginProfile loginProfile;
840 private final ProxyProfile proxyProfile;
841 private final VideoProfile videoProfile;
842 private final CommentProfile commentProfile;
843 private final GeneralProfile generalProfile;
845 private InqubusDownloadProfile() {
846 this.loginProfile = new ConfigLoginProfile();
847 this.proxyProfile = new ConfigProxyProfile();
848 this.videoProfile = new InqubusVideoProfile();
849 this.commentProfile = new InqubusCommentProfile();
850 this.generalProfile = new ConfigGeneralProfile();
854 public LoginProfile getLoginProfile() {
855 return this.loginProfile;
859 public ProxyProfile getProxyProfile() {
860 return this.proxyProfile;
864 public VideoProfile getVideoProfile() {
865 return this.videoProfile;
869 public CommentProfile getCommentProfile() {
870 return this.commentProfile;
874 public GeneralProfile getGeneralProfile() {
875 return this.generalProfile;
879 public String toString(){
880 return ToStringBuilder.reflectionToString(this);
884 private class InqubusVideoProfile implements VideoProfile {
885 private final boolean download;
886 private final File dir;
887 private final String fileName;
888 private final File localFile;
890 private InqubusVideoProfile(){
891 final Config p = Config.INSTANCE;
892 this.download = !cbVideoLocal.isSelected();
894 this.dir = new File(p.getVideoDir());
895 this.fileName = fldVideo.getText();
896 this.localFile = null;
899 this.fileName = null;
900 this.localFile = new File(fldVideo.getText());
905 public boolean isDownload() {
906 return this.download;
910 public File getDir() {
915 public String getFileName() {
916 return this.fileName;
920 public File getLocalFile() {
921 return this.localFile;
925 public String toString(){
926 return ToStringBuilder.reflectionToString(this);
930 private class InqubusCommentProfile extends ConfigCommentProfile {
931 private final boolean download;
932 private final File dir;
933 private final String fileName;
934 private final File localFile;
935 private final boolean disablePerMinComment;
936 private final long backLogPoint;
938 private InqubusCommentProfile() {
941 final Config p = Config.INSTANCE;
942 this.download = !cbCommentLocal.isSelected();
944 this.dir = new File(p.getCommentDir());
945 this.fileName = fldComment.getText();
946 this.localFile = null;
949 this.fileName = null;
950 this.localFile = new File(fldComment.getText());
953 if(cbBackLog.isSelected()) {
955 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
956 } catch (IOException ex) {
957 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
960 this.backLogPoint = -1L;
963 this.disablePerMinComment = cbBackLogReduce.isSelected();
967 public boolean isDownload() {
968 return this.download;
972 public File getDir() {
977 public String getFileName() {
978 return this.fileName;
982 public File getLocalFile() {
983 return this.localFile;
987 public boolean isDisablePerMinComment() {
988 return this.disablePerMinComment;
992 public long getBackLogPoint() {
993 return this.backLogPoint;
997 public String toString(){
998 return ToStringBuilder.reflectionToString(this);
1003 * ここからConvertProfile作成用クラスの定義
1005 private class InqubusConvertProfile extends ConfigConvertProfile {
1006 private final OutputProfile outputProfile;
1007 private final GeneralProfile generalProfile;
1008 private final FfmpegProfile ffmpegProfile;
1009 private final boolean convert;
1011 private InqubusConvertProfile() throws IOException {
1012 this.outputProfile = new InqubusOutputProfile();
1013 this.generalProfile = new ConfigGeneralProfile();
1015 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1017 this.ffmpegProfile = new ConfigFfmpegProfile();
1019 this.ffmpegProfile = new InqubusFfmpegProfile();
1022 this.convert = cbOutputEnable.isSelected();
1026 public OutputProfile getOutputProfile() {
1027 return this.outputProfile;
1031 public GeneralProfile getGeneralProfile() {
1032 return this.generalProfile;
1036 public FfmpegProfile getFfmpegOption() {
1037 return this.ffmpegProfile;
1041 public boolean isConvert() {
1042 return this.convert;
1046 public String toString(){
1047 return ToStringBuilder.reflectionToString(this);
1051 private class InqubusOutputProfile extends ConfigOutputProfile {
1052 private final String fileName;
1053 private final String videoId;
1054 private final String title;
1057 private InqubusOutputProfile() {
1058 this.fileName = fldOutput.getText();
1059 // TODO この時点でのID/Titleはどうするか…
1065 public String getFileName() {
1066 return this.fileName;
1070 public String getVideoId() {
1071 return this.videoId;
1075 public String getTitile() {
1080 public String toString(){
1081 return ToStringBuilder.reflectionToString(this);
1085 private class InqubusFfmpegProfile implements FfmpegProfile {
1086 private final String extOption;
1087 private final String inOption;
1088 private final String mainOption;
1089 private final String outOption;
1090 private final String avOption;
1091 private final boolean resize;
1092 private final int resizeWidth;
1093 private final int resizeHeight;
1094 private final boolean adjustRatio;
1096 private InqubusFfmpegProfile() throws IOException {
1097 String ext = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1098 if (!ext.startsWith(".")) {
1101 this.extOption = ext;
1102 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1103 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1104 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1105 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1106 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1107 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1108 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1109 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1113 public String getExtOption() {
1114 return this.extOption;
1118 public String getInOption() {
1119 return this.inOption;
1123 public String getMainOption() {
1124 return this.mainOption;
1128 public String getOutOption() {
1129 return this.outOption;
1133 public String getAvfilterOption() {
1134 return this.avOption;
1138 public boolean isResize() {
1143 public int getResizeWidth() {
1144 return this.resizeWidth;
1148 public int getResizeHeight() {
1149 return this.resizeHeight;
1153 public boolean isAdjustRatio() {
1154 return this.adjustRatio;
1158 public String toString(){
1159 return ToStringBuilder.reflectionToString(this);