diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java index 4169cc8..0228da1 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java @@ -39,8 +39,7 @@ 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 @@ @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 @@ File file = this.fc.getSelectedFile(); this.argField.setText(file.getAbsolutePath()); } - } catch (FileNotFoundException ex) { - this.argField.setText(ex.toString()); - } } } diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java index ac417c0..e651f92 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java @@ -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); + 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 custom icons for file types. + fc.setFileView(new ImageFileView()); + + //Add the preview pane. + fc.setAccessory(new ImagePreview(fc)); + + //Show it. + int returnVal = fc.showDialog(ParameterPanelImageFile.this, "選択"); + + //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); } - 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 custom icons for file types. - fc.setFileView(new ImageFileView()); - - //Add the preview pane. - fc.setAccessory(new ImagePreview(fc)); - - //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()); - } - - //Reset the file chooser for the next time it's shown. - fc.setSelectedFile(null); } /** @@ -72,7 +78,7 @@ 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(); diff --git a/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java b/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java index 8a7f4ca..b9a0bf8 100644 --- a/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java +++ b/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java @@ -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;