OSDN Git Service

Java11 - AdjustTime2
[importpicture/importpicture.git] / src / osm / jp / gpx / matchtime / gui / ParameterPanelFolder.java
1 package osm.jp.gpx.matchtime.gui;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.io.File;
6 import javax.swing.JButton;
7 import javax.swing.JFileChooser;
8
9 @SuppressWarnings("serial")
10 public class ParameterPanelFolder extends ParameterPanel implements ActionListener
11 {
12     JFileChooser fc;
13     JButton openButton;
14     int chooser;
15
16     @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
17     public ParameterPanelFolder(String label, String text, int chooser) {
18         super(label, text);
19
20         // Create a file chooser
21         this.chooser = chooser;
22
23         // "選択..."
24         openButton = new JButton(
25             i18n.getString("button.select"),
26             AdjustTime.createImageIcon("images/Open16.gif")
27         );
28         openButton.addActionListener(this);
29         this.add(openButton);
30     }
31
32     public ParameterPanelFolder(String label, String text) {
33         this(label, text, JFileChooser.DIRECTORIES_ONLY);
34     }
35
36     public void setEnable(boolean f) {
37         super.setEnabled(f);
38         openButton.setEnabled(f);
39     }
40         
41     @Override
42     public void actionPerformed(ActionEvent e) {
43         if (e.getSource() == openButton){
44             System.out.println("ParameterPanelFolder.actionPerformed(openButton)");
45             File sdir = new File(this.argField.getText());
46             if (sdir.exists()) {
47                 this.fc = new JFileChooser(sdir);
48             }
49             else {
50                 this.fc = new JFileChooser();
51             }
52             this.fc.setFileSelectionMode(this.chooser);
53
54             int returnVal = this.fc.showOpenDialog(ParameterPanelFolder.this);
55
56             if (returnVal == JFileChooser.APPROVE_OPTION) {
57                 File file = this.fc.getSelectedFile();
58                 this.argField.setText(file.getAbsolutePath());
59             }
60         }
61     }
62 }