OSDN Git Service

85e398da1af675d13449ac9f8ec440c3d68ff05c
[importpicture/importpicture.git] / importPicture / src / osm / jp / gpx / AppParameters.java
1 package osm.jp.gpx;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 import java.util.Properties;
9
10 @SuppressWarnings("serial")
11 public class AppParameters extends Properties {
12         static final String FILE_PATH = "AdjustTime.ini";
13         
14         // GPX: 時間的に間隔が開いたGPXログを別の<trkseg>セグメントに分割する。 {ON | OFF}
15         public static String GPX_GPXSPLIT = "GPX.gpxSplit";
16         
17         // GPX: <trkseg>セグメントの最初の1ノードは無視する。 {ON | OFF}
18         public static String GPX_NO_FIRST_NODE = "GPX.noFirstNode";
19         
20         // GPX: 生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も対象にする。 {ON | OFF}
21         public static String GPX_REUSE = "GPX.REUSE";
22         
23         // GPX: 基準時刻 {FILE_UPDATE | EXIF}
24         public static String GPX_BASETIME = "GPX.BASETIME";
25         
26         File file;
27         
28         public AppParameters() throws FileNotFoundException, IOException {
29                 super();
30                 syncFile();
31         }
32
33         public AppParameters(Properties defaults) throws FileNotFoundException, IOException {
34                 super(defaults);
35                 syncFile();
36         }
37         
38         void syncFile() throws FileNotFoundException, IOException {
39                 boolean update = false;
40                 
41                 this.file = new File(FILE_PATH);
42                 if (file.exists()) {
43                         // ファイルが存在すれば、その内容をロードする。
44                         this.load(new FileInputStream(file));
45                 }
46                 else {
47                         update = true;
48                 }
49                 
50                 //------------------------------------------------
51                 // GPX出力: 時間的に間隔が開いたGPXログを別の<trkseg>セグメントに分割する。 {ON | OFF}
52                 String valueStr = this.getProperty(GPX_GPXSPLIT);
53                 if (valueStr == null) {
54                         update = true;
55                         this.setProperty(GPX_GPXSPLIT, "ON");           
56                 }
57
58                 //------------------------------------------------
59                 // GPX出力: <trkseg>セグメントの最初の1ノードは無視する。 {ON | OFF}
60                 valueStr = this.getProperty(GPX_NO_FIRST_NODE);
61                 if (valueStr == null) {
62                         update = true;
63                         this.setProperty(GPX_NO_FIRST_NODE, "ON");              
64                 }
65
66                 //------------------------------------------------
67                 // GPX出力: 生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も対象にする。 {ON | OFF}
68                 valueStr = this.getProperty(GPX_REUSE);
69                 if (valueStr == null) {
70                         update = true;
71                         this.setProperty(GPX_REUSE, "OFF");
72                 }
73
74                 //------------------------------------------------
75                 //  GPX: 基準時刻 {FILE_UPDATE | EXIF}
76                 valueStr = this.getProperty(GPX_BASETIME);
77                 if (valueStr == null) {
78                         update = true;
79                         this.setProperty(GPX_BASETIME, "FILE_UPDATE");
80                 }
81
82                 if (update) {
83                         // ・ファイルがなければ新たに作る
84                         // ・項目が足りない時は書き足す。
85                         this.store(new FileOutputStream(this.file), "defuilt settings");        
86                 }
87         }
88         
89         public void store() throws FileNotFoundException, IOException {
90                 this.store(new FileOutputStream(this.file), "by AdjustTime");
91         }
92 }