1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
6 import java.io.FileNotFoundException;
7 import javax.swing.JButton;
8 import javax.swing.JFileChooser;
10 @SuppressWarnings("serial")
11 public class ParameterPanelFolder extends ParameterPanel implements ActionListener
17 @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
18 public ParameterPanelFolder(String label, String text, int chooser) {
21 // Create a file chooser
22 this.chooser = chooser;
25 openButton = new JButton(
26 i18n.getString("button.select"),
27 AdjustTime.createImageIcon("images/Open16.gif")
29 openButton.addActionListener(this);
33 public ParameterPanelFolder(String label, String text) {
34 this(label, text, JFileChooser.DIRECTORIES_ONLY);
37 public void setEnable(boolean f) {
39 openButton.setEnabled(f);
42 public File getDirectory() throws FileNotFoundException {
43 String path = this.argField.getText();
45 throw new FileNotFoundException("Image folder is Not specifiyed yet.");
47 File sdir = new File(path);
49 throw new FileNotFoundException(String.format("Image folder '%s' is Not exists.", path));
51 if (!sdir.isDirectory()) {
52 throw new FileNotFoundException(String.format("Image folder '%s' is Not directory.", path));
58 public void actionPerformed(ActionEvent e) {
59 if (e.getSource() == openButton){
61 System.out.println("ParameterPanelFolder.actionPerformed(openButton)");
62 File sdir = getDirectory();
64 this.fc = new JFileChooser(sdir);
67 this.fc = new JFileChooser();
69 this.fc.setFileSelectionMode(this.chooser);
71 int returnVal = this.fc.showOpenDialog(ParameterPanelFolder.this);
73 if (returnVal == JFileChooser.APPROVE_OPTION) {
74 File file = this.fc.getSelectedFile();
75 this.argField.setText(file.getAbsolutePath());
77 } catch (FileNotFoundException ex) {
78 this.argField.setText(ex.toString());
88 public boolean isEnable() {
89 String text = this.argField.getText();
94 File dir = new File(text);
95 return (dir.exists() && dir.isDirectory());