X-Git-Url: http://git.sourceforge.jp/view?p=coroid%2Finqubus.git;a=blobdiff_plain;f=frontend%2Fsrc%2Fyukihane%2Finqubus%2Fgui%2FMainFrame.java;h=5420b33e9f386139a85e8ad9db3f9ea61eddb6cd;hp=bb7a10accc35cb91f3a5bedb06baf4841bb065eb;hb=9523d1a98581ad6786d91b1d35bcd9e0b2aba83f;hpb=d92a74d16850cb2c068948a0fd33bce2ac2714b5 diff --git a/frontend/src/yukihane/inqubus/gui/MainFrame.java b/frontend/src/yukihane/inqubus/gui/MainFrame.java index bb7a10a..5420b33 100644 --- a/frontend/src/yukihane/inqubus/gui/MainFrame.java +++ b/frontend/src/yukihane/inqubus/gui/MainFrame.java @@ -7,7 +7,9 @@ package yukihane.inqubus.gui; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; +import java.awt.event.ItemEvent; import java.io.File; +import java.io.FilenameFilter; import java.util.Collection; import java.util.List; import java.util.regex.Matcher; @@ -15,7 +17,8 @@ import java.util.regex.Pattern; import javax.swing.TransferHandler; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; -import yukihane.inqubus.model.SourceTypeComboBoxModel; +import org.apache.commons.io.FilenameUtils; +import yukihane.inqubus.conifg.Properties; import yukihane.inqubus.model.Target; import yukihane.inqubus.model.TargetsTableModel; @@ -25,11 +28,13 @@ import yukihane.inqubus.model.TargetsTableModel; */ public class MainFrame extends javax.swing.JFrame { + private static final long serialVersionUID = 1L; private final TargetsTableModel targetModel = new TargetsTableModel(); /** Creates new form MainFrame */ public MainFrame() { initComponents(); + initInputPanel(); jPanel1.setTransferHandler(new DownloadListTransferHandler()); jTable1.setTransferHandler(new TableTransferHandler()); } @@ -51,18 +56,21 @@ public class MainFrame extends javax.swing.JFrame { jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); - jButton1 = new javax.swing.JButton(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jComboBox1 = new javax.swing.JComboBox(); - jComboBox2 = new javax.swing.JComboBox(); - jComboBox3 = new javax.swing.JComboBox(); - jCheckBox1 = new javax.swing.JCheckBox(); - jCheckBox2 = new javax.swing.JCheckBox(); - jTextField1 = new javax.swing.JTextField(); - jTextField2 = new javax.swing.JTextField(); - jTextField3 = new javax.swing.JTextField(); + idLabel = new javax.swing.JLabel(); + idField = new javax.swing.JTextField(); + movieLabel = new javax.swing.JLabel(); + useMovieLocalCheckBox = new javax.swing.JCheckBox(); + movieFileField = new javax.swing.JTextField(); + movieFileSelectButton = new javax.swing.JButton(); + commentLabel = new javax.swing.JLabel(); + useCommentLocalCheckBox = new javax.swing.JCheckBox(); + commentFileField = new javax.swing.JTextField(); + commentFileSelectButton = new javax.swing.JButton(); + outputLabel = new javax.swing.JLabel(); + outputConvertCheckBox = new javax.swing.JCheckBox(); + outputFileField = new javax.swing.JTextField(); + outputFileSelectButton = new javax.swing.JButton(); + applyButton = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); @@ -109,29 +117,48 @@ public class MainFrame extends javax.swing.JFrame { jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder()); - jButton1.setText("適用"); + idLabel.setText("ID"); - jLabel1.setText("動画"); + idField.addFocusListener(new java.awt.event.FocusAdapter() { + public void focusLost(java.awt.event.FocusEvent evt) { + idFieldFocusLost(evt); + } + }); - jLabel2.setText("コメント"); + movieLabel.setText("動画"); - jLabel3.setText("投コメ"); + useMovieLocalCheckBox.setText("local"); + useMovieLocalCheckBox.addItemListener(new java.awt.event.ItemListener() { + public void itemStateChanged(java.awt.event.ItemEvent evt) { + useMovieLocalCheckBoxItemStateChanged(evt); + } + }); - jComboBox1.setModel(new SourceTypeComboBoxModel()); + movieFileSelectButton.setText("..."); - jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + commentLabel.setText("コメント"); - jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + useCommentLocalCheckBox.setText("local"); + useCommentLocalCheckBox.addItemListener(new java.awt.event.ItemListener() { + public void itemStateChanged(java.awt.event.ItemEvent evt) { + useCommentLocalCheckBoxItemStateChanged(evt); + } + }); - jCheckBox1.setText("変換を行う"); + commentFileSelectButton.setText("..."); - jCheckBox2.setText("自動で処理開始"); + outputLabel.setText("出力"); - jTextField1.setText("jTextField1"); + outputConvertCheckBox.setText("変換"); + outputConvertCheckBox.addItemListener(new java.awt.event.ItemListener() { + public void itemStateChanged(java.awt.event.ItemEvent evt) { + outputConvertCheckBoxItemStateChanged(evt); + } + }); - jTextField2.setText("jTextField2"); + outputFileSelectButton.setText("..."); - jTextField3.setText("jTextField3"); + applyButton.setText("適用"); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); @@ -142,29 +169,32 @@ public class MainFrame extends javax.swing.JFrame { .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel3) - .addComponent(jLabel2) - .addComponent(jLabel1)) + .addComponent(commentLabel) + .addComponent(movieLabel) + .addComponent(idLabel) + .addComponent(outputLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(outputConvertCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)) + .addComponent(outputFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(outputFileSelectButton)) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(useCommentLocalCheckBox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(commentFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)) + .addComponent(commentFileSelectButton)) .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(useMovieLocalCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)))) - .addGroup(jPanel3Layout.createSequentialGroup() - .addComponent(jCheckBox1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jCheckBox2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 209, Short.MAX_VALUE) - .addComponent(jButton1))) + .addComponent(movieFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(movieFileSelectButton)) + .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(applyButton, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap()) ); jPanel3Layout.setVerticalGroup( @@ -172,24 +202,28 @@ public class MainFrame extends javax.swing.JFrame { .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(idLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(movieLabel) + .addComponent(movieFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(movieFileSelectButton) + .addComponent(useMovieLocalCheckBox)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) + .addComponent(commentLabel) + .addComponent(commentFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(commentFileSelectButton) + .addComponent(useCommentLocalCheckBox)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jCheckBox1) - .addComponent(jCheckBox2) - .addComponent(jButton1)) + .addComponent(outputLabel) + .addComponent(outputFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(outputFileSelectButton) + .addComponent(outputConvertCheckBox)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(applyButton) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -200,8 +234,8 @@ public class MainFrame extends javax.swing.JFrame { .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); @@ -209,12 +243,12 @@ public class MainFrame extends javax.swing.JFrame { jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addGap(24, 24, 24)) ); jMenu1.setText("File"); @@ -239,6 +273,65 @@ public class MainFrame extends javax.swing.JFrame { pack(); }// //GEN-END:initComponents + private File searchFileMatchId(final File dir, final String id) throws UnsupportedOperationException { + final File[] lists = dir.listFiles(new FilenameFilter() { + + @Override + public boolean accept(File dir, String name) { + return name.contains(id); + } + }); + + if (lists.length == 1) { + return lists[0]; + } else if (lists.length > 1) { + throw new UnsupportedOperationException(); + } else { + return null; + } + } + +private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged + final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED); + movieFileSelectButton.setEnabled(useLocal); +}//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged + +private void useCommentLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useCommentLocalCheckBoxItemStateChanged + final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED); + commentFileSelectButton.setEnabled(useLocal); +}//GEN-LAST:event_useCommentLocalCheckBoxItemStateChanged + +private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged + final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED); + outputFileField.setEnabled(convert); + outputFileSelectButton.setEnabled(convert); +}//GEN-LAST:event_outputConvertCheckBoxItemStateChanged + +private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost + final Properties p = Properties.INSTANCE; + final String id = idField.getText(); + if (id.isEmpty()) { + return; + } + + if (useMovieLocalCheckBox.isSelected() && movieFileField.getText().isEmpty()) { + final File dir = p.getMovieDirectory(); + final File file = searchFileMatchId(dir, id); + if (file != null) { + movieFileField.setText(file.getPath()); + } + } + + if (useCommentLocalCheckBox.isSelected() && commentFileField.getText().isEmpty()) { + final File dir = p.getCommentDirectory(); + final File file = searchFileMatchId(dir, id); + if (file != null) { + commentFileField.setText(file.getPath()); + } + } + +}//GEN-LAST:event_idFieldFocusLost + /** * @param args the command line arguments */ @@ -264,18 +357,15 @@ public class MainFrame extends javax.swing.JFrame { }); } // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton1; + private javax.swing.JButton applyButton; + private javax.swing.JTextField commentFileField; + private javax.swing.JButton commentFileSelectButton; + private javax.swing.JLabel commentLabel; + private javax.swing.JTextField idField; + private javax.swing.JLabel idLabel; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; - private javax.swing.JCheckBox jCheckBox1; - private javax.swing.JCheckBox jCheckBox2; - private javax.swing.JComboBox jComboBox1; - private javax.swing.JComboBox jComboBox2; - private javax.swing.JComboBox jComboBox3; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; @@ -284,13 +374,41 @@ public class MainFrame extends javax.swing.JFrame { private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; - private javax.swing.JTextField jTextField1; - private javax.swing.JTextField jTextField2; - private javax.swing.JTextField jTextField3; + private javax.swing.JTextField movieFileField; + private javax.swing.JButton movieFileSelectButton; + private javax.swing.JLabel movieLabel; + private javax.swing.JCheckBox outputConvertCheckBox; + private javax.swing.JTextField outputFileField; + private javax.swing.JButton outputFileSelectButton; + private javax.swing.JLabel outputLabel; + private javax.swing.JCheckBox useCommentLocalCheckBox; + private javax.swing.JCheckBox useMovieLocalCheckBox; // End of variables declaration//GEN-END:variables + private void initInputPanel() { + idField.setText(""); + + final Properties p = Properties.INSTANCE; + + final boolean movieLocal = p.getUseMovieFileLocal(); + useMovieLocalCheckBox.setSelected(movieLocal); + movieFileSelectButton.setEnabled(movieLocal); + + final boolean commentLocal = p.getCommentFileLocal(); + useCommentLocalCheckBox.setSelected(commentLocal); + commentFileSelectButton.setEnabled(commentLocal); + + final boolean convert = p.getOutputConvert(); + outputConvertCheckBox.setSelected(convert); + outputFileField.setEnabled(convert); + outputFileField.setText(p.getOutputFile().toString()); + outputFileSelectButton.setEnabled(convert); + + } + private class DownloadListTransferHandler extends TransferHandler { + private static final long serialVersionUID = 1L; private final Pattern movieIdPattern = Pattern.compile("(\\w\\w\\d+)"); @Override