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());
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 cbCommentLocal.addItemListener(new ItemListener() {
220 public void itemStateChanged(ItemEvent e) {
221 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
222 cbBackLogReduce.setEnabled(!selected);
223 cbBackLog.setEnabled(!selected);
226 btnComment.addActionListener(
227 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
228 fldComment.setTransferHandler(new ContentTransferHandler(fldComment.getTransferHandler(), cbCommentLocal));
229 final JLabel lblOutput = new JLabel();
230 cbOutputEnable = new JCheckBox();
231 fldOutput = new JTextField();
233 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
235 btnStop.addActionListener(new StopActionListener());
236 final ApplyActionListener applyListener = new ApplyActionListener();
237 btnApply.addActionListener(applyListener);
238 btnClear.addActionListener(new ActionListener() {
241 public void actionPerformed(ActionEvent e) {
246 pnlMain.setBorder(BorderFactory.createEtchedBorder());
248 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
249 scrDisplay.setViewportView(tblDisplay);
251 pnlButton.setBorder(BorderFactory.createEtchedBorder());
253 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
254 pnlButton.setLayout(gl_pnlButton);
255 gl_pnlButton.setHorizontalGroup(
256 gl_pnlButton.createParallelGroup(Alignment.LEADING)
257 .addGroup(gl_pnlButton.createSequentialGroup()
259 .addPreferredGap(ComponentPlacement.RELATED)
260 .addComponent(btnStop)
261 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
264 gl_pnlButton.setVerticalGroup(
265 gl_pnlButton.createParallelGroup(Alignment.LEADING)
266 .addGroup(gl_pnlButton.createSequentialGroup()
268 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
269 .addComponent(btnStop)
271 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
278 cmbId = new IdComboBox(videoFileWatcher);
279 cmbId.getEditorComponent().addActionListener(applyListener);
280 cmbId.getEditorComponent().addFocusListener(new java.awt.event.FocusAdapter() {
282 public void focusLost(java.awt.event.FocusEvent evt) {
283 idFieldFocusLost(evt);
287 lblVideo.setText("動画");
289 cbVideoLocal.setText("local");
290 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
292 public void itemStateChanged(java.awt.event.ItemEvent evt) {
293 useMovieLocalCheckBoxItemStateChanged(evt);
297 lblComment.setText("コメント");
299 cbCommentLocal.setText("local");
300 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
302 public void itemStateChanged(java.awt.event.ItemEvent evt) {
303 useMovieLocalCheckBoxItemStateChanged(evt);
307 lblOutput.setText("出力");
309 cbOutputEnable.setText("変換");
310 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
312 public void itemStateChanged(java.awt.event.ItemEvent evt) {
313 outputConvertCheckBoxItemStateChanged(evt);
318 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
319 pnlInputMain.setLayout(glInputMain);
320 glInputMain.setHorizontalGroup(
321 glInputMain.createParallelGroup(Alignment.LEADING)
322 .addGroup(glInputMain.createSequentialGroup()
325 .addPreferredGap(ComponentPlacement.RELATED)
326 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
327 .addPreferredGap(ComponentPlacement.UNRELATED)
328 .addComponent(cbBackLogReduce)
329 .addPreferredGap(ComponentPlacement.UNRELATED)
330 .addComponent(cbBackLog)
331 .addPreferredGap(ComponentPlacement.RELATED)
332 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
335 .addGroup(glInputMain.createSequentialGroup()
337 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
338 .addComponent(lblVideo)
339 .addComponent(lblComment)
340 .addComponent(lblOutput)
342 .addPreferredGap(ComponentPlacement.RELATED)
343 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
344 .addComponent(cbVideoLocal)
345 .addComponent(cbCommentLocal)
346 .addComponent(cbOutputEnable)
348 .addPreferredGap(ComponentPlacement.RELATED)
349 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
350 .addComponent(cmbVideo, 300, 300, Short.MAX_VALUE)
351 .addComponent(cmbComment, 300, 300, Short.MAX_VALUE)
352 .addComponent(fldOutput, 300, 300, Short.MAX_VALUE)
354 .addGroup(glInputMain.createParallelGroup()
355 .addComponent(btnVideo)
356 .addComponent(btnComment)
362 glInputMain.setVerticalGroup(
363 glInputMain.createParallelGroup(Alignment.LEADING)
364 .addGroup(glInputMain.createSequentialGroup()
366 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
367 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
369 .addComponent(cbBackLogReduce)
370 .addComponent(cbBackLog)
371 .addComponent(fldBackLog)
373 .addPreferredGap(ComponentPlacement.RELATED)
374 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
375 .addComponent(lblVideo)
376 .addComponent(cbVideoLocal)
377 .addComponent(cmbVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
378 .addComponent(btnVideo)
380 .addPreferredGap(ComponentPlacement.RELATED)
381 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
382 .addComponent(lblComment)
383 .addComponent(cbCommentLocal)
384 .addComponent(cmbComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
385 .addComponent(btnComment)
387 .addPreferredGap(ComponentPlacement.RELATED)
388 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
389 .addComponent(lblOutput)
390 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
391 .addComponent(cbOutputEnable)
397 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
398 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
399 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
400 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
403 public void actionPerformed(ActionEvent e) {
404 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
405 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
406 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
407 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
408 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
409 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
410 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
413 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
416 public void itemStateChanged(ItemEvent e) {
417 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
418 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
419 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
420 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
423 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
426 public void propertyChange(PropertyChangeEvent evt) {
427 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
428 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
429 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
430 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
431 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
436 tbpInput.add("メイン", pnlInputMain);
437 tbpInput.add("ffmpeg", pnlInputFfmpeg);
440 fldInputMessage.setEditable(false);
441 fldInputMessage.setEnabled(false);
442 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
444 final JPanel pnlInputButton = new JPanel();
445 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
446 pnlInputButton.setLayout(glInputButton);
447 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
449 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
450 .addPreferredGap(ComponentPlacement.UNRELATED)
451 .addComponent(btnClear)
452 .addPreferredGap(ComponentPlacement.UNRELATED)
453 .addComponent(btnApply)
456 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
458 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
459 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
460 .addComponent(btnClear)
461 .addComponent(btnApply)
467 final JPanel pnlInputAll = new JPanel();
468 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
469 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
470 pnlInputAll.setLayout(glInputAll);
471 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
472 .addComponent(tbpInput)
473 .addComponent(pnlInputButton)
475 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
476 .addComponent(tbpInput)
477 .addComponent(pnlInputButton)
480 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
481 pnlMain.setLayout(gl_pnlMain);
482 gl_pnlMain.setHorizontalGroup(
483 gl_pnlMain.createParallelGroup(Alignment.LEADING)
484 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
486 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
487 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
488 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
489 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
493 gl_pnlMain.setVerticalGroup(
494 gl_pnlMain.createParallelGroup(Alignment.LEADING)
495 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
497 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
498 .addPreferredGap(ComponentPlacement.RELATED)
499 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
500 .addPreferredGap(ComponentPlacement.RELATED)
501 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
507 JMenuBar menuBar = initMenuBar();
508 setJMenuBar(menuBar);
510 GroupLayout layout = new GroupLayout(getContentPane());
511 getContentPane().setLayout(layout);
512 layout.setHorizontalGroup(
513 layout.createParallelGroup(Alignment.LEADING)
514 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
516 layout.setVerticalGroup(
517 layout.createParallelGroup(Alignment.LEADING)
518 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
522 setMinimumSize(getSize());
525 * 画面のサイズや位置を前回終了時のものに設定する
527 final int windowWidth = p.getSystemWindowWidth();
528 final int windowHeight = p.getSystemWindowHeight();
529 if (windowWidth > 0 && windowHeight > 0) {
530 setSize(windowWidth, windowHeight);
533 final int windowPosX = p.getSystemWindowPosX();
534 final int windowPosY = p.getSystemWindowPosY();
535 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
536 if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
537 && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
538 setLocation(windowPosX, windowPosY);
540 setLocationByPlatform(true);
543 final int colId = p.getSystemColumnId();
545 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
547 final int colStatus = p.getSystemColumnStatus();
549 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
555 public void startWatcher() {
556 videoFileWatcherThread.start();
557 commentFileWatcherThread.start();
560 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
562 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
563 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
564 combo.setModel(model);
566 combo.setModel(new DefaultComboBoxModel<String>());
567 combo.getEditorComponent().setText(pattern);
571 private class GuiTaskManageListener implements TaskManageListener {
574 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
575 final String message) {
576 SwingUtilities.invokeLater(new Runnable() {
580 targetModel.setStatus(id, kind, status, percentage, message);
586 private class StopActionListener implements ActionListener {
589 public void actionPerformed(ActionEvent e) {
590 final int row = tblDisplay.getSelectedRow();
591 final Target t = targetModel.getTarget(row);
592 final boolean res = taskManager.cancel(t.getRowId());
593 logger.debug("停止: {} {}", t.getVideoId(), res);
595 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
600 private class ApplyActionListener implements ActionListener {
603 public void actionPerformed(ActionEvent e) {
605 final DownloadProfile downProf = new InqubusDownloadProfile();
606 final String id = Util.getVideoId(cmbId.getText());
607 final InqubusConvertProfile convProf = new InqubusConvertProfile();
608 logger.debug(downProf.toString());
609 logger.debug(convProf.toString());
611 final File tempDir = new File(Config.INSTANCE.getSystemTempDir());
612 thumbRepository.request(downProf.getProxyProfile(), tempDir, id);
614 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
616 targetModel.addTarget(new Target(rp));
618 } catch (Throwable th) {
619 logger.error(null, th);
620 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
626 * 動画, コメントの"local"チェックボックス更新時の処理.
628 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
629 final Config p = Config.INSTANCE;
631 final ItemSelectable source = evt.getItemSelectable();
637 if (source == cbVideoLocal) {
640 allFiles = videoFileWatcher.getFiles();
641 pattern = p.getVideoFileNamePattern();
645 allFiles = commentFileWatcher.getFiles();
646 pattern = p.getCommentFileNamePattern();
649 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
651 button.setEnabled(useLocal);
652 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
656 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
657 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
658 fldOutput.setEnabled(convert);
659 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
661 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
662 final Config p = Config.INSTANCE;
663 final String id = cmbId.getText();
665 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
666 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
667 }//GEN-LAST:event_idFieldFocusLost
668 // Variables declaration - do not modify//GEN-BEGIN:variables
669 private final JTable tblDisplay;
671 private final JButton btnStop = new JButton("停止");
673 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
675 private final IdComboBox cmbId;
676 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
677 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
678 private final JTextField fldBackLog = new JTextField();
679 private final JCheckBox cbVideoLocal;
680 private final FileComboBox cmbVideo = new FileComboBox();
681 private final JTextField fldVideo = cmbVideo.getEditorComponent();
682 private final JButton btnVideo = new JButton("...");
683 private final JCheckBox cbCommentLocal;
684 private final FileComboBox cmbComment = new FileComboBox();
685 private final JTextField fldComment = cmbComment.getEditorComponent();
686 private final JButton btnComment = new JButton("...");
687 private final JCheckBox cbOutputEnable;
688 private final JTextField fldOutput;
690 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
692 private final JTextField fldInputMessage = new JTextField();
693 private final JButton btnClear = new JButton("クリア");
694 private final JButton btnApply = new JButton("適用");
695 // End of variables declaration//GEN-END:variables
697 private void initInputPanel() {
700 tbpInput.setSelectedIndex(0);
701 cmbId.requestFocus();
704 private void initMainTab() {
705 final Config p = Config.INSTANCE;
708 cbBackLogReduce.setSelected(p.getCommentMinDisabled());
709 cbBackLog.setEnabled(true);
710 cbBackLog.setSelected(false);
711 fldBackLog.setEnabled(false);
712 fldBackLog.setText("");
714 final boolean videoLocal = p.getVideoUseLocal();
715 cbVideoLocal.setSelected(videoLocal);
717 fldVideo.setText(p.getVideoFileNamePattern());
719 btnVideo.setEnabled(videoLocal);
721 final boolean commentLocal = p.getCommentUseLocal();
722 cbCommentLocal.setSelected(commentLocal);
724 fldComment.setText(p.getCommentFileNamePattern());
726 btnComment.setEnabled(commentLocal);
728 final boolean convert = p.getOutputEnable();
729 cbOutputEnable.setSelected(convert);
730 fldOutput.setEnabled(convert);
731 fldOutput.setText(p.getOutputFileNamePattern());
734 private void initFfmpegTab() {
735 pnlInputFfmpeg.init(Config.INSTANCE);
738 private JMenuBar initMenuBar() {
739 final JMenuBar menuBar = new JMenuBar();
741 final JMenu mnFile = new JMenu("ファイル(F)");
744 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
745 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
746 final ActionListener exitActionListener = new ActionListener() {
749 public void actionPerformed(ActionEvent e) {
750 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
753 itExit.addActionListener(exitActionListener);
756 final JMenu mnTool = new JMenu("ツール(T)");
759 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
760 itOption.addActionListener(new ActionListener() {
763 public void actionPerformed(ActionEvent e) {
764 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
765 dlg.setLocationRelativeTo(MainFrame.this);
767 dlg.setVisible(true);
770 mnTool.add(itOption);
772 final JMenu mnHelp = new JMenu("ヘルプ(H)");
775 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
776 itAbout.addActionListener(new ActionListener() {
779 public void actionPerformed(ActionEvent e) {
780 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
782 dlg.setLocationRelativeTo(MainFrame.this);
784 dlg.setVisible(true);
792 private class MainFrameWindowListener extends WindowAdapter {
794 public void windowClosing(WindowEvent e) {
795 final Config p = Config.INSTANCE;
797 // 保存するのは最大化していない場合だけ
798 if (JFrame.NORMAL == getExtendedState()) {
799 final Dimension size = getSize();
800 p.setSystemWindowWidth(size.width);
801 p.setSystemWindowHeight(size.height);
803 final Point pos = getLocation();
804 p.setSystemWindowPosX(pos.x);
805 p.setSystemWindowPosY(pos.y);
808 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
809 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
810 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
811 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
812 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
815 } catch (ConfigurationException ex) {
816 logger.error("コンフィグ保存失敗", ex);
822 * ここからDownloadProfile作成用クラスの定義
824 private class InqubusDownloadProfile implements DownloadProfile {
826 private final LoginProfile loginProfile;
827 private final ProxyProfile proxyProfile;
828 private final VideoProfile videoProfile;
829 private final CommentProfile commentProfile;
830 private final GeneralProfile generalProfile;
832 private InqubusDownloadProfile() {
833 this.loginProfile = new ConfigLoginProfile();
834 this.proxyProfile = new ConfigProxyProfile();
835 this.videoProfile = new InqubusVideoProfile();
836 this.commentProfile = new InqubusCommentProfile();
837 this.generalProfile = new ConfigGeneralProfile();
841 public LoginProfile getLoginProfile() {
842 return this.loginProfile;
846 public ProxyProfile getProxyProfile() {
847 return this.proxyProfile;
851 public VideoProfile getVideoProfile() {
852 return this.videoProfile;
856 public CommentProfile getCommentProfile() {
857 return this.commentProfile;
861 public GeneralProfile getGeneralProfile() {
862 return this.generalProfile;
866 public String toString(){
867 return ToStringBuilder.reflectionToString(this);
871 private class InqubusVideoProfile implements VideoProfile {
872 private final boolean download;
873 private final File dir;
874 private final String fileName;
875 private final File localFile;
877 private InqubusVideoProfile(){
878 final Config p = Config.INSTANCE;
879 this.download = !cbVideoLocal.isSelected();
881 this.dir = new File(p.getVideoDir());
882 this.fileName = fldVideo.getText();
883 this.localFile = null;
886 this.fileName = null;
887 this.localFile = new File(fldVideo.getText());
892 public boolean isDownload() {
893 return this.download;
897 public File getDir() {
902 public String getFileName() {
903 return this.fileName;
907 public File getLocalFile() {
908 return this.localFile;
912 public String toString(){
913 return ToStringBuilder.reflectionToString(this);
917 private class InqubusCommentProfile extends ConfigCommentProfile {
918 private final boolean download;
919 private final File dir;
920 private final String fileName;
921 private final File localFile;
922 private final boolean disablePerMinComment;
923 private final long backLogPoint;
925 private InqubusCommentProfile() {
928 final Config p = Config.INSTANCE;
929 this.download = !cbCommentLocal.isSelected();
931 this.dir = new File(p.getCommentDir());
932 this.fileName = fldComment.getText();
933 this.localFile = null;
936 this.fileName = null;
937 this.localFile = new File(fldComment.getText());
940 if(cbBackLog.isSelected()) {
942 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
943 } catch (IOException ex) {
944 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
947 this.backLogPoint = -1L;
950 this.disablePerMinComment = cbBackLogReduce.isSelected();
954 public boolean isDownload() {
955 return this.download;
959 public File getDir() {
964 public String getFileName() {
965 return this.fileName;
969 public File getLocalFile() {
970 return this.localFile;
974 public boolean isDisablePerMinComment() {
975 return this.disablePerMinComment;
979 public long getBackLogPoint() {
980 return this.backLogPoint;
984 public String toString(){
985 return ToStringBuilder.reflectionToString(this);
990 * ここからConvertProfile作成用クラスの定義
992 private class InqubusConvertProfile extends ConfigConvertProfile {
993 private final OutputProfile outputProfile;
994 private final GeneralProfile generalProfile;
995 private final FfmpegProfile ffmpegProfile;
996 private final boolean convert;
998 private InqubusConvertProfile() throws IOException {
999 this.outputProfile = new InqubusOutputProfile();
1000 this.generalProfile = new ConfigGeneralProfile();
1002 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1004 this.ffmpegProfile = new ConfigFfmpegProfile();
1006 this.ffmpegProfile = new InqubusFfmpegProfile();
1009 this.convert = cbOutputEnable.isSelected();
1013 public OutputProfile getOutputProfile() {
1014 return this.outputProfile;
1018 public GeneralProfile getGeneralProfile() {
1019 return this.generalProfile;
1023 public FfmpegProfile getFfmpegOption() {
1024 return this.ffmpegProfile;
1028 public boolean isConvert() {
1029 return this.convert;
1033 public String toString(){
1034 return ToStringBuilder.reflectionToString(this);
1038 private class InqubusOutputProfile extends ConfigOutputProfile {
1039 private final String fileName;
1040 private final String videoId;
1041 private final String title;
1044 private InqubusOutputProfile() {
1045 this.fileName = fldOutput.getText();
1046 // TODO この時点でのID/Titleはどうするか…
1052 public String getFileName() {
1053 return this.fileName;
1057 public String getVideoId() {
1058 return this.videoId;
1062 public String getTitile() {
1067 public String toString(){
1068 return ToStringBuilder.reflectionToString(this);
1072 private class InqubusFfmpegProfile implements FfmpegProfile {
1073 private final String extOption;
1074 private final String inOption;
1075 private final String mainOption;
1076 private final String outOption;
1077 private final String avOption;
1078 private final boolean resize;
1079 private final int resizeWidth;
1080 private final int resizeHeight;
1081 private final boolean adjustRatio;
1083 private InqubusFfmpegProfile() throws IOException {
1084 String ext = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1085 if (!ext.startsWith(".")) {
1088 this.extOption = ext;
1089 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1090 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1091 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1092 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1093 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1094 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1095 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1096 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1100 public String getExtOption() {
1101 return this.extOption;
1105 public String getInOption() {
1106 return this.inOption;
1110 public String getMainOption() {
1111 return this.mainOption;
1115 public String getOutOption() {
1116 return this.outOption;
1120 public String getAvfilterOption() {
1121 return this.avOption;
1125 public boolean isResize() {
1130 public int getResizeWidth() {
1131 return this.resizeWidth;
1135 public int getResizeHeight() {
1136 return this.resizeHeight;
1140 public boolean isAdjustRatio() {
1141 return this.adjustRatio;
1145 public String toString(){
1146 return ToStringBuilder.reflectionToString(this);