OSDN Git Service

ウィジェットに名前を付ける
[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.conifg.Properties;
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 static final long serialVersionUID = 1L;
29     private final TargetsTableModel targetModel = new TargetsTableModel();
30
31     /** Creates new form MainFrame */
32     public MainFrame() {
33         initComponents();
34         initInputPanel();
35         jPanel1.setTransferHandler(new DownloadListTransferHandler());
36         jTable1.setTransferHandler(new TableTransferHandler());
37     }
38
39     /** This method is called from within the constructor to
40      * initialize the form.
41      * WARNING: Do NOT modify this code. The content of this method is
42      * always regenerated by the Form Editor.
43      */
44     @SuppressWarnings("unchecked")
45     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
46     private void initComponents() {
47
48         jPanel1 = new javax.swing.JPanel();
49         jScrollPane1 = new javax.swing.JScrollPane();
50         jTable1 = new javax.swing.JTable();
51         jPanel2 = new javax.swing.JPanel();
52         jButton2 = new javax.swing.JButton();
53         jButton3 = new javax.swing.JButton();
54         jButton4 = new javax.swing.JButton();
55         jPanel3 = new javax.swing.JPanel();
56         idLabel = new javax.swing.JLabel();
57         idField = new javax.swing.JTextField();
58         movieLabel = new javax.swing.JLabel();
59         useMovieLocalCheckBox = new javax.swing.JCheckBox();
60         movieFileField = new javax.swing.JTextField();
61         movieFileSelectButton = new javax.swing.JButton();
62         commentLabel = new javax.swing.JLabel();
63         useCommentLocalCheckBox = new javax.swing.JCheckBox();
64         commentFileField = new javax.swing.JTextField();
65         commentFileSelectButton = new javax.swing.JButton();
66         outputLabel = new javax.swing.JLabel();
67         outputConvertCheckBox = new javax.swing.JCheckBox();
68         outputFileField = new javax.swing.JTextField();
69         outputFileSelectButton = new javax.swing.JButton();
70         applyButton = 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         idLabel.setText("ID");
118
119         movieLabel.setText("動画");
120
121         useMovieLocalCheckBox.setText("local");
122
123         movieFileSelectButton.setText("...");
124
125         commentLabel.setText("コメント");
126
127         useCommentLocalCheckBox.setText("local");
128
129         commentFileSelectButton.setText("...");
130
131         outputLabel.setText("出力");
132
133         outputConvertCheckBox.setText("変換");
134
135         outputFileSelectButton.setText("...");
136
137         applyButton.setText("適用");
138
139         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
140         jPanel3.setLayout(jPanel3Layout);
141         jPanel3Layout.setHorizontalGroup(
142             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
143             .addGroup(jPanel3Layout.createSequentialGroup()
144                 .addContainerGap()
145                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146                     .addGroup(jPanel3Layout.createSequentialGroup()
147                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148                             .addComponent(commentLabel)
149                             .addComponent(movieLabel)
150                             .addComponent(idLabel)
151                             .addComponent(outputLabel))
152                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
153                         .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
154                             .addGroup(jPanel3Layout.createSequentialGroup()
155                                 .addComponent(outputConvertCheckBox)
156                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157                                 .addComponent(outputFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
158                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
159                                 .addComponent(outputFileSelectButton))
160                             .addGroup(jPanel3Layout.createSequentialGroup()
161                                 .addComponent(useCommentLocalCheckBox)
162                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
163                                 .addComponent(commentFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
164                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
165                                 .addComponent(commentFileSelectButton))
166                             .addGroup(jPanel3Layout.createSequentialGroup()
167                                 .addComponent(useMovieLocalCheckBox)
168                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
169                                 .addComponent(movieFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
170                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
171                                 .addComponent(movieFileSelectButton))
172                             .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
173                     .addComponent(applyButton, javax.swing.GroupLayout.Alignment.TRAILING))
174                 .addContainerGap())
175         );
176         jPanel3Layout.setVerticalGroup(
177             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178             .addGroup(jPanel3Layout.createSequentialGroup()
179                 .addContainerGap()
180                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
181                     .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182                     .addComponent(idLabel))
183                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
185                     .addComponent(movieLabel)
186                     .addComponent(movieFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
187                     .addComponent(movieFileSelectButton)
188                     .addComponent(useMovieLocalCheckBox))
189                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
190                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191                     .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
192                         .addComponent(commentLabel)
193                         .addComponent(commentFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
194                         .addComponent(commentFileSelectButton))
195                     .addComponent(useCommentLocalCheckBox))
196                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
197                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
198                     .addComponent(outputLabel)
199                     .addComponent(outputFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
200                     .addComponent(outputFileSelectButton)
201                     .addComponent(outputConvertCheckBox))
202                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
203                 .addComponent(applyButton)
204                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
205         );
206
207         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
208         jPanel1.setLayout(jPanel1Layout);
209         jPanel1Layout.setHorizontalGroup(
210             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
212                 .addContainerGap()
213                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
214                     .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
215                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
216                     .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
217                 .addContainerGap())
218         );
219         jPanel1Layout.setVerticalGroup(
220             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
222                 .addContainerGap()
223                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
224                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
226                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
227                 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
228                 .addGap(24, 24, 24))
229         );
230
231         jMenu1.setText("File");
232         jMenuBar1.add(jMenu1);
233
234         jMenu2.setText("Edit");
235         jMenuBar1.add(jMenu2);
236
237         setJMenuBar(jMenuBar1);
238
239         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
240         getContentPane().setLayout(layout);
241         layout.setHorizontalGroup(
242             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
244         );
245         layout.setVerticalGroup(
246             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
248         );
249
250         pack();
251     }// </editor-fold>//GEN-END:initComponents
252
253     /**
254      * @param args the command line arguments
255      */
256     public static void main(String args[]) {
257         try {
258             for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
259                 if ("Nimbus".equals(info.getName())) {
260                     UIManager.setLookAndFeel(info.getClassName());
261                     break;
262                 }
263             }
264         } catch (Exception e) {
265             try {
266                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
267             } catch (Exception ex) {
268             }
269         }
270         java.awt.EventQueue.invokeLater(new Runnable() {
271
272             public void run() {
273                 new MainFrame().setVisible(true);
274             }
275         });
276     }
277     // Variables declaration - do not modify//GEN-BEGIN:variables
278     private javax.swing.JButton applyButton;
279     private javax.swing.JTextField commentFileField;
280     private javax.swing.JButton commentFileSelectButton;
281     private javax.swing.JLabel commentLabel;
282     private javax.swing.JTextField idField;
283     private javax.swing.JLabel idLabel;
284     private javax.swing.JButton jButton2;
285     private javax.swing.JButton jButton3;
286     private javax.swing.JButton jButton4;
287     private javax.swing.JMenu jMenu1;
288     private javax.swing.JMenu jMenu2;
289     private javax.swing.JMenuBar jMenuBar1;
290     private javax.swing.JPanel jPanel1;
291     private javax.swing.JPanel jPanel2;
292     private javax.swing.JPanel jPanel3;
293     private javax.swing.JScrollPane jScrollPane1;
294     private javax.swing.JTable jTable1;
295     private javax.swing.JTextField movieFileField;
296     private javax.swing.JButton movieFileSelectButton;
297     private javax.swing.JLabel movieLabel;
298     private javax.swing.JCheckBox outputConvertCheckBox;
299     private javax.swing.JTextField outputFileField;
300     private javax.swing.JButton outputFileSelectButton;
301     private javax.swing.JLabel outputLabel;
302     private javax.swing.JCheckBox useCommentLocalCheckBox;
303     private javax.swing.JCheckBox useMovieLocalCheckBox;
304     // End of variables declaration//GEN-END:variables
305
306     private void initInputPanel() {
307 //        Properties.INSTANCE.getUseMovieFileLocal();
308     }
309
310     private class DownloadListTransferHandler extends TransferHandler {
311
312         private static final long serialVersionUID = 1L;
313         private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)");
314
315         @Override
316         public boolean canImport(TransferHandler.TransferSupport support) {
317             Transferable transferable = support.getTransferable();
318             if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
319                     || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
320                 return true;
321             }
322             return false;
323         }
324
325         @Override
326         public boolean importData(TransferHandler.TransferSupport support) {
327             try {
328                 Transferable transferable = support.getTransferable();
329                 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
330                     List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
331                     Collection<Target> targets = Target.from(data);
332                     targetModel.addTarget(targets);
333                 } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
334                     String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
335                     Matcher matcher = movieIdPattern.matcher(data);
336                     if (matcher.find()) {
337                         String movieId = matcher.group(1);
338                         Target target = Target.fromId(movieId);
339                         targetModel.addTarget(target);
340                     } else {
341                         return false;
342                     }
343
344                 }
345                 return false;
346             } catch (Exception e) {
347                 e.printStackTrace();
348                 return false;
349             }
350         }
351     }
352
353     private class TableTransferHandler extends DownloadListTransferHandler {
354
355         @Override
356         public boolean canImport(TransferHandler.TransferSupport support) {
357             return super.canImport(support);
358         }
359
360         @Override
361         public boolean importData(TransferHandler.TransferSupport support) {
362             return super.importData(support);
363         }
364     }
365 }