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 final int windowPosX = p.getSystemWindowPosX();
520 final int windowPosY = p.getSystemWindowPosY();
521 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
522 if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
523 && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
524 setLocation(windowPosX, windowPosY);
526 setLocationByPlatform(true);
529 final int colId = p.getSystemColumnId();
531 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
533 final int colStatus = p.getSystemColumnStatus();
535 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
539 pnlMain.setTransferHandler(new DownloadListTransferHandler());
540 tblDisplay.setTransferHandler(new TableTransferHandler());
543 public void startWatcher() {
544 videoFileWatcherThread.start();
545 commentFileWatcherThread.start();
548 private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set<Path> allFiles) {
550 final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
551 DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
552 combo.setModel(model);
554 combo.setModel(new DefaultComboBoxModel<String>());
555 combo.getEditorComponent().setText(pattern);
559 private class GuiTaskManageListener implements TaskManageListener {
562 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
563 final String message) {
564 SwingUtilities.invokeLater(new Runnable() {
568 targetModel.setStatus(id, kind, status, percentage, message);
574 private class StopActionListener implements ActionListener {
577 public void actionPerformed(ActionEvent e) {
578 final int row = tblDisplay.getSelectedRow();
579 final Target t = targetModel.getTarget(row);
580 final boolean res = taskManager.cancel(t.getRowId());
581 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
583 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
588 private class ApplyActionListener implements ActionListener {
591 public void actionPerformed(ActionEvent e) {
593 final DownloadProfile downProf = new InqubusDownloadProfile();
594 final String id = Util.getVideoId(cmbId.getText());
595 final InqubusConvertProfile convProf = new InqubusConvertProfile();
596 logger.log(Level.INFO, downProf.toString());
597 logger.log(Level.INFO, convProf.toString());
598 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
600 targetModel.addTarget(new Target(rp));
602 } catch (Throwable th) {
603 logger.log(Level.SEVERE, null, th);
604 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
610 * 動画, コメントの"local"チェックボックス更新時の処理.
612 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
613 final Config p = Config.INSTANCE;
615 final ItemSelectable source = evt.getItemSelectable();
621 if (source == cbVideoLocal) {
624 allFiles = videoFileWatcher.getFiles();
625 pattern = p.getVideoFileNamePattern();
629 allFiles = commentFileWatcher.getFiles();
630 pattern = p.getCommentFileNamePattern();
633 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
635 button.setEnabled(useLocal);
636 createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
640 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
641 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
642 fldOutput.setEnabled(convert);
643 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
645 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
646 final Config p = Config.INSTANCE;
647 final String id = cmbId.getText();
649 createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
650 createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles());
651 }//GEN-LAST:event_idFieldFocusLost
652 // Variables declaration - do not modify//GEN-BEGIN:variables
653 private final JTable tblDisplay;
655 private final JButton btnStop = new JButton("停止");
657 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
659 private final IdComboBox cmbId;
660 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
661 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
662 private final JTextField fldBackLog = new JTextField();
663 private final JCheckBox cbVideoLocal;
664 private final FileComboBox cmbVideo = new FileComboBox();
665 private final JTextField fldVideo = cmbVideo.getEditorComponent();
666 private final JButton btnVideo = new JButton("...");
667 private final JCheckBox cbCommentLocal;
668 private final FileComboBox cmbComment = new FileComboBox();
669 private final JTextField fldComment = cmbComment.getEditorComponent();
670 private final JButton btnComment = new JButton("...");
671 private final JCheckBox cbOutputEnable;
672 private final JTextField fldOutput;
674 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
676 private final JTextField fldInputMessage = new JTextField();
677 private final JButton btnClear = new JButton("クリア");
678 private final JButton btnApply = new JButton("適用");
679 // End of variables declaration//GEN-END:variables
681 private void initInputPanel() {
684 tbpInput.setSelectedIndex(0);
685 cmbId.requestFocus();
688 private void initMainTab() {
689 final Config p = Config.INSTANCE;
692 cbBackLogReduce.setSelected(p.getCommentMinDisabled());
693 cbBackLog.setEnabled(true);
694 fldBackLog.setEnabled(false);
696 final boolean videoLocal = p.getVideoUseLocal();
697 cbVideoLocal.setSelected(videoLocal);
699 fldVideo.setText(p.getVideoFileNamePattern());
701 btnVideo.setEnabled(videoLocal);
703 final boolean commentLocal = p.getCommentUseLocal();
704 cbCommentLocal.setSelected(commentLocal);
706 fldComment.setText(p.getCommentFileNamePattern());
708 btnComment.setEnabled(commentLocal);
710 final boolean convert = p.getOutputEnable();
711 cbOutputEnable.setSelected(convert);
712 fldOutput.setEnabled(convert);
713 fldOutput.setText(p.getOutputFileNamePattern());
716 private void initFfmpegTab() {
717 pnlInputFfmpeg.init(Config.INSTANCE);
720 private JMenuBar initMenuBar() {
721 final JMenuBar menuBar = new JMenuBar();
723 final JMenu mnFile = new JMenu("ファイル(F)");
726 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
727 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
728 final ActionListener exitActionListener = new ActionListener() {
731 public void actionPerformed(ActionEvent e) {
732 processWindowEvent(new WindowEvent(MainFrame.this, WindowEvent.WINDOW_CLOSING));
735 itExit.addActionListener(exitActionListener);
738 final JMenu mnTool = new JMenu("ツール(T)");
741 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
742 itOption.addActionListener(new ActionListener() {
745 public void actionPerformed(ActionEvent e) {
746 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
747 dlg.setLocationRelativeTo(MainFrame.this);
749 dlg.setVisible(true);
752 mnTool.add(itOption);
754 final JMenu mnHelp = new JMenu("ヘルプ(H)");
757 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
758 itAbout.addActionListener(new ActionListener() {
761 public void actionPerformed(ActionEvent e) {
762 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
764 dlg.setLocationRelativeTo(MainFrame.this);
766 dlg.setVisible(true);
774 private class DownloadListTransferHandler extends TransferHandler {
776 private static final long serialVersionUID = 1L;
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 // 保存するのは最大化していない場合だけ
840 if (JFrame.NORMAL == getExtendedState()) {
841 final Dimension size = getSize();
842 p.setSystemWindowWidth(size.width);
843 p.setSystemWindowHeight(size.height);
845 final Point pos = getLocation();
846 p.setSystemWindowPosX(pos.x);
847 p.setSystemWindowPosY(pos.y);
850 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
851 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
852 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
853 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
854 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
857 } catch (ConfigurationException ex) {
858 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
864 * ここからDownloadProfile作成用クラスの定義
866 private class InqubusDownloadProfile implements DownloadProfile {
868 private final LoginProfile loginProfile;
869 private final ProxyProfile proxyProfile;
870 private final VideoProfile videoProfile;
871 private final CommentProfile commentProfile;
872 private final GeneralProfile generalProfile;
874 private InqubusDownloadProfile() {
875 this.loginProfile = new ConfigLoginProfile();
876 this.proxyProfile = new ConfigProxyProfile();
877 this.videoProfile = new InqubusVideoProfile();
878 this.commentProfile = new InqubusCommentProfile();
879 this.generalProfile = new ConfigGeneralProfile();
883 public LoginProfile getLoginProfile() {
884 return this.loginProfile;
888 public ProxyProfile getProxyProfile() {
889 return this.proxyProfile;
893 public VideoProfile getVideoProfile() {
894 return this.videoProfile;
898 public CommentProfile getCommentProfile() {
899 return this.commentProfile;
903 public GeneralProfile getGeneralProfile() {
904 return this.generalProfile;
908 public String toString(){
909 return ToStringBuilder.reflectionToString(this);
913 private class InqubusVideoProfile implements VideoProfile {
914 private final boolean download;
915 private final File dir;
916 private final String fileName;
917 private final File localFile;
919 private InqubusVideoProfile(){
920 final Config p = Config.INSTANCE;
921 this.download = !cbVideoLocal.isSelected();
923 this.dir = new File(p.getVideoDir());
924 this.fileName = fldVideo.getText();
925 this.localFile = null;
928 this.fileName = null;
929 this.localFile = new File(fldVideo.getText());
934 public boolean isDownload() {
935 return this.download;
939 public File getDir() {
944 public String getFileName() {
945 return this.fileName;
949 public File getLocalFile() {
950 return this.localFile;
954 public String toString(){
955 return ToStringBuilder.reflectionToString(this);
959 private class InqubusCommentProfile extends ConfigCommentProfile {
960 private final boolean download;
961 private final File dir;
962 private final String fileName;
963 private final File localFile;
964 private final boolean disablePerMinComment;
965 private final long backLogPoint;
967 private InqubusCommentProfile() {
970 final Config p = Config.INSTANCE;
971 this.download = !cbCommentLocal.isSelected();
973 this.dir = new File(p.getCommentDir());
974 this.fileName = fldComment.getText();
975 this.localFile = null;
978 this.fileName = null;
979 this.localFile = new File(fldComment.getText());
982 if(cbBackLog.isSelected()) {
984 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
985 } catch (IOException ex) {
986 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
989 this.backLogPoint = -1L;
992 this.disablePerMinComment = cbBackLogReduce.isSelected();
996 public boolean isDownload() {
997 return this.download;
1001 public File getDir() {
1006 public String getFileName() {
1007 return this.fileName;
1011 public File getLocalFile() {
1012 return this.localFile;
1016 public boolean isDisablePerMinComment() {
1017 return this.disablePerMinComment;
1021 public long getBackLogPoint() {
1022 return this.backLogPoint;
1026 public String toString(){
1027 return ToStringBuilder.reflectionToString(this);
1032 * ここからConvertProfile作成用クラスの定義
1034 private class InqubusConvertProfile extends ConfigConvertProfile {
1035 private final OutputProfile outputProfile;
1036 private final GeneralProfile generalProfile;
1037 private final FfmpegProfile ffmpegProfile;
1038 private final boolean convert;
1040 private InqubusConvertProfile() throws IOException {
1041 final Config p = Config.INSTANCE;
1042 this.outputProfile = new InqubusOutputProfile();
1043 this.generalProfile = new ConfigGeneralProfile();
1045 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1047 this.ffmpegProfile = new ConfigFfmpegProfile();
1049 this.ffmpegProfile = new InqubusFfmpegProfile();
1052 this.convert = cbOutputEnable.isSelected();
1056 public OutputProfile getOutputProfile() {
1057 return this.outputProfile;
1061 public GeneralProfile getGeneralProfile() {
1062 return this.generalProfile;
1066 public FfmpegProfile getFfmpegOption() {
1067 return this.ffmpegProfile;
1071 public boolean isConvert() {
1072 return this.convert;
1076 public String toString(){
1077 return ToStringBuilder.reflectionToString(this);
1081 private class InqubusOutputProfile extends ConfigOutputProfile {
1082 private final String fileName;
1083 private final String videoId;
1084 private final String title;
1087 private InqubusOutputProfile() {
1088 final Config p = Config.INSTANCE;
1089 this.fileName = fldOutput.getText();
1090 // TODO この時点でのID/Titleはどうするか…
1096 public String getFileName() {
1097 return this.fileName;
1101 public String getVideoId() {
1102 return this.videoId;
1106 public String getTitile() {
1111 public String toString(){
1112 return ToStringBuilder.reflectionToString(this);
1116 private class InqubusFfmpegProfile implements FfmpegProfile {
1117 private final String extOption;
1118 private final String inOption;
1119 private final String mainOption;
1120 private final String outOption;
1121 private final String avOption;
1122 private final boolean resize;
1123 private final int resizeWidth;
1124 private final int resizeHeight;
1125 private final boolean adjustRatio;
1127 private InqubusFfmpegProfile() throws IOException {
1128 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1129 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1130 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1131 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1132 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1133 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1134 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1135 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1136 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1140 public String getExtOption() {
1141 return this.extOption;
1145 public String getInOption() {
1146 return this.inOption;
1150 public String getMainOption() {
1151 return this.mainOption;
1155 public String getOutOption() {
1156 return this.outOption;
1160 public String getAvfilterOption() {
1161 return this.avOption;
1165 public boolean isResize() {
1170 public int getResizeWidth() {
1171 return this.resizeWidth;
1175 public int getResizeHeight() {
1176 return this.resizeHeight;
1180 public boolean isAdjustRatio() {
1181 return this.adjustRatio;
1185 public String toString(){
1186 return ToStringBuilder.reflectionToString(this);