OSDN Git Service

bb7a10accc35cb91f3a5bedb06baf4841bb065eb
[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         jLabel3 = new javax.swing.JLabel();
58         jComboBox1 = new javax.swing.JComboBox();
59         jComboBox2 = new javax.swing.JComboBox();
60         jComboBox3 = new javax.swing.JComboBox();
61         jCheckBox1 = new javax.swing.JCheckBox();
62         jCheckBox2 = new javax.swing.JCheckBox();
63         jTextField1 = new javax.swing.JTextField();
64         jTextField2 = new javax.swing.JTextField();
65         jTextField3 = new javax.swing.JTextField();
66         jMenuBar1 = new javax.swing.JMenuBar();
67         jMenu1 = new javax.swing.JMenu();
68         jMenu2 = new javax.swing.JMenu();
69
70         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
71
72         jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
73
74         jTable1.setModel(targetModel);
75         jTable1.setDropMode(javax.swing.DropMode.INSERT_ROWS);
76         jScrollPane1.setViewportView(jTable1);
77
78         jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
79
80         jButton2.setText("開始");
81
82         jButton3.setText("停止");
83
84         jButton4.setText("選択解除");
85
86         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
87         jPanel2.setLayout(jPanel2Layout);
88         jPanel2Layout.setHorizontalGroup(
89             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
90             .addGroup(jPanel2Layout.createSequentialGroup()
91                 .addContainerGap()
92                 .addComponent(jButton2)
93                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
94                 .addComponent(jButton3)
95                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
96                 .addComponent(jButton4)
97                 .addContainerGap())
98         );
99         jPanel2Layout.setVerticalGroup(
100             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
101             .addGroup(jPanel2Layout.createSequentialGroup()
102                 .addContainerGap()
103                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
104                     .addComponent(jButton2)
105                     .addComponent(jButton3)
106                     .addComponent(jButton4))
107                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
108         );
109
110         jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
111
112         jButton1.setText("適用");
113
114         jLabel1.setText("動画");
115
116         jLabel2.setText("コメント");
117
118         jLabel3.setText("投コメ");
119
120         jComboBox1.setModel(new SourceTypeComboBoxModel());
121
122         jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
123
124         jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
125
126         jCheckBox1.setText("変換を行う");
127
128         jCheckBox2.setText("自動で処理開始");
129
130         jTextField1.setText("jTextField1");
131
132         jTextField2.setText("jTextField2");
133
134         jTextField3.setText("jTextField3");
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(jLabel3)
146                             .addComponent(jLabel2)
147                             .addComponent(jLabel1))
148                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
149                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
150                             .addGroup(jPanel3Layout.createSequentialGroup()
151                                 .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
153                                 .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE))
154                             .addGroup(jPanel3Layout.createSequentialGroup()
155                                 .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
156                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157                                 .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE))
158                             .addGroup(jPanel3Layout.createSequentialGroup()
159                                 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
160                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
161                                 .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))))
162                     .addGroup(jPanel3Layout.createSequentialGroup()
163                         .addComponent(jCheckBox1)
164                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
165                         .addComponent(jCheckBox2)
166                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 209, Short.MAX_VALUE)
167                         .addComponent(jButton1)))
168                 .addContainerGap())
169         );
170         jPanel3Layout.setVerticalGroup(
171             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
172             .addGroup(jPanel3Layout.createSequentialGroup()
173                 .addContainerGap()
174                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
175                     .addComponent(jLabel1)
176                     .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
177                     .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
178                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
179                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
180                     .addComponent(jLabel2)
181                     .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182                     .addComponent(jTextField2, 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(jLabel3)
186                     .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
187                     .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
188                 .addGap(18, 18, 18)
189                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
190                     .addComponent(jCheckBox1)
191                     .addComponent(jCheckBox2)
192                     .addComponent(jButton1))
193                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
194         );
195
196         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
197         jPanel1.setLayout(jPanel1Layout);
198         jPanel1Layout.setHorizontalGroup(
199             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
201                 .addContainerGap()
202                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
203                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
204                     .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
205                     .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
206                 .addContainerGap())
207         );
208         jPanel1Layout.setVerticalGroup(
209             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
211                 .addContainerGap()
212                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
213                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
214                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
215                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
216                 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
217                 .addContainerGap())
218         );
219
220         jMenu1.setText("File");
221         jMenuBar1.add(jMenu1);
222
223         jMenu2.setText("Edit");
224         jMenuBar1.add(jMenu2);
225
226         setJMenuBar(jMenuBar1);
227
228         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
229         getContentPane().setLayout(layout);
230         layout.setHorizontalGroup(
231             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
233         );
234         layout.setVerticalGroup(
235             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
236             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
237         );
238
239         pack();
240     }// </editor-fold>//GEN-END:initComponents
241
242     /**
243      * @param args the command line arguments
244      */
245     public static void main(String args[]) {
246         try {
247             for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
248                 if ("Nimbus".equals(info.getName())) {
249                     UIManager.setLookAndFeel(info.getClassName());
250                     break;
251                 }
252             }
253         } catch (Exception e) {
254             try {
255                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
256             } catch (Exception ex) {
257             }
258         }
259         java.awt.EventQueue.invokeLater(new Runnable() {
260
261             public void run() {
262                 new MainFrame().setVisible(true);
263             }
264         });
265     }
266     // Variables declaration - do not modify//GEN-BEGIN:variables
267     private javax.swing.JButton jButton1;
268     private javax.swing.JButton jButton2;
269     private javax.swing.JButton jButton3;
270     private javax.swing.JButton jButton4;
271     private javax.swing.JCheckBox jCheckBox1;
272     private javax.swing.JCheckBox jCheckBox2;
273     private javax.swing.JComboBox jComboBox1;
274     private javax.swing.JComboBox jComboBox2;
275     private javax.swing.JComboBox jComboBox3;
276     private javax.swing.JLabel jLabel1;
277     private javax.swing.JLabel jLabel2;
278     private javax.swing.JLabel jLabel3;
279     private javax.swing.JMenu jMenu1;
280     private javax.swing.JMenu jMenu2;
281     private javax.swing.JMenuBar jMenuBar1;
282     private javax.swing.JPanel jPanel1;
283     private javax.swing.JPanel jPanel2;
284     private javax.swing.JPanel jPanel3;
285     private javax.swing.JScrollPane jScrollPane1;
286     private javax.swing.JTable jTable1;
287     private javax.swing.JTextField jTextField1;
288     private javax.swing.JTextField jTextField2;
289     private javax.swing.JTextField jTextField3;
290     // End of variables declaration//GEN-END:variables
291
292     private class DownloadListTransferHandler extends TransferHandler {
293
294         private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
295
296         @Override
297         public boolean canImport(TransferHandler.TransferSupport support) {
298             Transferable transferable = support.getTransferable();
299             if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
300                     || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
301                 return true;
302             }
303             return false;
304         }
305
306         @Override
307         public boolean importData(TransferHandler.TransferSupport support) {
308             try {
309                 Transferable transferable = support.getTransferable();
310                 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
311                     List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
312                     Collection<Target> targets = Target.from(data);
313                     targetModel.addTarget(targets);
314                 } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
315                     String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
316                     Matcher matcher = movieIdPattern.matcher(data);
317                     if (matcher.find()) {
318                         String movieId = matcher.group(1);
319                         Target target = Target.fromId(movieId);
320                         targetModel.addTarget(target);
321                     } else {
322                         return false;
323                     }
324
325                 }
326                 return false;
327             } catch (Exception e) {
328                 e.printStackTrace();
329                 return false;
330             }
331         }
332     }
333
334     private class TableTransferHandler extends DownloadListTransferHandler {
335
336         @Override
337         public boolean canImport(TransferHandler.TransferSupport support) {
338             return super.canImport(support);
339         }
340
341         @Override
342         public boolean importData(TransferHandler.TransferSupport support) {
343             return super.importData(support);
344         }
345     }
346 }