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;
25 import java.net.MalformedURLException;
27 import java.nio.file.FileSystem;
28 import java.nio.file.FileSystems;
29 import java.nio.file.Path;
30 import java.util.ArrayList;
31 import java.util.HashSet;
32 import java.util.List;
34 import java.util.SortedSet;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import javax.swing.BorderFactory;
38 import javax.swing.DefaultComboBoxModel;
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.WindowConstants;
60 import javax.swing.border.BevelBorder;
61 import javax.swing.table.TableModel;
62 import org.apache.commons.configuration.ConfigurationException;
63 import org.apache.commons.lang.builder.ToStringBuilder;
64 import saccubus.MainFrame_AboutBox;
65 import saccubus.util.WayBackTimeParser;
66 import saccubus.worker.profile.CommentProfile;
67 import saccubus.worker.profile.DownloadProfile;
68 import saccubus.worker.profile.FfmpegProfile;
69 import saccubus.worker.profile.GeneralProfile;
70 import saccubus.worker.profile.LoginProfile;
71 import saccubus.worker.profile.OutputProfile;
72 import saccubus.worker.profile.ProxyProfile;
73 import saccubus.worker.profile.VideoProfile;
75 import yukihane.inqubus.config.Config;
76 import yukihane.inqubus.config.ConfigCommentProfile;
77 import yukihane.inqubus.config.ConfigConvertProfile;
78 import yukihane.inqubus.config.ConfigFfmpegProfile;
79 import yukihane.inqubus.config.ConfigGeneralProfile;
80 import yukihane.inqubus.config.ConfigLoginProfile;
81 import yukihane.inqubus.config.ConfigOutputProfile;
82 import yukihane.inqubus.config.ConfigProxyProfile;
83 import yukihane.inqubus.filewatch.FileWatch;
84 import yukihane.inqubus.filewatch.FileWatchUtil;
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;
92 import yukihane.inqubus.thumbnail.Repository;
93 import yukihane.inqubus.thumbnail.Thumbnail;
99 public class MainFrame extends JFrame {
101 private static final long serialVersionUID = 1L;
102 private static final Logger logger = LoggerFactory.getLogger(MainFrame.class);
103 private final Repository thumbRepository = new Repository();
104 private final TargetsTableModel targetModel = new TargetsTableModel();
105 private final TaskManage taskManager;
106 private final Thread videoFileWatcherThread;
107 private final FileWatch videoFileWatcher;
108 private final Thread commentFileWatcherThread;
109 private final FileWatch commentFileWatcher;
112 /** Creates new form MainFrame */
115 addWindowListener(new MainFrameWindowListener());
116 setTitle(MainFrame_AboutBox.VERSION);
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());
127 final FileSystem fs = FileSystems.getDefault();
129 final List<String> videoSearchDirs = p.getSearchVideoDirs();
130 videoSearchDirs.add(p.getVideoDir());
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 List<String> commentSearchDirs = p.getSearchCommentDirs();
140 commentSearchDirs.add(p.getCommentDir());
141 final Set<Path> commentPaths = new HashSet<>(commentSearchDirs.size());
142 for(String s : commentSearchDirs) {
143 commentPaths.add(fs.getPath(s));
145 commentFileWatcher = new FileWatch(commentPaths);
146 this.commentFileWatcherThread = new Thread(commentFileWatcher);
147 this.commentFileWatcherThread.setDaemon(true);
149 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
150 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
151 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
152 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
153 final List<Image> images = new ArrayList<>(2);
156 setIconImages(images);
158 final JPanel pnlMain = new JPanel();
159 final JScrollPane scrDisplay = new JScrollPane();
160 tblDisplay = new JTable(targetModel, new TargetsColumnModel()) {
161 private static final long serialVersionUID = 1L;
164 public String getToolTipText(MouseEvent e) {
165 int row = convertRowIndexToModel(rowAtPoint(e.getPoint()));
166 TableModel m = getModel();
167 final String videoId = (String) m.getValueAt(row, 0);
169 final Thumbnail thumbnail = thumbRepository.getThumnail(videoId);
170 if (thumbnail == null) {
171 return videoId + ": 動画情報未取得";
174 final URL imageUrl = thumbnail.getImageFile().toURI().toURL();
176 return "<html>" + videoId + ": " + thumbnail.getTitle()
177 + " (" + thumbnail.getLength() + ")" + "<br/>"
178 + "<img src=\"" + imageUrl + "\"/>"
180 } catch (Throwable ex) {
181 logger.warn(null, ex);
182 return videoId + ": 情報取得できません";
186 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
187 final JPanel pnlButton = new JPanel();
188 final JPanel pnlInputMain = new JPanel();
189 final JLabel lblId = new JLabel();
190 final JLabel lblVideo = new JLabel();
191 cbVideoLocal = new JCheckBox();
192 btnVideo.addActionListener(
193 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldVideo));
194 fldVideo.setTransferHandler(new ContentTransferHandler(fldVideo.getTransferHandler(), cbVideoLocal));
195 final JLabel lblComment = new JLabel();
197 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
198 cbBackLog.addItemListener(new ItemListener() {
201 public void itemStateChanged(ItemEvent e) {
202 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
203 fldBackLog.setEnabled(selected);
206 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
209 public void propertyChange(PropertyChangeEvent evt) {
210 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
211 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
212 fldBackLog.setEnabled(fldEnabled);
215 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
217 cbCommentLocal = new JCheckBox();
218 cbCommentLocal.addItemListener(new ItemListener() {
221 public void itemStateChanged(ItemEvent e) {
222 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
223 cbBackLogReduce.setEnabled(!selected);
224 cbBackLog.setEnabled(!selected);
227 btnComment.addActionListener(
228 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
229 fldComment.setTransferHandler(new ContentTransferHandler(fldComment.getTransferHandler(), cbCommentLocal));
230 final JLabel lblOutput = new JLabel();
231 cbOutputEnable = new JCheckBox();
232 fldOutput = new JTextField();
234 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
236 btnStop.addActionListener(new StopActionListener());
237 final ApplyActionListener applyListener = new ApplyActionListener();
238 btnApply.addActionListener(applyListener);
239 btnClear.addActionListener(new ActionListener() {
242 public void actionPerformed(ActionEvent e) {
247 pnlMain.setBorder(BorderFactory.createEtchedBorder());
249 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
250 scrDisplay.setViewportView(tblDisplay);
252 pnlButton.setBorder(BorderFactory.createEtchedBorder());
254 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
255 pnlButton.setLayout(gl_pnlButton);
256 gl_pnlButton.setHorizontalGroup(
257 gl_pnlButton.createParallelGroup(Alignment.LEADING)
258 .addGroup(gl_pnlButton.createSequentialGroup()
260 .addPreferredGap(ComponentPlacement.RELATED)
261 .addComponent(btnStop)
262 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
265 gl_pnlButton.setVerticalGroup(
266 gl_pnlButton.createParallelGroup(Alignment.LEADING)
267 .addGroup(gl_pnlButton.createSequentialGroup()
269 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
270 .addComponent(btnStop)
272 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
279 cmbId = new IdComboBox(videoFileWatcher);
280 cmbId.getEditorComponent().addActionListener(applyListener);
281 cmbId.getEditorComponent().addFocusListener(new java.awt.event.FocusAdapter() {
284 public void focusLost(java.awt.event.FocusEvent evt) {
285 idFieldFocusLost(evt);
289 lblVideo.setText("動画");
291 cbVideoLocal.setText("local");
292 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
295 public void itemStateChanged(java.awt.event.ItemEvent evt) {
296 useMovieLocalCheckBoxItemStateChanged(evt);
300 lblComment.setText("コメント");
302 cbCommentLocal.setText("local");
303 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
306 public void itemStateChanged(java.awt.event.ItemEvent evt) {
307 useMovieLocalCheckBoxItemStateChanged(evt);
311 lblOutput.setText("出力");
313 cbOutputEnable.setText("変換");
314 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
317 public void itemStateChanged(java.awt.event.ItemEvent evt) {
318 outputConvertCheckBoxItemStateChanged(evt);
323 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
324 pnlInputMain.setLayout(glInputMain);
325 glInputMain.setHorizontalGroup(
326 glInputMain.createParallelGroup(Alignment.LEADING)
327 .addGroup(glInputMain.createSequentialGroup()
330 .addPreferredGap(ComponentPlacement.RELATED)
331 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
332 .addPreferredGap(ComponentPlacement.UNRELATED)
333 .addComponent(cbBackLogReduce)
334 .addPreferredGap(ComponentPlacement.UNRELATED)
335 .addComponent(cbBackLog)
336 .addPreferredGap(ComponentPlacement.RELATED)
337 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
340 .addGroup(glInputMain.createSequentialGroup()
342 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
343 .addComponent(lblVideo)
344 .addComponent(lblComment)
345 .addComponent(lblOutput)
347 .addPreferredGap(ComponentPlacement.RELATED)
348 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
349 .addComponent(cbVideoLocal)
350 .addComponent(cbCommentLocal)
351 .addComponent(cbOutputEnable)
353 .addPreferredGap(ComponentPlacement.RELATED)
354 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
355 .addComponent(cmbVideo, 300, 300, Short.MAX_VALUE)
356 .addComponent(cmbComment, 300, 300, Short.MAX_VALUE)
357 .addComponent(fldOutput, 300, 300, Short.MAX_VALUE)
359 .addGroup(glInputMain.createParallelGroup()
360 .addComponent(btnVideo)
361 .addComponent(btnComment)
367 glInputMain.setVerticalGroup(
368 glInputMain.createParallelGroup(Alignment.LEADING)
369 .addGroup(glInputMain.createSequentialGroup()
371 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
372 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
374 .addComponent(cbBackLogReduce)
375 .addComponent(cbBackLog)
376 .addComponent(fldBackLog)
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(lblOutput)
395 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
396 .addComponent(cbOutputEnable)
402 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
403 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
404 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
405 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
408 public void actionPerformed(ActionEvent e) {
409 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
410 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
411 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
412 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
413 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
414 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
415 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
418 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
421 public void itemStateChanged(ItemEvent e) {
422 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
423 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
424 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
425 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
428 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
431 public void propertyChange(PropertyChangeEvent evt) {
432 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
433 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
434 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
435 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
436 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
441 tbpInput.add("メイン", pnlInputMain);
442 tbpInput.add("ffmpeg", pnlInputFfmpeg);
445 fldInputMessage.setEditable(false);
446 fldInputMessage.setEnabled(false);
447 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
449 final JPanel pnlInputButton = new JPanel();
450 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
451 pnlInputButton.setLayout(glInputButton);
452 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
454 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
455 .addPreferredGap(ComponentPlacement.UNRELATED)
456 .addComponent(btnClear)
457 .addPreferredGap(ComponentPlacement.UNRELATED)
458 .addComponent(btnApply)
461 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
463 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
464 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
465 .addComponent(btnClear)
466 .addComponent(btnApply)
472 final JPanel pnlInputAll = new JPanel();
473 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
474 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
475 pnlInputAll.setLayout(glInputAll);
476 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
477 .addComponent(tbpInput)
478 .addComponent(pnlInputButton)
480 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
481 .addComponent(tbpInput)
482 .addComponent(pnlInputButton)
485 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
486 pnlMain.setLayout(gl_pnlMain);
487 gl_pnlMain.setHorizontalGroup(
488 gl_pnlMain.createParallelGroup(Alignment.LEADING)
489 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
491 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
492 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
493 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
494 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
498 gl_pnlMain.setVerticalGroup(
499 gl_pnlMain.createParallelGroup(Alignment.LEADING)
500 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
502 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
503 .addPreferredGap(ComponentPlacement.RELATED)
504 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
505 .addPreferredGap(ComponentPlacement.RELATED)
506 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
512 JMenuBar menuBar = initMenuBar();
513 setJMenuBar(menuBar);
515 GroupLayout layout = new GroupLayout(getContentPane());
516 getContentPane().setLayout(layout);
517 layout.setHorizontalGroup(
518 layout.createParallelGroup(Alignment.LEADING)
519 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
521 layout.setVerticalGroup(
522 layout.createParallelGroup(Alignment.LEADING)
523 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
527 setMinimumSize(getSize());
530 * 画面のサイズや位置を前回終了時のものに設定する
532 final int windowWidth = p.getSystemWindowWidth();
533 final int windowHeight = p.getSystemWindowHeight();
534 if (windowWidth > 0 && windowHeight > 0) {
535 setSize(windowWidth, windowHeight);
538 final int windowPosX = p.getSystemWindowPosX();
539 final int windowPosY = p.getSystemWindowPosY();
540 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
541 if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
542 && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
543 setLocation(windowPosX, windowPosY);
545 setLocationByPlatform(true);
548 final int colId = p.getSystemColumnId();
550 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
552 final int colStatus = p.getSystemColumnStatus();
554 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
560 public void startWatcher() {
561 videoFileWatcherThread.start();
562 commentFileWatcherThread.start();
565 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
567 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
568 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
569 combo.setModel(model);
571 combo.setModel(new DefaultComboBoxModel<String>());
572 combo.getEditorComponent().setText(pattern);
576 private class GuiTaskManageListener implements TaskManageListener {
579 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
580 final String message) {
581 SwingUtilities.invokeLater(new Runnable() {
585 targetModel.setStatus(id, kind, status, percentage, message);
591 private class StopActionListener implements ActionListener {
594 public void actionPerformed(ActionEvent e) {
595 final int row = tblDisplay.getSelectedRow();
596 final Target t = targetModel.getTarget(row);
597 final boolean res = taskManager.cancel(t.getRowId());
598 logger.debug("停止: {} {}", t.getVideoId(), res);
600 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
605 private class ApplyActionListener implements ActionListener {
608 public void actionPerformed(ActionEvent e) {
610 final DownloadProfile downProf = new InqubusDownloadProfile();
611 final String id = Util.getVideoId(cmbId.getText());
612 final InqubusConvertProfile convProf = new InqubusConvertProfile();
613 logger.debug(downProf.toString());
614 logger.debug(convProf.toString());
616 final File tempDir = new File(Config.INSTANCE.getSystemTempDir());
617 thumbRepository.request(downProf.getProxyProfile(), tempDir, id);
619 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
621 targetModel.addTarget(new Target(rp));
623 } catch (Throwable th) {
624 logger.error(null, th);
625 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
631 * 動画, コメントの"local"チェックボックス更新時の処理.
633 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
634 final Config p = Config.INSTANCE;
636 final ItemSelectable source = evt.getItemSelectable();
642 if (source == cbVideoLocal) {
645 allFiles = videoFileWatcher.getFiles();
646 pattern = p.getVideoFileNamePattern();
650 allFiles = commentFileWatcher.getFiles();
651 pattern = p.getCommentFileNamePattern();
654 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
656 button.setEnabled(useLocal);
657 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
661 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
662 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
663 fldOutput.setEnabled(convert);
664 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
666 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
667 final Config p = Config.INSTANCE;
668 final String id = cmbId.getText();
670 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
671 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
672 }//GEN-LAST:event_idFieldFocusLost
673 // Variables declaration - do not modify//GEN-BEGIN:variables
674 private final JTable tblDisplay;
676 private final JButton btnStop = new JButton("停止");
678 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
680 private final IdComboBox cmbId;
681 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
682 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
683 private final JTextField fldBackLog = new JTextField();
684 private final JCheckBox cbVideoLocal;
685 private final FileComboBox cmbVideo = new FileComboBox();
686 private final JTextField fldVideo = cmbVideo.getEditorComponent();
687 private final JButton btnVideo = new JButton("...");
688 private final JCheckBox cbCommentLocal;
689 private final FileComboBox cmbComment = new FileComboBox();
690 private final JTextField fldComment = cmbComment.getEditorComponent();
691 private final JButton btnComment = new JButton("...");
692 private final JCheckBox cbOutputEnable;
693 private final JTextField fldOutput;
695 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
697 private final JTextField fldInputMessage = new JTextField();
698 private final JButton btnClear = new JButton("クリア");
699 private final JButton btnApply = new JButton("適用");
700 // End of variables declaration//GEN-END:variables
702 private void initInputPanel() {
705 tbpInput.setSelectedIndex(0);
706 cmbId.requestFocus();
709 private void initMainTab() {
710 final Config p = Config.INSTANCE;
713 cbBackLogReduce.setSelected(p.getCommentMinDisabled());
714 cbBackLog.setEnabled(true);
715 cbBackLog.setSelected(false);
716 fldBackLog.setEnabled(false);
717 fldBackLog.setText("");
719 final boolean videoLocal = p.getVideoUseLocal();
720 cbVideoLocal.setSelected(videoLocal);
722 fldVideo.setText(p.getVideoFileNamePattern());
724 btnVideo.setEnabled(videoLocal);
726 final boolean commentLocal = p.getCommentUseLocal();
727 cbCommentLocal.setSelected(commentLocal);
729 fldComment.setText(p.getCommentFileNamePattern());
731 btnComment.setEnabled(commentLocal);
733 final boolean convert = p.getOutputEnable();
734 cbOutputEnable.setSelected(convert);
735 fldOutput.setEnabled(convert);
736 fldOutput.setText(p.getOutputFileNamePattern());
739 private void initFfmpegTab() {
740 pnlInputFfmpeg.init(Config.INSTANCE);
743 private JMenuBar initMenuBar() {
744 final JMenuBar menuBar = new JMenuBar();
746 final JMenu mnFile = new JMenu("ファイル(F)");
749 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
750 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
751 final ActionListener exitActionListener = new ActionListener() {
754 public void actionPerformed(ActionEvent e) {
755 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
758 itExit.addActionListener(exitActionListener);
761 final JMenu mnTool = new JMenu("ツール(T)");
764 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
765 itOption.addActionListener(new ActionListener() {
768 public void actionPerformed(ActionEvent e) {
769 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
770 dlg.setLocationRelativeTo(MainFrame.this);
772 dlg.setVisible(true);
775 mnTool.add(itOption);
777 final JMenu mnHelp = new JMenu("ヘルプ(H)");
780 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
781 itAbout.addActionListener(new ActionListener() {
784 public void actionPerformed(ActionEvent e) {
785 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
787 dlg.setLocationRelativeTo(MainFrame.this);
789 dlg.setVisible(true);
797 private class MainFrameWindowListener extends WindowAdapter {
799 public void windowClosing(WindowEvent e) {
800 final Config p = Config.INSTANCE;
802 // 保存するのは最大化していない場合だけ
803 if (JFrame.NORMAL == getExtendedState()) {
804 final Dimension size = getSize();
805 p.setSystemWindowWidth(size.width);
806 p.setSystemWindowHeight(size.height);
808 final Point pos = getLocation();
809 p.setSystemWindowPosX(pos.x);
810 p.setSystemWindowPosY(pos.y);
813 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
814 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
815 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
816 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
817 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
820 } catch (ConfigurationException ex) {
821 logger.error("コンフィグ保存失敗", ex);
827 * ここからDownloadProfile作成用クラスの定義
829 private class InqubusDownloadProfile implements DownloadProfile {
831 private final LoginProfile loginProfile;
832 private final ProxyProfile proxyProfile;
833 private final VideoProfile videoProfile;
834 private final CommentProfile commentProfile;
835 private final GeneralProfile generalProfile;
837 private InqubusDownloadProfile() {
838 this.loginProfile = new ConfigLoginProfile();
839 this.proxyProfile = new ConfigProxyProfile();
840 this.videoProfile = new InqubusVideoProfile();
841 this.commentProfile = new InqubusCommentProfile();
842 this.generalProfile = new ConfigGeneralProfile();
846 public LoginProfile getLoginProfile() {
847 return this.loginProfile;
851 public ProxyProfile getProxyProfile() {
852 return this.proxyProfile;
856 public VideoProfile getVideoProfile() {
857 return this.videoProfile;
861 public CommentProfile getCommentProfile() {
862 return this.commentProfile;
866 public GeneralProfile getGeneralProfile() {
867 return this.generalProfile;
871 public String toString(){
872 return ToStringBuilder.reflectionToString(this);
876 private class InqubusVideoProfile implements VideoProfile {
877 private final boolean download;
878 private final File dir;
879 private final String fileName;
880 private final File localFile;
882 private InqubusVideoProfile(){
883 final Config p = Config.INSTANCE;
884 this.download = !cbVideoLocal.isSelected();
886 this.dir = new File(p.getVideoDir());
887 this.fileName = fldVideo.getText();
888 this.localFile = null;
891 this.fileName = null;
892 this.localFile = new File(fldVideo.getText());
897 public boolean isDownload() {
898 return this.download;
902 public File getDir() {
907 public String getFileName() {
908 return this.fileName;
912 public File getLocalFile() {
913 return this.localFile;
917 public String toString(){
918 return ToStringBuilder.reflectionToString(this);
922 private class InqubusCommentProfile extends ConfigCommentProfile {
923 private final boolean download;
924 private final File dir;
925 private final String fileName;
926 private final File localFile;
927 private final boolean disablePerMinComment;
928 private final long backLogPoint;
930 private InqubusCommentProfile() {
933 final Config p = Config.INSTANCE;
934 this.download = !cbCommentLocal.isSelected();
936 this.dir = new File(p.getCommentDir());
937 this.fileName = fldComment.getText();
938 this.localFile = null;
941 this.fileName = null;
942 this.localFile = new File(fldComment.getText());
945 if(cbBackLog.isSelected()) {
947 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
948 } catch (IOException ex) {
949 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
952 this.backLogPoint = -1L;
955 this.disablePerMinComment = cbBackLogReduce.isSelected();
959 public boolean isDownload() {
960 return this.download;
964 public File getDir() {
969 public String getFileName() {
970 return this.fileName;
974 public File getLocalFile() {
975 return this.localFile;
979 public boolean isDisablePerMinComment() {
980 return this.disablePerMinComment;
984 public long getBackLogPoint() {
985 return this.backLogPoint;
989 public String toString(){
990 return ToStringBuilder.reflectionToString(this);
995 * ここからConvertProfile作成用クラスの定義
997 private class InqubusConvertProfile extends ConfigConvertProfile {
998 private final OutputProfile outputProfile;
999 private final GeneralProfile generalProfile;
1000 private final FfmpegProfile ffmpegProfile;
1001 private final boolean convert;
1003 private InqubusConvertProfile() throws IOException {
1004 this.outputProfile = new InqubusOutputProfile();
1005 this.generalProfile = new ConfigGeneralProfile();
1007 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1009 this.ffmpegProfile = new ConfigFfmpegProfile();
1011 this.ffmpegProfile = new InqubusFfmpegProfile();
1014 this.convert = cbOutputEnable.isSelected();
1018 public OutputProfile getOutputProfile() {
1019 return this.outputProfile;
1023 public GeneralProfile getGeneralProfile() {
1024 return this.generalProfile;
1028 public FfmpegProfile getFfmpegOption() {
1029 return this.ffmpegProfile;
1033 public boolean isConvert() {
1034 return this.convert;
1038 public String toString(){
1039 return ToStringBuilder.reflectionToString(this);
1043 private class InqubusOutputProfile extends ConfigOutputProfile {
1044 private final String fileName;
1045 private final String videoId;
1046 private final String title;
1049 private InqubusOutputProfile() {
1050 this.fileName = fldOutput.getText();
1051 // TODO この時点でのID/Titleはどうするか…
1057 public String getFileName() {
1058 return this.fileName;
1062 public String getVideoId() {
1063 return this.videoId;
1067 public String getTitile() {
1072 public String toString(){
1073 return ToStringBuilder.reflectionToString(this);
1077 private class InqubusFfmpegProfile implements FfmpegProfile {
1078 private final String extOption;
1079 private final String inOption;
1080 private final String mainOption;
1081 private final String outOption;
1082 private final String avOption;
1083 private final boolean resize;
1084 private final int resizeWidth;
1085 private final int resizeHeight;
1086 private final boolean adjustRatio;
1088 private InqubusFfmpegProfile() throws IOException {
1089 String ext = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1090 if (!ext.startsWith(".")) {
1093 this.extOption = ext;
1094 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1095 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1096 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1097 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1098 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1099 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1100 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1101 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1105 public String getExtOption() {
1106 return this.extOption;
1110 public String getInOption() {
1111 return this.inOption;
1115 public String getMainOption() {
1116 return this.mainOption;
1120 public String getOutOption() {
1121 return this.outOption;
1125 public String getAvfilterOption() {
1126 return this.avOption;
1130 public boolean isResize() {
1135 public int getResizeWidth() {
1136 return this.resizeWidth;
1140 public int getResizeHeight() {
1141 return this.resizeHeight;
1145 public boolean isAdjustRatio() {
1146 return this.adjustRatio;
1150 public String toString(){
1151 return ToStringBuilder.reflectionToString(this);