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.FilenameFilter;
26 import java.io.IOException;
28 import java.nio.file.FileSystem;
29 import java.nio.file.FileSystems;
30 import java.nio.file.Path;
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.List;
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.DropMode;
40 import javax.swing.GroupLayout;
41 import javax.swing.GroupLayout.Alignment;
42 import javax.swing.JButton;
43 import javax.swing.JCheckBox;
44 import javax.swing.JFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuBar;
48 import javax.swing.JMenuItem;
49 import javax.swing.JOptionPane;
50 import javax.swing.JPanel;
51 import javax.swing.JScrollPane;
52 import javax.swing.JTabbedPane;
53 import javax.swing.JTable;
54 import javax.swing.JTextField;
55 import javax.swing.KeyStroke;
56 import javax.swing.LayoutStyle.ComponentPlacement;
57 import javax.swing.SwingUtilities;
58 import javax.swing.TransferHandler;
59 import javax.swing.WindowConstants;
60 import javax.swing.border.BevelBorder;
61 import org.apache.commons.configuration.ConfigurationException;
62 import org.apache.commons.lang.StringUtils;
63 import org.apache.commons.lang.builder.ToStringBuilder;
64 import saccubus.FfmpegOption;
65 import saccubus.MainFrame_AboutBox;
66 import saccubus.util.WayBackTimeParser;
67 import saccubus.worker.impl.convert.ConvertProgress;
68 import saccubus.worker.impl.download.DownloadProgress;
69 import saccubus.worker.WorkerListener;
70 import saccubus.worker.impl.convert.ConvertResult;
71 import saccubus.worker.impl.download.DownloadResult;
72 import saccubus.worker.profile.CommentProfile;
73 import saccubus.worker.profile.ConvertProfile;
74 import saccubus.worker.profile.DownloadProfile;
75 import saccubus.worker.profile.FfmpegProfile;
76 import saccubus.worker.profile.GeneralProfile;
77 import saccubus.worker.profile.LoginProfile;
78 import saccubus.worker.profile.OutputProfile;
79 import saccubus.worker.profile.ProxyProfile;
80 import saccubus.worker.profile.VideoProfile;
82 import yukihane.inqubus.Config;
83 import yukihane.inqubus.filewatch.FileWatch;
84 import yukihane.inqubus.manager.RequestProcess;
85 import yukihane.inqubus.manager.TaskKind;
86 import yukihane.inqubus.manager.TaskManage;
87 import yukihane.inqubus.manager.TaskManageListener;
88 import yukihane.inqubus.manager.TaskStatus;
89 import yukihane.inqubus.model.Target;
90 import yukihane.inqubus.model.TargetsTableModel;
96 public class MainFrame extends JFrame {
98 private static final long serialVersionUID = 1L;
99 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
100 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
101 private static final String FILE_LOCALBUTTON_TOOLTIP
102 = "<html>ダウンロードする場合はチェックを外します。<br/>ローカルファイルを使用する場合はチェックを入れます。</html>";
103 private static final String FILE_INPUTFIELD_TOOLTIP
104 = "<html>ダウンロードする場合はファイル命名規則を入力します。<br/>"
105 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。</html>";
106 private static final String FILE_OUTPUTFIELD_TOOLTIP
108 private final TargetsTableModel targetModel = new TargetsTableModel();
109 private final TaskManage taskManager;
110 private final Thread videoFileWatcherThread;
111 private final FileWatch videoFileWatcher;
113 /** Creates new form MainFrame */
116 addWindowListener(new MainFrameWindowListener());
118 final Config p = Config.INSTANCE;
121 final int thDownload = p.getSystemDownloadThread();
122 final int secDownload = p.getSystemDownloadWait();
123 final int thConvert = p.getSystemConvertThread();
124 taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
126 // TODO ディレクトリ監視スレッド生成
127 final List<String> videoSearchDirs = p.getSearchVideoDirs();
128 videoSearchDirs.add(p.getVideoDir());
129 final FileSystem fs = FileSystems.getDefault();
130 final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
131 for (String s : videoSearchDirs) {
132 videoPaths.add(fs.getPath(s));
134 videoFileWatcher = new FileWatch(videoPaths);
135 this.videoFileWatcherThread = new Thread(videoFileWatcher);
136 this.videoFileWatcherThread.setDaemon(true);
138 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
139 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
140 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
141 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
142 final List<Image> images = new ArrayList<>(2);
145 setIconImages(images);
147 final JPanel pnlMain = new JPanel();
148 final JScrollPane scrDisplay = new JScrollPane();
149 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
150 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
151 final JPanel pnlButton = new JPanel();
152 final JPanel pnlInputMain = new JPanel();
153 final JLabel lblId = new JLabel();
154 final JLabel lblVideo = new JLabel();
155 cbVideoLocal = new JCheckBox();
156 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
157 fldVideo = new JTextField();
158 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
159 final JLabel lblComment = new JLabel();
161 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
162 cbBackLog.addItemListener(new ItemListener() {
165 public void itemStateChanged(ItemEvent e) {
166 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
167 fldBackLog.setEnabled(selected);
170 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
173 public void propertyChange(PropertyChangeEvent evt) {
174 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
175 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
176 fldBackLog.setEnabled(fldEnabled);
179 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
181 cbCommentLocal = new JCheckBox();
182 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
183 cbCommentLocal.addItemListener(new ItemListener() {
186 public void itemStateChanged(ItemEvent e) {
187 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
188 cbBackLogReduce.setEnabled(!selected);
189 cbBackLog.setEnabled(!selected);
192 fldComment = new JTextField();
193 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
194 final JLabel lblOutput = new JLabel();
195 cbOutputEnable = new JCheckBox();
196 fldOutput = new JTextField();
197 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
199 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
201 btnStop.addActionListener(new StopActionListener());
202 final ApplyActionListener applyListener = new ApplyActionListener();
203 btnApply.addActionListener(applyListener);
205 pnlMain.setBorder(BorderFactory.createEtchedBorder());
207 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
208 scrDisplay.setViewportView(tblDisplay);
210 pnlButton.setBorder(BorderFactory.createEtchedBorder());
212 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
213 pnlButton.setLayout(gl_pnlButton);
214 gl_pnlButton.setHorizontalGroup(
215 gl_pnlButton.createParallelGroup(Alignment.LEADING)
216 .addGroup(gl_pnlButton.createSequentialGroup()
218 .addComponent(btnStart)
219 .addPreferredGap(ComponentPlacement.RELATED)
220 .addComponent(btnStop)
221 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
222 .addComponent(btnDeselect)
225 gl_pnlButton.setVerticalGroup(
226 gl_pnlButton.createParallelGroup(Alignment.LEADING)
227 .addGroup(gl_pnlButton.createSequentialGroup()
229 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
230 .addComponent(btnStart)
231 .addComponent(btnStop)
232 .addComponent(btnDeselect))
233 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
239 fldId = new IdComboBox(videoFileWatcher);
240 fldId.setToolTipText(ID_FIELD_TOOLTIP);
241 fldId.getEditorComponent().addActionListener(applyListener);
242 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
244 public void focusLost(java.awt.event.FocusEvent evt) {
245 idFieldFocusLost(evt);
249 lblVideo.setText("動画");
251 cbVideoLocal.setText("local");
252 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
254 public void itemStateChanged(java.awt.event.ItemEvent evt) {
255 useMovieLocalCheckBoxItemStateChanged(evt);
259 lblComment.setText("コメント");
261 cbCommentLocal.setText("local");
262 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
264 public void itemStateChanged(java.awt.event.ItemEvent evt) {
265 useMovieLocalCheckBoxItemStateChanged(evt);
269 lblOutput.setText("出力");
271 cbOutputEnable.setText("変換");
272 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
274 public void itemStateChanged(java.awt.event.ItemEvent evt) {
275 outputConvertCheckBoxItemStateChanged(evt);
280 final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
281 pnlInputMain.setLayout(glInputMain);
282 glInputMain.setHorizontalGroup(
283 glInputMain.createParallelGroup(Alignment.LEADING)
284 .addGroup(glInputMain.createSequentialGroup()
287 .addPreferredGap(ComponentPlacement.RELATED)
288 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
289 .addPreferredGap(ComponentPlacement.UNRELATED)
290 .addComponent(cbBackLogReduce)
291 .addPreferredGap(ComponentPlacement.UNRELATED)
292 .addComponent(cbBackLog)
293 .addPreferredGap(ComponentPlacement.RELATED)
294 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
297 .addGroup(glInputMain.createSequentialGroup()
299 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
300 .addComponent(lblVideo)
301 .addComponent(lblComment)
302 .addComponent(lblOutput)
304 .addPreferredGap(ComponentPlacement.RELATED)
305 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
306 .addComponent(cbVideoLocal)
307 .addComponent(cbCommentLocal)
308 .addComponent(cbOutputEnable)
310 .addPreferredGap(ComponentPlacement.RELATED)
311 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
312 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
313 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
314 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
320 glInputMain.setVerticalGroup(
321 glInputMain.createParallelGroup(Alignment.LEADING)
322 .addGroup(glInputMain.createSequentialGroup()
324 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
325 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
327 .addComponent(cbBackLogReduce)
328 .addComponent(cbBackLog)
329 .addComponent(fldBackLog)
331 .addPreferredGap(ComponentPlacement.RELATED)
332 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
333 .addComponent(lblVideo)
334 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
335 .addComponent(cbVideoLocal))
336 .addPreferredGap(ComponentPlacement.RELATED)
337 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
338 .addComponent(lblComment)
339 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
340 .addComponent(cbCommentLocal))
341 .addPreferredGap(ComponentPlacement.RELATED)
342 .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
343 .addComponent(lblOutput)
344 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
345 .addComponent(cbOutputEnable)
351 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
352 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
353 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
354 pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
357 public void actionPerformed(ActionEvent e) {
358 final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
359 pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
360 pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
361 pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
362 pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
363 pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
364 pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
367 pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
370 public void itemStateChanged(ItemEvent e) {
371 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
372 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
373 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
374 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
377 pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
380 public void propertyChange(PropertyChangeEvent evt) {
381 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
382 final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
383 pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
384 pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
385 pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
390 tbpInput.add("メイン", pnlInputMain);
391 tbpInput.add("ffmpeg", pnlInputFfmpeg);
394 fldInputMessage.setEditable(false);
395 fldInputMessage.setEnabled(false);
396 fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
398 final JPanel pnlInputButton = new JPanel();
399 final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
400 pnlInputButton.setLayout(glInputButton);
401 glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
403 .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
404 .addPreferredGap(ComponentPlacement.UNRELATED)
405 .addComponent(btnApply)
408 glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
410 .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
411 .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
412 .addComponent(btnApply)
418 final JPanel pnlInputAll = new JPanel();
419 pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
420 final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
421 pnlInputAll.setLayout(glInputAll);
422 glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
423 .addComponent(tbpInput)
424 .addComponent(pnlInputButton)
426 glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
427 .addComponent(tbpInput)
428 .addComponent(pnlInputButton)
431 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
432 pnlMain.setLayout(gl_pnlMain);
433 gl_pnlMain.setHorizontalGroup(
434 gl_pnlMain.createParallelGroup(Alignment.LEADING)
435 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
437 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
438 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
439 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
440 .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
444 gl_pnlMain.setVerticalGroup(
445 gl_pnlMain.createParallelGroup(Alignment.LEADING)
446 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
448 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
449 .addPreferredGap(ComponentPlacement.RELATED)
450 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
451 .addPreferredGap(ComponentPlacement.RELATED)
452 .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
458 JMenuBar menuBar = initMenuBar();
459 setJMenuBar(menuBar);
461 GroupLayout layout = new GroupLayout(getContentPane());
462 getContentPane().setLayout(layout);
463 layout.setHorizontalGroup(
464 layout.createParallelGroup(Alignment.LEADING)
465 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
467 layout.setVerticalGroup(
468 layout.createParallelGroup(Alignment.LEADING)
469 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
475 * 画面のサイズや位置を前回終了時のものに設定する
477 final int windowWidth = p.getSystemWindowWidth();
478 final int windowHeight = p.getSystemWindowHeight();
479 if (windowWidth > 0 && windowHeight > 0) {
480 setSize(windowWidth, windowHeight);
483 final int windowPosX = p.getSystemWindowPosX();
484 final int windowPosY = p.getSystemWindowPosY();
485 if (windowPosX > 0 && windowPosY > 0) {
486 setLocation(windowPosX, windowPosY);
488 setLocationByPlatform(true);
491 final int colId = p.getSystemColumnId();
493 tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
495 final int colStatus = p.getSystemColumnStatus();
497 tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
501 pnlMain.setTransferHandler(new DownloadListTransferHandler());
502 tblDisplay.setTransferHandler(new TableTransferHandler());
505 public void startWatcher() {
506 videoFileWatcherThread.start();
509 private class GuiTaskManageListener implements TaskManageListener {
512 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
513 final String message) {
514 SwingUtilities.invokeLater(new Runnable() {
518 targetModel.setStatus(id, kind, status, percentage, message);
524 private class StopActionListener implements ActionListener {
527 public void actionPerformed(ActionEvent e) {
528 final int row = tblDisplay.getSelectedRow();
529 final Target t = targetModel.getTarget(row);
530 final boolean res = taskManager.cancel(t.getRowId());
531 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
533 targetModel.setStatus(t.getRowId(), null, TaskStatus.CANCELLED, -1.0, "キャンセル");
538 private class ApplyActionListener implements ActionListener {
541 public void actionPerformed(ActionEvent e) {
543 final DownloadProfile downProf = new InqubusDownloadProfile();
544 final String id = Util.getVideoId(fldId.getText());
545 final InqubusConvertProfile convProf = new InqubusConvertProfile();
546 logger.log(Level.INFO, downProf.toString());
547 logger.log(Level.INFO, convProf.toString());
548 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
550 targetModel.addTarget(new Target(rp));
552 } catch (Throwable th) {
553 logger.log(Level.SEVERE, null, th);
554 JOptionPane.showMessageDialog(MainFrame.this, th.getMessage(), "中断しました", JOptionPane.ERROR_MESSAGE);
559 private File searchFileMatchId(final File dir, final String id) {
560 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
565 final File[] lists = dir.listFiles(new FilenameFilter() {
567 final Pattern pattern = Pattern.compile(id + "\\D");
570 public boolean accept(File dir, String name) {
571 return pattern.matcher(name).find();
575 if (lists.length == 1) {
577 } else if (lists.length > 1) {
578 throw new UnsupportedOperationException();
585 * 動画, コメントの"local"チェックボックス更新時の処理.
587 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
588 final Config p = Config.INSTANCE;
590 final ItemSelectable source = evt.getItemSelectable();
594 if (source == cbVideoLocal) {
596 dir = new File(p.getVideoDir());
599 dir = new File(p.getCommentDir());
602 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
606 final File f = searchFileMatchId(dir, fldId.getText());
613 text = p.getVideoFileNamePattern();
617 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
619 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
620 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
621 fldOutput.setEnabled(convert);
622 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
624 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
625 final Config p = Config.INSTANCE;
626 final String id = fldId.getText();
631 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
632 final File dir = new File(p.getVideoDir());
633 final File file = searchFileMatchId(dir, id);
635 fldVideo.setText(file.getPath());
639 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
640 final File dir = new File(p.getCommentDir());
641 final File file = searchFileMatchId(dir, id);
643 fldComment.setText(file.getPath());
647 }//GEN-LAST:event_idFieldFocusLost
648 // Variables declaration - do not modify//GEN-BEGIN:variables
649 private final JTable tblDisplay;
651 private final JButton btnStart = new JButton("開始");
652 private final JButton btnStop = new JButton("停止");
653 private final JButton btnDeselect = new JButton("選択解除");
655 private final JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
657 private final IdComboBox fldId;
658 private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
659 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
660 private final JTextField fldBackLog = new JTextField();
661 private final JCheckBox cbVideoLocal;
662 private final JTextField fldVideo;
663 private final JCheckBox cbCommentLocal;
664 private final JTextField fldComment;
665 private final JCheckBox cbOutputEnable;
666 private final JTextField fldOutput;
668 private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
670 private final JTextField fldInputMessage = new JTextField();
671 private final JButton btnApply = new JButton("適用");
672 // End of variables declaration//GEN-END:variables
674 private void initInputPanel() {
677 tbpInput.setSelectedIndex(0);
678 fldId.requestFocus();
681 private void initMainTab() {
682 final Config p = Config.INSTANCE;
685 fldBackLog.setEnabled(false);
686 cbBackLog.setEnabled(true);
688 final boolean movieLocal = p.getVideoUseLocal();
689 cbVideoLocal.setSelected(movieLocal);
691 fldVideo.setText(p.getVideoFileNamePattern());
694 final boolean commentLocal = p.getCommentUseLocal();
695 cbCommentLocal.setSelected(commentLocal);
697 fldComment.setText(p.getCommentFileNamePattern());
700 final boolean convert = p.getOutputEnable();
701 cbOutputEnable.setSelected(convert);
702 fldOutput.setEnabled(convert);
703 fldOutput.setText(p.getOutputFileNamePattern());
706 private void initFfmpegTab() {
707 pnlInputFfmpeg.init(Config.INSTANCE);
710 private JMenuBar initMenuBar() {
711 final JMenuBar menuBar = new JMenuBar();
713 final JMenu mnFile = new JMenu("ファイル(F)");
716 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
717 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
718 itExit.addActionListener(new ActionListener() {
721 public void actionPerformed(ActionEvent e) {
722 throw new UnsupportedOperationException("Not supported yet.");
727 final JMenu mnTool = new JMenu("ツール(T)");
730 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
732 itOption.addActionListener(new ActionListener() {
735 public void actionPerformed(ActionEvent e) {
736 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
737 dlg.setLocationRelativeTo(MainFrame.this);
739 dlg.setVisible(true);
742 mnTool.add(itOption);
744 final JMenu mnHelp = new JMenu("ヘルプ(H)");
747 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
748 itAbout.addActionListener(new ActionListener() {
751 public void actionPerformed(ActionEvent e) {
752 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
754 dlg.setLocationRelativeTo(MainFrame.this);
756 dlg.setVisible(true);
764 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
767 public void process(DownloadProgress progress) {
768 throw new UnsupportedOperationException("Not supported yet.");
772 public void cancelled() {
773 throw new UnsupportedOperationException("Not supported yet.");
777 public void done(DownloadResult result) {
778 throw new UnsupportedOperationException("Not supported yet.");
782 public void error(Throwable th) {
783 throw new UnsupportedOperationException("Not supported yet.");
787 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
790 public void process(ConvertProgress progress) {
791 throw new UnsupportedOperationException("Not supported yet.");
795 public void cancelled() {
796 throw new UnsupportedOperationException("Not supported yet.");
800 public void done(ConvertResult result) {
801 throw new UnsupportedOperationException("Not supported yet.");
805 public void error(Throwable th) {
806 throw new UnsupportedOperationException("Not supported yet.");
812 private class DownloadListTransferHandler extends TransferHandler {
814 private static final long serialVersionUID = 1L;
815 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
818 public boolean canImport(TransferHandler.TransferSupport support) {
819 Transferable transferable = support.getTransferable();
820 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
821 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
828 public boolean importData(TransferHandler.TransferSupport support) {
830 // Transferable transferable = support.getTransferable();
831 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
832 // @SuppressWarnings("unchecked")
833 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
834 // Collection<Target> targets = Target.from(data);
835 // targetModel.addTarget(targets);
836 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
837 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
838 // Matcher matcher = movieIdPattern.matcher(data);
839 // if (matcher.find()) {
840 // String movieId = matcher.group(1);
841 // Target target = Target.fromId(movieId);
842 // targetModel.addTarget(target);
849 // } catch (Exception e) {
850 // logger.log(Level.SEVERE, null, e);
853 // TODO 上記実装見直し(Locationは削除された)
858 private class TableTransferHandler extends DownloadListTransferHandler {
860 private static final long serialVersionUID = 1L;
863 public boolean canImport(TransferHandler.TransferSupport support) {
864 return super.canImport(support);
868 public boolean importData(TransferHandler.TransferSupport support) {
869 return super.importData(support);
873 private class MainFrameWindowListener extends WindowAdapter {
875 public void windowClosing(WindowEvent e) {
876 final Config p = Config.INSTANCE;
878 final Dimension size = getSize();
879 p.setSystemWindowWidth(size.width);
880 p.setSystemWindowHeight(size.height);
882 final Point pos = getLocation();
883 p.setSystemWindowPosX(pos.x);
884 p.setSystemWindowPosY(pos.y);
886 p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
887 p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
888 p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
889 p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
890 p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
893 } catch (ConfigurationException ex) {
894 logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
900 * ここからDownloadProfile作成用クラスの定義
903 private class InqubusDownloadProfile implements DownloadProfile {
905 private final LoginProfile loginProfile;
906 private final ProxyProfile proxyProfile;
907 private final VideoProfile videoProfile;
908 private final CommentProfile commentProfile;
909 private final GeneralProfile generalProfile;
911 private InqubusDownloadProfile() {
912 this.loginProfile = new InqubusLoginProfile();
913 this.proxyProfile = new InqubusProxyProfile();
914 this.videoProfile = new InqubusVideoProfile();
915 this.commentProfile = new InqubusCommentProfile();
916 this.generalProfile = new InqubusGeneralProfile();
920 public LoginProfile getLoginInfo() {
921 return this.loginProfile;
925 public ProxyProfile getProxyProfile() {
926 return this.proxyProfile;
930 public VideoProfile getVideoProfile() {
931 return this.videoProfile;
935 public CommentProfile getCommentProfile() {
936 return this.commentProfile;
940 public GeneralProfile getGeneralProfile() {
941 return this.generalProfile;
945 public String toString(){
946 return ToStringBuilder.reflectionToString(this);
950 private class InqubusLoginProfile implements LoginProfile {
951 private final String mail;
952 private final String password;
954 private InqubusLoginProfile(){
955 final Config p = Config.INSTANCE;
956 this.mail = p.getId();
957 this.password = p.getPassword();
961 public String getMail() {
966 public String getPassword() {
967 return this.password;
971 public String toString(){
972 return ToStringBuilder.reflectionToString(this);
976 private class InqubusProxyProfile implements ProxyProfile {
977 private final boolean use;
978 private final String host;
979 private final int port;
981 private InqubusProxyProfile(){
982 final Config p = Config.INSTANCE;
983 this.use = p.getProxyUse();
984 this.host = p.getProxyHost();
985 final String pp = p.getProxyPort();
986 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
990 public boolean use() {
995 public String getHost() {
1000 public int getPort() {
1005 public String toString(){
1006 return ToStringBuilder.reflectionToString(this);
1010 private class InqubusVideoProfile implements VideoProfile {
1011 private final boolean download;
1012 private final File dir;
1013 private final String fileName;
1014 private final File localFile;
1016 private InqubusVideoProfile(){
1017 final Config p = Config.INSTANCE;
1018 this.download = !cbVideoLocal.isSelected();
1019 if (this.download) {
1020 this.dir = new File(p.getVideoDir());
1021 this.fileName = fldVideo.getText();
1022 this.localFile = null;
1025 this.fileName = null;
1026 this.localFile = new File(fldVideo.getText());
1031 public boolean isDownload() {
1032 return this.download;
1036 public File getDir() {
1041 public String getFileName() {
1042 return this.fileName;
1046 public File getLocalFile() {
1047 return this.localFile;
1051 public String toString(){
1052 return ToStringBuilder.reflectionToString(this);
1056 private class InqubusCommentProfile implements CommentProfile {
1057 private final boolean download;
1058 private final File dir;
1059 private final String fileName;
1060 private final File localFile;
1061 private final int lengthRelatedCommentSize;
1062 private final boolean disablePerMinComment;
1063 private final int perMinCommentSize;
1064 private final long backLogPoint;
1066 private InqubusCommentProfile() {
1067 final Config p = Config.INSTANCE;
1068 this.download = !cbCommentLocal.isSelected();
1069 if (this.download) {
1070 this.dir = new File(p.getCommentDir());
1071 this.fileName = fldComment.getText();
1072 this.localFile = null;
1075 this.fileName = null;
1076 this.localFile = new File(fldComment.getText());
1079 if(cbBackLog.isSelected()) {
1081 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
1082 } catch (IOException ex) {
1083 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
1086 this.backLogPoint = -1L;
1089 this.disablePerMinComment = cbBackLogReduce.isSelected();
1090 this.lengthRelatedCommentSize
1091 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
1092 this.perMinCommentSize
1093 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
1097 public boolean isDownload() {
1098 return this.download;
1102 public File getDir() {
1107 public String getFileName() {
1108 return this.fileName;
1112 public File getLocalFile() {
1113 return this.localFile;
1117 public int getLengthRelatedCommentSize() {
1118 return this.lengthRelatedCommentSize;
1122 public boolean isDisablePerMinComment() {
1123 return this.disablePerMinComment;
1127 public int getPerMinCommentSize() {
1128 return this.perMinCommentSize;
1132 public long getBackLogPoint() {
1133 return this.backLogPoint;
1137 public String toString(){
1138 return ToStringBuilder.reflectionToString(this);
1142 private class InqubusGeneralProfile implements GeneralProfile {
1143 private final String replaceFrom;
1144 private final String replaceTo;
1145 private InqubusGeneralProfile() {
1146 final Config p = Config.INSTANCE;
1147 this.replaceFrom = p.getReplaceFrom();
1148 this.replaceTo = p.getReplaceTo();
1152 public String getReplaceFrom() {
1153 return this.replaceFrom;
1157 public String getReplaceTo() {
1158 return this.replaceTo;
1162 public String toString(){
1163 return ToStringBuilder.reflectionToString(this);
1168 * ここからConvertProfile作成用クラスの定義
1170 private class InqubusConvertProfile implements ConvertProfile {
1171 private final OutputProfile outputProfile;
1172 private final GeneralProfile generalProfile;
1173 private final FfmpegProfile ffmpegProfile;
1174 private final boolean convert;
1175 private final File ffmpeg;
1176 private final boolean vhookDisabled;
1177 private final boolean commentOverlay;
1178 private final File vhook;
1179 private final File tmpDir;
1180 private final File font;
1181 private final int fontIndex;
1182 private final boolean commentOpaque;
1183 private final boolean disableFontSizeArrange;
1184 private final int shadowIndex;
1185 private final boolean showConvrting;
1186 private final int maxNumOfComment;
1187 private final HideCondition ngSetting;
1189 private InqubusConvertProfile() throws IOException {
1190 final Config p = Config.INSTANCE;
1191 this.outputProfile = new InqubusOutputProfile();
1192 this.generalProfile = new InqubusGeneralProfile();
1193 this.ffmpegProfile = new InqubusFfmpegProfile();
1194 this.convert = cbOutputEnable.isSelected();
1195 this.ffmpeg = new File(p.getFfmpegPath());
1197 this.vhookDisabled = false;
1198 this.commentOverlay = p.getOutputCommentOverlay();
1199 this.vhook = new File(p.getFfmpegDllPath());
1200 this.tmpDir = new File(p.getSystemTempDir());
1201 this.font = new File(p.getFontPath());
1202 this.fontIndex = Integer.parseInt(p.getFontIndex());
1203 this.commentOpaque = p.getCommentOpaque();
1204 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1205 this.shadowIndex = p.getFontShadow();
1207 this.showConvrting = true;
1208 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1209 getCommentDisplaySizeManual());
1210 this.ngSetting = new InqubusHideCondition();
1214 public OutputProfile getOutputProfile() {
1215 return this.outputProfile;
1219 public GeneralProfile getGeneralProfile() {
1220 return this.generalProfile;
1224 public FfmpegProfile getFfmpegOption() {
1225 return this.ffmpegProfile;
1229 public boolean isConvert() {
1230 return this.convert;
1234 public File getFfmpeg() {
1239 public boolean isVhookDisabled() {
1240 return this.vhookDisabled;
1244 public boolean isCommentOverlay() {
1245 return this.commentOverlay;
1249 public File getVhook() {
1254 public File getTempDir() {
1259 public File getFont() {
1264 public int getFontIndex() {
1265 return this.fontIndex;
1269 public boolean isCommentOpaque() {
1270 return this.commentOpaque;
1274 public boolean isDisableFontSizeArrange() {
1275 return this.disableFontSizeArrange;
1279 public int getShadowIndex() {
1280 return this.shadowIndex;
1284 public boolean isShowConverting() {
1285 return this.showConvrting;
1289 public int getMaxNumOfComment() {
1290 return this.maxNumOfComment;
1294 public HideCondition getNgSetting() {
1295 return this.ngSetting;
1299 public String toString(){
1300 return ToStringBuilder.reflectionToString(this);
1304 private class InqubusOutputProfile implements OutputProfile {
1305 private final File dir;
1306 private final String fileName;
1307 private final String videoId;
1308 private final String title;
1311 private InqubusOutputProfile(){
1312 final Config p = Config.INSTANCE;
1313 this.dir = new File(p.getOutputDir());
1314 this.fileName = fldOutput.getText();
1315 // TODO この時点でのID/Titleはどうするか…
1321 public File getDir() {
1326 public String getFileName() {
1327 return this.fileName;
1331 public String getVideoId() {
1332 return this.videoId;
1336 public String getTitile() {
1341 public String toString(){
1342 return ToStringBuilder.reflectionToString(this);
1346 private class InqubusFfmpegProfile implements FfmpegProfile {
1347 private final String extOption;
1348 private final String inOption;
1349 private final String mainOption;
1350 private final String outOption;
1351 private final String avOption;
1352 private final boolean resize;
1353 private final int resizeWidth;
1354 private final int resizeHeight;
1355 private final boolean adjustRatio;
1357 private InqubusFfmpegProfile() throws IOException {
1358 final File file = pnlInputFfmpeg.mdlFfmpegOption.getSelectedFile();
1360 final FfmpegOption ffop = FfmpegOption.load(file);
1361 this.extOption = ffop.getExtOption();
1362 this.inOption = ffop.getInOption();
1363 this.mainOption = ffop.getMainOption();
1364 this.outOption = ffop.getMainOption();
1365 this.avOption = ffop.getAvfilterOption();
1366 this.resize = ffop.isResize();
1367 this.resizeWidth = ffop.getResizeWidth();
1368 this.resizeHeight = ffop.getResizeHeight();
1369 this.adjustRatio = ffop.isAdjustRatio();
1371 this.extOption = pnlInputFfmpeg.fldFfmpegOptionExtension.getText();
1372 this.inOption = pnlInputFfmpeg.fldFfmpegOptionIn.getText();
1373 this.mainOption = pnlInputFfmpeg.fldFfmpegOptionMain.getText();
1374 this.outOption = pnlInputFfmpeg.fldFfmpegOptionOut.getText();
1375 this.avOption = pnlInputFfmpeg.fldFfmpegOptionAv.getText();
1376 this.resize = pnlInputFfmpeg.cbFfmpegOptionResize.isSelected();
1377 this.resizeWidth = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeWidth.getText());
1378 this.resizeHeight = Integer.parseInt(pnlInputFfmpeg.fldFfmpegOptionResizeHeight.getText());
1379 this.adjustRatio = pnlInputFfmpeg.cbFfmpegOptionKeepAspect.isSelected();
1384 public String getExtOption() {
1385 return this.extOption;
1389 public String getInOption() {
1390 return this.inOption;
1394 public String getMainOption() {
1395 return this.mainOption;
1399 public String getOutOption() {
1400 return this.outOption;
1404 public String getAvfilterOption() {
1405 return this.avOption;
1409 public boolean isResize() {
1414 public int getResizeWidth() {
1415 return this.resizeWidth;
1419 public int getResizeHeight() {
1420 return this.resizeHeight;
1424 public boolean isAdjustRatio() {
1425 return this.adjustRatio;
1429 public String toString(){
1430 return ToStringBuilder.reflectionToString(this);
1434 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1437 public String getWord() {
1443 public String getId() {
1449 public String toString(){
1450 return ToStringBuilder.reflectionToString(this);