OSDN Git Service

コメントパネルのファイル選択ボタン
authoryukihane <yukihane.feather@gmail.com>
Fri, 2 Sep 2011 10:03:04 +0000 (19:03 +0900)
committeryukihane <yukihane.feather@gmail.com>
Fri, 9 Sep 2011 11:40:16 +0000 (20:40 +0900)
frontend/src/yukihane/inqubus/gui/ConfigDialog.java
frontend/src/yukihane/inqubus/gui/FileChooseAction.java [new file with mode: 0644]

index f7a628f..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;
@@ -70,7 +71,6 @@ public class ConfigDialog extends JDialog {
         final JLabel lblOutputFileNamePattern = new JLabel();
         fldOutputDir = new JTextField();
         fldOutputFileNamePattern = new JTextField();
-        btnOutputDir = new JButton();
         cbOutputEnable = new JCheckBox();
         cbOutputCommentOverlay = new JCheckBox();
         cbOutputDisplayProgress = new JCheckBox();
@@ -225,7 +225,8 @@ public class ConfigDialog extends JDialog {
 
         lblOutputFileNamePattern.setText("ファイル名規則");
 
-        btnOutputDir.setText("...");
+        btnOutputDir.addActionListener(
+                new FileChooseAction(ConfigDialog.this, JFileChooser.DIRECTORIES_ONLY, fldOutputDir));
 
         cbOutputEnable.setText("変換");
 
@@ -782,7 +783,7 @@ public class ConfigDialog extends JDialog {
     // ファイル - 変換動画
     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;
@@ -1047,7 +1048,6 @@ public class ConfigDialog extends JDialog {
 
 class DownloadLocationPanel extends JPanel {
     final JTextField fldDir = new JTextField();
-    final JButton btnDir = new JButton("...");
     final JTextField fldFileNamePattern = new JTextField();
     final JCheckBox cbLocal = new JCheckBox("local");
 
@@ -1057,6 +1057,10 @@ class DownloadLocationPanel extends JPanel {
         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(
diff --git a/frontend/src/yukihane/inqubus/gui/FileChooseAction.java b/frontend/src/yukihane/inqubus/gui/FileChooseAction.java
new file mode 100644 (file)
index 0000000..7d10eec
--- /dev/null
@@ -0,0 +1,37 @@
+package yukihane.inqubus.gui;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import javax.swing.JFileChooser;
+import javax.swing.JTextField;
+
+/**
+ *
+ * @author user
+ */
+public class FileChooseAction implements ActionListener {
+
+    private final Component parent;
+    private final int fileSelectionMode;
+    private final JTextField textField;
+
+    public FileChooseAction(Component parent, int fileSelectionMode, JTextField field) {
+        this.parent = parent;
+        this.fileSelectionMode = fileSelectionMode;
+        this.textField = field;
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+
+        final JFileChooser fc = new JFileChooser();
+        fc.setFileSelectionMode(fileSelectionMode);
+        fc.setCurrentDirectory(new File(textField.getText()));
+        final int res = fc.showOpenDialog(parent);
+        if (res == JFileChooser.APPROVE_OPTION) {
+            textField.setText(fc.getSelectedFile().getPath());
+        }
+    }
+}