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.");
}
@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);
}
File file = this.fc.getSelectedFile();
this.argField.setText(file.getAbsolutePath());
}
- } catch (FileNotFoundException ex) {
- this.argField.setText(ex.toString());
- }
}
}
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);
+ }
}
/**
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();