OSDN Git Service

024e4ef6c531c6bc1407f38b471ab9312a0c5c08
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
1 /*
2  * MainFrame.java
3  *
4  * Created on 2011/05/28, 18:14:51
5  */
6 package yukihane.inqubus.gui;
7
8 import java.awt.datatransfer.DataFlavor;
9 import java.awt.datatransfer.Transferable;
10 import java.io.File;
11 import java.util.Collection;
12 import java.util.List;
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15 import javax.swing.TransferHandler;
16 import javax.swing.UIManager;
17 import javax.swing.UIManager.LookAndFeelInfo;
18 import yukihane.inqubus.model.Target;
19 import yukihane.inqubus.model.TargetsTableModel;
20
21 /**
22  *
23  * @author yuki
24  */
25 public class MainFrame extends javax.swing.JFrame {
26
27     private final TargetsTableModel targetModel = new TargetsTableModel();
28
29     /** Creates new form MainFrame */
30     public MainFrame() {
31         initComponents();
32         jPanel1.setTransferHandler(new DownloadListTransferHandler());
33         jTable1.setTransferHandler(new TableTransferHandler());
34     }
35
36     /** This method is called from within the constructor to
37      * initialize the form.
38      * WARNING: Do NOT modify this code. The content of this method is
39      * always regenerated by the Form Editor.
40      */
41     @SuppressWarnings("unchecked")
42     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
43     private void initComponents() {
44
45         jPanel1 = new javax.swing.JPanel();
46         jScrollPane1 = new javax.swing.JScrollPane();
47         jTable1 = new javax.swing.JTable();
48         jPanel2 = new javax.swing.JPanel();
49         jButton2 = new javax.swing.JButton();
50         jButton3 = new javax.swing.JButton();
51         jButton4 = new javax.swing.JButton();
52         jPanel3 = new javax.swing.JPanel();
53         jButton1 = new javax.swing.JButton();
54         jLabel1 = new javax.swing.JLabel();
55         jLabel2 = new javax.swing.JLabel();
56         jTextField1 = new javax.swing.JTextField();
57         jTextField2 = new javax.swing.JTextField();
58         jLabel3 = new javax.swing.JLabel();
59         jTextField3 = new javax.swing.JTextField();
60         jLabel4 = new javax.swing.JLabel();
61         jButton5 = new javax.swing.JButton();
62         jButton6 = new javax.swing.JButton();
63         jTextField4 = new javax.swing.JTextField();
64         jButton7 = new javax.swing.JButton();
65         jCheckBox3 = new javax.swing.JCheckBox();
66         jCheckBox4 = new javax.swing.JCheckBox();
67         jCheckBox5 = new javax.swing.JCheckBox();
68         jMenuBar1 = new javax.swing.JMenuBar();
69         jMenu1 = new javax.swing.JMenu();
70         jMenu2 = new javax.swing.JMenu();
71
72         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
73
74         jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
75
76         jTable1.setModel(targetModel);
77         jTable1.setDropMode(javax.swing.DropMode.INSERT_ROWS);
78         jScrollPane1.setViewportView(jTable1);
79
80         jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
81
82         jButton2.setText("開始");
83
84         jButton3.setText("停止");
85
86         jButton4.setText("選択解除");
87
88         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
89         jPanel2.setLayout(jPanel2Layout);
90         jPanel2Layout.setHorizontalGroup(
91             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
92             .addGroup(jPanel2Layout.createSequentialGroup()
93                 .addContainerGap()
94                 .addComponent(jButton2)
95                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
96                 .addComponent(jButton3)
97                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
98                 .addComponent(jButton4)
99                 .addContainerGap())
100         );
101         jPanel2Layout.setVerticalGroup(
102             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
103             .addGroup(jPanel2Layout.createSequentialGroup()
104                 .addContainerGap()
105                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
106                     .addComponent(jButton2)
107                     .addComponent(jButton3)
108                     .addComponent(jButton4))
109                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
110         );
111
112         jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
113
114         jButton1.setText("適用");
115
116         jLabel1.setText("動画");
117
118         jLabel2.setText("コメント");
119
120         jLabel3.setText("ID");
121
122         jLabel4.setText("出力");
123
124         jButton5.setText("...");
125
126         jButton6.setText("...");
127
128         jButton7.setText("...");
129
130         jCheckBox3.setText("local");
131
132         jCheckBox4.setText("local");
133
134         jCheckBox5.setText("変換");
135
136         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
137         jPanel3.setLayout(jPanel3Layout);
138         jPanel3Layout.setHorizontalGroup(
139             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140             .addGroup(jPanel3Layout.createSequentialGroup()
141                 .addContainerGap()
142                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
143                     .addGroup(jPanel3Layout.createSequentialGroup()
144                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
145                             .addComponent(jLabel2)
146                             .addComponent(jLabel1)
147                             .addComponent(jLabel3)
148                             .addComponent(jLabel4))
149                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
150                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151                             .addGroup(jPanel3Layout.createSequentialGroup()
152                                 .addComponent(jCheckBox5)
153                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154                                 .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
155                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
156                                 .addComponent(jButton7))
157                             .addGroup(jPanel3Layout.createSequentialGroup()
158                                 .addComponent(jCheckBox4)
159                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
160                                 .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
161                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
162                                 .addComponent(jButton6))
163                             .addGroup(jPanel3Layout.createSequentialGroup()
164                                 .addComponent(jCheckBox3)
165                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
166                                 .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
167                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
168                                 .addComponent(jButton5))
169                             .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
170                     .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
171                 .addContainerGap())
172         );
173         jPanel3Layout.setVerticalGroup(
174             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175             .addGroup(jPanel3Layout.createSequentialGroup()
176                 .addContainerGap()
177                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
178                     .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
179                     .addComponent(jLabel3))
180                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
181                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
182                     .addComponent(jLabel1)
183                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
184                     .addComponent(jButton5)
185                     .addComponent(jCheckBox3))
186                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
187                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188                     .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
189                         .addComponent(jLabel2)
190                         .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
191                         .addComponent(jButton6))
192                     .addComponent(jCheckBox4))
193                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
194                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
195                     .addComponent(jLabel4)
196                     .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
197                     .addComponent(jButton7)
198                     .addComponent(jCheckBox5))
199                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
200                 .addComponent(jButton1)
201                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
202         );
203
204         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
205         jPanel1.setLayout(jPanel1Layout);
206         jPanel1Layout.setHorizontalGroup(
207             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
209                 .addContainerGap()
210                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
211                     .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
212                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
213                     .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
214                 .addContainerGap())
215         );
216         jPanel1Layout.setVerticalGroup(
217             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
219                 .addContainerGap()
220                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
221                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
223                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
224                 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
225                 .addGap(24, 24, 24))
226         );
227
228         jMenu1.setText("File");
229         jMenuBar1.add(jMenu1);
230
231         jMenu2.setText("Edit");
232         jMenuBar1.add(jMenu2);
233
234         setJMenuBar(jMenuBar1);
235
236         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
237         getContentPane().setLayout(layout);
238         layout.setHorizontalGroup(
239             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
241         );
242         layout.setVerticalGroup(
243             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
245         );
246
247         pack();
248     }// </editor-fold>//GEN-END:initComponents
249
250     /**
251      * @param args the command line arguments
252      */
253     public static void main(String args[]) {
254         try {
255             for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
256                 if ("Nimbus".equals(info.getName())) {
257                     UIManager.setLookAndFeel(info.getClassName());
258                     break;
259                 }
260             }
261         } catch (Exception e) {
262             try {
263                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
264             } catch (Exception ex) {
265             }
266         }
267         java.awt.EventQueue.invokeLater(new Runnable() {
268
269             public void run() {
270                 new MainFrame().setVisible(true);
271             }
272         });
273     }
274     // Variables declaration - do not modify//GEN-BEGIN:variables
275     private javax.swing.JButton jButton1;
276     private javax.swing.JButton jButton2;
277     private javax.swing.JButton jButton3;
278     private javax.swing.JButton jButton4;
279     private javax.swing.JButton jButton5;
280     private javax.swing.JButton jButton6;
281     private javax.swing.JButton jButton7;
282     private javax.swing.JCheckBox jCheckBox3;
283     private javax.swing.JCheckBox jCheckBox4;
284     private javax.swing.JCheckBox jCheckBox5;
285     private javax.swing.JLabel jLabel1;
286     private javax.swing.JLabel jLabel2;
287     private javax.swing.JLabel jLabel3;
288     private javax.swing.JLabel jLabel4;
289     private javax.swing.JMenu jMenu1;
290     private javax.swing.JMenu jMenu2;
291     private javax.swing.JMenuBar jMenuBar1;
292     private javax.swing.JPanel jPanel1;
293     private javax.swing.JPanel jPanel2;
294     private javax.swing.JPanel jPanel3;
295     private javax.swing.JScrollPane jScrollPane1;
296     private javax.swing.JTable jTable1;
297     private javax.swing.JTextField jTextField1;
298     private javax.swing.JTextField jTextField2;
299     private javax.swing.JTextField jTextField3;
300     private javax.swing.JTextField jTextField4;
301     // End of variables declaration//GEN-END:variables
302
303     private class DownloadListTransferHandler extends TransferHandler {
304
305         private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
306
307         @Override
308         public boolean canImport(TransferHandler.TransferSupport support) {
309             Transferable transferable = support.getTransferable();
310             if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
311                     || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
312                 return true;
313             }
314             return false;
315         }
316
317         @Override
318         public boolean importData(TransferHandler.TransferSupport support) {
319             try {
320                 Transferable transferable = support.getTransferable();
321                 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
322                     List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
323                     Collection<Target> targets = Target.from(data);
324                     targetModel.addTarget(targets);
325                 } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
326                     String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
327                     Matcher matcher = movieIdPattern.matcher(data);
328                     if (matcher.find()) {
329                         String movieId = matcher.group(1);
330                         Target target = Target.fromId(movieId);
331                         targetModel.addTarget(target);
332                     } else {
333                         return false;
334                     }
335
336                 }
337                 return false;
338             } catch (Exception e) {
339                 e.printStackTrace();
340                 return false;
341             }
342         }
343     }
344
345     private class TableTransferHandler extends DownloadListTransferHandler {
346
347         @Override
348         public boolean canImport(TransferHandler.TransferSupport support) {
349             return super.canImport(support);
350         }
351
352         @Override
353         public boolean importData(TransferHandler.TransferSupport support) {
354             return super.importData(support);
355         }
356     }
357 }