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.WindowAdapter;
19 import java.awt.event.WindowEvent;
20 import java.beans.PropertyChangeEvent;
21 import java.beans.PropertyChangeListener;
23 import java.io.IOException;
25 import java.nio.file.FileSystem;
26 import java.nio.file.FileSystems;
27 import java.nio.file.Path;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.List;
32 import java.util.SortedSet;
33 import java.util.logging.Level;
34 import java.util.logging.Logger;
35 import javax.swing.BorderFactory;
36 import javax.swing.DefaultComboBoxModel;
37 import javax.swing.DropMode;
38 import javax.swing.GroupLayout;
39 import javax.swing.GroupLayout.Alignment;
40 import javax.swing.JButton;
41 import javax.swing.JCheckBox;
42 import javax.swing.JFileChooser;
43 import javax.swing.JFrame;
44 import javax.swing.JLabel;
45 import javax.swing.JMenu;
46 import javax.swing.JMenuBar;
47 import javax.swing.JMenuItem;
48 import javax.swing.JOptionPane;
49 import javax.swing.JPanel;
50 import javax.swing.JScrollPane;
51 import javax.swing.JTabbedPane;
52 import javax.swing.JTable;
53 import javax.swing.JTextField;
54 import javax.swing.KeyStroke;
55 import javax.swing.LayoutStyle.ComponentPlacement;
56 import javax.swing.SwingUtilities;
57 import javax.swing.WindowConstants;
58 import javax.swing.border.BevelBorder;
59 import org.apache.commons.configuration.ConfigurationException;
60 import org.apache.commons.lang.builder.ToStringBuilder;
61 import saccubus.MainFrame_AboutBox;
62 import saccubus.util.WayBackTimeParser;
63 import saccubus.worker.profile.CommentProfile;
64 import saccubus.worker.profile.DownloadProfile;
65 import saccubus.worker.profile.FfmpegProfile;
66 import saccubus.worker.profile.GeneralProfile;
67 import saccubus.worker.profile.LoginProfile;
68 import saccubus.worker.profile.OutputProfile;
69 import saccubus.worker.profile.ProxyProfile;
70 import saccubus.worker.profile.VideoProfile;
72 import yukihane.inqubus.config.Config;
73 import yukihane.inqubus.config.ConfigCommentProfile;
74 import yukihane.inqubus.config.ConfigConvertProfile;
75 import yukihane.inqubus.config.ConfigFfmpegProfile;
76 import yukihane.inqubus.config.ConfigGeneralProfile;
77 import yukihane.inqubus.config.ConfigLoginProfile;
78 import yukihane.inqubus.config.ConfigOutputProfile;
79 import yukihane.inqubus.config.ConfigProxyProfile;
80 import yukihane.inqubus.filewatch.FileWatch;
81 import yukihane.inqubus.filewatch.FileWatchUtil;
82 import yukihane.inqubus.manager.RequestProcess;
83 import yukihane.inqubus.manager.TaskKind;
84 import yukihane.inqubus.manager.TaskManage;
85 import yukihane.inqubus.manager.TaskManageListener;
86 import yukihane.inqubus.manager.TaskStatus;
87 import yukihane.inqubus.model.Target;
88 import yukihane.inqubus.model.TargetsTableModel;
94 public class MainFrame extends JFrame {
96 private static final long serialVersionUID = 1L;
97 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
98 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
99 private static final String FILE_LOCALBUTTON_TOOLTIP
100 = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
101 private static final String FILE_INPUTFIELD_TOOLTIP
102 = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
103 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
104 private static final String FILE_OUTPUTFIELD_TOOLTIP
106 private final TargetsTableModel targetModel = new TargetsTableModel();
107 private final TaskManage taskManager;
108 private final Thread videoFileWatcherThread;
109 private final FileWatch videoFileWatcher;
110 private final Thread commentFileWatcherThread;
111 private final FileWatch commentFileWatcher;
114 /** Creates new form MainFrame */
117 addWindowListener(new MainFrameWindowListener());
119 final Config p = Config.INSTANCE;
122 final int thDownload = p.getSystemDownloadThread();
123 final int secDownload = p.getSystemDownloadWait();
124 final int thConvert = p.getSystemConvertThread();
125 taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
128 final FileSystem fs = FileSystems.getDefault();
130 final List<String> videoSearchDirs = p.getSearchVideoDirs();
131 videoSearchDirs.add(p.getVideoDir());
132 final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
133 for (String s : videoSearchDirs) {
134 videoPaths.add(fs.getPath(s));
136 videoFileWatcher = new FileWatch(videoPaths);
137 this.videoFileWatcherThread = new Thread(videoFileWatcher);
138 this.videoFileWatcherThread.setDaemon(true);
140 final List<String> commentSearchDirs = p.getSearchCommentDirs();
141 commentSearchDirs.add(p.getCommentDir());
142 final Set<Path> commentPaths = new HashSet<>(commentSearchDirs.size());
143 for(String s : commentSearchDirs) {
144 commentPaths.add(fs.getPath(s));
146 commentFileWatcher = new FileWatch(commentPaths);
147 this.commentFileWatcherThread = new Thread(commentFileWatcher);
148 this.commentFileWatcherThread.setDaemon(true);
150 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
151 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
152 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
153 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
154 final List<Image> images = new ArrayList<>(2);
157 setIconImages(images);
159 final JPanel pnlMain = new JPanel();
160 final JScrollPane scrDisplay = new JScrollPane();
161 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
162 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
163 final JPanel pnlButton = new JPanel();
164 final JPanel pnlInputMain = new JPanel();
165 final JLabel lblId = new JLabel();
166 final JLabel lblVideo = new JLabel();
167 cbVideoLocal = new JCheckBox();
168 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
169 cmbVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
170 btnVideo.addActionListener(
171 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldVideo));
172 fldVideo.setTransferHandler(new ContentTransferHandler(fldVideo.getTransferHandler(), cbVideoLocal));
173 final JLabel lblComment = new JLabel();
175 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
176 cbBackLog.addItemListener(new ItemListener() {
179 public void itemStateChanged(ItemEvent e) {
180 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
181 fldBackLog.setEnabled(selected);
184 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
187 public void propertyChange(PropertyChangeEvent evt) {
188 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
189 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
190 fldBackLog.setEnabled(fldEnabled);
193 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
195 cbCommentLocal = new JCheckBox();
196 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
197 cbCommentLocal.addItemListener(new ItemListener() {
200 public void itemStateChanged(ItemEvent e) {
201 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
202 cbBackLogReduce.setEnabled(!selected);
203 cbBackLog.setEnabled(!selected);
206 cmbComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
207 btnComment.addActionListener(
208 new FileChooseActionListener(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
209 fldComment.setTransferHandler(new ContentTransferHandler(fldComment.getTransferHandler(), cbCommentLocal));
210 final JLabel lblOutput = new JLabel();
211 cbOutputEnable = new JCheckBox();
212 fldOutput = new JTextField();
213 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
215 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
217 btnStop.addActionListener(new StopActionListener());
218 final ApplyActionListener applyListener = new ApplyActionListener();
219 btnApply.addActionListener(applyListener);
220 btnClear.addActionListener(new ActionListener() {
223 public void actionPerformed(ActionEvent e) {
228 pnlMain.setBorder(BorderFactory.createEtchedBorder());
230 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
231 scrDisplay.setViewportView(tblDisplay);
233 pnlButton.setBorder(BorderFactory.createEtchedBorder());
235 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
236 pnlButton.setLayout(gl_pnlButton);
237 gl_pnlButton.setHorizontalGroup(
238 gl_pnlButton.createParallelGroup(Alignment.LEADING)
239 .addGroup(gl_pnlButton.createSequentialGroup()
241 .addPreferredGap(ComponentPlacement.RELATED)
242 .addComponent(btnStop)
243 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
246 gl_pnlButton.setVerticalGroup(
247 gl_pnlButton.createParallelGroup(Alignment.LEADING)
248 .addGroup(gl_pnlButton.createSequentialGroup()
250 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
251 .addComponent(btnStop)
253 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
260 cmbId = new IdComboBox(videoFileWatcher);
261 cmbId.setToolTipText(ID_FIELD_TOOLTIP);
262 cmbId.getEditorComponent().addActionListener(applyListener);
263 cmbId.getEditorComponent().addFocusListener(new java.awt.event.FocusAdapter() {
265 public void focusLost(java.awt.event.FocusEvent evt) {
266 idFieldFocusLost(evt);
270 lblVideo.setText("動画");
272 cbVideoLocal.setText("local");
273 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
275 public void itemStateChanged(java.awt.event.ItemEvent evt) {
276 useMovieLocalCheckBoxItemStateChanged(evt);
280 lblComment.setText("コメント");
282 cbCommentLocal.setText("local");
283 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
285 public void itemStateChanged(java.awt.event.ItemEvent evt) {
286 useMovieLocalCheckBoxItemStateChanged(evt);
290 lblOutput.setText("出力");
292 cbOutputEnable.setText("変換");
293 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
295 public void itemStateChanged(java.awt.event.ItemEvent evt) {
296 outputConvertCheckBoxItemStateChanged(evt);
301 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
302 pnlInputMain.setLayout(glInputMain);
303 glInputMain.setHorizontalGroup(
304 glInputMain.createParallelGroup(Alignment.LEADING)
305 .addGroup(glInputMain.createSequentialGroup()
308 .addPreferredGap(ComponentPlacement.RELATED)
309 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
310 .addPreferredGap(ComponentPlacement.UNRELATED)
311 .addComponent(cbBackLogReduce)
312 .addPreferredGap(ComponentPlacement.UNRELATED)
313 .addComponent(cbBackLog)
314 .addPreferredGap(ComponentPlacement.RELATED)
315 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
318 .addGroup(glInputMain.createSequentialGroup()
320 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
321 .addComponent(lblVideo)
322 .addComponent(lblComment)
323 .addComponent(lblOutput)
325 .addPreferredGap(ComponentPlacement.RELATED)
326 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
327 .addComponent(cbVideoLocal)
328 .addComponent(cbCommentLocal)
329 .addComponent(cbOutputEnable)
331 .addPreferredGap(ComponentPlacement.RELATED)
332 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
333 .addComponent(cmbVideo, 300, 300, Short.MAX_VALUE)
334 .addComponent(cmbComment, 300, 300, Short.MAX_VALUE)
335 .addComponent(fldOutput, 300, 300, Short.MAX_VALUE)
337 .addGroup(glInputMain.createParallelGroup()
338 .addComponent(btnVideo)
339 .addComponent(btnComment)
345 glInputMain.setVerticalGroup(
346 glInputMain.createParallelGroup(Alignment.LEADING)
347 .addGroup(glInputMain.createSequentialGroup()
349 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
350 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
352 .addComponent(cbBackLogReduce)
353 .addComponent(cbBackLog)
354 .addComponent(fldBackLog)
356 .addPreferredGap(ComponentPlacement.RELATED)
357 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
358 .addComponent(lblVideo)
359 .addComponent(cbVideoLocal)
360 .addComponent(cmbVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
361 .addComponent(btnVideo)
363 .addPreferredGap(ComponentPlacement.RELATED)
364 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
365 .addComponent(lblComment)
366 .addComponent(cbCommentLocal)
367 .addComponent(cmbComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
368 .addComponent(btnComment)
370 .addPreferredGap(ComponentPlacement.RELATED)
371 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
372 .addComponent(lblOutput)
373 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
374 .addComponent(cbOutputEnable)
380 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
381 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
382 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
383 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
386 public void actionPerformed(ActionEvent e) {
387 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
388 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
389 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
390 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
391 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
392 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
393 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
396 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
399 public void itemStateChanged(ItemEvent e) {
400 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
401 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
402 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
403 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
406 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
409 public void propertyChange(PropertyChangeEvent evt) {
410 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
411 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
412 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
413 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
414 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
419 tbpInput.add("メイン", pnlInputMain);
420 tbpInput.add("ffmpeg", pnlInputFfmpeg);
423 fldInputMessage.setEditable(false);
424 fldInputMessage.setEnabled(false);
425 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
427 final JPanel pnlInputButton = new JPanel();
428 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
429 pnlInputButton.setLayout(glInputButton);
430 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
432 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
433 .addPreferredGap(ComponentPlacement.UNRELATED)
434 .addComponent(btnClear)
435 .addPreferredGap(ComponentPlacement.UNRELATED)
436 .addComponent(btnApply)
439 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
441 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
442 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
443 .addComponent(btnClear)
444 .addComponent(btnApply)
450 final JPanel pnlInputAll = new JPanel();
451 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
452 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
453 pnlInputAll.setLayout(glInputAll);
454 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
455 .addComponent(tbpInput)
456 .addComponent(pnlInputButton)
458 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
459 .addComponent(tbpInput)
460 .addComponent(pnlInputButton)
463 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
464 pnlMain.setLayout(gl_pnlMain);
465 gl_pnlMain.setHorizontalGroup(
466 gl_pnlMain.createParallelGroup(Alignment.LEADING)
467 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
469 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
470 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
471 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
472 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
476 gl_pnlMain.setVerticalGroup(
477 gl_pnlMain.createParallelGroup(Alignment.LEADING)
478 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
480 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
481 .addPreferredGap(ComponentPlacement.RELATED)
482 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
483 .addPreferredGap(ComponentPlacement.RELATED)
484 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
490 JMenuBar menuBar = initMenuBar();
491 setJMenuBar(menuBar);
493 GroupLayout layout = new GroupLayout(getContentPane());
494 getContentPane().setLayout(layout);
495 layout.setHorizontalGroup(
496 layout.createParallelGroup(Alignment.LEADING)
497 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
499 layout.setVerticalGroup(
500 layout.createParallelGroup(Alignment.LEADING)
501 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
505 setMinimumSize(getSize());
508 * 画面のサイズや位置を前回終了時のものに設定する
510 final int windowWidth = p.getSystemWindowWidth();
511 final int windowHeight = p.getSystemWindowHeight();
512 if (windowWidth > 0 && windowHeight > 0) {
513 setSize(windowWidth, windowHeight);
516 final int windowPosX = p.getSystemWindowPosX();
517 final int windowPosY = p.getSystemWindowPosY();
518 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
519 if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
520 && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
521 setLocation(windowPosX, windowPosY);
523 setLocationByPlatform(true);
526 final int colId = p.getSystemColumnId();
528 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
530 final int colStatus = p.getSystemColumnStatus();
532 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
538 public void startWatcher() {
539 videoFileWatcherThread.start();
540 commentFileWatcherThread.start();
543 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
545 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
546 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
547 combo.setModel(model);
549 combo.setModel(new DefaultComboBoxModel<String>());
550 combo.getEditorComponent().setText(pattern);
554 private class GuiTaskManageListener implements TaskManageListener {
557 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
558 final String message) {
559 SwingUtilities.invokeLater(new Runnable() {
563 targetModel.setStatus(id, kind, status, percentage, message);
569 private class StopActionListener implements ActionListener {
572 public void actionPerformed(ActionEvent e) {
573 final int row = tblDisplay.getSelectedRow();
574 final Target t = targetModel.getTarget(row);
575 final boolean res = taskManager.cancel(t.getRowId());
576 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
578 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
583 private class ApplyActionListener implements ActionListener {
586 public void actionPerformed(ActionEvent e) {
588 final DownloadProfile downProf = new InqubusDownloadProfile();
589 final String id = Util.getVideoId(cmbId.getText());
590 final InqubusConvertProfile convProf = new InqubusConvertProfile();
591 logger.log(Level.INFO, downProf.toString());
592 logger.log(Level.INFO, convProf.toString());
593 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
595 targetModel.addTarget(new Target(rp));
597 } catch (Throwable th) {
598 logger.log(Level.SEVERE, null, th);
599 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
605 * 動画, コメントの"local"チェックボックス更新時の処理.
607 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
608 final Config p = Config.INSTANCE;
610 final ItemSelectable source = evt.getItemSelectable();
616 if (source == cbVideoLocal) {
619 allFiles = videoFileWatcher.getFiles();
620 pattern = p.getVideoFileNamePattern();
624 allFiles = commentFileWatcher.getFiles();
625 pattern = p.getCommentFileNamePattern();
628 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
630 button.setEnabled(useLocal);
631 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
635 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
636 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
637 fldOutput.setEnabled(convert);
638 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
640 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
641 final Config p = Config.INSTANCE;
642 final String id = cmbId.getText();
644 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
645 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
646 }//GEN-LAST:event_idFieldFocusLost
647 // Variables declaration - do not modify//GEN-BEGIN:variables
648 private final JTable tblDisplay;
650 private final JButton btnStop = new JButton("停止");
652 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
654 private final IdComboBox cmbId;
655 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
656 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
657 private final JTextField fldBackLog = new JTextField();
658 private final JCheckBox cbVideoLocal;
659 private final FileComboBox cmbVideo = new FileComboBox();
660 private final JTextField fldVideo = cmbVideo.getEditorComponent();
661 private final JButton btnVideo = new JButton("...");
662 private final JCheckBox cbCommentLocal;
663 private final FileComboBox cmbComment = new FileComboBox();
664 private final JTextField fldComment = cmbComment.getEditorComponent();
665 private final JButton btnComment = new JButton("...");
666 private final JCheckBox cbOutputEnable;
667 private final JTextField fldOutput;
669 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
671 private final JTextField fldInputMessage = new JTextField();
672 private final JButton btnClear = new JButton("クリア");
673 private final JButton btnApply = new JButton("適用");
674 // End of variables declaration//GEN-END:variables
676 private void initInputPanel() {
679 tbpInput.setSelectedIndex(0);
680 cmbId.requestFocus();
683 private void initMainTab() {
684 final Config p = Config.INSTANCE;
687 cbBackLogReduce.setSelected(p.getCommentMinDisabled());
688 cbBackLog.setEnabled(true);
689 cbBackLog.setSelected(false);
690 fldBackLog.setEnabled(false);
691 fldBackLog.setText("");
693 final boolean videoLocal = p.getVideoUseLocal();
694 cbVideoLocal.setSelected(videoLocal);
696 fldVideo.setText(p.getVideoFileNamePattern());
698 btnVideo.setEnabled(videoLocal);
700 final boolean commentLocal = p.getCommentUseLocal();
701 cbCommentLocal.setSelected(commentLocal);
703 fldComment.setText(p.getCommentFileNamePattern());
705 btnComment.setEnabled(commentLocal);
707 final boolean convert = p.getOutputEnable();
708 cbOutputEnable.setSelected(convert);
709 fldOutput.setEnabled(convert);
710 fldOutput.setText(p.getOutputFileNamePattern());
713 private void initFfmpegTab() {
714 pnlInputFfmpeg.init(Config.INSTANCE);
717 private JMenuBar initMenuBar() {
718 final JMenuBar menuBar = new JMenuBar();
720 final JMenu mnFile = new JMenu("ファイル(F)");
723 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
724 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
725 final ActionListener exitActionListener = new ActionListener() {
728 public void actionPerformed(ActionEvent e) {
729 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
732 itExit.addActionListener(exitActionListener);
735 final JMenu mnTool = new JMenu("ツール(T)");
738 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
739 itOption.addActionListener(new ActionListener() {
742 public void actionPerformed(ActionEvent e) {
743 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
744 dlg.setLocationRelativeTo(MainFrame.this);
746 dlg.setVisible(true);
749 mnTool.add(itOption);
751 final JMenu mnHelp = new JMenu("ヘルプ(H)");
754 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
755 itAbout.addActionListener(new ActionListener() {
758 public void actionPerformed(ActionEvent e) {
759 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
761 dlg.setLocationRelativeTo(MainFrame.this);
763 dlg.setVisible(true);
771 private class MainFrameWindowListener extends WindowAdapter {
773 public void windowClosing(WindowEvent e) {
774 final Config p = Config.INSTANCE;
776 // 保存するのは最大化していない場合だけ
777 if (JFrame.NORMAL == getExtendedState()) {
778 final Dimension size = getSize();
779 p.setSystemWindowWidth(size.width);
780 p.setSystemWindowHeight(size.height);
782 final Point pos = getLocation();
783 p.setSystemWindowPosX(pos.x);
784 p.setSystemWindowPosY(pos.y);
787 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
788 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
789 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
790 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
791 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
794 } catch (ConfigurationException ex) {
795 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
801 * ここからDownloadProfile作成用クラスの定義
803 private class InqubusDownloadProfile implements DownloadProfile {
805 private final LoginProfile loginProfile;
806 private final ProxyProfile proxyProfile;
807 private final VideoProfile videoProfile;
808 private final CommentProfile commentProfile;
809 private final GeneralProfile generalProfile;
811 private InqubusDownloadProfile() {
812 this.loginProfile = new ConfigLoginProfile();
813 this.proxyProfile = new ConfigProxyProfile();
814 this.videoProfile = new InqubusVideoProfile();
815 this.commentProfile = new InqubusCommentProfile();
816 this.generalProfile = new ConfigGeneralProfile();
820 public LoginProfile getLoginProfile() {
821 return this.loginProfile;
825 public ProxyProfile getProxyProfile() {
826 return this.proxyProfile;
830 public VideoProfile getVideoProfile() {
831 return this.videoProfile;
835 public CommentProfile getCommentProfile() {
836 return this.commentProfile;
840 public GeneralProfile getGeneralProfile() {
841 return this.generalProfile;
845 public String toString(){
846 return ToStringBuilder.reflectionToString(this);
850 private class InqubusVideoProfile implements VideoProfile {
851 private final boolean download;
852 private final File dir;
853 private final String fileName;
854 private final File localFile;
856 private InqubusVideoProfile(){
857 final Config p = Config.INSTANCE;
858 this.download = !cbVideoLocal.isSelected();
860 this.dir = new File(p.getVideoDir());
861 this.fileName = fldVideo.getText();
862 this.localFile = null;
865 this.fileName = null;
866 this.localFile = new File(fldVideo.getText());
871 public boolean isDownload() {
872 return this.download;
876 public File getDir() {
881 public String getFileName() {
882 return this.fileName;
886 public File getLocalFile() {
887 return this.localFile;
891 public String toString(){
892 return ToStringBuilder.reflectionToString(this);
896 private class InqubusCommentProfile extends ConfigCommentProfile {
897 private final boolean download;
898 private final File dir;
899 private final String fileName;
900 private final File localFile;
901 private final boolean disablePerMinComment;
902 private final long backLogPoint;
904 private InqubusCommentProfile() {
907 final Config p = Config.INSTANCE;
908 this.download = !cbCommentLocal.isSelected();
910 this.dir = new File(p.getCommentDir());
911 this.fileName = fldComment.getText();
912 this.localFile = null;
915 this.fileName = null;
916 this.localFile = new File(fldComment.getText());
919 if(cbBackLog.isSelected()) {
921 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
922 } catch (IOException ex) {
923 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
926 this.backLogPoint = -1L;
929 this.disablePerMinComment = cbBackLogReduce.isSelected();
933 public boolean isDownload() {
934 return this.download;
938 public File getDir() {
943 public String getFileName() {
944 return this.fileName;
948 public File getLocalFile() {
949 return this.localFile;
953 public boolean isDisablePerMinComment() {
954 return this.disablePerMinComment;
958 public long getBackLogPoint() {
959 return this.backLogPoint;
963 public String toString(){
964 return ToStringBuilder.reflectionToString(this);
969 * ここからConvertProfile作成用クラスの定義
971 private class InqubusConvertProfile extends ConfigConvertProfile {
972 private final OutputProfile outputProfile;
973 private final GeneralProfile generalProfile;
974 private final FfmpegProfile ffmpegProfile;
975 private final boolean convert;
977 private InqubusConvertProfile() throws IOException {
978 final Config p = Config.INSTANCE;
979 this.outputProfile = new InqubusOutputProfile();
980 this.generalProfile = new ConfigGeneralProfile();
982 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
984 this.ffmpegProfile = new ConfigFfmpegProfile();
986 this.ffmpegProfile = new InqubusFfmpegProfile();
989 this.convert = cbOutputEnable.isSelected();
993 public OutputProfile getOutputProfile() {
994 return this.outputProfile;
998 public GeneralProfile getGeneralProfile() {
999 return this.generalProfile;
1003 public FfmpegProfile getFfmpegOption() {
1004 return this.ffmpegProfile;
1008 public boolean isConvert() {
1009 return this.convert;
1013 public String toString(){
1014 return ToStringBuilder.reflectionToString(this);
1018 private class InqubusOutputProfile extends ConfigOutputProfile {
1019 private final String fileName;
1020 private final String videoId;
1021 private final String title;
1024 private InqubusOutputProfile() {
1025 final Config p = Config.INSTANCE;
1026 this.fileName = fldOutput.getText();
1027 // TODO この時点でのID/Titleはどうするか…
1033 public String getFileName() {
1034 return this.fileName;
1038 public String getVideoId() {
1039 return this.videoId;
1043 public String getTitile() {
1048 public String toString(){
1049 return ToStringBuilder.reflectionToString(this);
1053 private class InqubusFfmpegProfile implements FfmpegProfile {
1054 private final String extOption;
1055 private final String inOption;
1056 private final String mainOption;
1057 private final String outOption;
1058 private final String avOption;
1059 private final boolean resize;
1060 private final int resizeWidth;
1061 private final int resizeHeight;
1062 private final boolean adjustRatio;
1064 private InqubusFfmpegProfile() throws IOException {
1065 String ext = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1066 if (!ext.startsWith(".")) {
1069 this.extOption = ext;
1070 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1071 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1072 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1073 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1074 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1075 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1076 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1077 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1081 public String getExtOption() {
1082 return this.extOption;
1086 public String getInOption() {
1087 return this.inOption;
1091 public String getMainOption() {
1092 return this.mainOption;
1096 public String getOutOption() {
1097 return this.outOption;
1101 public String getAvfilterOption() {
1102 return this.avOption;
1106 public boolean isResize() {
1111 public int getResizeWidth() {
1112 return this.resizeWidth;
1116 public int getResizeHeight() {
1117 return this.resizeHeight;
1121 public boolean isAdjustRatio() {
1122 return this.adjustRatio;
1126 public String toString(){
1127 return ToStringBuilder.reflectionToString(this);