OSDN Git Service

cd5f759d1f3521153945731ed6b602522c0b8df1
[restamp/Restamp-gui.git] / src / main / java / osm / surveyor / matchtime / gui / ParameterPanelGpx.java
1 package osm.surveyor.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.JCheckBox;
9 import javax.swing.JFileChooser;
10
11 @SuppressWarnings("serial")
12 public class ParameterPanelGpx extends ParameterPanel implements ActionListener
13 {
14     JFileChooser fc;
15     JButton selectButton;
16     public JCheckBox noFirstNode;      // CheckBox: "セグメント'trkseg'の最初の1ノードは無視する。"
17     public JCheckBox gpxReuse;         // CheckBox: "生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も変換の対象にする"
18     
19     /**
20      * コンストラクタ
21      * @param label
22      * @param text 
23      */
24     public ParameterPanelGpx(String label, String text) {
25         super(label, text);
26
27         // "選択..."
28         selectButton = new JButton(
29                 i18n.getString("button.select"), 
30                 ReStamp.createImageIcon("/images/Open16.gif")
31         );
32         selectButton.addActionListener(this);
33         this.add(selectButton);
34     }
35
36     @Override
37     public void actionPerformed(ActionEvent e) {
38         if (e.getSource() == selectButton){
39             System.out.println("ParameterPanelGpx.actionPerformed(openButton)");
40             File sdir = new File(this.argField.getText());
41             if (sdir.exists()) {
42                 this.fc = new JFileChooser(sdir);
43             }
44             else {
45                 this.fc = new JFileChooser();
46             }
47             this.fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
48             this.fc.addChoosableFileFilter(new GpxAndFolderFilter());
49             this.fc.setAcceptAllFileFilterUsed(false);
50
51             int returnVal = this.fc.showOpenDialog(ParameterPanelGpx.this);
52
53             if (returnVal == JFileChooser.APPROVE_OPTION) {
54                 File file = this.fc.getSelectedFile();
55                 this.argField.setText(file.getAbsolutePath());
56             }
57         }
58     }
59
60     public File getGpxFile() {
61         if (isEnable()) {
62             return new File(getText());
63         }
64         return null;
65     }
66     
67     public boolean isNoFirstNodeSelected() {
68         return (noFirstNode != null) && noFirstNode.isSelected();
69     }
70     
71     public boolean isGpxReuseSelected() {
72         return (gpxReuse != null) && gpxReuse.isSelected();
73     }
74         
75     /**
76      * このフィールドに有効な値が設定されているかどうか
77      * @return 
78      */
79     @Override
80     public boolean isEnable() {
81         String text = this.argField.getText();
82         if (text != null) {
83             File file = new File(text);
84             if (file.exists()) {
85                 if (file.isFile()) {
86                     String name = file.getName().toUpperCase();
87                     if (name.endsWith(".GPX")) {
88                         return true;
89                     }
90                 }
91                 else if (file.isDirectory()) {
92                     return true;
93                 }
94             }
95         }
96         return false;
97     }
98 }