OSDN Git Service

コメントパネルのファイル選択ボタン
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / ConfigDialog.java
index 96e48b1..8ee37d1 100644 (file)
@@ -23,6 +23,7 @@ import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
+import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
@@ -65,26 +66,11 @@ public class ConfigDialog extends JDialog {
         fldProxyHost = new JTextField();
         fldProxyPort = new JTextField();
         final JPanel pnlFile = new JPanel();
-        final JPanel pnlFileVideo = new JPanel();
-        final JLabel lblVideoDir = new JLabel();
-        final JLabel lblVideoFileNamepattern = new JLabel();
-        fldVideoDir = new JTextField();
-        fldVideoFileNamePattern = new JTextField();
-        btnVideoDir = new JButton();
-        cbVideoLocal = new JCheckBox();
-        final JPanel pnlFileComment = new JPanel();
-        final JLabel lblCommentDir = new JLabel();
-        final JLabel lblCommentFileNamePattern = new JLabel();
-        fldCommentDir = new JTextField();
-        fldCommentFileNamePattern = new JTextField();
-        btnCommentDir = new JButton();
-        cbCommentLocal = new JCheckBox();
         final JPanel pnlFileOutput = new JPanel();
         final JLabel lblOutputDir = new JLabel();
         final JLabel lblOutputFileNamePattern = new JLabel();
         fldOutputDir = new JTextField();
         fldOutputFileNamePattern = new JTextField();
-        btnOutputDir = new JButton();
         cbOutputEnable = new JCheckBox();
         cbOutputCommentOverlay = new JCheckBox();
         cbOutputDisplayProgress = new JCheckBox();
@@ -231,103 +217,16 @@ public class ConfigDialog extends JDialog {
 
         pnlFileVideo.setBorder(BorderFactory.createTitledBorder("動画"));
 
-        lblVideoDir.setText("保存フォルダ");
-
-        lblVideoFileNamepattern.setText("ファイル名規則");
-
-        btnVideoDir.setText("...");
-
-        cbVideoLocal.setText("local");
-
-        GroupLayout gl_pnlFileVideo = new GroupLayout(pnlFileVideo);
-        pnlFileVideo.setLayout(gl_pnlFileVideo);
-        gl_pnlFileVideo.setHorizontalGroup(
-            gl_pnlFileVideo.createParallelGroup(GroupLayout.Alignment.LEADING)
-            .addGroup(GroupLayout.Alignment.TRAILING, gl_pnlFileVideo.createSequentialGroup()
-                .addContainerGap()
-                .addGroup(gl_pnlFileVideo.createParallelGroup(GroupLayout.Alignment.LEADING)
-                    .addComponent(lblVideoFileNamepattern)
-                    .addComponent(lblVideoDir))
-                .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlFileVideo.createParallelGroup(GroupLayout.Alignment.LEADING)
-                    .addGroup(gl_pnlFileVideo.createSequentialGroup()
-                        .addComponent(fldVideoDir, GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(btnVideoDir))
-                    .addGroup(GroupLayout.Alignment.TRAILING, gl_pnlFileVideo.createSequentialGroup()
-                        .addComponent(fldVideoFileNamePattern, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
-                        .addPreferredGap(ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
-                        .addComponent(cbVideoLocal)))
-                .addContainerGap())
-        );
-        gl_pnlFileVideo.setVerticalGroup(
-            gl_pnlFileVideo.createParallelGroup(GroupLayout.Alignment.LEADING)
-            .addGroup(gl_pnlFileVideo.createSequentialGroup()
-                .addGroup(gl_pnlFileVideo.createParallelGroup(GroupLayout.Alignment.BASELINE)
-                    .addComponent(lblVideoDir)
-                    .addComponent(fldVideoDir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                    .addComponent(btnVideoDir))
-                .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlFileVideo.createParallelGroup(GroupLayout.Alignment.BASELINE)
-                    .addComponent(lblVideoFileNamepattern)
-                    .addComponent(fldVideoFileNamePattern, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                    .addComponent(cbVideoLocal))
-                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-        );
-
         pnlFileComment.setBorder(BorderFactory.createTitledBorder("コメント"));
 
-        lblCommentDir.setText("保存フォルダ");
-
-        lblCommentFileNamePattern.setText("ファイル名規則");
-
-        btnCommentDir.setText("...");
-
-        cbCommentLocal.setText("local");
-
-        GroupLayout gl_pnlFileComment = new GroupLayout(pnlFileComment);
-        pnlFileComment.setLayout(gl_pnlFileComment);
-        gl_pnlFileComment.setHorizontalGroup(
-            gl_pnlFileComment.createParallelGroup(GroupLayout.Alignment.LEADING)
-            .addGroup(gl_pnlFileComment.createSequentialGroup()
-                .addContainerGap()
-                .addGroup(gl_pnlFileComment.createParallelGroup(GroupLayout.Alignment.LEADING)
-                    .addComponent(lblCommentFileNamePattern)
-                    .addComponent(lblCommentDir))
-                .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlFileComment.createParallelGroup(GroupLayout.Alignment.LEADING)
-                    .addGroup(gl_pnlFileComment.createSequentialGroup()
-                        .addComponent(fldCommentFileNamePattern, GroupLayout.PREFERRED_SIZE, 166, GroupLayout.PREFERRED_SIZE)
-                        .addPreferredGap(ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
-                        .addComponent(cbCommentLocal))
-                    .addGroup(gl_pnlFileComment.createSequentialGroup()
-                        .addComponent(fldCommentDir, GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
-                        .addPreferredGap(ComponentPlacement.RELATED)
-                        .addComponent(btnCommentDir)))
-                .addContainerGap())
-        );
-        gl_pnlFileComment.setVerticalGroup(
-            gl_pnlFileComment.createParallelGroup(GroupLayout.Alignment.LEADING)
-            .addGroup(gl_pnlFileComment.createSequentialGroup()
-                .addGroup(gl_pnlFileComment.createParallelGroup(GroupLayout.Alignment.BASELINE)
-                    .addComponent(lblCommentDir)
-                    .addComponent(fldCommentDir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                    .addComponent(btnCommentDir))
-                .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlFileComment.createParallelGroup(GroupLayout.Alignment.BASELINE)
-                    .addComponent(lblCommentFileNamePattern)
-                    .addComponent(fldCommentFileNamePattern, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                    .addComponent(cbCommentLocal))
-                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
-        );
-
         pnlFileOutput.setBorder(BorderFactory.createTitledBorder("変換動画"));
 
         lblOutputDir.setText("保存フォルダ");
 
         lblOutputFileNamePattern.setText("ファイル名規則");
 
-        btnOutputDir.setText("...");
+        btnOutputDir.addActionListener(
+                new FileChooseAction(ConfigDialog.this, JFileChooser.DIRECTORIES_ONLY, fldOutputDir));
 
         cbOutputEnable.setText("変換");
 
@@ -751,6 +650,13 @@ public class ConfigDialog extends JDialog {
             }
         });
         final JButton btnCancel = new JButton("Cancel");
+        btnCancel.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                dispose();
+            }
+        });
         pnlButton.add(btnOk);
         pnlButton.add(btnCancel);
 
@@ -836,7 +742,6 @@ public class ConfigDialog extends JDialog {
      */
     public static void main(String args[]) {
         /* Set the Nimbus look and feel */
-        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
          */
@@ -847,16 +752,9 @@ public class ConfigDialog extends JDialog {
                     break;
                 }
             }
-        } catch (ClassNotFoundException ex) {
-            java.util.logging.Logger.getLogger(ConfigDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (InstantiationException ex) {
-            java.util.logging.Logger.getLogger(ConfigDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (IllegalAccessException ex) {
-            java.util.logging.Logger.getLogger(ConfigDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-        } catch (UnsupportedLookAndFeelException ex) {
+        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
             java.util.logging.Logger.getLogger(ConfigDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
         }
-        //</editor-fold>
 
         /* Create and display the form */
         java.awt.EventQueue.invokeLater(new Runnable() {
@@ -879,19 +777,13 @@ public class ConfigDialog extends JDialog {
     private final JTextField fldProxyPort;
     // ファイル
     // ファイル - 動画
-    private final JTextField fldVideoDir;
-    private final JButton btnVideoDir;
-    private final JTextField fldVideoFileNamePattern;
-    private final JCheckBox cbVideoLocal;
+    private final DownloadLocationPanel pnlFileVideo = new DownloadLocationPanel();
     // ファイル - コメント
-    private final JTextField fldCommentDir;
-    private final JButton btnCommentDir;
-    private final JTextField fldCommentFileNamePattern;
-    private final JCheckBox cbCommentLocal;
+    private final DownloadLocationPanel pnlFileComment = new DownloadLocationPanel();
     // ファイル - 変換動画
     private final JTextField fldOutputDir;
     private final JTextField fldOutputFileNamePattern;
-    private final JButton btnOutputDir;
+    private final JButton btnOutputDir = new JButton("...");
     private final JCheckBox cbOutputEnable;
     private final JCheckBox cbOutputCommentOverlay;
     private final JCheckBox cbOutputDisplayProgress;
@@ -961,16 +853,16 @@ public class ConfigDialog extends JDialog {
         /*
          * ファイル - 動画
          */
-        fldVideoDir.setText(p.getVideoDir());
-        fldVideoFileNamePattern.setText(p.getVideoFileNamePattern());
-        cbVideoLocal.setSelected(p.getVideoUseLocal());
+        pnlFileVideo.fldDir.setText(p.getVideoDir());
+        pnlFileVideo.fldFileNamePattern.setText(p.getVideoFileNamePattern());
+        pnlFileVideo.cbLocal.setSelected(p.getVideoUseLocal());
 
         /*
          * ファイル - コメント
          */
-        fldCommentDir.setText(p.getCommentDir());
-        fldCommentFileNamePattern.setText(p.getCommentFileNamePattern());
-        cbCommentLocal.setSelected(p.getCommentUseLocal());
+        pnlFileComment.fldDir.setText(p.getCommentDir());
+        pnlFileComment.fldFileNamePattern.setText(p.getCommentFileNamePattern());
+        pnlFileComment.cbLocal.setSelected(p.getCommentUseLocal());
 
         /*
          * ファイル - 変換動画
@@ -1026,6 +918,12 @@ public class ConfigDialog extends JDialog {
         pnlNgId.init(ngIds);
 
         /*
+         * 検索
+         */
+        pnlSearchVideo.init(p.getSearchVideoDirs());
+        pnlSearchComment.init(p.getSearchCommentDirs());
+
+        /*
          * システム
          */
         fldSystemThreadDownload.setText(Integer.toString(p.getSystemDownloadThread()));
@@ -1054,16 +952,16 @@ public class ConfigDialog extends JDialog {
         /*
          * ファイル - 動画
          */
-        p.setVideoDir(fldVideoDir.getText());
-        p.setVideoFileNamePattern(fldVideoFileNamePattern.getText());
-        p.setVideoUseLocal(cbVideoLocal.isSelected());
+        p.setVideoDir(pnlFileVideo.fldDir.getText());
+        p.setVideoFileNamePattern(pnlFileVideo.fldFileNamePattern.getText());
+        p.setVideoUseLocal(pnlFileVideo.cbLocal.isSelected());
 
         /*
          * ファイル - コメント
          */
-        p.setCommentDir(fldCommentDir.getText());
-        p.setCommentFileNamePattern(fldCommentFileNamePattern.getText());
-        p.setCommentUseLocal(cbCommentLocal.isSelected());
+        p.setCommentDir(pnlFileComment.fldDir.getText());
+        p.setCommentFileNamePattern(pnlFileComment.fldFileNamePattern.getText());
+        p.setCommentUseLocal(pnlFileComment.cbLocal.isSelected());
 
         /*
          * ファイル - 変換動画
@@ -1127,6 +1025,12 @@ public class ConfigDialog extends JDialog {
         p.setNgIds(pnlNgId.getAllElements());
 
         /*
+         * 検索
+         */
+        p.setSearchVideoDirs(pnlSearchVideo.getAllElements());
+        p.setSearchCommentDirs(pnlSearchComment.getAllElements());
+
+        /*
          * システム
          */
         p.setSystemDownloadThread(Integer.parseInt(fldSystemThreadDownload.getText()));
@@ -1141,3 +1045,57 @@ public class ConfigDialog extends JDialog {
         }
     }
 }
+
+class DownloadLocationPanel extends JPanel {
+    final JTextField fldDir = new JTextField();
+    final JTextField fldFileNamePattern = new JTextField();
+    final JCheckBox cbLocal = new JCheckBox("local");
+
+    DownloadLocationPanel(){
+        super();
+
+        final JLabel lblVideoDir = new JLabel("保存フォルダ");
+        final JLabel lblVideoFileNamepattern = new JLabel("ファイル名規則");
+
+        final JButton btnDir = new JButton("...");
+        btnDir.addActionListener(
+                new FileChooseAction(DownloadLocationPanel.this, JFileChooser.DIRECTORIES_ONLY, fldDir));
+
+        final GroupLayout gl = new GroupLayout(this);
+        setLayout(gl);
+        gl.setHorizontalGroup(
+            gl.createParallelGroup(GroupLayout.Alignment.LEADING)
+            .addGroup(GroupLayout.Alignment.TRAILING, gl.createSequentialGroup()
+                .addContainerGap()
+                .addGroup(gl.createParallelGroup(GroupLayout.Alignment.LEADING)
+                    .addComponent(lblVideoFileNamepattern)
+                    .addComponent(lblVideoDir))
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addGroup(gl.createParallelGroup(GroupLayout.Alignment.LEADING)
+                    .addGroup(gl.createSequentialGroup()
+                        .addComponent(fldDir, GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
+                        .addPreferredGap(ComponentPlacement.RELATED)
+                        .addComponent(btnDir))
+                    .addGroup(GroupLayout.Alignment.TRAILING, gl.createSequentialGroup()
+                        .addComponent(fldFileNamePattern, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
+                        .addPreferredGap(ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
+                        .addComponent(cbLocal)))
+                .addContainerGap())
+        );
+        gl.setVerticalGroup(
+            gl.createParallelGroup(GroupLayout.Alignment.LEADING)
+            .addGroup(gl.createSequentialGroup()
+                .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                    .addComponent(lblVideoDir)
+                    .addComponent(fldDir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                    .addComponent(btnDir))
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                    .addComponent(lblVideoFileNamepattern)
+                    .addComponent(fldFileNamePattern, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                    .addComponent(cbLocal))
+                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+        );
+
+    }
+}