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.datatransfer.DataFlavor;
14 import java.awt.datatransfer.Transferable;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.awt.event.ItemEvent;
18 import java.awt.event.ItemListener;
19 import java.awt.event.KeyEvent;
20 import java.awt.event.WindowAdapter;
21 import java.awt.event.WindowEvent;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
25 import java.io.IOException;
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 java.util.logging.Level;
36 import java.util.logging.Logger;
37 import java.util.regex.Pattern;
38 import javax.swing.BorderFactory;
39 import javax.swing.DefaultComboBoxModel;
40 import javax.swing.DropMode;
41 import javax.swing.GroupLayout;
42 import javax.swing.GroupLayout.Alignment;
43 import javax.swing.JButton;
44 import javax.swing.JCheckBox;
45 import javax.swing.JFileChooser;
46 import javax.swing.JFrame;
47 import javax.swing.JLabel;
48 import javax.swing.JMenu;
49 import javax.swing.JMenuBar;
50 import javax.swing.JMenuItem;
51 import javax.swing.JOptionPane;
52 import javax.swing.JPanel;
53 import javax.swing.JScrollPane;
54 import javax.swing.JTabbedPane;
55 import javax.swing.JTable;
56 import javax.swing.JTextField;
57 import javax.swing.KeyStroke;
58 import javax.swing.LayoutStyle.ComponentPlacement;
59 import javax.swing.SwingUtilities;
60 import javax.swing.TransferHandler;
61 import javax.swing.WindowConstants;
62 import javax.swing.border.BevelBorder;
63 import org.apache.commons.configuration.ConfigurationException;
64 import org.apache.commons.lang.builder.ToStringBuilder;
65 import saccubus.MainFrame_AboutBox;
66 import saccubus.util.WayBackTimeParser;
67 import saccubus.worker.profile.CommentProfile;
68 import saccubus.worker.profile.ConvertProfile;
69 import saccubus.worker.profile.DownloadProfile;
70 import saccubus.worker.profile.FfmpegProfile;
71 import saccubus.worker.profile.GeneralProfile;
72 import saccubus.worker.profile.LoginProfile;
73 import saccubus.worker.profile.OutputProfile;
74 import saccubus.worker.profile.ProxyProfile;
75 import saccubus.worker.profile.VideoProfile;
77 import yukihane.inqubus.config.Config;
78 import yukihane.inqubus.config.ConfigCommentProfile;
79 import yukihane.inqubus.config.ConfigConvertProfile;
80 import yukihane.inqubus.config.ConfigFfmpegProfile;
81 import yukihane.inqubus.config.ConfigGeneralProfile;
82 import yukihane.inqubus.config.ConfigLoginProfile;
83 import yukihane.inqubus.config.ConfigOutputProfile;
84 import yukihane.inqubus.config.ConfigProxyProfile;
85 import yukihane.inqubus.filewatch.FileWatch;
86 import yukihane.inqubus.filewatch.FileWatchUtil;
87 import yukihane.inqubus.manager.RequestProcess;
88 import yukihane.inqubus.manager.TaskKind;
89 import yukihane.inqubus.manager.TaskManage;
90 import yukihane.inqubus.manager.TaskManageListener;
91 import yukihane.inqubus.manager.TaskStatus;
92 import yukihane.inqubus.model.Target;
93 import yukihane.inqubus.model.TargetsTableModel;
99 public class MainFrame extends JFrame {
101 private static final long serialVersionUID = 1L;
102 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
103 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
104 private static final String FILE_LOCALBUTTON_TOOLTIP
105 = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
106 private static final String FILE_INPUTFIELD_TOOLTIP
107 = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
108 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
109 private static final String FILE_OUTPUTFIELD_TOOLTIP
111 private final TargetsTableModel targetModel = new TargetsTableModel();
112 private final TaskManage taskManager;
113 private final Thread videoFileWatcherThread;
114 private final FileWatch videoFileWatcher;
115 private final Thread commentFileWatcherThread;
116 private final FileWatch commentFileWatcher;
119 /** Creates new form MainFrame */
122 addWindowListener(new MainFrameWindowListener());
124 final Config p = Config.INSTANCE;
127 final int thDownload = p.getSystemDownloadThread();
128 final int secDownload = p.getSystemDownloadWait();
129 final int thConvert = p.getSystemConvertThread();
130 taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
133 final FileSystem fs = FileSystems.getDefault();
135 final List<String> videoSearchDirs = p.getSearchVideoDirs();
136 videoSearchDirs.add(p.getVideoDir());
137 final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
138 for (String s : videoSearchDirs) {
139 videoPaths.add(fs.getPath(s));
141 videoFileWatcher = new FileWatch(videoPaths);
142 this.videoFileWatcherThread = new Thread(videoFileWatcher);
143 this.videoFileWatcherThread.setDaemon(true);
145 final List<String> commentSearchDirs = p.getSearchCommentDirs();
146 commentSearchDirs.add(p.getCommentDir());
147 final Set<Path> commentPaths = new HashSet<>(commentSearchDirs.size());
148 for(String s : commentSearchDirs) {
149 commentPaths.add(fs.getPath(s));
151 commentFileWatcher = new FileWatch(commentPaths);
152 this.commentFileWatcherThread = new Thread(commentFileWatcher);
153 this.commentFileWatcherThread.setDaemon(true);
155 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
156 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
157 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
158 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
159 final List<Image> images = new ArrayList<>(2);
162 setIconImages(images);
164 final JPanel pnlMain = new JPanel();
165 final JScrollPane scrDisplay = new JScrollPane();
166 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
167 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
168 final JPanel pnlButton = new JPanel();
169 final JPanel pnlInputMain = new JPanel();
170 final JLabel lblId = new JLabel();
171 final JLabel lblVideo = new JLabel();
172 cbVideoLocal = new JCheckBox();
173 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
174 cmbVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
175 btnVideo.addActionListener(
176 new FileChooseAction(MainFrame.this, JFileChooser.FILES_ONLY, fldVideo));
177 final JLabel lblComment = new JLabel();
179 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
180 cbBackLog.addItemListener(new ItemListener() {
183 public void itemStateChanged(ItemEvent e) {
184 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
185 fldBackLog.setEnabled(selected);
188 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
191 public void propertyChange(PropertyChangeEvent evt) {
192 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
193 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
194 fldBackLog.setEnabled(fldEnabled);
197 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
199 cbCommentLocal = new JCheckBox();
200 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
201 cbCommentLocal.addItemListener(new ItemListener() {
204 public void itemStateChanged(ItemEvent e) {
205 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
206 cbBackLogReduce.setEnabled(!selected);
207 cbBackLog.setEnabled(!selected);
210 cmbComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
211 btnComment.addActionListener(
212 new FileChooseAction(MainFrame.this, JFileChooser.FILES_ONLY, fldComment));
213 final JLabel lblOutput = new JLabel();
214 cbOutputEnable = new JCheckBox();
215 fldOutput = new JTextField();
216 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
218 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
220 btnStop.addActionListener(new StopActionListener());
221 final ApplyActionListener applyListener = new ApplyActionListener();
222 btnApply.addActionListener(applyListener);
223 btnClear.addActionListener(new ActionListener() {
226 public void actionPerformed(ActionEvent e) {
231 pnlMain.setBorder(BorderFactory.createEtchedBorder());
233 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
234 scrDisplay.setViewportView(tblDisplay);
236 pnlButton.setBorder(BorderFactory.createEtchedBorder());
238 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
239 pnlButton.setLayout(gl_pnlButton);
240 gl_pnlButton.setHorizontalGroup(
241 gl_pnlButton.createParallelGroup(Alignment.LEADING)
242 .addGroup(gl_pnlButton.createSequentialGroup()
244 .addPreferredGap(ComponentPlacement.RELATED)
245 .addComponent(btnStop)
246 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
249 gl_pnlButton.setVerticalGroup(
250 gl_pnlButton.createParallelGroup(Alignment.LEADING)
251 .addGroup(gl_pnlButton.createSequentialGroup()
253 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
254 .addComponent(btnStop)
256 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
263 cmbId = new IdComboBox(videoFileWatcher);
264 cmbId.setToolTipText(ID_FIELD_TOOLTIP);
265 cmbId.getEditorComponent().addActionListener(applyListener);
266 cmbId.getEditorComponent().addFocusListener(new java.awt.event.FocusAdapter() {
268 public void focusLost(java.awt.event.FocusEvent evt) {
269 idFieldFocusLost(evt);
273 lblVideo.setText("動画");
275 cbVideoLocal.setText("local");
276 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
278 public void itemStateChanged(java.awt.event.ItemEvent evt) {
279 useMovieLocalCheckBoxItemStateChanged(evt);
283 lblComment.setText("コメント");
285 cbCommentLocal.setText("local");
286 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
288 public void itemStateChanged(java.awt.event.ItemEvent evt) {
289 useMovieLocalCheckBoxItemStateChanged(evt);
293 lblOutput.setText("出力");
295 cbOutputEnable.setText("変換");
296 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
298 public void itemStateChanged(java.awt.event.ItemEvent evt) {
299 outputConvertCheckBoxItemStateChanged(evt);
304 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
305 pnlInputMain.setLayout(glInputMain);
306 glInputMain.setHorizontalGroup(
307 glInputMain.createParallelGroup(Alignment.LEADING)
308 .addGroup(glInputMain.createSequentialGroup()
311 .addPreferredGap(ComponentPlacement.RELATED)
312 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
313 .addPreferredGap(ComponentPlacement.UNRELATED)
314 .addComponent(cbBackLogReduce)
315 .addPreferredGap(ComponentPlacement.UNRELATED)
316 .addComponent(cbBackLog)
317 .addPreferredGap(ComponentPlacement.RELATED)
318 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
321 .addGroup(glInputMain.createSequentialGroup()
323 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
324 .addComponent(lblVideo)
325 .addComponent(lblComment)
326 .addComponent(lblOutput)
328 .addPreferredGap(ComponentPlacement.RELATED)
329 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
330 .addComponent(cbVideoLocal)
331 .addComponent(cbCommentLocal)
332 .addComponent(cbOutputEnable)
334 .addPreferredGap(ComponentPlacement.RELATED)
335 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
336 .addComponent(cmbVideo, 300, 300, Short.MAX_VALUE)
337 .addComponent(cmbComment, 300, 300, Short.MAX_VALUE)
338 .addComponent(fldOutput, 300, 300, Short.MAX_VALUE)
340 .addGroup(glInputMain.createParallelGroup()
341 .addComponent(btnVideo)
342 .addComponent(btnComment)
348 glInputMain.setVerticalGroup(
349 glInputMain.createParallelGroup(Alignment.LEADING)
350 .addGroup(glInputMain.createSequentialGroup()
352 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
353 .addComponent(cmbId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
355 .addComponent(cbBackLogReduce)
356 .addComponent(cbBackLog)
357 .addComponent(fldBackLog)
359 .addPreferredGap(ComponentPlacement.RELATED)
360 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
361 .addComponent(lblVideo)
362 .addComponent(cbVideoLocal)
363 .addComponent(cmbVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
364 .addComponent(btnVideo)
366 .addPreferredGap(ComponentPlacement.RELATED)
367 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
368 .addComponent(lblComment)
369 .addComponent(cbCommentLocal)
370 .addComponent(cmbComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
371 .addComponent(btnComment)
373 .addPreferredGap(ComponentPlacement.RELATED)
374 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
375 .addComponent(lblOutput)
376 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
377 .addComponent(cbOutputEnable)
383 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
384 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
385 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
386 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
389 public void actionPerformed(ActionEvent e) {
390 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
391 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
392 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
393 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
394 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
395 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
396 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
399 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
402 public void itemStateChanged(ItemEvent e) {
403 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
404 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
405 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
406 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
409 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
412 public void propertyChange(PropertyChangeEvent evt) {
413 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
414 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
415 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
416 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
417 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
422 tbpInput.add("メイン", pnlInputMain);
423 tbpInput.add("ffmpeg", pnlInputFfmpeg);
426 fldInputMessage.setEditable(false);
427 fldInputMessage.setEnabled(false);
428 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
430 final JPanel pnlInputButton = new JPanel();
431 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
432 pnlInputButton.setLayout(glInputButton);
433 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
435 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
436 .addPreferredGap(ComponentPlacement.UNRELATED)
437 .addComponent(btnClear)
438 .addPreferredGap(ComponentPlacement.UNRELATED)
439 .addComponent(btnApply)
442 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
444 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
445 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
446 .addComponent(btnClear)
447 .addComponent(btnApply)
453 final JPanel pnlInputAll = new JPanel();
454 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
455 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
456 pnlInputAll.setLayout(glInputAll);
457 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
458 .addComponent(tbpInput)
459 .addComponent(pnlInputButton)
461 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
462 .addComponent(tbpInput)
463 .addComponent(pnlInputButton)
466 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
467 pnlMain.setLayout(gl_pnlMain);
468 gl_pnlMain.setHorizontalGroup(
469 gl_pnlMain.createParallelGroup(Alignment.LEADING)
470 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
472 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
473 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
474 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
475 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
479 gl_pnlMain.setVerticalGroup(
480 gl_pnlMain.createParallelGroup(Alignment.LEADING)
481 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
483 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
484 .addPreferredGap(ComponentPlacement.RELATED)
485 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
486 .addPreferredGap(ComponentPlacement.RELATED)
487 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
493 JMenuBar menuBar = initMenuBar();
494 setJMenuBar(menuBar);
496 GroupLayout layout = new GroupLayout(getContentPane());
497 getContentPane().setLayout(layout);
498 layout.setHorizontalGroup(
499 layout.createParallelGroup(Alignment.LEADING)
500 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
502 layout.setVerticalGroup(
503 layout.createParallelGroup(Alignment.LEADING)
504 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
508 setMinimumSize(getSize());
511 * 画面のサイズや位置を前回終了時のものに設定する
513 final int windowWidth = p.getSystemWindowWidth();
514 final int windowHeight = p.getSystemWindowHeight();
515 if (windowWidth > 0 && windowHeight > 0) {
516 setSize(windowWidth, windowHeight);
519 // TODO 最大化した状態で終了した場合の考慮
520 final int windowPosX = p.getSystemWindowPosX();
521 final int windowPosY = p.getSystemWindowPosY();
522 if (windowPosX > 1024 && windowPosY > 1024) {
523 setLocation(windowPosX, windowPosY);
525 setLocationByPlatform(true);
528 final int colId = p.getSystemColumnId();
530 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
532 final int colStatus = p.getSystemColumnStatus();
534 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
538 pnlMain.setTransferHandler(new DownloadListTransferHandler());
539 tblDisplay.setTransferHandler(new TableTransferHandler());
542 public void startWatcher() {
543 videoFileWatcherThread.start();
544 commentFileWatcherThread.start();
547 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
549 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
550 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
551 combo.setModel(model);
553 combo.setModel(new DefaultComboBoxModel<String>());
554 combo.getEditorComponent().setText(pattern);
558 private class GuiTaskManageListener implements TaskManageListener {
561 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
562 final String message) {
563 SwingUtilities.invokeLater(new Runnable() {
567 targetModel.setStatus(id, kind, status, percentage, message);
573 private class StopActionListener implements ActionListener {
576 public void actionPerformed(ActionEvent e) {
577 final int row = tblDisplay.getSelectedRow();
578 final Target t = targetModel.getTarget(row);
579 final boolean res = taskManager.cancel(t.getRowId());
580 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
582 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
587 private class ApplyActionListener implements ActionListener {
590 public void actionPerformed(ActionEvent e) {
592 final DownloadProfile downProf = new InqubusDownloadProfile();
593 final String id = Util.getVideoId(cmbId.getText());
594 final InqubusConvertProfile convProf = new InqubusConvertProfile();
595 logger.log(Level.INFO, downProf.toString());
596 logger.log(Level.INFO, convProf.toString());
597 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
599 targetModel.addTarget(new Target(rp));
601 } catch (Throwable th) {
602 logger.log(Level.SEVERE, null, th);
603 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
609 * 動画, コメントの"local"チェックボックス更新時の処理.
611 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
612 final Config p = Config.INSTANCE;
614 final ItemSelectable source = evt.getItemSelectable();
620 if (source == cbVideoLocal) {
623 allFiles = videoFileWatcher.getFiles();
624 pattern = p.getVideoFileNamePattern();
628 allFiles = commentFileWatcher.getFiles();
629 pattern = p.getCommentFileNamePattern();
632 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
634 button.setEnabled(useLocal);
635 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
639 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
640 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
641 fldOutput.setEnabled(convert);
642 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
644 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
645 final Config p = Config.INSTANCE;
646 final String id = cmbId.getText();
648 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
649 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
650 }//GEN-LAST:event_idFieldFocusLost
651 // Variables declaration - do not modify//GEN-BEGIN:variables
652 private final JTable tblDisplay;
654 private final JButton btnStop = new JButton("停止");
656 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
658 private final IdComboBox cmbId;
659 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
660 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
661 private final JTextField fldBackLog = new JTextField();
662 private final JCheckBox cbVideoLocal;
663 private final FileComboBox cmbVideo = new FileComboBox();
664 private final JTextField fldVideo = cmbVideo.getEditorComponent();
665 private final JButton btnVideo = new JButton("...");
666 private final JCheckBox cbCommentLocal;
667 private final FileComboBox cmbComment = new FileComboBox();
668 private final JTextField fldComment = cmbComment.getEditorComponent();
669 private final JButton btnComment = new JButton("...");
670 private final JCheckBox cbOutputEnable;
671 private final JTextField fldOutput;
673 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
675 private final JTextField fldInputMessage = new JTextField();
676 private final JButton btnClear = new JButton("クリア");
677 private final JButton btnApply = new JButton("適用");
678 // End of variables declaration//GEN-END:variables
680 private void initInputPanel() {
683 tbpInput.setSelectedIndex(0);
684 cmbId.requestFocus();
687 private void initMainTab() {
688 final Config p = Config.INSTANCE;
691 fldBackLog.setEnabled(false);
692 cbBackLog.setEnabled(true);
694 final boolean videoLocal = p.getVideoUseLocal();
695 cbVideoLocal.setSelected(videoLocal);
697 fldVideo.setText(p.getVideoFileNamePattern());
699 btnVideo.setEnabled(videoLocal);
701 final boolean commentLocal = p.getCommentUseLocal();
702 cbCommentLocal.setSelected(commentLocal);
704 fldComment.setText(p.getCommentFileNamePattern());
706 btnComment.setEnabled(commentLocal);
708 final boolean convert = p.getOutputEnable();
709 cbOutputEnable.setSelected(convert);
710 fldOutput.setEnabled(convert);
711 fldOutput.setText(p.getOutputFileNamePattern());
714 private void initFfmpegTab() {
715 pnlInputFfmpeg.init(Config.INSTANCE);
718 private JMenuBar initMenuBar() {
719 final JMenuBar menuBar = new JMenuBar();
721 final JMenu mnFile = new JMenu("ファイル(F)");
724 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
725 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
726 final ActionListener exitActionListener = new ActionListener() {
729 public void actionPerformed(ActionEvent e) {
730 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
733 itExit.addActionListener(exitActionListener);
736 final JMenu mnTool = new JMenu("ツール(T)");
739 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
741 itOption.addActionListener(new ActionListener() {
744 public void actionPerformed(ActionEvent e) {
745 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
746 dlg.setLocationRelativeTo(MainFrame.this);
748 dlg.setVisible(true);
751 mnTool.add(itOption);
753 final JMenu mnHelp = new JMenu("ヘルプ(H)");
756 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
757 itAbout.addActionListener(new ActionListener() {
760 public void actionPerformed(ActionEvent e) {
761 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
763 dlg.setLocationRelativeTo(MainFrame.this);
765 dlg.setVisible(true);
773 private class DownloadListTransferHandler extends TransferHandler {
775 private static final long serialVersionUID = 1L;
776 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
779 public boolean canImport(TransferHandler.TransferSupport support) {
780 Transferable transferable = support.getTransferable();
781 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
782 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
789 public boolean importData(TransferHandler.TransferSupport support) {
791 // Transferable transferable = support.getTransferable();
792 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
793 // @SuppressWarnings("unchecked")
794 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
795 // Collection<Target> targets = Target.from(data);
796 // targetModel.addTarget(targets);
797 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
798 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
799 // Matcher matcher = movieIdPattern.matcher(data);
800 // if (matcher.find()) {
801 // String movieId = matcher.group(1);
802 // Target target = Target.fromId(movieId);
803 // targetModel.addTarget(target);
810 // } catch (Exception e) {
811 // logger.log(Level.SEVERE, null, e);
814 // TODO 上記実装見直し(Locationは削除された)
819 private class TableTransferHandler extends DownloadListTransferHandler {
821 private static final long serialVersionUID = 1L;
824 public boolean canImport(TransferHandler.TransferSupport support) {
825 return super.canImport(support);
829 public boolean importData(TransferHandler.TransferSupport support) {
830 return super.importData(support);
834 private class MainFrameWindowListener extends WindowAdapter {
836 public void windowClosing(WindowEvent e) {
837 final Config p = Config.INSTANCE;
839 final Dimension size = getSize();
840 p.setSystemWindowWidth(size.width);
841 p.setSystemWindowHeight(size.height);
843 final Point pos = getLocation();
844 p.setSystemWindowPosX(pos.x);
845 p.setSystemWindowPosY(pos.y);
847 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
848 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
849 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
850 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
851 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
854 } catch (ConfigurationException ex) {
855 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
861 * ここからDownloadProfile作成用クラスの定義
864 private class InqubusDownloadProfile implements DownloadProfile {
866 private final LoginProfile loginProfile;
867 private final ProxyProfile proxyProfile;
868 private final VideoProfile videoProfile;
869 private final CommentProfile commentProfile;
870 private final GeneralProfile generalProfile;
872 private InqubusDownloadProfile() {
873 this.loginProfile = new ConfigLoginProfile();
874 this.proxyProfile = new ConfigProxyProfile();
875 this.videoProfile = new InqubusVideoProfile();
876 this.commentProfile = new InqubusCommentProfile();
877 this.generalProfile = new ConfigGeneralProfile();
881 public LoginProfile getLoginProfile() {
882 return this.loginProfile;
886 public ProxyProfile getProxyProfile() {
887 return this.proxyProfile;
891 public VideoProfile getVideoProfile() {
892 return this.videoProfile;
896 public CommentProfile getCommentProfile() {
897 return this.commentProfile;
901 public GeneralProfile getGeneralProfile() {
902 return this.generalProfile;
906 public String toString(){
907 return ToStringBuilder.reflectionToString(this);
911 private class InqubusVideoProfile implements VideoProfile {
912 private final boolean download;
913 private final File dir;
914 private final String fileName;
915 private final File localFile;
917 private InqubusVideoProfile(){
918 final Config p = Config.INSTANCE;
919 this.download = !cbVideoLocal.isSelected();
921 this.dir = new File(p.getVideoDir());
922 this.fileName = fldVideo.getText();
923 this.localFile = null;
926 this.fileName = null;
927 this.localFile = new File(fldVideo.getText());
932 public boolean isDownload() {
933 return this.download;
937 public File getDir() {
942 public String getFileName() {
943 return this.fileName;
947 public File getLocalFile() {
948 return this.localFile;
952 public String toString(){
953 return ToStringBuilder.reflectionToString(this);
957 private class InqubusCommentProfile extends ConfigCommentProfile {
958 private final boolean download;
959 private final File dir;
960 private final String fileName;
961 private final File localFile;
962 private final boolean disablePerMinComment;
963 private final long backLogPoint;
965 private InqubusCommentProfile() {
968 final Config p = Config.INSTANCE;
969 this.download = !cbCommentLocal.isSelected();
971 this.dir = new File(p.getCommentDir());
972 this.fileName = fldComment.getText();
973 this.localFile = null;
976 this.fileName = null;
977 this.localFile = new File(fldComment.getText());
980 if(cbBackLog.isSelected()) {
982 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
983 } catch (IOException ex) {
984 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
987 this.backLogPoint = -1L;
990 this.disablePerMinComment = cbBackLogReduce.isSelected();
994 public boolean isDownload() {
995 return this.download;
999 public File getDir() {
1004 public String getFileName() {
1005 return this.fileName;
1009 public File getLocalFile() {
1010 return this.localFile;
1014 public boolean isDisablePerMinComment() {
1015 return this.disablePerMinComment;
1019 public long getBackLogPoint() {
1020 return this.backLogPoint;
1024 public String toString(){
1025 return ToStringBuilder.reflectionToString(this);
1030 * ここからConvertProfile作成用クラスの定義
1032 private class InqubusConvertProfile extends ConfigConvertProfile {
1033 private final OutputProfile outputProfile;
1034 private final GeneralProfile generalProfile;
1035 private final FfmpegProfile ffmpegProfile;
1036 private final boolean convert;
1038 private InqubusConvertProfile() throws IOException {
1039 final Config p = Config.INSTANCE;
1040 this.outputProfile = new InqubusOutputProfile();
1041 this.generalProfile = new ConfigGeneralProfile();
1043 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1045 this.ffmpegProfile = new ConfigFfmpegProfile();
1047 this.ffmpegProfile = new InqubusFfmpegProfile();
1050 this.convert = cbOutputEnable.isSelected();
1054 public OutputProfile getOutputProfile() {
1055 return this.outputProfile;
1059 public GeneralProfile getGeneralProfile() {
1060 return this.generalProfile;
1064 public FfmpegProfile getFfmpegOption() {
1065 return this.ffmpegProfile;
1069 public boolean isConvert() {
1070 return this.convert;
1074 public String toString(){
1075 return ToStringBuilder.reflectionToString(this);
1079 private class InqubusOutputProfile extends ConfigOutputProfile {
1080 private final String fileName;
1081 private final String videoId;
1082 private final String title;
1085 private InqubusOutputProfile() {
1086 final Config p = Config.INSTANCE;
1087 this.fileName = fldOutput.getText();
1088 // TODO この時点でのID/Titleはどうするか…
1094 public String getFileName() {
1095 return this.fileName;
1099 public String getVideoId() {
1100 return this.videoId;
1104 public String getTitile() {
1109 public String toString(){
1110 return ToStringBuilder.reflectionToString(this);
1114 private class InqubusFfmpegProfile implements FfmpegProfile {
1115 private final String extOption;
1116 private final String inOption;
1117 private final String mainOption;
1118 private final String outOption;
1119 private final String avOption;
1120 private final boolean resize;
1121 private final int resizeWidth;
1122 private final int resizeHeight;
1123 private final boolean adjustRatio;
1125 private InqubusFfmpegProfile() throws IOException {
1126 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1127 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1128 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1129 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1130 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1131 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1132 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1133 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1134 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1138 public String getExtOption() {
1139 return this.extOption;
1143 public String getInOption() {
1144 return this.inOption;
1148 public String getMainOption() {
1149 return this.mainOption;
1153 public String getOutOption() {
1154 return this.outOption;
1158 public String getAvfilterOption() {
1159 return this.avOption;
1163 public boolean isResize() {
1168 public int getResizeWidth() {
1169 return this.resizeWidth;
1173 public int getResizeHeight() {
1174 return this.resizeHeight;
1178 public boolean isAdjustRatio() {
1179 return this.adjustRatio;
1183 public String toString(){
1184 return ToStringBuilder.reflectionToString(this);