OSDN Git Service

e3230f1cbc50e2df259812ef789d2d3690591348
[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         // 対象IMGフォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ)
27         public static String IMG_SOURCE_FOLDER = "IMG.SOURCE_FOLDER";
28         
29         // 基準時刻画像(正確な撮影時刻が判明できる画像)
30         public static String IMG_BASE_FILE = "IMG.BASE_FILE";
31         
32         // 対象GPXフォルダ:(GPXファイルが格納されているフォルダ)
33         public static String GPX_SOURCE_FOLDER = "GPX.SOURCE_FOLDER";
34         
35         // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ)
36         public static String IMG_OUTPUT_FOLDER = "IMG.OUTPUT_FOLDER";
37         
38         File file;
39         
40         public AppParameters() throws FileNotFoundException, IOException {
41                 super();
42                 syncFile();
43         }
44
45         public AppParameters(Properties defaults) throws FileNotFoundException, IOException {
46                 super(defaults);
47                 syncFile();
48         }
49         
50         void syncFile() throws FileNotFoundException, IOException {
51                 boolean update = false;
52                 
53                 this.file = new File(FILE_PATH);
54                 if (file.exists()) {
55                         // ファイルが存在すれば、その内容をロードする。
56                         this.load(new FileInputStream(file));
57                 }
58                 else {
59                         update = true;
60                 }
61                 
62                 //------------------------------------------------
63                 // 対象フォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ)
64                 String valueStr = this.getProperty(IMG_SOURCE_FOLDER);
65                 if (valueStr == null) {
66                         update = true;
67                         this.setProperty(IMG_SOURCE_FOLDER, (new File(".")).getAbsolutePath());
68                 }
69
70                 //------------------------------------------------
71                 // 対象フォルダ:(GPXファイルが格納されているフォルダ)
72                 valueStr = this.getProperty(GPX_SOURCE_FOLDER);
73                 if (valueStr == null) {
74                         update = true;
75                         this.setProperty(GPX_SOURCE_FOLDER, (new File(".")).getAbsolutePath());
76                 }
77
78                 //------------------------------------------------
79                 // 基準時刻画像(正確な撮影時刻が判明できる画像)
80                 valueStr = this.getProperty(IMG_BASE_FILE);
81                 if (valueStr == null) {
82                         update = true;
83                         this.setProperty(IMG_BASE_FILE, "");
84                 }
85
86                 //------------------------------------------------
87                 // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ)
88                 valueStr = this.getProperty(IMG_OUTPUT_FOLDER);
89                 if (valueStr == null) {
90                         update = true;
91                         this.setProperty(IMG_OUTPUT_FOLDER, (new File(".")).getAbsolutePath());
92                 }
93
94                 //------------------------------------------------
95                 // GPX出力: 時間的に間隔が開いたGPXログを別の<trkseg>セグメントに分割する。 {ON | OFF}
96                 valueStr = this.getProperty(GPX_GPXSPLIT);
97                 if (valueStr == null) {
98                         update = true;
99                         this.setProperty(GPX_GPXSPLIT, "ON");           
100                 }
101
102                 //------------------------------------------------
103                 // GPX出力: <trkseg>セグメントの最初の1ノードは無視する。 {ON | OFF}
104                 valueStr = this.getProperty(GPX_NO_FIRST_NODE);
105                 if (valueStr == null) {
106                         update = true;
107                         this.setProperty(GPX_NO_FIRST_NODE, "ON");              
108                 }
109
110                 //------------------------------------------------
111                 // GPX出力: 生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も対象にする。 {ON | OFF}
112                 valueStr = this.getProperty(GPX_REUSE);
113                 if (valueStr == null) {
114                         update = true;
115                         this.setProperty(GPX_REUSE, "OFF");
116                 }
117
118                 //------------------------------------------------
119                 //  GPX: 基準時刻 {FILE_UPDATE | EXIF}
120                 valueStr = this.getProperty(GPX_BASETIME);
121                 if (valueStr == null) {
122                         update = true;
123                         this.setProperty(GPX_BASETIME, "FILE_UPDATE");
124                 }
125
126                 if (update) {
127                         // ・ファイルがなければ新たに作る
128                         // ・項目が足りない時は書き足す。
129                         this.store(new FileOutputStream(this.file), "defuilt settings");        
130                 }
131         }
132         
133         public void store() throws FileNotFoundException, IOException {
134                 this.store(new FileOutputStream(this.file), "by AdjustTime");
135         }
136 }