OSDN Git Service

step by step
[importpicture/importpicture.git] / src / osm / jp / gpx / matchtime / gui / ParameterPanelGpx.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
7 import javax.swing.JButton;
8 import javax.swing.JFileChooser;
9
10 @SuppressWarnings("serial")
11 public class ParameterPanelGpx extends ParameterPanel implements ActionListener
12 {
13     JFileChooser fc;
14     JButton openButton;
15
16     @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
17     public ParameterPanelGpx(String label, String text) {
18         super(label, text);
19
20         // "選択..."
21         openButton = new JButton(
22             i18n.getString("button.select"), 
23             AdjustTime.createImageIcon("images/Open16.gif")
24         );
25         openButton.addActionListener(this);
26         this.add(openButton);
27     }
28
29     public void setEnable(boolean f) {
30         super.setEnabled(f);
31         openButton.setEnabled(f);
32     }
33         
34     @Override
35     public void actionPerformed(ActionEvent e) {
36         if (e.getSource() == openButton){
37             System.out.println("ParameterPanelGpx.actionPerformed(openButton)");
38             File sdir = new File(this.argField.getText());
39             if (sdir.exists()) {
40                 this.fc = new JFileChooser(sdir);
41             }
42             else {
43                 this.fc = new JFileChooser();
44             }
45             this.fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
46             this.fc.addChoosableFileFilter(new GpxAndFolderFilter());
47             this.fc.setAcceptAllFileFilterUsed(false);
48
49             int returnVal = this.fc.showOpenDialog(ParameterPanelGpx.this);
50
51             if (returnVal == JFileChooser.APPROVE_OPTION) {
52                 File file = this.fc.getSelectedFile();
53                 this.argField.setText(file.getAbsolutePath());
54             }
55         }
56     }
57 }