OSDN Git Service

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