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 .addGroup(glInputMain.createSequentialGroup()
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)
360 .addGroup(glInputMain.createSequentialGroup()
361 .addComponent(cbOwnerComment)
362 .addPreferredGap(ComponentPlacement.UNRELATED)
363 .addComponent(cbBackLogReduce)
364 .addPreferredGap(ComponentPlacement.UNRELATED)
365 .addComponent(cbBackLog)
366 .addPreferredGap(ComponentPlacement.RELATED)
367 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
373 glInputMain.setVerticalGroup(
374 glInputMain.createParallelGroup(Alignment.LEADING)
375 .addGroup(glInputMain.createSequentialGroup()
377 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
378 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
381 .addPreferredGap(ComponentPlacement.RELATED)
382 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
383 .addComponent(lblVideo)
384 .addComponent(cbVideoLocal)
385 .addComponent(cmbVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
386 .addComponent(btnVideo)
388 .addPreferredGap(ComponentPlacement.RELATED)
389 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
390 .addComponent(lblComment)
391 .addComponent(cbCommentLocal)
392 .addComponent(cmbComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
393 .addComponent(btnComment)
395 .addPreferredGap(ComponentPlacement.RELATED)
396 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
397 .addComponent(cbOwnerComment)
398 .addComponent(cbBackLogReduce)
399 .addComponent(cbBackLog)
400 .addComponent(fldBackLog)
402 .addPreferredGap(ComponentPlacement.RELATED)
403 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
404 .addComponent(lblOutput)
405 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
406 .addComponent(cbOutputEnable)
412 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
413 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
414 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
415 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
418 public void actionPerformed(ActionEvent e) {
419 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
420 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
421 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
422 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
423 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
424 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
425 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
428 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
431 public void itemStateChanged(ItemEvent e) {
432 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
433 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
434 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
435 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
438 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
441 public void propertyChange(PropertyChangeEvent evt) {
442 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
443 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
444 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
445 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
446 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
451 tbpInput.add("メイン", pnlInputMain);
452 tbpInput.add("ffmpeg", pnlInputFfmpeg);
455 fldInputMessage.setEditable(false);
456 fldInputMessage.setEnabled(false);
457 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
459 final JPanel pnlInputButton = new JPanel();
460 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
461 pnlInputButton.setLayout(glInputButton);
462 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
464 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
465 .addPreferredGap(ComponentPlacement.UNRELATED)
466 .addComponent(btnClear)
467 .addPreferredGap(ComponentPlacement.UNRELATED)
468 .addComponent(btnApply)
471 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
473 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
474 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
475 .addComponent(btnClear)
476 .addComponent(btnApply)
482 final JPanel pnlInputAll = new JPanel();
483 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
484 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
485 pnlInputAll.setLayout(glInputAll);
486 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
487 .addComponent(tbpInput)
488 .addComponent(pnlInputButton)
490 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
491 .addComponent(tbpInput)
492 .addComponent(pnlInputButton)
495 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
496 pnlMain.setLayout(gl_pnlMain);
497 gl_pnlMain.setHorizontalGroup(
498 gl_pnlMain.createParallelGroup(Alignment.LEADING)
499 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
501 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
502 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
503 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
504 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
508 gl_pnlMain.setVerticalGroup(
509 gl_pnlMain.createParallelGroup(Alignment.LEADING)
510 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
512 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
513 .addPreferredGap(ComponentPlacement.RELATED)
514 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
515 .addPreferredGap(ComponentPlacement.RELATED)
516 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
522 JMenuBar menuBar = initMenuBar();
523 setJMenuBar(menuBar);
525 GroupLayout layout = new GroupLayout(getContentPane());
526 getContentPane().setLayout(layout);
527 layout.setHorizontalGroup(
528 layout.createParallelGroup(Alignment.LEADING)
529 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
531 layout.setVerticalGroup(
532 layout.createParallelGroup(Alignment.LEADING)
533 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
537 setMinimumSize(getSize());
540 * 画面のサイズや位置を前回終了時のものに設定する
542 final int windowWidth = p.getSystemWindowWidth();
543 final int windowHeight = p.getSystemWindowHeight();
544 if (windowWidth > 0 && windowHeight > 0) {
545 setSize(windowWidth, windowHeight);
548 final int windowPosX = p.getSystemWindowPosX();
549 final int windowPosY = p.getSystemWindowPosY();
550 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
551 if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
552 && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
553 setLocation(windowPosX, windowPosY);
555 setLocationByPlatform(true);
558 final int colId = p.getSystemColumnId();
560 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
562 final int colStatus = p.getSystemColumnStatus();
564 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
570 public void startWatcher() {
571 videoFileWatcherThread.start();
572 commentFileWatcherThread.start();
575 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
577 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
578 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
579 combo.setModel(model);
581 combo.setModel(new DefaultComboBoxModel<String>());
582 combo.getEditorComponent().setText(pattern);
586 private class GuiTaskManageListener implements TaskManageListener {
589 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
590 final String message) {
591 SwingUtilities.invokeLater(new Runnable() {
595 targetModel.setStatus(id, kind, status, percentage, message);
601 private class StopActionListener implements ActionListener {
604 public void actionPerformed(ActionEvent e) {
605 final int row = tblDisplay.getSelectedRow();
606 final Target t = targetModel.getTarget(row);
607 final boolean res = taskManager.cancel(t.getRowId());
608 logger.debug("停止: {} {}", t.getVideoId(), res);
610 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
615 private class ApplyActionListener implements ActionListener {
618 public void actionPerformed(ActionEvent e) {
620 final DownloadProfile downProf = new InqubusDownloadProfile();
621 final String id = Util.getVideoId(cmbId.getText());
622 final InqubusConvertProfile convProf = new InqubusConvertProfile();
623 logger.debug(downProf.toString());
624 logger.debug(convProf.toString());
626 final File tempDir = new File(Config.INSTANCE.getSystemTempDir());
627 thumbRepository.request(downProf.getProxyProfile(), tempDir, id);
629 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
630 final boolean res = taskManager.add(rp);
632 targetModel.addTarget(new Target(rp));
635 fldInputMessage.setText("行うべき処理がありません");
637 } catch (Throwable th) {
638 logger.error(null, th);
639 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
645 * 動画, コメントの"local"チェックボックス更新時の処理.
647 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
648 final Config p = Config.INSTANCE;
650 final ItemSelectable source = evt.getItemSelectable();
656 if (source == cbVideoLocal) {
659 allFiles = videoFileWatcher.getFiles();
660 pattern = p.getVideoFileNamePattern();
664 allFiles = commentFileWatcher.getFiles();
665 pattern = p.getCommentFileNamePattern();
668 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
670 button.setEnabled(useLocal);
671 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
675 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
676 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
677 fldOutput.setEnabled(convert);
678 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
680 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
681 final Config p = Config.INSTANCE;
682 final String id = cmbId.getText();
684 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
685 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
686 }//GEN-LAST:event_idFieldFocusLost
687 // Variables declaration - do not modify//GEN-BEGIN:variables
688 private final JTable tblDisplay;
690 private final JButton btnStop = new JButton("停止");
692 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
694 private final IdComboBox cmbId;
695 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
696 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
697 private final JTextField fldBackLog = new JTextField();
698 private final JCheckBox cbVideoLocal;
699 private final FileComboBox cmbVideo = new FileComboBox();
700 private final JTextField fldVideo = cmbVideo.getEditorComponent();
701 private final JButton btnVideo = new JButton("...");
702 private final JCheckBox cbCommentLocal;
703 private final FileComboBox cmbComment = new FileComboBox();
704 private final JTextField fldComment = cmbComment.getEditorComponent();
705 private final JButton btnComment = new JButton("...");
706 private final JCheckBox cbOwnerComment;
707 private final JCheckBox cbOutputEnable;
708 private final JTextField fldOutput;
710 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
712 private final JTextField fldInputMessage = new JTextField();
713 private final JButton btnClear = new JButton("クリア");
714 private final JButton btnApply = new JButton("適用");
715 // End of variables declaration//GEN-END:variables
717 private void initInputPanel() {
718 fldInputMessage.setText("");
721 tbpInput.setSelectedIndex(0);
722 cmbId.requestFocus();
725 private void initMainTab() {
726 final Config p = Config.INSTANCE;
729 cbOwnerComment.setSelected(p.getCommentOwnerOnly());
730 cbBackLogReduce.setSelected(p.getCommentMinDisabled());
731 cbBackLog.setEnabled(true);
732 cbBackLog.setSelected(false);
733 fldBackLog.setEnabled(false);
734 fldBackLog.setText("");
736 final boolean videoLocal = p.getVideoUseLocal();
737 cbVideoLocal.setSelected(videoLocal);
739 fldVideo.setText(p.getVideoFileNamePattern());
741 btnVideo.setEnabled(videoLocal);
743 final boolean commentLocal = p.getCommentUseLocal();
744 cbCommentLocal.setSelected(commentLocal);
746 fldComment.setText(p.getCommentFileNamePattern());
748 btnComment.setEnabled(commentLocal);
750 final boolean convert = p.getOutputEnable();
751 cbOutputEnable.setSelected(convert);
752 fldOutput.setEnabled(convert);
753 fldOutput.setText(p.getOutputFileNamePattern());
756 private void initFfmpegTab() {
757 pnlInputFfmpeg.init(Config.INSTANCE);
760 private JMenuBar initMenuBar() {
761 final JMenuBar menuBar = new JMenuBar();
763 final JMenu mnFile = new JMenu("ファイル(F)");
766 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
767 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
768 final ActionListener exitActionListener = new ActionListener() {
771 public void actionPerformed(ActionEvent e) {
772 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
775 itExit.addActionListener(exitActionListener);
778 final JMenu mnTool = new JMenu("ツール(T)");
781 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
782 itOption.addActionListener(new ActionListener() {
785 public void actionPerformed(ActionEvent e) {
786 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
787 dlg.setLocationRelativeTo(MainFrame.this);
789 dlg.setVisible(true);
792 mnTool.add(itOption);
794 final JMenu mnHelp = new JMenu("ヘルプ(H)");
797 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
798 itAbout.addActionListener(new ActionListener() {
801 public void actionPerformed(ActionEvent e) {
802 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
804 dlg.setLocationRelativeTo(MainFrame.this);
806 dlg.setVisible(true);
814 private class MainFrameWindowListener extends WindowAdapter {
816 public void windowClosing(WindowEvent e) {
817 final Config p = Config.INSTANCE;
819 // 保存するのは最大化していない場合だけ
820 if (JFrame.NORMAL == getExtendedState()) {
821 final Dimension size = getSize();
822 p.setSystemWindowWidth(size.width);
823 p.setSystemWindowHeight(size.height);
825 final Point pos = getLocation();
826 p.setSystemWindowPosX(pos.x);
827 p.setSystemWindowPosY(pos.y);
830 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
831 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
832 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
833 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
834 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
837 } catch (ConfigurationException ex) {
838 logger.error("コンフィグ保存失敗", ex);
844 * ここからDownloadProfile作成用クラスの定義
846 private class InqubusDownloadProfile implements DownloadProfile {
848 private final LoginProfile loginProfile;
849 private final ProxyProfile proxyProfile;
850 private final VideoProfile videoProfile;
851 private final CommentProfile commentProfile;
852 private final GeneralProfile generalProfile;
854 private InqubusDownloadProfile() {
855 this.loginProfile = new ConfigLoginProfile();
856 this.proxyProfile = new ConfigProxyProfile();
857 this.videoProfile = new InqubusVideoProfile();
858 this.commentProfile = new InqubusCommentProfile();
859 this.generalProfile = new ConfigGeneralProfile();
863 public LoginProfile getLoginProfile() {
864 return this.loginProfile;
868 public ProxyProfile getProxyProfile() {
869 return this.proxyProfile;
873 public VideoProfile getVideoProfile() {
874 return this.videoProfile;
878 public CommentProfile getCommentProfile() {
879 return this.commentProfile;
883 public GeneralProfile getGeneralProfile() {
884 return this.generalProfile;
888 public String toString(){
889 return ToStringBuilder.reflectionToString(this);
893 private class InqubusVideoProfile implements VideoProfile {
894 private final boolean download;
895 private final File dir;
896 private final String fileName;
897 private final File localFile;
899 private InqubusVideoProfile(){
900 final Config p = Config.INSTANCE;
901 this.download = !cbVideoLocal.isSelected();
903 this.dir = new File(p.getVideoDir());
904 this.fileName = fldVideo.getText();
905 this.localFile = null;
908 this.fileName = null;
909 this.localFile = new File(fldVideo.getText());
914 public boolean isDownload() {
915 return this.download;
919 public File getDir() {
924 public String getFileName() {
925 return this.fileName;
929 public File getLocalFile() {
930 return this.localFile;
934 public String toString(){
935 return ToStringBuilder.reflectionToString(this);
939 private class InqubusCommentProfile extends ConfigCommentProfile {
940 private final boolean download;
941 private final boolean ownerCommentOnly;
942 private final File dir;
943 private final String fileName;
944 private final File localFile;
945 private final boolean disablePerMinComment;
946 private final long backLogPoint;
948 private InqubusCommentProfile() {
951 final Config p = Config.INSTANCE;
952 this.download = !cbCommentLocal.isSelected();
954 this.dir = new File(p.getCommentDir());
955 this.fileName = fldComment.getText();
956 this.localFile = null;
957 this.ownerCommentOnly = cbOwnerComment.isSelected();
960 this.fileName = null;
961 this.localFile = new File(fldComment.getText());
962 this.ownerCommentOnly = false;
965 if(cbBackLog.isSelected()) {
967 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
968 } catch (IOException ex) {
969 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
972 this.backLogPoint = -1L;
975 this.disablePerMinComment = cbBackLogReduce.isSelected();
979 public boolean isDownload() {
980 return this.download;
984 public boolean isOwnerCommentOnly(){
985 return this.ownerCommentOnly;
989 public File getDir() {
994 public String getFileName() {
995 return this.fileName;
999 public File getLocalFile() {
1000 return this.localFile;
1004 public boolean isDisablePerMinComment() {
1005 return this.disablePerMinComment;
1009 public long getBackLogPoint() {
1010 return this.backLogPoint;
1014 public String toString(){
1015 return ToStringBuilder.reflectionToString(this);
1020 * ここからConvertProfile作成用クラスの定義
1022 private class InqubusConvertProfile extends ConfigConvertProfile {
1023 private final OutputProfile outputProfile;
1024 private final GeneralProfile generalProfile;
1025 private final FfmpegProfile ffmpegProfile;
1026 private final boolean convert;
1028 private InqubusConvertProfile() throws IOException {
1029 this.outputProfile = new InqubusOutputProfile();
1030 this.generalProfile = new ConfigGeneralProfile();
1032 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1034 this.ffmpegProfile = new ConfigFfmpegProfile();
1036 this.ffmpegProfile = new InqubusFfmpegProfile();
1039 this.convert = cbOutputEnable.isSelected();
1043 public OutputProfile getOutputProfile() {
1044 return this.outputProfile;
1048 public GeneralProfile getGeneralProfile() {
1049 return this.generalProfile;
1053 public FfmpegProfile getFfmpegOption() {
1054 return this.ffmpegProfile;
1058 public boolean isConvert() {
1059 return this.convert;
1063 public String toString(){
1064 return ToStringBuilder.reflectionToString(this);
1068 private class InqubusOutputProfile extends ConfigOutputProfile {
1069 private final String fileName;
1070 private final String videoId;
1071 private final String title;
1074 private InqubusOutputProfile() {
1075 this.fileName = fldOutput.getText();
1076 // TODO この時点でのID/Titleはどうするか…
1082 public String getFileName() {
1083 return this.fileName;
1087 public String getVideoId() {
1088 return this.videoId;
1092 public String getTitile() {
1097 public String toString(){
1098 return ToStringBuilder.reflectionToString(this);
1102 private class InqubusFfmpegProfile implements FfmpegProfile {
1103 private final String extOption;
1104 private final String inOption;
1105 private final String mainOption;
1106 private final String outOption;
1107 private final String avOption;
1108 private final boolean resize;
1109 private final int resizeWidth;
1110 private final int resizeHeight;
1111 private final boolean adjustRatio;
1113 private InqubusFfmpegProfile() throws IOException {
1114 String ext = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1115 if (!ext.startsWith(".")) {
1118 this.extOption = ext;
1119 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1120 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1121 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1122 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1123 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1124 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1125 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1126 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1130 public String getExtOption() {
1131 return this.extOption;
1135 public String getInOption() {
1136 return this.inOption;
1140 public String getMainOption() {
1141 return this.mainOption;
1145 public String getOutOption() {
1146 return this.outOption;
1150 public String getAvfilterOption() {
1151 return this.avOption;
1155 public boolean isResize() {
1160 public int getResizeWidth() {
1161 return this.resizeWidth;
1165 public int getResizeHeight() {
1166 return this.resizeHeight;
1170 public boolean isAdjustRatio() {
1171 return this.adjustRatio;
1175 public String toString(){
1176 return ToStringBuilder.reflectionToString(this);