1 package osm.surveyor.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 public ParameterPanelFolder(String label, String text, int chooser) {
30 // Create a file chooser
31 this.chooser = chooser;
34 selectButton = new JButton(
35 i18n.getString("button.select"),
36 ReStamp.createImageIcon("/images/Open16.gif")
38 selectButton.addActionListener(this);
39 this.add(selectButton);
42 public void setEnable(boolean f) {
44 selectButton.setEnabled(f);
47 public File getDirectory() throws FileNotFoundException {
48 String path = this.argField.getText();
50 throw new FileNotFoundException("Folder is Not specifiyed yet.");
52 File sdir = new File(path);
54 throw new FileNotFoundException(String.format("Folder '%s' is Not exists.", path));
56 if (!sdir.isDirectory()) {
57 throw new FileNotFoundException(String.format("Folder '%s' is Not directory.", path));
63 public void actionPerformed(ActionEvent e) {
64 if (e.getSource() == selectButton){
67 sdir = getDirectory();
68 } catch (FileNotFoundException ex) {
70 this.argField.setText(sdir.getAbsolutePath());
73 this.fc = new JFileChooser(sdir);
76 this.fc = new JFileChooser();
78 this.fc.setFileSelectionMode(this.chooser);
80 int returnVal = this.fc.showOpenDialog(ParameterPanelFolder.this);
82 if (returnVal == JFileChooser.APPROVE_OPTION) {
83 File file = this.fc.getSelectedFile();
84 this.argField.setText(file.getAbsolutePath());
94 public boolean isEnable() {
95 String text = this.argField.getText();
100 File dir = new File(text);
101 return (dir.exists() && dir.isDirectory());
103 catch (Exception e) {