OSDN Git Service

fixed: 対象フォルダが入力されたら次のパネルを有効にする
authorhaya4 <hayashi.yuu@gmail.com>
Thu, 10 Oct 2019 19:02:15 +0000 (04:02 +0900)
committerhaya4 <hayashi.yuu@gmail.com>
Thu, 10 Oct 2019 19:02:15 +0000 (04:02 +0900)
src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java
src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java
src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java

index 4169cc8..0228da1 100644 (file)
@@ -39,8 +39,7 @@ public class ParameterPanelFolder extends ParameterPanel implements ActionListen
         openButton.setEnabled(f);
     }
 
-    public File getDirectory() throws FileNotFoundException {
-        String path = this.argField.getText();
+    public File getDirectory(String path) throws FileNotFoundException {
         if (path == null) {
             throw new FileNotFoundException("Image folder is Not specifiyed yet.");
         }
@@ -57,9 +56,14 @@ public class ParameterPanelFolder extends ParameterPanel implements ActionListen
     @Override
     public void actionPerformed(ActionEvent e) {
         if (e.getSource() == openButton){
-            try {
                 System.out.println("ParameterPanelFolder.actionPerformed(openButton)");
-                File sdir = getDirectory();
+                File sdir;
+                try {
+                    sdir = getDirectory(this.argField.getText());
+                } catch (FileNotFoundException ex) {
+                    sdir = new File(".");
+                    this.argField.setText(sdir.getAbsolutePath());
+                }
                 if (sdir.exists()) {
                     this.fc = new JFileChooser(sdir);
                 }
@@ -74,9 +78,6 @@ public class ParameterPanelFolder extends ParameterPanel implements ActionListen
                     File file = this.fc.getSelectedFile();
                     this.argField.setText(file.getAbsolutePath());
                 }
-            } catch (FileNotFoundException ex) {
-                this.argField.setText(ex.toString());
-            }
         }
     }
 
index ac417c0..e651f92 100644 (file)
@@ -1,65 +1,71 @@
 package osm.jp.gpx.matchtime.gui;
 
 import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.io.File;
 import java.io.FileNotFoundException;
 import javax.swing.JButton;
 import javax.swing.JFileChooser;
 
 @SuppressWarnings("serial")
-public class ParameterPanelImageFile extends ParameterPanel implements ActionListener {
+public class ParameterPanelImageFile extends ParameterPanel {
     JFileChooser fc;
     public JButton openButton;
     public ParameterPanelFolder paramDir;
 
     @SuppressWarnings("OverridableMethodCallInConstructor")
-    public ParameterPanelImageFile(String label, String text, ParameterPanelFolder paramDir) {
+    public ParameterPanelImageFile(
+            String label, String text, 
+            ParameterPanelFolder paramDir
+    ) {
         super(label, text);
 
         // "選択..."
+        SelectButtonAction buttonAction = new SelectButtonAction();
         openButton = new JButton(i18n.getString("button.select"));
-        openButton.addActionListener(this);
+        openButton.addActionListener(buttonAction);
         this.add(openButton);
         
         //Create a file chooser
         this.paramDir = paramDir;
     }
 
-    @SuppressWarnings("override")
-    public void actionPerformed(ActionEvent e) {
-        //Set up the file chooser.
-        File sdir = new File(paramDir.getText());
-        System.out.println(sdir.toPath());
-        if (sdir.isDirectory()) {
-            fc = new JFileChooser(sdir);
-        }
-        else {
-            fc = new JFileChooser();
-        }
+    class SelectButtonAction implements java.awt.event.ActionListener
+    {
+        @SuppressWarnings("override")
+        public void actionPerformed(ActionEvent e) {
+            //Set up the file chooser.
+            File sdir = new File(paramDir.getText());
+            System.out.println(sdir.toPath());
+            if (sdir.isDirectory()) {
+                fc = new JFileChooser(sdir);
+            }
+            else {
+                fc = new JFileChooser();
+            }
 
-        //Add a custom file filter and disable the default
-        //(Accept All) file filter.
-        fc.addChoosableFileFilter(new ImageFilter());
-        fc.setAcceptAllFileFilterUsed(false);
+            //Add a custom file filter and disable the default
+            //(Accept All) file filter.
+            fc.addChoosableFileFilter(new ImageFilter());
+            fc.setAcceptAllFileFilterUsed(false);
 
-        //Add custom icons for file types.
-        fc.setFileView(new ImageFileView());
+            //Add custom icons for file types.
+            fc.setFileView(new ImageFileView());
 
-        //Add the preview pane.
-        fc.setAccessory(new ImagePreview(fc));
+            //Add the preview pane.
+            fc.setAccessory(new ImagePreview(fc));
 
-        //Show it.
-        int returnVal = fc.showDialog(ParameterPanelImageFile.this, "選択");
+            //Show it.
+            int returnVal = fc.showDialog(ParameterPanelImageFile.this, "選択");
 
-        //Process the results.
-        if (returnVal == JFileChooser.APPROVE_OPTION) {
-            File file = fc.getSelectedFile();
-            this.argField.setText(file.getName());
-        }
+            //Process the results.
+            if (returnVal == JFileChooser.APPROVE_OPTION) {
+                File file = fc.getSelectedFile();
+                argField.setText(file.getName());
+            }
 
-        //Reset the file chooser for the next time it's shown.
-        fc.setSelectedFile(null);
+            //Reset the file chooser for the next time it's shown.
+            fc.setSelectedFile(null);
+        }
     }
 
     /**
@@ -72,7 +78,7 @@ public class ParameterPanelImageFile extends ParameterPanel implements ActionLis
             String text = this.argField.getText();
             if (text != null) {
                 try {
-                    File dir = this.paramDir.getDirectory();
+                    File dir = this.paramDir.getDirectory(text);
                     File file = new File(dir, text);
                     if (file.exists() && file.isFile()) {
                         String name = file.getName().toUpperCase();
index 8a7f4ca..b9a0bf8 100644 (file)
@@ -1,8 +1,6 @@
 package osm.jp.gpx.matchtime.gui.restamp;
 
 import java.awt.BorderLayout;
-import java.io.File;
-import java.io.FileNotFoundException;
 import javax.swing.BoxLayout;
 import javax.swing.JLabel;
 import javax.swing.JPanel;