OSDN Git Service

8f5a06e8399efb5489002c94160e1e3d4f6883ec
[coroid/inqubus.git] / frontend / src / saccubus / worker / TestFrame.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package saccubus.worker;
6
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.io.File;
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.ConvertProfile;
20 import saccubus.worker.profile.FfmpegProfile;
21 import saccubus.worker.profile.GeneralProfile;
22 import saccubus.worker.profile.LoginProfile;
23 import saccubus.worker.profile.OutputProfile;
24 import saccubus.worker.profile.DownloadProfile;
25 import saccubus.worker.profile.ProxyProfile;
26 import saccubus.worker.profile.VideoProfile;
27
28 /**
29  *
30  * @author yuki
31  */
32 public class TestFrame extends JFrame {
33
34     private static final long serialVersionUID = 1L;
35     private final JTextField fldVideoId = new JTextField();
36     private final JButton btnDownload = new JButton("DOWNLOAD");
37     private final JButton btnCancel = new JButton("Cancel");
38     private final JTextField fldStatus = new JTextField();
39     private final JButton btnConv = new JButton("Conv");
40     private final JButton btnConvCancel = new JButton("ConvCancl");
41     private Download downloader;
42     private Convert converter;
43
44     public TestFrame() {
45         JPanel panel = new JPanel();
46         GroupLayout lo = new GroupLayout(panel);
47         panel.setLayout(lo);
48
49         lo.setHorizontalGroup(lo.createParallelGroup().addGroup(lo.createSequentialGroup().addComponent(fldVideoId).
50                 addComponent(btnDownload)).addGroup(lo.createSequentialGroup().addComponent(fldStatus).addComponent(
51                 btnCancel)));
52
53         lo.setVerticalGroup(lo.createSequentialGroup().addGroup(lo.createParallelGroup().addComponent(fldVideoId).
54                 addComponent(btnDownload)).addGroup(lo.createParallelGroup().addComponent(fldStatus).addComponent(
55                 btnCancel)));
56
57         setContentPane(panel);
58         pack();
59
60
61         btnDownload.addActionListener(new DownloadListener());
62         btnCancel.addActionListener(new CancelListener());
63         btnConv.addActionListener(new ConvertListener());
64         btnConvCancel.addActionListener(new ConvCnclListener());
65     }
66
67     private class ConvCnclListener implements ActionListener {
68
69         @Override
70         public void actionPerformed(ActionEvent e) {
71             if (converter != null) {
72                 converter.cancel(true);
73             }
74         }
75     }
76
77     private class ConvertListener implements ActionListener {
78
79         @Override
80         public void actionPerformed(ActionEvent e) {
81             converter = new Convert(new MyConvProfile(), new File("out/sm9.flv"), new File("out/sm9.xml")) {
82
83                 @Override
84                 protected void process(List<ConvertProgress> chunks) {
85                     ConvertProgress chunk = chunks.get(chunks.size() - 1);
86                     fldStatus.setText(chunk.getMessage());
87                 }
88
89                 @Override
90                 protected void done() {
91                     btnConv.setEnabled(true);
92                     try {
93                         ConvertResult res = get();
94                     } catch (InterruptedException ex) {
95                         ex.printStackTrace();
96                     } catch (ExecutionException ex) {
97                         ex.printStackTrace();
98                     }
99                 }
100             };
101
102             btnConv.setEnabled(false);
103             converter.execute();
104
105         }
106     }
107
108     private class CancelListener implements ActionListener {
109
110         @Override
111         public void actionPerformed(ActionEvent e) {
112             if (downloader != null) {
113                 downloader.cancel(true);
114             }
115         }
116     }
117
118     private class DownloadListener implements ActionListener {
119
120         @Override
121         public void actionPerformed(ActionEvent e) {
122             downloader = new Download(new MyProfile(), fldVideoId.getText()) {
123
124                 @Override
125                 protected void process(List<DownloadProgress> chunks) {
126                     DownloadProgress chunk = chunks.get(chunks.size() - 1);
127                     fldStatus.setText(chunk.getMessage());
128                 }
129
130                 @Override
131                 protected void done() {
132                     btnDownload.setEnabled(true);
133                     try {
134                         DownloadResult res = get();
135                     } catch (InterruptedException ex) {
136                         ex.printStackTrace();
137                     } catch (ExecutionException ex) {
138                         ex.printStackTrace();
139                     }
140                 }
141             };
142
143             btnDownload.setEnabled(false);
144             downloader.execute();
145
146         }
147     }
148
149     public static void main(String[] args) {
150         SwingUtilities.invokeLater(new Runnable() {
151
152             @Override
153             public void run() {
154                 TestFrame view = new TestFrame();
155                 view.setDefaultCloseOperation(EXIT_ON_CLOSE);
156                 view.setVisible(true);
157             }
158         });
159     }
160
161     private static class MyProfile implements DownloadProfile {
162
163         @Override
164         public LoginProfile getLoginInfo() {
165             return new LoginProfile() {
166
167                 @Override
168                 public String getMail() {
169                     return "yamamoto5_5963@hotmail.com";
170                 }
171
172                 @Override
173                 public String getPassword() {
174                     return "piyopiyo";
175                 }
176             };
177         }
178
179         @Override
180         public ProxyProfile getProxySetting() {
181             return new ProxyProfile() {
182
183                 @Override
184                 public boolean use() {
185                     return false;
186                 }
187
188                 @Override
189                 public String getHost() {
190                     throw new UnsupportedOperationException("Not supported yet.");
191                 }
192
193                 @Override
194                 public int getPort() {
195                     throw new UnsupportedOperationException("Not supported yet.");
196                 }
197             };
198         }
199
200         @Override
201         public VideoProfile getVideoSetting() {
202             return new VideoProfile() {
203
204                 @Override
205                 public boolean isDownload() {
206                     return true;
207                 }
208
209                 @Override
210                 public File getDir() {
211                     return new File("out");
212                 }
213
214                 @Override
215                 public String getFileName() {
216                     return "{id}_{title}";
217                 }
218
219                 @Override
220                 public File getLocalFile() {
221                     throw new UnsupportedOperationException("Not supported yet.");
222                 }
223             };
224         }
225
226         @Override
227         public CommentProfile getCommentSetting() {
228             return new CommentProfile() {
229
230                 @Override
231                 public int getLengthRelatedCommentSize() {
232                     return -1;
233                 }
234
235                 @Override
236                 public boolean isDisablePerMinComment() {
237                     return false;
238                 }
239
240                 @Override
241                 public int getPerMinCommentSize() {
242                     return -1;
243                 }
244
245                 @Override
246                 public long getBackLogPoint() {
247                     return -1;
248                 }
249
250                 @Override
251                 public boolean isDownload() {
252                     return true;
253                 }
254
255                 @Override
256                 public File getDir() {
257                     return new File("out");
258                 }
259
260                 @Override
261                 public String getFileName() {
262                     return "{id}_{title}";
263                 }
264
265                 @Override
266                 public File getLocalFile() {
267                     throw new UnsupportedOperationException("Not supported yet.");
268                 }
269             };
270         }
271
272 //        @Override
273 //        public OutputProfile getOutputFileSetting() {
274 //            return new OutputProfile() {
275 //
276 //                @Override
277 //                public boolean isConvert() {
278 //                    return false;
279 //                }
280 //
281 //                @Override
282 //                public boolean isAddComment() {
283 //                    throw new UnsupportedOperationException("Not supported yet.");
284 //                }
285 //
286 //                @Override
287 //                public File getDir() {
288 //                    throw new UnsupportedOperationException("Not supported yet.");
289 //                }
290 //
291 //                @Override
292 //                public String getFileName() {
293 //                    throw new UnsupportedOperationException("Not supported yet.");
294 //                }
295 //            };
296 //        }
297         @Override
298         public GeneralProfile getGeneralSetting() {
299             return new GeneralProfile() {
300
301                 @Override
302                 public String getReplaceFrom() {
303                     return "<>\\/#";
304                 }
305
306                 @Override
307                 public String getReplaceTo() {
308                     return "_";
309                 }
310             };
311         }
312     }
313
314     private class MyConvProfile implements ConvertProfile {
315
316         @Override
317         public FfmpegProfile getFfmpegOption() {
318             throw new UnsupportedOperationException("Not supported yet.");
319         }
320
321         @Override
322         public File getFfmpeg() {
323             throw new UnsupportedOperationException("Not supported yet.");
324         }
325
326         @Override
327         public boolean isVhookDisabled() {
328             throw new UnsupportedOperationException("Not supported yet.");
329         }
330
331         @Override
332         public File getVhook() {
333             throw new UnsupportedOperationException("Not supported yet.");
334         }
335
336         @Override
337         public File getTempDir() {
338             throw new UnsupportedOperationException("Not supported yet.");
339         }
340
341         @Override
342         public File getFont() {
343             throw new UnsupportedOperationException("Not supported yet.");
344         }
345
346         @Override
347         public int getFontIndex() {
348             throw new UnsupportedOperationException("Not supported yet.");
349         }
350
351         @Override
352         public boolean isCommentOpaque() {
353             throw new UnsupportedOperationException("Not supported yet.");
354         }
355
356         @Override
357         public boolean isDisableFontSizeArrange() {
358             throw new UnsupportedOperationException("Not supported yet.");
359         }
360
361         @Override
362         public int getShadowIndex() {
363             throw new UnsupportedOperationException("Not supported yet.");
364         }
365
366         @Override
367         public boolean isShowConverting() {
368             throw new UnsupportedOperationException("Not supported yet.");
369         }
370
371         @Override
372         public int getMaxNumOfComment() {
373             throw new UnsupportedOperationException("Not supported yet.");
374         }
375
376         @Override
377         public HideCondition getNgSetting() {
378             throw new UnsupportedOperationException("Not supported yet.");
379         }
380
381         @Override
382         public OutputProfile getOutputProfile() {
383             throw new UnsupportedOperationException("Not supported yet.");
384         }
385
386         @Override
387         public GeneralProfile getGeneralProfile() {
388             throw new UnsupportedOperationException("Not supported yet.");
389         }
390     }
391 }