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
23 public ParameterPanelFolder(String label, String text) {
24 this(label, text, JFileChooser.DIRECTORIES_ONLY);
27 @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
28 public ParameterPanelFolder(String label, String text, int chooser) {
31 // Create a file chooser
32 this.chooser = chooser;
35 selectButton = new JButton(
36 i18n.getString("button.select"),
37 AdjustTime.createImageIcon("images/Open16.gif")
39 selectButton.addActionListener(this);
40 this.add(selectButton);
43 public void setEnable(boolean f) {
45 selectButton.setEnabled(f);
48 public File getDirectory() throws FileNotFoundException {
49 String path = this.argField.getText();
51 throw new FileNotFoundException("Folder is Not specifiyed yet.");
53 File sdir = new File(path);
55 throw new FileNotFoundException(String.format("Folder '%s' is Not exists.", path));
57 if (!sdir.isDirectory()) {
58 throw new FileNotFoundException(String.format("Folder '%s' is Not directory.", path));
64 public void actionPerformed(ActionEvent e) {
65 if (e.getSource() == selectButton){
68 sdir = getDirectory();
69 } catch (FileNotFoundException ex) {
71 this.argField.setText(sdir.getAbsolutePath());
74 this.fc = new JFileChooser(sdir);
77 this.fc = new JFileChooser();
79 this.fc.setFileSelectionMode(this.chooser);
81 int returnVal = this.fc.showOpenDialog(ParameterPanelFolder.this);
83 if (returnVal == JFileChooser.APPROVE_OPTION) {
84 File file = this.fc.getSelectedFile();
85 this.argField.setText(file.getAbsolutePath());
95 public boolean isEnable() {
96 String text = this.argField.getText();
101 File dir = new File(text);
102 return (dir.exists() && dir.isDirectory());
104 catch (Exception e) {