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;
19 import java.io.FilenameFilter;
20 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29 import javax.swing.BorderFactory;
30 import javax.swing.DropMode;
31 import javax.swing.GroupLayout;
32 import javax.swing.GroupLayout.Alignment;
33 import javax.swing.JButton;
34 import javax.swing.JCheckBox;
35 import javax.swing.JFrame;
36 import javax.swing.JLabel;
37 import javax.swing.JMenu;
38 import javax.swing.JMenuBar;
39 import javax.swing.JMenuItem;
40 import javax.swing.JPanel;
41 import javax.swing.JScrollPane;
42 import javax.swing.JTable;
43 import javax.swing.JTextField;
44 import javax.swing.KeyStroke;
45 import javax.swing.LayoutStyle.ComponentPlacement;
46 import javax.swing.SwingUtilities;
47 import javax.swing.TransferHandler;
48 import javax.swing.WindowConstants;
49 import org.apache.commons.lang.StringUtils;
50 import org.apache.commons.lang.builder.ToStringBuilder;
51 import saccubus.MainFrame_AboutBox;
52 import saccubus.util.WayBackTimeParser;
53 import saccubus.worker.impl.convert.ConvertProgress;
54 import saccubus.worker.impl.download.DownloadProgress;
55 import saccubus.worker.WorkerListener;
56 import saccubus.worker.impl.convert.ConvertResult;
57 import saccubus.worker.impl.download.DownloadResult;
58 import saccubus.worker.profile.CommentProfile;
59 import saccubus.worker.profile.ConvertProfile;
60 import saccubus.worker.profile.DownloadProfile;
61 import saccubus.worker.profile.FfmpegProfile;
62 import saccubus.worker.profile.GeneralProfile;
63 import saccubus.worker.profile.LoginProfile;
64 import saccubus.worker.profile.OutputProfile;
65 import saccubus.worker.profile.ProxyProfile;
66 import saccubus.worker.profile.VideoProfile;
68 import yukihane.inqubus.Config;
69 import yukihane.inqubus.manager.RequestProcess;
70 import yukihane.inqubus.manager.TaskKind;
71 import yukihane.inqubus.manager.TaskManage;
72 import yukihane.inqubus.manager.TaskManageListener;
73 import yukihane.inqubus.manager.TaskStatus;
74 import yukihane.inqubus.model.Target;
75 import yukihane.inqubus.model.TargetsTableModel;
81 public class MainFrame extends JFrame {
83 private static final long serialVersionUID = 1L;
84 private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
85 private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
86 private static final String FILE_LOCALBUTTON_TOOLTIP
87 = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
88 private static final String FILE_INPUTFIELD_TOOLTIP
89 = "ダウンロードする場合はファイル命名規則を入力します。"
90 + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
91 private static final String FILE_OUTPUTFIELD_TOOLTIP
93 private final TargetsTableModel targetModel = new TargetsTableModel();
94 private final TaskManage taskManager;
96 /** Creates new form MainFrame */
98 final URL url = MainFrame_AboutBox.class.getResource("icon.png");
99 final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
100 final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
101 final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
102 final List<Image> images = new ArrayList<Image>(2);
105 setIconImages(images);
107 final JPanel pnlMain = new JPanel();
108 final JScrollPane scrDisplay = new JScrollPane();
109 tblDisplay = new MainTable();
110 final JPanel pnlButton = new JPanel();
111 btnStart = new JButton();
112 btnStop = new JButton();
113 btnDeselect = new JButton();
114 final JPanel pnlInputMain = new JPanel();
115 final JLabel lblId = new JLabel();
116 fldId = new JTextField();
117 fldId.setToolTipText(ID_FIELD_TOOLTIP);
118 final JLabel lblVideo = new JLabel();
119 cbVideoLocal = new JCheckBox();
120 cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
121 fldVideo = new JTextField();
122 fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
123 btnVideo = new JButton();
124 final JLabel lblComment = new JLabel();
125 cbCommentLocal = new JCheckBox();
126 cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
127 cbCommentLocal.addItemListener(new ItemListener() {
130 public void itemStateChanged(ItemEvent e) {
131 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
132 cbBackLogReduce.setEnabled(!selected);
133 cbBackLog.setEnabled(!selected);
135 cbBackLog.setSelected(false);
139 fldComment = new JTextField();
140 fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
141 btnComment = new JButton();
142 final JLabel lblOutput = new JLabel();
143 cbOutputEnable = new JCheckBox();
144 fldOutput = new JTextField();
145 fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
147 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
149 btnApply.addActionListener(new ApplyActionListener());
151 pnlMain.setBorder(BorderFactory.createEtchedBorder());
153 tblDisplay.setModel(targetModel);
154 tblDisplay.setDropMode(DropMode.INSERT_ROWS);
155 scrDisplay.setViewportView(tblDisplay);
157 pnlButton.setBorder(BorderFactory.createEtchedBorder());
159 btnStart.setText("開始");
161 btnStop.setText("停止");
163 btnDeselect.setText("選択解除");
165 GroupLayout gl_pnlButton = new GroupLayout(pnlButton);
166 pnlButton.setLayout(gl_pnlButton);
167 gl_pnlButton.setHorizontalGroup(
168 gl_pnlButton.createParallelGroup(Alignment.LEADING)
169 .addGroup(gl_pnlButton.createSequentialGroup()
171 .addComponent(btnStart)
172 .addPreferredGap(ComponentPlacement.RELATED)
173 .addComponent(btnStop)
174 .addPreferredGap(ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
175 .addComponent(btnDeselect)
178 gl_pnlButton.setVerticalGroup(
179 gl_pnlButton.createParallelGroup(Alignment.LEADING)
180 .addGroup(gl_pnlButton.createSequentialGroup()
182 .addGroup(gl_pnlButton.createParallelGroup(Alignment.BASELINE)
183 .addComponent(btnStart)
184 .addComponent(btnStop)
185 .addComponent(btnDeselect))
186 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
189 pnlInputMain.setBorder(BorderFactory.createEtchedBorder());
193 fldId.addFocusListener(new java.awt.event.FocusAdapter() {
195 public void focusLost(java.awt.event.FocusEvent evt) {
196 idFieldFocusLost(evt);
200 lblVideo.setText("動画");
202 cbVideoLocal.setText("local");
203 cbVideoLocal.addItemListener(new java.awt.event.ItemListener() {
205 public void itemStateChanged(java.awt.event.ItemEvent evt) {
206 useMovieLocalCheckBoxItemStateChanged(evt);
210 btnVideo.setText("...");
212 lblComment.setText("コメント");
214 cbCommentLocal.setText("local");
215 cbCommentLocal.addItemListener(new java.awt.event.ItemListener() {
217 public void itemStateChanged(java.awt.event.ItemEvent evt) {
218 useMovieLocalCheckBoxItemStateChanged(evt);
222 btnComment.setText("...");
224 lblOutput.setText("出力");
226 cbOutputEnable.setText("変換");
227 cbOutputEnable.addItemListener(new java.awt.event.ItemListener() {
229 public void itemStateChanged(java.awt.event.ItemEvent evt) {
230 outputConvertCheckBoxItemStateChanged(evt);
235 GroupLayout gl_pnlInputMain = new GroupLayout(pnlInputMain);
236 pnlInputMain.setLayout(gl_pnlInputMain);
237 gl_pnlInputMain.setHorizontalGroup(
238 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
239 .addGroup(gl_pnlInputMain.createSequentialGroup()
241 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
242 .addGroup(gl_pnlInputMain.createSequentialGroup()
243 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
244 .addComponent(lblComment)
245 .addComponent(lblVideo)
247 .addComponent(lblOutput))
248 .addPreferredGap(ComponentPlacement.RELATED)
249 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
250 .addGroup(gl_pnlInputMain.createSequentialGroup()
251 .addComponent(cbVideoLocal)
252 .addPreferredGap(ComponentPlacement.RELATED)
253 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
254 .addPreferredGap(ComponentPlacement.RELATED)
255 .addComponent(btnVideo))
256 .addGroup(gl_pnlInputMain.createSequentialGroup()
257 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
258 .addPreferredGap(ComponentPlacement.UNRELATED)
259 .addComponent(cbBackLogReduce)
260 .addComponent(cbBackLog)
261 .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
263 .addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
264 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
265 .addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
266 .addComponent(cbOutputEnable)
267 .addPreferredGap(ComponentPlacement.RELATED)
268 .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
269 .addGroup(gl_pnlInputMain.createSequentialGroup()
270 .addComponent(cbCommentLocal)
271 .addPreferredGap(ComponentPlacement.RELATED)
272 .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
273 .addPreferredGap(ComponentPlacement.RELATED)
274 .addComponent(btnComment))))
275 .addComponent(btnApply, Alignment.TRAILING))
278 gl_pnlInputMain.setVerticalGroup(
279 gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
280 .addGroup(gl_pnlInputMain.createSequentialGroup()
282 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
283 .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
285 .addComponent(cbBackLogReduce)
286 .addComponent(cbBackLog)
287 .addComponent(fldBackLog)
289 .addPreferredGap(ComponentPlacement.RELATED)
290 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
291 .addComponent(lblVideo)
292 .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
293 .addComponent(btnVideo)
294 .addComponent(cbVideoLocal))
295 .addPreferredGap(ComponentPlacement.RELATED)
296 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
297 .addComponent(lblComment)
298 .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
299 .addComponent(btnComment)
300 .addComponent(cbCommentLocal))
301 .addPreferredGap(ComponentPlacement.RELATED)
302 .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
303 .addComponent(lblOutput)
304 .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
305 .addComponent(cbOutputEnable))
306 .addPreferredGap(ComponentPlacement.UNRELATED)
307 .addComponent(btnApply)
308 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
311 GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
312 pnlMain.setLayout(gl_pnlMain);
313 gl_pnlMain.setHorizontalGroup(
314 gl_pnlMain.createParallelGroup(Alignment.LEADING)
315 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
317 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
318 .addComponent(pnlInputMain, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
319 .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
320 .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
323 gl_pnlMain.setVerticalGroup(
324 gl_pnlMain.createParallelGroup(Alignment.LEADING)
325 .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
327 .addComponent(scrDisplay, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
328 .addPreferredGap(ComponentPlacement.RELATED)
329 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
330 .addPreferredGap(ComponentPlacement.RELATED)
331 .addComponent(pnlInputMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
336 JMenuBar menuBar = initMenuBar();
337 setJMenuBar(menuBar);
339 GroupLayout layout = new GroupLayout(getContentPane());
340 getContentPane().setLayout(layout);
341 layout.setHorizontalGroup(
342 layout.createParallelGroup(Alignment.LEADING)
343 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
345 layout.setVerticalGroup(
346 layout.createParallelGroup(Alignment.LEADING)
347 .addComponent(pnlMain, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
352 pnlMain.setTransferHandler(new DownloadListTransferHandler());
353 tblDisplay.setTransferHandler(new TableTransferHandler());
355 final Config p = Config.INSTANCE;
357 taskManager = new TaskManage(1, 1, new GuiTaskManageListener());
360 private class GuiTaskManageListener implements TaskManageListener {
363 public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
364 final String message) {
365 SwingUtilities.invokeLater(new Runnable() {
369 targetModel.setStatus(id, kind, status, percentage, message);
375 private class ApplyActionListener implements ActionListener {
378 public void actionPerformed(ActionEvent e) {
379 final DownloadProfile downProf = new InqubusDownloadProfile();
380 final String id = Util.getVideoId(fldId.getText());
381 final InqubusConvertProfile convProf = new InqubusConvertProfile();
382 logger.log(Level.INFO, downProf.toString());
383 logger.log(Level.INFO, convProf.toString());
384 final RequestProcess rp = new RequestProcess(downProf, id, convProf);
386 targetModel.addTarget(new Target(rp));
389 /** This method is called from within the constructor to
390 * initialize the form.
391 * WARNING: Do NOT modify this code. The content of this method is
392 * always regenerated by the Form Editor.
394 @SuppressWarnings("unchecked")
395 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
396 private void initComponents() {
397 }// </editor-fold>//GEN-END:initComponents
399 private File searchFileMatchId(final File dir, final String id) {
400 // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
405 final File[] lists = dir.listFiles(new FilenameFilter() {
407 final Pattern pattern = Pattern.compile(id + "\\D");
410 public boolean accept(File dir, String name) {
411 return pattern.matcher(name).find();
415 if (lists.length == 1) {
417 } else if (lists.length > 1) {
418 throw new UnsupportedOperationException();
424 private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
425 final Config p = Config.INSTANCE;
427 final ItemSelectable source = evt.getItemSelectable();
432 if (source == cbVideoLocal) {
435 dir = new File(p.getVideoDir());
439 dir = new File(p.getCommentDir());
442 final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
443 btn.setEnabled(useLocal);
447 final File f = searchFileMatchId(dir, fldId.getText());
454 text = p.getVideoFileNamePattern();
458 fldId.setEnabled(!(cbVideoLocal.isSelected() && cbCommentLocal.isSelected()));
460 }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
462 private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
463 final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
464 fldOutput.setEnabled(convert);
465 }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
467 private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
468 final Config p = Config.INSTANCE;
469 final String id = fldId.getText();
474 if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
475 final File dir = new File(p.getVideoDir());
476 final File file = searchFileMatchId(dir, id);
478 fldVideo.setText(file.getPath());
482 if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
483 final File dir = new File(p.getCommentDir());
484 final File file = searchFileMatchId(dir, id);
486 fldComment.setText(file.getPath());
490 }//GEN-LAST:event_idFieldFocusLost
491 // Variables declaration - do not modify//GEN-BEGIN:variables
492 private final JTable tblDisplay;
494 private final JButton btnStart;
495 private final JButton btnStop;
496 private final JButton btnDeselect;
498 private final JTextField fldId;
499 private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
500 private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
501 private final JTextField fldBackLog = new JTextField();
502 private final JCheckBox cbVideoLocal;
503 private final JTextField fldVideo;
504 private final JButton btnVideo;
505 private final JCheckBox cbCommentLocal;
506 private final JTextField fldComment;
507 private final JButton btnComment;
508 private final JCheckBox cbOutputEnable;
509 private final JTextField fldOutput;
511 private final JButton btnApply = new JButton("適用");
512 // End of variables declaration//GEN-END:variables
514 private void initInputPanel() {
515 final Config p = Config.INSTANCE;
518 fldBackLog.setEnabled(false);
519 fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
520 cbBackLog.setEnabled(true);
521 cbBackLog.addItemListener(new ItemListener() {
524 public void itemStateChanged(ItemEvent e) {
525 final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
526 fldBackLog.setEnabled(selected);
529 cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
531 final boolean movieLocal = p.getVideoUseLocal();
532 cbVideoLocal.setSelected(movieLocal);
533 btnVideo.setEnabled(movieLocal);
535 fldVideo.setText(p.getVideoFileNamePattern());
538 final boolean commentLocal = p.getCommentUseLocal();
539 cbCommentLocal.setSelected(commentLocal);
540 btnComment.setEnabled(commentLocal);
542 fldComment.setText(p.getCommentFileNamePattern());
545 final boolean convert = p.getOutputEnable();
546 cbOutputEnable.setSelected(convert);
547 fldOutput.setEnabled(convert);
548 fldOutput.setText(p.getOutputFileNamePattern());
552 private JMenuBar initMenuBar() {
553 final JMenuBar menuBar = new JMenuBar();
555 final JMenu mnFile = new JMenu("ファイル(F)");
558 final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
559 itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
560 itExit.addActionListener(new ActionListener() {
563 public void actionPerformed(ActionEvent e) {
564 throw new UnsupportedOperationException("Not supported yet.");
569 final JMenu mnTool = new JMenu("ツール(T)");
572 final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
574 itOption.addActionListener(new ActionListener() {
577 public void actionPerformed(ActionEvent e) {
578 final yukihane.inqubus.gui.ConfigDialog dlg = new yukihane.inqubus.gui.ConfigDialog(MainFrame.this);
579 dlg.setLocationRelativeTo(MainFrame.this);
581 dlg.setVisible(true);
584 mnTool.add(itOption);
586 final JMenu mnHelp = new JMenu("ヘルプ(H)");
589 final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
590 itAbout.addActionListener(new ActionListener() {
593 public void actionPerformed(ActionEvent e) {
594 MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
596 dlg.setLocationRelativeTo(MainFrame.this);
598 dlg.setVisible(true);
606 private class DownloadProgressListener implements WorkerListener<DownloadResult, DownloadProgress> {
609 public void process(DownloadProgress progress) {
610 throw new UnsupportedOperationException("Not supported yet.");
614 public void cancelled() {
615 throw new UnsupportedOperationException("Not supported yet.");
619 public void done(DownloadResult result) {
620 throw new UnsupportedOperationException("Not supported yet.");
624 public void error(Throwable th) {
625 throw new UnsupportedOperationException("Not supported yet.");
629 private class ConvertProgressListener implements WorkerListener<ConvertResult, ConvertProgress> {
632 public void process(ConvertProgress progress) {
633 throw new UnsupportedOperationException("Not supported yet.");
637 public void cancelled() {
638 throw new UnsupportedOperationException("Not supported yet.");
642 public void done(ConvertResult result) {
643 throw new UnsupportedOperationException("Not supported yet.");
647 public void error(Throwable th) {
648 throw new UnsupportedOperationException("Not supported yet.");
654 private class DownloadListTransferHandler extends TransferHandler {
656 private static final long serialVersionUID = 1L;
657 private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
660 public boolean canImport(TransferHandler.TransferSupport support) {
661 Transferable transferable = support.getTransferable();
662 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
663 || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
670 public boolean importData(TransferHandler.TransferSupport support) {
672 // Transferable transferable = support.getTransferable();
673 // if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
674 // @SuppressWarnings("unchecked")
675 // final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
676 // Collection<Target> targets = Target.from(data);
677 // targetModel.addTarget(targets);
678 // } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
679 // String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
680 // Matcher matcher = movieIdPattern.matcher(data);
681 // if (matcher.find()) {
682 // String movieId = matcher.group(1);
683 // Target target = Target.fromId(movieId);
684 // targetModel.addTarget(target);
691 // } catch (Exception e) {
692 // logger.log(Level.SEVERE, null, e);
695 // TODO 上記実装見直し(Locationは削除された)
700 private class TableTransferHandler extends DownloadListTransferHandler {
702 private static final long serialVersionUID = 1L;
705 public boolean canImport(TransferHandler.TransferSupport support) {
706 return super.canImport(support);
710 public boolean importData(TransferHandler.TransferSupport support) {
711 return super.importData(support);
716 * ここからDownloadProfile作成用クラスの定義
719 private class InqubusDownloadProfile implements DownloadProfile {
721 private final LoginProfile loginProfile;
722 private final ProxyProfile proxyProfile;
723 private final VideoProfile videoProfile;
724 private final CommentProfile commentProfile;
725 private final GeneralProfile generalProfile;
727 private InqubusDownloadProfile() {
728 this.loginProfile = new InqubusLoginProfile();
729 this.proxyProfile = new InqubusProxyProfile();
730 this.videoProfile = new InqubusVideoProfile();
731 this.commentProfile = new InqubusCommentProfile();
732 this.generalProfile = new InqubusGeneralProfile();
736 public LoginProfile getLoginInfo() {
737 return this.loginProfile;
741 public ProxyProfile getProxyProfile() {
742 return this.proxyProfile;
746 public VideoProfile getVideoProfile() {
747 return this.videoProfile;
751 public CommentProfile getCommentProfile() {
752 return this.commentProfile;
756 public GeneralProfile getGeneralProfile() {
757 return this.generalProfile;
761 public String toString(){
762 return ToStringBuilder.reflectionToString(this);
766 private class InqubusLoginProfile implements LoginProfile {
767 private final String mail;
768 private final String password;
770 private InqubusLoginProfile(){
771 final Config p = Config.INSTANCE;
772 this.mail = p.getId();
773 this.password = p.getPassword();
777 public String getMail() {
782 public String getPassword() {
783 return this.password;
787 public String toString(){
788 return ToStringBuilder.reflectionToString(this);
792 private class InqubusProxyProfile implements ProxyProfile {
793 private final boolean use;
794 private final String host;
795 private final int port;
797 private InqubusProxyProfile(){
798 final Config p = Config.INSTANCE;
799 this.use = p.getProxyUse();
800 this.host = p.getProxyHost();
801 final String pp = p.getProxyPort();
802 this.port = StringUtils.isBlank(pp) ? -1 : Integer.parseInt(pp);
806 public boolean use() {
811 public String getHost() {
816 public int getPort() {
821 public String toString(){
822 return ToStringBuilder.reflectionToString(this);
826 private class InqubusVideoProfile implements VideoProfile {
827 private final boolean download;
828 private final File dir;
829 private final String fileName;
830 private final File localFile;
832 private InqubusVideoProfile(){
833 final Config p = Config.INSTANCE;
834 this.download = !cbVideoLocal.isSelected();
836 this.dir = new File(p.getVideoDir());
837 this.fileName = fldVideo.getText();
838 this.localFile = null;
841 this.fileName = null;
842 this.localFile = new File(fldVideo.getText());
847 public boolean isDownload() {
848 return this.download;
852 public File getDir() {
857 public String getFileName() {
858 return this.fileName;
862 public File getLocalFile() {
863 return this.localFile;
867 public String toString(){
868 return ToStringBuilder.reflectionToString(this);
872 private class InqubusCommentProfile implements CommentProfile {
873 private final boolean download;
874 private final File dir;
875 private final String fileName;
876 private final File localFile;
877 private final int lengthRelatedCommentSize;
878 private final boolean disablePerMinComment;
879 private final int perMinCommentSize;
880 private final long backLogPoint;
882 private InqubusCommentProfile() {
883 final Config p = Config.INSTANCE;
884 this.download = !cbVideoLocal.isSelected();
886 this.dir = new File(p.getVideoDir());
887 this.fileName = fldVideo.getText();
888 this.localFile = null;
891 this.fileName = null;
892 this.localFile = new File(fldVideo.getText());
895 if(cbBackLog.isSelected()) {
897 this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
898 } catch (IOException ex) {
899 throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
902 this.backLogPoint = -1L;
905 this.disablePerMinComment = cbBackLogReduce.isSelected();
906 this.lengthRelatedCommentSize
907 = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
908 this.perMinCommentSize
909 = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
913 public boolean isDownload() {
914 return this.download;
918 public File getDir() {
923 public String getFileName() {
924 return this.fileName;
928 public File getLocalFile() {
929 return this.localFile;
933 public int getLengthRelatedCommentSize() {
934 return this.lengthRelatedCommentSize;
938 public boolean isDisablePerMinComment() {
939 return this.disablePerMinComment;
943 public int getPerMinCommentSize() {
944 return this.perMinCommentSize;
948 public long getBackLogPoint() {
949 return this.backLogPoint;
953 public String toString(){
954 return ToStringBuilder.reflectionToString(this);
958 private class InqubusGeneralProfile implements GeneralProfile {
959 private final String replaceFrom;
960 private final String replaceTo;
961 private InqubusGeneralProfile() {
962 final Config p = Config.INSTANCE;
963 this.replaceFrom = p.getReplaceFrom();
964 this.replaceTo = p.getReplaceTo();
968 public String getReplaceFrom() {
969 return this.replaceFrom;
973 public String getReplaceTo() {
974 return this.replaceTo;
978 public String toString(){
979 return ToStringBuilder.reflectionToString(this);
984 * ここからConvertProfile作成用クラスの定義
986 private class InqubusConvertProfile implements ConvertProfile {
987 private final OutputProfile outputProfile;
988 private final GeneralProfile generalProfile;
989 private final FfmpegProfile ffmpegProfile;
990 private final boolean convert;
991 private final File ffmpeg;
992 private final boolean vhookDisabled;
993 private final boolean commentOverlay;
994 private final File vhook;
995 private final File tmpDir;
996 private final File font;
997 private final int fontIndex;
998 private final boolean commentOpaque;
999 private final boolean disableFontSizeArrange;
1000 private final int shadowIndex;
1001 private final boolean showConvrting;
1002 private final int maxNumOfComment;
1003 private final HideCondition ngSetting;
1005 private InqubusConvertProfile() {
1006 final Config p = Config.INSTANCE;
1007 this.outputProfile = new InqubusOutputProfile();
1008 this.generalProfile = new InqubusGeneralProfile();
1009 this.ffmpegProfile = new InqubusFfmpegProfile();
1010 this.convert = cbOutputEnable.isSelected();
1011 this.ffmpeg = new File(p.getFfmpegPath());
1013 this.vhookDisabled = false;
1014 this.commentOverlay = p.getOutputCommentOverlay();
1015 this.vhook = new File(p.getFfmpegDllPath());
1017 this.tmpDir = new File(".");
1018 this.font = new File(p.getFontPath());
1019 this.fontIndex = Integer.parseInt(p.getFontIndex());
1020 this.commentOpaque = p.getCommentOpaque();
1021 this.disableFontSizeArrange = p.getFontSizeArrangeDisable();
1022 this.shadowIndex = p.getFontShadow();
1024 this.showConvrting = true;
1025 this.maxNumOfComment = (p.getCommentDisplaySizeDefault()) ? -1 : Integer.parseInt(p.
1026 getCommentDisplaySizeManual());
1027 this.ngSetting = new InqubusHideCondition();
1031 public OutputProfile getOutputProfile() {
1032 return this.outputProfile;
1036 public GeneralProfile getGeneralProfile() {
1037 return this.generalProfile;
1041 public FfmpegProfile getFfmpegOption() {
1042 return this.ffmpegProfile;
1046 public boolean isConvert() {
1047 return this.convert;
1051 public File getFfmpeg() {
1056 public boolean isVhookDisabled() {
1057 return this.vhookDisabled;
1061 public boolean isCommentOverlay() {
1062 return this.commentOverlay;
1066 public File getVhook() {
1071 public File getTempDir() {
1076 public File getFont() {
1081 public int getFontIndex() {
1082 return this.fontIndex;
1086 public boolean isCommentOpaque() {
1087 return this.commentOpaque;
1091 public boolean isDisableFontSizeArrange() {
1092 return this.disableFontSizeArrange;
1096 public int getShadowIndex() {
1097 return this.shadowIndex;
1101 public boolean isShowConverting() {
1102 return this.showConvrting;
1106 public int getMaxNumOfComment() {
1107 return this.maxNumOfComment;
1111 public HideCondition getNgSetting() {
1112 return this.ngSetting;
1116 public String toString(){
1117 return ToStringBuilder.reflectionToString(this);
1121 private class InqubusOutputProfile implements OutputProfile {
1122 private final File dir;
1123 private final String fileName;
1124 private final String videoId;
1125 private final String title;
1128 private InqubusOutputProfile(){
1129 final Config p = Config.INSTANCE;
1130 this.dir = new File(p.getOutputDir());
1131 this.fileName = fldOutput.getText();
1132 // TODO この時点でのID/Titleはどうするか…
1138 public File getDir() {
1143 public String getFileName() {
1144 return this.fileName;
1148 public String getVideoId() {
1149 return this.videoId;
1153 public String getTitile() {
1158 public String toString(){
1159 return ToStringBuilder.reflectionToString(this);
1163 private class InqubusFfmpegProfile implements FfmpegProfile {
1164 private final String extOption;
1165 private final String inOption;
1166 private final String mainOption;
1167 private final String outOption;
1168 private final String avOption;
1169 private final boolean resize;
1170 private final int resizeWidth;
1171 private final int resizeHeight;
1172 private final boolean adjustRatio;
1174 private InqubusFfmpegProfile() {
1175 // TODO FFMPEGオプションは、後でメイン画面でも設定できるようにするかも
1176 final Config p = Config.INSTANCE;
1177 this.extOption = p.getFfmpegExtension();
1178 this.inOption = p.getFfmpegInOption();
1179 this.mainOption = p.getFfmpegMainOption();
1180 this.outOption = p.getFfmpegOutOption();
1181 this.avOption = p.getFfmpegAvOption();
1182 this.resize = p.getFfmpegResizeEnable();
1183 this.resizeWidth = Integer.parseInt(p.getFfmpegResizeWidth());
1184 this.resizeHeight = Integer.parseInt(p.getFfmpegResizeHeight());
1185 this.adjustRatio = p.getFfmpegKeepAspect();
1189 public String getExtOption() {
1190 return this.extOption;
1194 public String getInOption() {
1195 return this.inOption;
1199 public String getMainOption() {
1200 return this.mainOption;
1204 public String getOutOption() {
1205 return this.outOption;
1209 public String getAvfilterOption() {
1210 return this.avOption;
1214 public boolean isResize() {
1219 public int getResizeWidth() {
1220 return this.resizeWidth;
1224 public int getResizeHeight() {
1225 return this.resizeHeight;
1229 public boolean isAdjustRatio() {
1230 return this.adjustRatio;
1234 public String toString(){
1235 return ToStringBuilder.reflectionToString(this);
1239 private class InqubusHideCondition implements ConvertProfile.HideCondition{
1242 public String getWord() {
1248 public String getId() {
1254 public String toString(){
1255 return ToStringBuilder.reflectionToString(this);