import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.TransferHandler;
import javax.swing.WindowConstants;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ToStringBuilder;
import saccubus.MainFrame_AboutBox;
-import saccubus.worker.Download;
+import saccubus.util.WayBackTimeParser;
+import saccubus.worker.convert.ConvertProgress;
+import saccubus.worker.download.DownloadProgress;
+import saccubus.worker.WorkerListener;
import saccubus.worker.profile.CommentProfile;
import saccubus.worker.profile.DownloadProfile;
import saccubus.worker.profile.GeneralProfile;
import saccubus.worker.profile.VideoProfile;
import yukihane.Util;
import yukihane.inqubus.Config;
+import yukihane.inqubus.manager.TaskManage;
import yukihane.inqubus.model.Target;
import yukihane.inqubus.model.TargetsTableModel;
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(MainFrame.class.getName());
+ private static final String ID_FIELD_TOOLTIP = "動画のIDまたはURLを入力します。";
+ private static final String FILE_LOCALBUTTON_TOOLTIP
+ = "ダウンロードする場合はチェックを外します。ローカルファイルを使用する場合はチェックを入れます。";
+ private static final String FILE_INPUTFIELD_TOOLTIP
+ = "ダウンロードする場合はファイル命名規則を入力します。"
+ + "ローカルファイルを使用する場合はパスを含むファイル名を入力します。";
+ private static final String FILE_OUTPUTFIELD_TOOLTIP
+ = "ファイル命名規則入力します。";
private final TargetsTableModel targetModel = new TargetsTableModel();
+ private final TaskManage taskManager;
+ private final DownloadProgressListener downloadProgressListener = new DownloadProgressListener();
+ private final ConvertProgressListener convertProgressListener = new ConvertProgressListener();
/** Creates new form MainFrame */
public MainFrame() {
final JPanel pnlInputMain = new JPanel();
final JLabel lblId = new JLabel();
fldId = new JTextField();
+ fldId.setToolTipText(ID_FIELD_TOOLTIP);
final JLabel lblVideo = new JLabel();
cbVideoLocal = new JCheckBox();
+ cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
fldVideo = new JTextField();
+ fldVideo.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
btnVideo = new JButton();
final JLabel lblComment = new JLabel();
cbCommentLocal = new JCheckBox();
+ cbCommentLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
+ cbCommentLocal.addItemListener(new ItemListener() {
+
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
+ cbBackLogReduce.setEnabled(!selected);
+ cbBackLog.setEnabled(!selected);
+ if(selected) {
+ cbBackLog.setSelected(false);
+ }
+ }
+ });
fldComment = new JTextField();
+ fldComment.setToolTipText(FILE_INPUTFIELD_TOOLTIP);
btnComment = new JButton();
final JLabel lblOutput = new JLabel();
cbOutputEnable = new JCheckBox();
fldOutput = new JTextField();
+ fldOutput.setToolTipText(FILE_OUTPUTFIELD_TOOLTIP);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
.addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnVideo))
- .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
+ .addGroup(gl_pnlInputMain.createSequentialGroup()
+ .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(ComponentPlacement.UNRELATED)
+ .addComponent(cbBackLogReduce)
+ .addComponent(cbBackLog)
+ .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
+ )
.addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
.addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
.addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
.addContainerGap()
.addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
.addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(lblId))
+ .addComponent(lblId)
+ .addComponent(cbBackLogReduce)
+ .addComponent(cbBackLog)
+ .addComponent(fldBackLog)
+ )
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
.addComponent(lblVideo)
initInputPanel();
pnlMain.setTransferHandler(new DownloadListTransferHandler());
tblDisplay.setTransferHandler(new TableTransferHandler());
+
+ final Config p = Config.INSTANCE;
+ // TODO コンフィグからスレッド数
+ taskManager = new TaskManage(1, 1);
+
}
private class ApplyActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
final DownloadProfile prof = new InqubusDownloadProfile();
final String id = Util.getVideoId(fldId.getText());
-
- new Download(prof, id).execute();
+ logger.log(Level.INFO, prof.toString());
+ // TODO 処理開始
+// new Download(prof, id).execute();
}
}
/** This method is called from within the constructor to
private void initComponents() {
}// </editor-fold>//GEN-END:initComponents
- private File searchFileMatchId(final File dir, final String id) throws UnsupportedOperationException {
+ private File searchFileMatchId(final File dir, final String id) {
// TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
if (id.isEmpty()) {
return null;
text = p.getVideoFileNamePattern();
}
field.setText(text);
+
+ fldId.setEnabled(!(cbVideoLocal.isSelected() && cbCommentLocal.isSelected()));
+
}//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
private final JButton btnDeselect;
//入力領域 - 標準
private final JTextField fldId;
+ private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
+ private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
+ private final JTextField fldBackLog = new JTextField();
private final JCheckBox cbVideoLocal;
private final JTextField fldVideo;
private final JButton btnVideo;
// End of variables declaration//GEN-END:variables
private void initInputPanel() {
+ final Config p = Config.INSTANCE;
+
fldId.setText("");
+ fldBackLog.setEnabled(false);
+ fldBackLog.setToolTipText("YYYY/MM/DD hh:mm:ss形式、あるいは1970/01/01からの経過秒を入力します。");
+ cbBackLog.setEnabled(true);
+ cbBackLog.addItemListener(new ItemListener() {
- final Config p = Config.INSTANCE;
+ @Override
+ public void itemStateChanged(ItemEvent e) {
+ final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
+ fldBackLog.setEnabled(selected);
+ }
+ });
+ cbBackLogReduce.setToolTipText("「コメントの量を減らす」場合はチェックを付けます。");
final boolean movieLocal = p.getVideoUseLocal();
cbVideoLocal.setSelected(movieLocal);
return menuBar;
}
+ private class DownloadProgressListener implements WorkerListener<DownloadProgress> {
+
+ @Override
+ public void process(DownloadProgress progress) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+
+ private class ConvertProgressListener implements WorkerListener<ConvertProgress> {
+
+ @Override
+ public void process(ConvertProgress progress) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+
+
+
private class DownloadListTransferHandler extends TransferHandler {
private static final long serialVersionUID = 1L;
private final LoginProfile loginProfile;
private final ProxyProfile proxyProfile;
+ private final VideoProfile videoProfile;
+ private final CommentProfile commentProfile;
+ private final GeneralProfile generalProfile;
private InqubusDownloadProfile() {
this.loginProfile = new InqubusLoginProfile();
this.proxyProfile = new InqubusProxyProfile();
+ this.videoProfile = new InqubusVideoProfile();
+ this.commentProfile = new InqubusCommentProfile();
+ this.generalProfile = new InqubusGeneralProfile();
}
@Override
}
@Override
- public ProxyProfile getProxySetting() {
+ public ProxyProfile getProxyProfile() {
return this.proxyProfile;
}
@Override
- public VideoProfile getVideoSetting() {
- throw new UnsupportedOperationException("Not supported yet.");
+ public VideoProfile getVideoProfile() {
+ return this.videoProfile;
}
@Override
- public CommentProfile getCommentSetting() {
- throw new UnsupportedOperationException("Not supported yet.");
+ public CommentProfile getCommentProfile() {
+ return this.commentProfile;
}
@Override
- public GeneralProfile getGeneralSetting() {
- throw new UnsupportedOperationException("Not supported yet.");
+ public GeneralProfile getGeneralProfile() {
+ return this.generalProfile;
+ }
+
+ @Override
+ public String toString(){
+ return ToStringBuilder.reflectionToString(this);
}
}
public String getPassword() {
return this.password;
}
+
+ @Override
+ public String toString(){
+ return ToStringBuilder.reflectionToString(this);
+ }
}
private class InqubusProxyProfile implements ProxyProfile {
public int getPort() {
return this.port;
}
+
+ @Override
+ public String toString(){
+ return ToStringBuilder.reflectionToString(this);
+ }
+ }
+
+ private class InqubusVideoProfile implements VideoProfile {
+ private final boolean download;
+ private final File dir;
+ private final String fileName;
+ private final File localFile;
+
+ private InqubusVideoProfile(){
+ final Config p = Config.INSTANCE;
+ this.download = !cbVideoLocal.isSelected();
+ if (this.download) {
+ this.dir = new File(p.getVideoDir());
+ this.fileName = fldVideo.getText();
+ this.localFile = null;
+ } else {
+ this.dir = null;
+ this.fileName = null;
+ this.localFile = new File(fldVideo.getText());
+ }
+ }
+
+ @Override
+ public boolean isDownload() {
+ return this.download;
+ }
+
+ @Override
+ public File getDir() {
+ return this.dir;
+ }
+
+ @Override
+ public String getFileName() {
+ return this.fileName;
+ }
+
+ @Override
+ public File getLocalFile() {
+ return this.localFile;
+ }
+
+ @Override
+ public String toString(){
+ return ToStringBuilder.reflectionToString(this);
+ }
+ }
+
+ private class InqubusCommentProfile implements CommentProfile {
+ private final boolean download;
+ private final File dir;
+ private final String fileName;
+ private final File localFile;
+ private final int lengthRelatedCommentSize;
+ private final boolean disablePerMinComment;
+ private final int perMinCommentSize;
+ private final long backLogPoint;
+
+ private InqubusCommentProfile() {
+ final Config p = Config.INSTANCE;
+ this.download = !cbVideoLocal.isSelected();
+ if (this.download) {
+ this.dir = new File(p.getVideoDir());
+ this.fileName = fldVideo.getText();
+ this.localFile = null;
+ } else {
+ this.dir = null;
+ this.fileName = null;
+ this.localFile = new File(fldVideo.getText());
+ }
+
+ if(cbBackLog.isSelected()) {
+ try {
+ this.backLogPoint = WayBackTimeParser.parse(fldBackLog.getText());
+ } catch (IOException ex) {
+ throw new IllegalArgumentException("過去ログ時刻指定が誤っています。", ex);
+ }
+ } else {
+ this.backLogPoint = -1L;
+ }
+
+ this.disablePerMinComment = cbBackLogReduce.isSelected();
+ this.lengthRelatedCommentSize
+ = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
+ this.perMinCommentSize
+ = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
+ }
+
+ @Override
+ public boolean isDownload() {
+ return this.download;
+ }
+
+ @Override
+ public File getDir() {
+ return this.dir;
+ }
+
+ @Override
+ public String getFileName() {
+ return this.fileName;
+ }
+
+ @Override
+ public File getLocalFile() {
+ return this.localFile;
+ }
+
+ @Override
+ public int getLengthRelatedCommentSize() {
+ return this.lengthRelatedCommentSize;
+ }
+
+ @Override
+ public boolean isDisablePerMinComment() {
+ return this.disablePerMinComment;
+ }
+
+ @Override
+ public int getPerMinCommentSize() {
+ return this.perMinCommentSize;
+ }
+
+ @Override
+ public long getBackLogPoint() {
+ return this.backLogPoint;
+ }
+
+ @Override
+ public String toString(){
+ return ToStringBuilder.reflectionToString(this);
+ }
+ }
+
+ private class InqubusGeneralProfile implements GeneralProfile {
+ private final String replaceFrom;
+ private final String replaceTo;
+ private InqubusGeneralProfile() {
+ final Config p = Config.INSTANCE;
+ this.replaceFrom = p.getReplaceFrom();
+ this.replaceTo = p.getReplaceTo();
+ }
+
+ @Override
+ public String getReplaceFrom() {
+ return this.replaceFrom;
+ }
+
+ @Override
+ public String getReplaceTo() {
+ return this.replaceTo;
+ }
+
+ @Override
+ public String toString(){
+ return ToStringBuilder.reflectionToString(this);
+ }
}
}