OSDN Git Service

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