2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package saccubus.worker;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
10 import java.util.List;
11 import java.util.concurrent.ExecutionException;
12 import javax.swing.GroupLayout;
13 import javax.swing.JButton;
14 import javax.swing.JFrame;
15 import javax.swing.JPanel;
16 import javax.swing.JTextField;
17 import javax.swing.SwingUtilities;
18 import saccubus.worker.profile.CommentProfile;
19 import saccubus.worker.profile.GeneralProfile;
20 import saccubus.worker.profile.LoginProfile;
21 import saccubus.worker.profile.OutputProfile;
22 import saccubus.worker.profile.Profile;
23 import saccubus.worker.profile.ProxyProfile;
24 import saccubus.worker.profile.VideoProfile;
30 public class TestFrame extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private final JTextField fldVideoId = new JTextField();
34 private final JButton btnDownload = new JButton("DOWNLOAD");
35 private final JButton btnCancel = new JButton("Cancel");
36 private final JTextField fldStatus = new JTextField();
37 private Download downloadWorker;
40 JPanel panel = new JPanel();
41 GroupLayout lo = new GroupLayout(panel);
44 lo.setHorizontalGroup(lo.createParallelGroup()
45 .addGroup(lo.createSequentialGroup()
46 .addComponent(fldVideoId).addComponent(btnDownload))
47 .addGroup(lo.createSequentialGroup()
48 .addComponent(fldStatus).addComponent(btnCancel)));
50 lo.setVerticalGroup(lo.createSequentialGroup()
51 .addGroup(lo.createParallelGroup()
52 .addComponent(fldVideoId).addComponent(btnDownload))
53 .addGroup(lo.createParallelGroup()
54 .addComponent(fldStatus).addComponent(btnCancel)));
56 setContentPane(panel);
60 btnDownload.addActionListener(new DownloadListener());
61 btnCancel.addActionListener(new CancelListener());
64 private class CancelListener implements ActionListener {
67 public void actionPerformed(ActionEvent e) {
68 if(downloadWorker != null){
69 downloadWorker.cancel(true);
74 private class DownloadListener implements ActionListener {
76 public void actionPerformed(ActionEvent e) {
77 downloadWorker = new Download(new MyProfile(), fldVideoId.getText()){
79 protected void process(List<DownloadProgress> chunks){
80 DownloadProgress chunk = chunks.get(chunks.size()-1);
81 fldStatus.setText(chunk.getMessage());
85 protected void done(){
86 btnDownload.setEnabled(true);
88 DownloadResult res = get();
89 } catch (InterruptedException ex) {
91 } catch (ExecutionException ex) {
97 btnDownload.setEnabled(false);
98 downloadWorker.execute();
104 public static void main(String[] args){
105 SwingUtilities.invokeLater(new Runnable() {
109 TestFrame view = new TestFrame();
110 view.setDefaultCloseOperation(EXIT_ON_CLOSE);
111 view.setVisible(true);
116 private static class MyProfile implements Profile{
119 public LoginProfile getLoginInfo() {
120 return new LoginProfile() {
123 public String getMail() {
124 return "yamamoto5_5963@hotmail.com";
128 public String getPassword() {
135 public ProxyProfile getProxySetting() {
136 return new ProxyProfile() {
139 public boolean use() {
144 public String getHost() {
145 throw new UnsupportedOperationException("Not supported yet.");
149 public int getPort() {
150 throw new UnsupportedOperationException("Not supported yet.");
156 public VideoProfile getVideoSetting() {
157 return new VideoProfile() {
160 public boolean isDownload() {
165 public File getDir() {
166 return new File("out");
170 public String getFileName() {
171 return "{id}_{title}";
175 public File getLocalFile() {
176 throw new UnsupportedOperationException("Not supported yet.");
182 public CommentProfile getCommentSetting() {
183 return new CommentProfile() {
186 public int getLengthRelatedCommentSize() {
191 public boolean isDisablePerMinComment() {
196 public int getPerMinCommentSize() {
201 public long getBackLogPoint() {
206 public boolean isDownload() {
211 public File getDir() {
212 return new File("out");
216 public String getFileName() {
217 return "{id}_{title}";
221 public File getLocalFile() {
222 throw new UnsupportedOperationException("Not supported yet.");
228 public OutputProfile getOutputFileSetting() {
229 return new OutputProfile() {
232 public boolean isConvert() {
237 public boolean isAddComment() {
238 throw new UnsupportedOperationException("Not supported yet.");
242 public File getDir() {
243 throw new UnsupportedOperationException("Not supported yet.");
247 public String getFileName() {
248 throw new UnsupportedOperationException("Not supported yet.");
254 public GeneralProfile getGeneralSetting() {
255 return new GeneralProfile() {
258 public String getReplaceFrom() {
263 public String getReplaceTo() {