4 * Created on 2011/05/28, 18:14:51
6 package yukihane.inqubus.gui;
9 import java.awt.ItemSelectable;
10 import java.awt.Toolkit;
11 import java.awt.datatransfer.DataFlavor;
12 import java.awt.datatransfer.Transferable;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.awt.event.ItemEvent;
16 import java.awt.event.ItemListener;
17 import java.awt.event.KeyEvent;
18 import java.beans.PropertyChangeEvent;
19 import java.beans.PropertyChangeListener;
21 import java.io.FilenameFilter;
22 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.regex.Matcher;
30 import java.util.regex.Pattern;
31 import javax.swing.BorderFactory;
32 import javax.swing.DropMode;
33 import javax.swing.GroupLayout;
34 import javax.swing.GroupLayout.Alignment;
35 import javax.swing.JButton;
36 import javax.swing.JCheckBox;
37 import javax.swing.JFrame;
38 import javax.swing.JLabel;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuBar;
41 import javax.swing.JMenuItem;
42 import javax.swing.JPanel;
43 import javax.swing.JScrollPane;
44 import javax.swing.JTable;
45 import javax.swing.JTextField;
46 import javax.swing.KeyStroke;
47 import javax.swing.LayoutStyle.ComponentPlacement;
48 import javax.swing.SwingUtilities;
49 import javax.swing.TransferHandler;
50 import javax.swing.WindowConstants;
51 import org.apache.commons.lang.StringUtils;
52 import org.apache.commons.lang.builder.ToStringBuilder;
53 import saccubus.MainFrame_AboutBox;
54 import saccubus.util.WayBackTimeParser;
55 import saccubus.worker.impl.convert.ConvertProgress;
56 import saccubus.worker.impl.download.DownloadProgress;
57 import saccubus.worker.WorkerListener;
58 import saccubus.worker.impl.convert.ConvertResult;
59 import saccubus.worker.impl.download.DownloadResult;
60 import saccubus.worker.profile.CommentProfile;
61 import saccubus.worker.profile.ConvertProfile;
62 import saccubus.worker.profile.DownloadProfile;
63 import saccubus.worker.profile.FfmpegProfile;
64 import saccubus.worker.profile.GeneralProfile;
65 import saccubus.worker.profile.LoginProfile;
66 import saccubus.worker.profile.OutputProfile;
67 import saccubus.worker.profile.ProxyProfile;
68 import saccubus.worker.profile.VideoProfile;
70 import yukihane.inqubus.Config;
71 import yukihane.inqubus.manager.RequestProcess;
72 import yukihane.inqubus.manager.TaskKind;
73 import yukihane.inqubus.manager.TaskManage;
74 import yukihane.inqubus.manager.TaskManageListener;
75 import yukihane.inqubus.manager.TaskStatus;
76 import yukihane.inqubus.model.Target;
77 import yukihane.inqubus.model.TargetsTableModel;
83 public class MainFrame extends JFrame {
85 private static final long serialVersionUID = 1L;
86 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
87 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
88 private static final String FILE_LOCALBUTTON_TOOLTIP
89 = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
90 private static final String FILE_INPUTFIELD_TOOLTIP
91 = "ダウンロードする場合はファイル命名規則を入力します。"
92 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
93 private static final String FILE_OUTPUTFIELD_TOOLTIP
95 private final TargetsTableModel targetModel = new TargetsTableModel();
96 private final TaskManage taskManager;
98 /** Creates new form MainFrame */
100 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
101 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
102 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
103 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
104 final List<Image> images = new ArrayList<Image>(2);
107 setIconImages(images);
109 final JPanel pnlMain = new JPanel();
110 final JScrollPane scrDisplay = new JScrollPane();
111 tblDisplay = new JTable(targetModel, new TargetsColumnModel());
112 tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
113 final JPanel pnlButton = new JPanel();
114 final JPanel pnlInputMain = new JPanel();
115 final JLabel lblId = new JLabel();
116 fldId.setToolTipText(ID_FIELD_TOOLTIP);
117 final JLabel lblVideo = new JLabel();
118 cbVideoLocal = new JCheckBox();
119 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
120 fldVideo = new JTextField();
121 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
122 btnVideo = new JButton();
123 final JLabel lblComment = new JLabel();
125 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
126 cbBackLog.addItemListener(new ItemListener() {
129 public void itemStateChanged(ItemEvent e) {
130 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
131 fldBackLog.setEnabled(selected);
134 cbBackLog.addPropertyChangeListener("enabled", new PropertyChangeListener() {
137 public void propertyChange(PropertyChangeEvent evt) {
138 final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
139 final boolean fldEnabled = enabled ? cbBackLog.isSelected() : false;
140 fldBackLog.setEnabled(fldEnabled);
143 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
145 cbCommentLocal = new JCheckBox();
146 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
147 cbCommentLocal.addItemListener(new ItemListener() {
150 public void itemStateChanged(ItemEvent e) {
151 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
152 cbBackLogReduce.setEnabled(!selected);
153 cbBackLog.setEnabled(!selected);
156 fldComment = new JTextField();
157 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
158 btnComment = new JButton();
159 final JLabel lblOutput = new JLabel();
160 cbOutputEnable = new JCheckBox();
161 fldOutput = new JTextField();
162 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
164 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
166 btnStop.addActionListener(new StopActionListener());
167 btnApply.addActionListener(new ApplyActionListener());
169 pnlMain.setBorder(BorderFactory.createEtchedBorder());
171 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
172 scrDisplay.setViewportView(tblDisplay);
174 pnlButton.setBorder(BorderFactory.createEtchedBorder());
176 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
177 pnlButton.setLayout(gl_pnlButton);
178 gl_pnlButton.setHorizontalGroup(
179 gl_pnlButton.createParallelGroup(Alignment.LEADING)
180 .addGroup(gl_pnlButton.createSequentialGroup()
182 .addComponent(btnStart)
183 .addPreferredGap(ComponentPlacement.RELATED)
184 .addComponent(btnStop)
185 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
186 .addComponent(btnDeselect)
189 gl_pnlButton.setVerticalGroup(
190 gl_pnlButton.createParallelGroup(Alignment.LEADING)
191 .addGroup(gl_pnlButton.createSequentialGroup()
193 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
194 .addComponent(btnStart)
195 .addComponent(btnStop)
196 .addComponent(btnDeselect))
197 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
200 pnlInputMain.setBorder(BorderFactory.createEtchedBorder());
204 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
206 public void focusLost(java.awt.event.FocusEvent evt) {
207 idFieldFocusLost(evt);
211 lblVideo.setText("動画");
213 cbVideoLocal.setText("local");
214 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
216 public void itemStateChanged(java.awt.event.ItemEvent evt) {
217 useMovieLocalCheckBoxItemStateChanged(evt);
221 btnVideo.setText("...");
223 lblComment.setText("コメント");
225 cbCommentLocal.setText("local");
226 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
228 public void itemStateChanged(java.awt.event.ItemEvent evt) {
229 useMovieLocalCheckBoxItemStateChanged(evt);
233 btnComment.setText("...");
235 lblOutput.setText("出力");
237 cbOutputEnable.setText("変換");
238 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
240 public void itemStateChanged(java.awt.event.ItemEvent evt) {
241 outputConvertCheckBoxItemStateChanged(evt);
246 GroupLayout gl_pnlInputMain = new GroupLayout(pnlInputMain);
247 pnlInputMain.setLayout(gl_pnlInputMain);
248 gl_pnlInputMain.setHorizontalGroup(
249 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
250 .addGroup(gl_pnlInputMain.createSequentialGroup()
252 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
253 .addGroup(gl_pnlInputMain.createSequentialGroup()
254 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
255 .addComponent(lblComment)
256 .addComponent(lblVideo)
258 .addComponent(lblOutput))
259 .addPreferredGap(ComponentPlacement.RELATED)
260 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
261 .addGroup(gl_pnlInputMain.createSequentialGroup()
262 .addComponent(cbVideoLocal)
263 .addPreferredGap(ComponentPlacement.RELATED)
264 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
265 .addPreferredGap(ComponentPlacement.RELATED)
266 .addComponent(btnVideo))
267 .addGroup(gl_pnlInputMain.createSequentialGroup()
268 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
269 .addPreferredGap(ComponentPlacement.UNRELATED)
270 .addComponent(cbBackLogReduce)
271 .addComponent(cbBackLog)
272 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
274 .addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
275 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
276 .addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
277 .addComponent(cbOutputEnable)
278 .addPreferredGap(ComponentPlacement.RELATED)
279 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
280 .addGroup(gl_pnlInputMain.createSequentialGroup()
281 .addComponent(cbCommentLocal)
282 .addPreferredGap(ComponentPlacement.RELATED)
283 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
284 .addPreferredGap(ComponentPlacement.RELATED)
285 .addComponent(btnComment))))
286 .addComponent(btnApply, Alignment.TRAILING))
289 gl_pnlInputMain.setVerticalGroup(
290 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
291 .addGroup(gl_pnlInputMain.createSequentialGroup()
293 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
294 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
296 .addComponent(cbBackLogReduce)
297 .addComponent(cbBackLog)
298 .addComponent(fldBackLog)
300 .addPreferredGap(ComponentPlacement.RELATED)
301 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
302 .addComponent(lblVideo)
303 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
304 .addComponent(btnVideo)
305 .addComponent(cbVideoLocal))
306 .addPreferredGap(ComponentPlacement.RELATED)
307 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
308 .addComponent(lblComment)
309 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
310 .addComponent(btnComment)
311 .addComponent(cbCommentLocal))
312 .addPreferredGap(ComponentPlacement.RELATED)
313 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
314 .addComponent(lblOutput)
315 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
316 .addComponent(cbOutputEnable))
317 .addPreferredGap(ComponentPlacement.UNRELATED)
318 .addComponent(btnApply)
319 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
322 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
323 pnlMain.setLayout(gl_pnlMain);
324 gl_pnlMain.setHorizontalGroup(
325 gl_pnlMain.createParallelGroup(Alignment.LEADING)
326 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
328 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
329 .addComponent(pnlInputMain, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
330 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
331 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
334 gl_pnlMain.setVerticalGroup(
335 gl_pnlMain.createParallelGroup(Alignment.LEADING)
336 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
338 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
339 .addPreferredGap(ComponentPlacement.RELATED)
340 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
341 .addPreferredGap(ComponentPlacement.RELATED)
342 .addComponent(pnlInputMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
347 JMenuBar menuBar = initMenuBar();
348 setJMenuBar(menuBar);
350 GroupLayout layout = new GroupLayout(getContentPane());
351 getContentPane().setLayout(layout);
352 layout.setHorizontalGroup(
353 layout.createParallelGroup(Alignment.LEADING)
354 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
356 layout.setVerticalGroup(
357 layout.createParallelGroup(Alignment.LEADING)
358 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
363 pnlMain.setTransferHandler(new DownloadListTransferHandler());
364 tblDisplay.setTransferHandler(new TableTransferHandler());
366 final Config p = Config.INSTANCE;
368 // TODO downloadの連続処理時待ち時間設定も必要...
369 final int thDownload = p.getSystemDownloadThread();
370 final int secDownload = p.getSystemDownloadWait();
371 final int thConvert = p.getSystemConvertThread();
372 taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
375 private class GuiTaskManageListener implements TaskManageListener {
378 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
379 final String message) {
380 SwingUtilities.invokeLater(new Runnable() {
384 targetModel.setStatus(id, kind, status, percentage, message);
390 private class StopActionListener implements ActionListener {
393 public void actionPerformed(ActionEvent e) {
394 // FIXME 待機中に停止しても「状態」の表示が変わらない。
395 final int row = tblDisplay.getSelectedRow();
396 final Target t = targetModel.getTarget(row);
397 final boolean res = taskManager.cancel(t.getRowId());
398 logger.log(Level.FINE, "停止: {0} {1}", new Object[]{t.getVideoId(), res});
402 private class ApplyActionListener implements ActionListener {
405 public void actionPerformed(ActionEvent e) {
406 final DownloadProfile downProf = new InqubusDownloadProfile();
407 final String id = Util.getVideoId(fldId.getText());
408 final InqubusConvertProfile convProf = new InqubusConvertProfile();
409 logger.log(Level.INFO, downProf.toString());
410 logger.log(Level.INFO, convProf.toString());
411 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
413 targetModel.addTarget(new Target(rp));
417 /** This method is called from within the constructor to
418 * initialize the form.
419 * WARNING: Do NOT modify this code. The content of this method is
420 * always regenerated by the Form Editor.
422 @SuppressWarnings("unchecked")
423 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
424 private void initComponents() {
425 }// </editor-fold>//GEN-END:initComponents
427 private File searchFileMatchId(final File dir, final String id) {
428 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
433 final File[] lists = dir.listFiles(new FilenameFilter() {
435 final Pattern pattern = Pattern.compile(id + "\\D");
438 public boolean accept(File dir, String name) {
439 return pattern.matcher(name).find();
443 if (lists.length == 1) {
445 } else if (lists.length > 1) {
446 throw new UnsupportedOperationException();
453 * 動画, コメントの"local"チェックボックス更新時の処理.
455 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
456 final Config p = Config.INSTANCE;
458 final ItemSelectable source = evt.getItemSelectable();
463 if (source == cbVideoLocal) {
466 dir = new File(p.getVideoDir());
470 dir = new File(p.getCommentDir());
473 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
474 btn.setEnabled(useLocal);
478 final File f = searchFileMatchId(dir, fldId.getText());
485 text = p.getVideoFileNamePattern();
489 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
491 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
492 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
493 fldOutput.setEnabled(convert);
494 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
496 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
497 final Config p = Config.INSTANCE;
498 final String id = fldId.getText();
503 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
504 final File dir = new File(p.getVideoDir());
505 final File file = searchFileMatchId(dir, id);
507 fldVideo.setText(file.getPath());
511 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
512 final File dir = new File(p.getCommentDir());
513 final File file = searchFileMatchId(dir, id);
515 fldComment.setText(file.getPath());
519 }//GEN-LAST:event_idFieldFocusLost
520 // Variables declaration - do not modify//GEN-BEGIN:variables
521 private final JTable tblDisplay;
523 private final JButton btnStart = new JButton("開始");
524 private final JButton btnStop = new JButton("停止");
525 private final JButton btnDeselect = new JButton("選択解除");
527 private final JTextField fldId = new JTextField();
528 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
529 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
530 private final JTextField fldBackLog = new JTextField();
531 private final JCheckBox cbVideoLocal;
532 private final JTextField fldVideo;
533 private final JButton btnVideo;
534 private final JCheckBox cbCommentLocal;
535 private final JTextField fldComment;
536 private final JButton btnComment;
537 private final JCheckBox cbOutputEnable;
538 private final JTextField fldOutput;
540 private final JButton btnApply = new JButton("適用");
541 // End of variables declaration//GEN-END:variables
543 private void initInputPanel() {
544 final Config p = Config.INSTANCE;
547 fldBackLog.setEnabled(false);
548 cbBackLog.setEnabled(true);
550 final boolean movieLocal = p.getVideoUseLocal();
551 cbVideoLocal.setSelected(movieLocal);
552 btnVideo.setEnabled(movieLocal);
554 fldVideo.setText(p.getVideoFileNamePattern());
557 final boolean commentLocal = p.getCommentUseLocal();
558 cbCommentLocal.setSelected(commentLocal);
559 btnComment.setEnabled(commentLocal);
561 fldComment.setText(p.getCommentFileNamePattern());
564 final boolean convert = p.getOutputEnable();
565 cbOutputEnable.setSelected(convert);
566 fldOutput.setEnabled(convert);
567 fldOutput.setText(p.getOutputFileNamePattern());
571 private JMenuBar initMenuBar() {
572 final JMenuBar menuBar = new JMenuBar();
574 final JMenu mnFile = new JMenu("ファイル(F)");
577 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
578 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
579 itExit.addActionListener(new ActionListener() {
582 public void actionPerformed(ActionEvent e) {
583 throw new UnsupportedOperationException("Not supported yet.");
588 final JMenu mnTool = new JMenu("ツール(T)");
591 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
593 itOption.addActionListener(new ActionListener() {
596 public void actionPerformed(ActionEvent e) {
597 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
598 dlg.setLocationRelativeTo(MainFrame.this);
600 dlg.setVisible(true);
603 mnTool.add(itOption);
605 final JMenu mnHelp = new JMenu("ヘルプ(H)");
608 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
609 itAbout.addActionListener(new ActionListener() {
612 public void actionPerformed(ActionEvent e) {
613 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
615 dlg.setLocationRelativeTo(MainFrame.this);
617 dlg.setVisible(true);
625 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
628 public void process(DownloadProgress progress) {
629 throw new UnsupportedOperationException("Not supported yet.");
633 public void cancelled() {
634 throw new UnsupportedOperationException("Not supported yet.");
638 public void done(DownloadResult result) {
639 throw new UnsupportedOperationException("Not supported yet.");
643 public void error(Throwable th) {
644 throw new UnsupportedOperationException("Not supported yet.");
648 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
651 public void process(ConvertProgress progress) {
652 throw new UnsupportedOperationException("Not supported yet.");
656 public void cancelled() {
657 throw new UnsupportedOperationException("Not supported yet.");
661 public void done(ConvertResult result) {
662 throw new UnsupportedOperationException("Not supported yet.");
666 public void error(Throwable th) {
667 throw new UnsupportedOperationException("Not supported yet.");
673 private class DownloadListTransferHandler extends TransferHandler {
675 private static final long serialVersionUID = 1L;
676 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
679 public boolean canImport(TransferHandler.TransferSupport support) {
680 Transferable transferable = support.getTransferable();
681 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
682 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
689 public boolean importData(TransferHandler.TransferSupport support) {
691 // Transferable transferable = support.getTransferable();
692 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
693 // @SuppressWarnings("unchecked")
694 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
695 // Collection<Target> targets = Target.from(data);
696 // targetModel.addTarget(targets);
697 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
698 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
699 // Matcher matcher = movieIdPattern.matcher(data);
700 // if (matcher.find()) {
701 // String movieId = matcher.group(1);
702 // Target target = Target.fromId(movieId);
703 // targetModel.addTarget(target);
710 // } catch (Exception e) {
711 // logger.log(Level.SEVERE, null, e);
714 // TODO 上記実装見直し(Locationは削除された)
719 private class TableTransferHandler extends DownloadListTransferHandler {
721 private static final long serialVersionUID = 1L;
724 public boolean canImport(TransferHandler.TransferSupport support) {
725 return super.canImport(support);
729 public boolean importData(TransferHandler.TransferSupport support) {
730 return super.importData(support);
735 * ここからDownloadProfile作成用クラスの定義
738 private class InqubusDownloadProfile implements DownloadProfile {
740 private final LoginProfile loginProfile;
741 private final ProxyProfile proxyProfile;
742 private final VideoProfile videoProfile;
743 private final CommentProfile commentProfile;
744 private final GeneralProfile generalProfile;
746 private InqubusDownloadProfile() {
747 this.loginProfile = new InqubusLoginProfile();
748 this.proxyProfile = new InqubusProxyProfile();
749 this.videoProfile = new InqubusVideoProfile();
750 this.commentProfile = new InqubusCommentProfile();
751 this.generalProfile = new InqubusGeneralProfile();
755 public LoginProfile getLoginInfo() {
756 return this.loginProfile;
760 public ProxyProfile getProxyProfile() {
761 return this.proxyProfile;
765 public VideoProfile getVideoProfile() {
766 return this.videoProfile;
770 public CommentProfile getCommentProfile() {
771 return this.commentProfile;
775 public GeneralProfile getGeneralProfile() {
776 return this.generalProfile;
780 public String toString(){
781 return ToStringBuilder.reflectionToString(this);
785 private class InqubusLoginProfile implements LoginProfile {
786 private final String mail;
787 private final String password;
789 private InqubusLoginProfile(){
790 final Config p = Config.INSTANCE;
791 this.mail = p.getId();
792 this.password = p.getPassword();
796 public String getMail() {
801 public String getPassword() {
802 return this.password;
806 public String toString(){
807 return ToStringBuilder.reflectionToString(this);
811 private class InqubusProxyProfile implements ProxyProfile {
812 private final boolean use;
813 private final String host;
814 private final int port;
816 private InqubusProxyProfile(){
817 final Config p = Config.INSTANCE;
818 this.use = p.getProxyUse();
819 this.host = p.getProxyHost();
820 final String pp = p.getProxyPort();
821 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
825 public boolean use() {
830 public String getHost() {
835 public int getPort() {
840 public String toString(){
841 return ToStringBuilder.reflectionToString(this);
845 private class InqubusVideoProfile implements VideoProfile {
846 private final boolean download;
847 private final File dir;
848 private final String fileName;
849 private final File localFile;
851 private InqubusVideoProfile(){
852 final Config p = Config.INSTANCE;
853 this.download = !cbVideoLocal.isSelected();
855 this.dir = new File(p.getVideoDir());
856 this.fileName = fldVideo.getText();
857 this.localFile = null;
860 this.fileName = null;
861 this.localFile = new File(fldVideo.getText());
866 public boolean isDownload() {
867 return this.download;
871 public File getDir() {
876 public String getFileName() {
877 return this.fileName;
881 public File getLocalFile() {
882 return this.localFile;
886 public String toString(){
887 return ToStringBuilder.reflectionToString(this);
891 private class InqubusCommentProfile implements CommentProfile {
892 private final boolean download;
893 private final File dir;
894 private final String fileName;
895 private final File localFile;
896 private final int lengthRelatedCommentSize;
897 private final boolean disablePerMinComment;
898 private final int perMinCommentSize;
899 private final long backLogPoint;
901 private InqubusCommentProfile() {
902 final Config p = Config.INSTANCE;
903 this.download = !cbCommentLocal.isSelected();
905 this.dir = new File(p.getCommentDir());
906 this.fileName = fldComment.getText();
907 this.localFile = null;
910 this.fileName = null;
911 this.localFile = new File(fldComment.getText());
914 if(cbBackLog.isSelected()) {
916 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
917 } catch (IOException ex) {
918 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
921 this.backLogPoint = -1L;
924 this.disablePerMinComment = cbBackLogReduce.isSelected();
925 this.lengthRelatedCommentSize
926 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
927 this.perMinCommentSize
928 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
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 int getLengthRelatedCommentSize() {
953 return this.lengthRelatedCommentSize;
957 public boolean isDisablePerMinComment() {
958 return this.disablePerMinComment;
962 public int getPerMinCommentSize() {
963 return this.perMinCommentSize;
967 public long getBackLogPoint() {
968 return this.backLogPoint;
972 public String toString(){
973 return ToStringBuilder.reflectionToString(this);
977 private class InqubusGeneralProfile implements GeneralProfile {
978 private final String replaceFrom;
979 private final String replaceTo;
980 private InqubusGeneralProfile() {
981 final Config p = Config.INSTANCE;
982 this.replaceFrom = p.getReplaceFrom();
983 this.replaceTo = p.getReplaceTo();
987 public String getReplaceFrom() {
988 return this.replaceFrom;
992 public String getReplaceTo() {
993 return this.replaceTo;
997 public String toString(){
998 return ToStringBuilder.reflectionToString(this);
1003 * ここからConvertProfile作成用クラスの定義
1005 private class InqubusConvertProfile implements ConvertProfile {
1006 private final OutputProfile outputProfile;
1007 private final GeneralProfile generalProfile;
1008 private final FfmpegProfile ffmpegProfile;
1009 private final boolean convert;
1010 private final File ffmpeg;
1011 private final boolean vhookDisabled;
1012 private final boolean commentOverlay;
1013 private final File vhook;
1014 private final File tmpDir;
1015 private final File font;
1016 private final int fontIndex;
1017 private final boolean commentOpaque;
1018 private final boolean disableFontSizeArrange;
1019 private final int shadowIndex;
1020 private final boolean showConvrting;
1021 private final int maxNumOfComment;
1022 private final HideCondition ngSetting;
1024 private InqubusConvertProfile() {
1025 final Config p = Config.INSTANCE;
1026 this.outputProfile = new InqubusOutputProfile();
1027 this.generalProfile = new InqubusGeneralProfile();
1028 this.ffmpegProfile = new InqubusFfmpegProfile();
1029 this.convert = cbOutputEnable.isSelected();
1030 this.ffmpeg = new File(p.getFfmpegPath());
1032 this.vhookDisabled = false;
1033 this.commentOverlay = p.getOutputCommentOverlay();
1034 this.vhook = new File(p.getFfmpegDllPath());
1036 this.tmpDir = new File(".");
1037 this.font = new File(p.getFontPath());
1038 this.fontIndex = Integer.parseInt(p.getFontIndex());
1039 this.commentOpaque = p.getCommentOpaque();
1040 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1041 this.shadowIndex = p.getFontShadow();
1043 this.showConvrting = true;
1044 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1045 getCommentDisplaySizeManual());
1046 this.ngSetting = new InqubusHideCondition();
1050 public OutputProfile getOutputProfile() {
1051 return this.outputProfile;
1055 public GeneralProfile getGeneralProfile() {
1056 return this.generalProfile;
1060 public FfmpegProfile getFfmpegOption() {
1061 return this.ffmpegProfile;
1065 public boolean isConvert() {
1066 return this.convert;
1070 public File getFfmpeg() {
1075 public boolean isVhookDisabled() {
1076 return this.vhookDisabled;
1080 public boolean isCommentOverlay() {
1081 return this.commentOverlay;
1085 public File getVhook() {
1090 public File getTempDir() {
1095 public File getFont() {
1100 public int getFontIndex() {
1101 return this.fontIndex;
1105 public boolean isCommentOpaque() {
1106 return this.commentOpaque;
1110 public boolean isDisableFontSizeArrange() {
1111 return this.disableFontSizeArrange;
1115 public int getShadowIndex() {
1116 return this.shadowIndex;
1120 public boolean isShowConverting() {
1121 return this.showConvrting;
1125 public int getMaxNumOfComment() {
1126 return this.maxNumOfComment;
1130 public HideCondition getNgSetting() {
1131 return this.ngSetting;
1135 public String toString(){
1136 return ToStringBuilder.reflectionToString(this);
1140 private class InqubusOutputProfile implements OutputProfile {
1141 private final File dir;
1142 private final String fileName;
1143 private final String videoId;
1144 private final String title;
1147 private InqubusOutputProfile(){
1148 final Config p = Config.INSTANCE;
1149 this.dir = new File(p.getOutputDir());
1150 this.fileName = fldOutput.getText();
1151 // TODO この時点でのID/Titleはどうするか…
1157 public File getDir() {
1162 public String getFileName() {
1163 return this.fileName;
1167 public String getVideoId() {
1168 return this.videoId;
1172 public String getTitile() {
1177 public String toString(){
1178 return ToStringBuilder.reflectionToString(this);
1182 private class InqubusFfmpegProfile implements FfmpegProfile {
1183 private final String extOption;
1184 private final String inOption;
1185 private final String mainOption;
1186 private final String outOption;
1187 private final String avOption;
1188 private final boolean resize;
1189 private final int resizeWidth;
1190 private final int resizeHeight;
1191 private final boolean adjustRatio;
1193 private InqubusFfmpegProfile() {
1194 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1195 final Config p = Config.INSTANCE;
1196 this.extOption = p.getFfmpegExtension();
1197 this.inOption = p.getFfmpegInOption();
1198 this.mainOption = p.getFfmpegMainOption();
1199 this.outOption = p.getFfmpegOutOption();
1200 this.avOption = p.getFfmpegAvOption();
1201 this.resize = p.getFfmpegResizeEnable();
1202 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1203 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1204 this.adjustRatio = p.getFfmpegKeepAspect();
1208 public String getExtOption() {
1209 return this.extOption;
1213 public String getInOption() {
1214 return this.inOption;
1218 public String getMainOption() {
1219 return this.mainOption;
1223 public String getOutOption() {
1224 return this.outOption;
1228 public String getAvfilterOption() {
1229 return this.avOption;
1233 public boolean isResize() {
1238 public int getResizeWidth() {
1239 return this.resizeWidth;
1243 public int getResizeHeight() {
1244 return this.resizeHeight;
1248 public boolean isAdjustRatio() {
1249 return this.adjustRatio;
1253 public String toString(){
1254 return ToStringBuilder.reflectionToString(this);
1258 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1261 public String getWord() {
1267 public String getId() {
1273 public String toString(){
1274 return ToStringBuilder.reflectionToString(this);