OSDN Git Service

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