diff --git a/src/main/java/osm/jp/gpx/AppParameters.java b/src/main/java/osm/jp/gpx/AppParameters.java index 655fa98..8e7c610 100644 --- a/src/main/java/osm/jp/gpx/AppParameters.java +++ b/src/main/java/osm/jp/gpx/AppParameters.java @@ -10,7 +10,7 @@ @SuppressWarnings("serial") public class AppParameters extends Properties { static final String FILE_PATH = "AdjustTime.ini"; - + // GPX: 時間的に間隔が開いたGPXログを別のセグメントに分割する。 {ON | OFF} public static String GPX_GPXSPLIT = "GPX.gpxSplit"; @@ -50,6 +50,13 @@ // 出力GPX: ソースGPXのを無視する {ON | OFF} public static String GPX_OVERWRITE_MAGVAR = "GPX.OVERWRITE_MAGVAR"; + + public static String GPX_REUSE = "GPX.REUSE"; + + //public boolean param_ImgOutputAll = false; + //public boolean exif = false; + //public boolean param_GpxSplit = false; + //public boolean param_GpxReuse = false; File file; @@ -178,9 +185,48 @@ valueStr = this.getProperty(GPX_BASETIME); if (valueStr == null) { update = true; - this.setProperty(GPX_BASETIME, "FILE_UPDATE"); + setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE"); } + // その他のパラメータを読み取る + valueStr = getProperty(AppParameters.GPX_GPXSPLIT); + if (valueStr == null) { + update = true; + setProperty(AppParameters.GPX_GPXSPLIT, Boolean.toString(false)); + } + + valueStr = getProperty(AppParameters.GPX_NO_FIRST_NODE); + if (valueStr == null) { + update = true; + setProperty(AppParameters.GPX_NO_FIRST_NODE, Boolean.toString(false)); + } + + valueStr = getProperty(AppParameters.IMG_OUTPUT_ALL); + if (valueStr == null) { + update = true; + setProperty(AppParameters.IMG_OUTPUT_ALL, Boolean.toString(false)); + } + + valueStr = getProperty(AppParameters.GPX_OVERWRITE_MAGVAR); + if (valueStr == null) { + update = true; + setProperty(AppParameters.GPX_OVERWRITE_MAGVAR, Boolean.toString(false)); + } + + + valueStr = getProperty(AppParameters.GPX_OUTPUT_SPEED); + if (valueStr == null) { + update = true; + setProperty(AppParameters.GPX_OUTPUT_SPEED, Boolean.toString(false)); + } + + valueStr = getProperty(AppParameters.GPX_REUSE); + if (valueStr == null) { + update = true; + setProperty(AppParameters.GPX_REUSE, Boolean.toString(false)); + } + + if (update) { // ・ファイルがなければ新たに作る // ・項目が足りない時は書き足す。 @@ -191,4 +237,108 @@ public void store() throws FileNotFoundException, IOException { this.store(new FileOutputStream(this.file), "by AdjustTime"); } + + public void printout() { + System.out.println(" - param: "+ AppParameters.IMG_TIME +"="+ getProperty(AppParameters.IMG_TIME) ); + System.out.println(" - param: "+ AppParameters.IMG_BASE_FILE +"="+ getProperty(AppParameters.IMG_BASE_FILE) ); + System.out.println(" - param: "+ AppParameters.GPX_BASETIME +"="+ getProperty(AppParameters.GPX_BASETIME) ); + System.out.println(" - param: "+ AppParameters.IMG_SOURCE_FOLDER +"="+ getProperty(AppParameters.IMG_SOURCE_FOLDER) ); + System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_FOLDER +"="+ getProperty(AppParameters.IMG_OUTPUT_FOLDER) ); + System.out.println(" - param: "+ AppParameters.IMG_OUTPUT +"="+ getProperty(AppParameters.IMG_OUTPUT)); + System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_ALL +"="+ isImgOutputAll()); + System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_EXIF +"= "+ isImgOutputExif()); + System.out.println(" - param: "+ AppParameters.GPX_SOURCE_FOLDER +"="+ getProperty(AppParameters.GPX_SOURCE_FOLDER)); + System.out.println(" - param: "+ AppParameters.GPX_OVERWRITE_MAGVAR +"="+ getProperty(AppParameters.GPX_OVERWRITE_MAGVAR)); + System.out.println(" - param: "+ AppParameters.GPX_OUTPUT_SPEED +"="+ getProperty(AppParameters.GPX_OUTPUT_SPEED)); + System.out.println(" - param: "+ AppParameters.GPX_GPXSPLIT +"="+ isGpxSplit()); + System.out.println(" - param: "+ AppParameters.GPX_NO_FIRST_NODE +"="+ isGpxNoFirstNode()); + System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ isGpxReuse()); + } + + /** + * 基準時刻(ファイル更新日時 | EXIF撮影日時) + * @return boolean exifBase = false; + */ + public boolean isExifBase() { + return (getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")); + } + + /** + * IMG出力: IMGを出力する + * @return + */ + public boolean isImgOutput() { + String valueStr = getProperty(AppParameters.IMG_OUTPUT); + if ((valueStr != null) && valueStr.equals(Boolean.toString(true))) { + return true; + } + return false; + } + + public boolean isImgOutputExif() { + String valueStr = getProperty(AppParameters.IMG_OUTPUT_EXIF); + if ((valueStr != null) && valueStr.equals(Boolean.toString(true))) { + return true; + } + return false; + } + + /** + * AppParameters.IMG_SOURCE_FOLDER + * @return new File(getProperty(AppParameters.IMG_SOURCE_FOLDER)); + */ + public File getImgSourceFolder() { + return new File(getProperty(AppParameters.IMG_SOURCE_FOLDER)); + } + + public File getGpxSourceFolder() { + String str = getProperty(AppParameters.GPX_SOURCE_FOLDER); + if (str == null) { + return null; + } + if (str.isEmpty()) { + return null; + } + return new File(str); + } + + /** + * AppParameters.GPX_GPXSPLIT + * @return + */ + public boolean isGpxSplit() { + return isParam(AppParameters.GPX_GPXSPLIT); + } + + public boolean isGpxNoFirstNode() { + return isParam(AppParameters.GPX_NO_FIRST_NODE); + } + + public boolean isImgOutputAll() { + return isParam(AppParameters.IMG_OUTPUT_ALL); + } + + public boolean isGpxOverwriteMagvar() { + return isParam(AppParameters.GPX_OVERWRITE_MAGVAR); + } + + public void setGpxOverwriteMagvar(boolean v) { + this.setProperty(GPX_OVERWRITE_MAGVAR, String.valueOf(v)); + } + + public boolean isGpxOutputSpeed() { + return isParam(AppParameters.GPX_OUTPUT_SPEED); + } + + public boolean isGpxReuse() { + return isParam(AppParameters.GPX_REUSE); + } + + boolean isParam(String item) { + String valueStr = getProperty(item); + if ((valueStr != null) && valueStr.equals(Boolean.toString(true))) { + return true; + } + return false; + } } diff --git a/src/main/java/osm/jp/gpx/Complementation.java b/src/main/java/osm/jp/gpx/Complementation.java index f358fe4..4b5b878 100644 --- a/src/main/java/osm/jp/gpx/Complementation.java +++ b/src/main/java/osm/jp/gpx/Complementation.java @@ -7,8 +7,8 @@ public TagTrkpt imaTag = null; public TagTrkpt maeTag = null; - public static boolean param_GpxOutputSpeed = false; - public static boolean param_GpxOverwriteMagvar = false; + //public static boolean param_GpxOutputSpeed = false; + //public static boolean param_GpxOverwriteMagvar = false; /** * @param imaE diff --git a/src/main/java/osm/jp/gpx/ElementMapTRKPT.java b/src/main/java/osm/jp/gpx/ElementMapTRKPT.java index 0ef9948..2599ccd 100644 --- a/src/main/java/osm/jp/gpx/ElementMapTRKPT.java +++ b/src/main/java/osm/jp/gpx/ElementMapTRKPT.java @@ -7,9 +7,11 @@ @SuppressWarnings("serial") public class ElementMapTRKPT extends TreeMap { public static final long DIFF_MAE_TIME = 3000L; // before 3 secound + AppParameters params; - public ElementMapTRKPT() { + public ElementMapTRKPT(AppParameters params) { super(new TimeComparator()); + this.params = params; } /** @@ -48,12 +50,12 @@ // がなければ、 // 直前の位置と、現在地から進行方向を求める // 経度(longitude)と経度から進行方向を求める - if (Complementation.param_GpxOverwriteMagvar) { + if (params.isGpxOverwriteMagvar()) { comp.complementationMagvar(); } // 緯度・経度と時間差から速度(km/h)を求める - if (Complementation.param_GpxOutputSpeed) { + if (params.isGpxOutputSpeed()) { comp.complementationSpeed(); } //return (TagTrkpt)(comp.imaTag.trkpt.cloneNode(true)); diff --git a/src/main/java/osm/jp/gpx/GpxFile.java b/src/main/java/osm/jp/gpx/GpxFile.java index f3f1632..d8d5c2f 100644 --- a/src/main/java/osm/jp/gpx/GpxFile.java +++ b/src/main/java/osm/jp/gpx/GpxFile.java @@ -13,10 +13,13 @@ @SuppressWarnings("serial") public class GpxFile extends File { - GpxParser gpx = new GpxParser(); - - public GpxFile(File file) throws ParserConfigurationException, SAXException, IOException, ParseException { + GpxParser gpx; + AppParameters params; + + public GpxFile(AppParameters params, File file) throws ParserConfigurationException, SAXException, IOException, ParseException { super(file.getParentFile(), file.getName()); + this.params = params; + this.gpx = new GpxParser(params); } public ElementMapTRKSEG parse() throws ParserConfigurationException, SAXException, IOException { diff --git a/src/main/java/osm/jp/gpx/GpxParser.java b/src/main/java/osm/jp/gpx/GpxParser.java index 352621c..919c5c0 100644 --- a/src/main/java/osm/jp/gpx/GpxParser.java +++ b/src/main/java/osm/jp/gpx/GpxParser.java @@ -29,8 +29,16 @@ int kptCnt = 0; boolean kpt = false; TagTrkpt tag = null; - public ElementMapTRKPT trkpt = new ElementMapTRKPT(); + public ElementMapTRKPT trkpt; public ElementMapTRKSEG trkseg = new ElementMapTRKSEG(); + + AppParameters params; + + public GpxParser(AppParameters params) { + super(); + this.params = params; + trkpt = new ElementMapTRKPT(params); + } /** * ドキュメント開始 diff --git a/src/main/java/osm/jp/gpx/ImgFolder.java b/src/main/java/osm/jp/gpx/ImgFolder.java new file mode 100644 index 0000000..1f557c0 --- /dev/null +++ b/src/main/java/osm/jp/gpx/ImgFolder.java @@ -0,0 +1,434 @@ +package osm.jp.gpx; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.text.DecimalFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Comparator; +import java.util.Date; +import java.util.Map; +import java.util.TimeZone; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.ImageWriteException; +import org.apache.commons.imaging.Imaging; +import org.apache.commons.imaging.common.ImageMetadata; +import org.apache.commons.imaging.common.RationalNumber; +import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; +import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; +import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; +import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; +import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; +import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; +import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; +import org.xml.sax.SAXException; + +public class ImgFolder extends ArrayList { + File[] imgfiles; + AppParameters params; + File imgDir; + File outDir; + + public ImgFolder(AppParameters params) { + this.params = params; + imgDir = params.getImgSourceFolder(); + imgfiles = imgDir.listFiles(new JpegFileFilter()); + Arrays.sort(imgfiles, new FileSort()); + } + + public ImgFolder setParams(AppParameters params) { + this.params = params; + return this; + } + + public void setOutDir(File outDir) { + this.outDir = outDir; + } + + public File getImgDir() { + return this.imgDir; + } + + public File getImgBaseFile() { + return new File(imgDir, params.getProperty(AppParameters.IMG_BASE_FILE)); + } + + /** + * 個別のGPXファイルを処理する + * + * @throws ParserConfigurationException + * @throws IOException + * @throws SAXException + * @throws ParseException + * @throws ImageWriteException + * @throws ImageReadException + * @throws TransformerException + */ + void procGPXfile(GpxFile gpxFile) throws ParserConfigurationException, SAXException, IOException, ParseException, ImageReadException, ImageWriteException, TransformerException { + System.gc(); + + ElementMapTRKSEG seg = gpxFile.parse(); + + long delta = 0; + String timeStr = params.getProperty(AppParameters.IMG_TIME); + try { + Date t = ImportPicture.toUTCDate(timeStr); + + // 基準時刻ファイルの「更新日時」を使って時刻合わせを行う。 + // argv[1] --> AppParameters.IMG_BASE_FILE に置き換え + Date imgtime = adjustTime(getImgBaseFile()); + delta = t.getTime() - imgtime.getTime(); + } + catch (ParseException e) { + // "'%s'の書式が違います(%s)" + System.out.println( + String.format( + ImportPicture.i18n.getString("msg.130"), + timeStr, + ImportPicture.TIME_FORMAT_STRING + ) + ); + return; + } + + + System.out.println("time difference: "+ (delta / 1000) +"(sec)"); + System.out.println(" Target GPX: ["+ gpxFile.getAbsolutePath() +"]"); + System.out.println(" EXIF: "+ (params.isImgOutputExif() ? ("convert to '" + outDir.getAbsolutePath() +"'") : "off")); + System.out.println(); + + // imgDir内の画像ファイルを処理する + System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); + System.out.println("| name | Camera Time | GPStime | Latitude | Longitude | ele |magvar| km/h |"); + System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); + + proc(delta, seg, params.isImgOutputExif(), gpxFile); + + System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); + } + + /** + * 再帰メソッド + * @throws ParseException + * @throws IOException + * @throws ImageReadException + * @throws ImageWriteException + */ + boolean proc(long delta, ElementMapTRKSEG mapTRKSEG, boolean exifWrite, GpxFile gpxFile) throws ParseException, ImageReadException, IOException, ImageWriteException { + boolean ret = false; + for (File image : imgfiles) { + System.out.print(String.format("|%-32s|", image.getName())); + if (image.isDirectory()) { + ret = (new ImgFolder(params)).proc(delta, mapTRKSEG, exifWrite, gpxFile); + continue; + } + + String imageName = image.getName(); + if (!checkFile(imageName)) { + System.out.println(String.format("%20s ", "it is not image file.")); + continue; + } + + Discripter result = procImageFile(image, delta, mapTRKSEG, exifWrite, gpxFile); + ret |= result.ret; + switch (result.control) { + case Discripter.CONTINUE: + continue; + case Discripter.BREAK: + break; + } + } + return ret; + } + + Discripter procImageFile(File imageFile, long delta, ElementMapTRKSEG mapTRKSEG, boolean exifWrite, GpxFile gpxFile) throws ParseException, ImageReadException, IOException, ImageWriteException { + Discripter result = new Discripter(false); + + // itime <-- 画像ファイルの撮影時刻 + // ファイルの更新日時/EXIFの撮影日時 + Date itime = new Date(imageFile.lastModified()); + if (params.isExifBase()) { + // 基準時刻(EXIF撮影日時) + ImageMetadata meta = Imaging.getMetadata(imageFile); + JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; + if (jpegMetadata == null) { + // "'%s'にEXIF情報がありません" + System.out.println( + String.format( + ImportPicture.i18n.getString("msg.140"), + imageFile.getAbsolutePath() + ) + ); + result.control = Discripter.CONTINUE; + return result; + } + TiffImageMetadata exif = jpegMetadata.getExif(); + if (exif == null) { + // "'%s'にEXIF情報がありません" + System.out.println( + String.format( + ImportPicture.i18n.getString("msg.140"), + imageFile.getAbsolutePath() + ) + ); + result.control = Discripter.CONTINUE; + return result; + } + String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]; + itime = ImportPicture.toEXIFDate(dateTimeOriginal); + } + System.out.print(String.format("%20s|", ImportPicture.toUTCString(itime))); + + // uktime <-- 画像撮影時刻に対応するGPX時刻(補正日時) + Date correctedtime = new Date(itime.getTime() + delta); + System.out.print(String.format("%20s|", ImportPicture.toUTCString(correctedtime))); + + // 時刻uktimeにおけるをtrkptに追加する + String eleStr = "-"; + String magvarStr = "-"; + String speedStr = "-"; + TagTrkpt trkptT = null; + + for (Map.Entry map : mapTRKSEG.entrySet()) { + ElementMapTRKPT mapTRKPT = map.getValue(); + trkptT = mapTRKPT.getValue(correctedtime); + if (trkptT != null) { + break; + } + } + + if (trkptT == null) { + System.out.print(String.format("%-14s|%-14s|", "", "")); + System.out.println(String.format("%8s|%6s|%6s|", "", "", "")); + if (!params.isImgOutputAll()) { + result.control = Discripter.CONTINUE; + return result; + } + } + else { + double latitude = trkptT.lat; + double longitude = trkptT.lon; + + if (trkptT.eleStr != null) { + eleStr = trkptT.eleStr; + } + + if (trkptT.magvarStr != null) { + magvarStr = trkptT.magvarStr; + } + + if (trkptT.speedStr != null) { + speedStr = trkptT.speedStr; + } + System.out.print(String.format("%14.10f|%14.10f|", latitude, longitude)); + System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); + } + + result.ret = true; + outDir.mkdir(); + + if (exifWrite) { + exifWrite(imageFile, correctedtime, trkptT); + } + else { + if (params.isImgOutputAll()) { + // EXIFの変換を伴わない単純なファイルコピー + FileInputStream sStream = new FileInputStream(imageFile); + FileInputStream dStream = new FileInputStream(new File(outDir, imageFile.getName())); + FileChannel srcChannel = sStream.getChannel(); + FileChannel destChannel = dStream.getChannel(); + try { + srcChannel.transferTo(0, srcChannel.size(), destChannel); + } + finally { + srcChannel.close(); + destChannel.close(); + sStream.close(); + dStream.close(); + } + } + } + result.control = Discripter.NEXT; + return result; + } + + void exifWrite(File imageFile, Date correctedtime, TagTrkpt trkptT) throws ImageReadException, IOException, ImageWriteException { + DecimalFormat yearFormatter = new DecimalFormat("0000"); + DecimalFormat monthFormatter = new DecimalFormat("00"); + DecimalFormat dayFormatter = new DecimalFormat("00"); + + TiffOutputSet outputSet = null; + + ImageMetadata meta = Imaging.getMetadata(imageFile); + JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; + if (jpegMetadata != null) { + TiffImageMetadata exif = jpegMetadata.getExif(); + if (exif != null) { + outputSet = exif.getOutputSet(); + } + } + + if (outputSet == null) { + outputSet = new TiffOutputSet(); + } + + //---- EXIF_TAG_DATE_TIME_ORIGINAL / 「撮影日時/オリジナル画像の生成日時」---- + TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory(); + { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + cal.setTime(correctedtime); + exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); + exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, ImportPicture.toEXIFString(cal.getTime())); + } + + //---- EXIF GPS_TIME_STAMP ---- + TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory(); + { + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + cal.setTimeZone(TimeZone.getTimeZone("GMT+00")); + cal.setTime(correctedtime); + final String yearStr = yearFormatter.format(cal.get(Calendar.YEAR)); + final String monthStr = monthFormatter.format(cal.get(Calendar.MONTH) + 1); + final String dayStr = dayFormatter.format(cal.get(Calendar.DAY_OF_MONTH)); + final String dateStamp = yearStr +":"+ monthStr +":"+ dayStr; + + gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_TIME_STAMP); + gpsDir.add( + GpsTagConstants.GPS_TAG_GPS_TIME_STAMP, + RationalNumber.valueOf(cal.get(Calendar.HOUR_OF_DAY)), + RationalNumber.valueOf(cal.get(Calendar.MINUTE)), + RationalNumber.valueOf(cal.get(Calendar.SECOND)) + ); + gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP); + gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, dateStamp); + } + + if (trkptT != null) { + //---- EXIF GPS elevation/ALTITUDE ---- + if (trkptT.eleStr != null) { + final double altitude = Double.parseDouble(trkptT.eleStr); + gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); + gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, RationalNumber.valueOf(altitude)); + } + + //---- EXIF GPS magvar/IMG_DIRECTION ---- + if (trkptT.magvarStr != null) { + final double magvar = Double.parseDouble(trkptT.magvarStr); + gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); + gpsDir.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(magvar)); + } + + //---- EXIF GPS_ ---- + outputSet.setGPSInDegrees(trkptT.lon, trkptT.lat); + } + + ExifRewriter rewriter = new ExifRewriter(); + try (FileOutputStream fos = new FileOutputStream(new File(outDir, imageFile.getName()))) { + rewriter.updateExifMetadataLossy(imageFile, fos, outputSet); + } + } + + /** + * 基準時刻ファイルの「更新日時」を使って時刻合わせを行う。 + * @param baseFile = new File(this.imgDir, this.params.getProperty(AppParameters.IMG_BASE_FILE)); + * @return + * @throws ImageReadException + * @throws IOException + * @throws ParseException + */ + private Date adjustTime(File baseFile) throws ImageReadException, IOException, ParseException { + if (params.isExifBase()) { + // 基準時刻(EXIF撮影日時) + ImageMetadata meta = Imaging.getMetadata(baseFile); + JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; + if (jpegMetadata == null) { + // "'%s'にEXIF情報がありません" + System.out.println( + String.format( + ImportPicture.i18n.getString("msg.140"), + baseFile.getAbsolutePath() + ) + ); + return null; + } + TiffImageMetadata exif = jpegMetadata.getExif(); + if (exif == null) { + // "'%s'にEXIF情報がありません" + System.out.println( + String.format( + ImportPicture.i18n.getString("msg.140"), + baseFile.getAbsolutePath() + ) + ); + return null; + } + String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]; + return new Date(ImportPicture.toEXIFDate(dateTimeOriginal).getTime()); + } + else { + // 基準時刻(ファイル更新日時) + return new Date(baseFile.lastModified()); + } + } + + /** + * 対象は '*.JPG' のみ対象とする + * @return + * @param name + */ + public static boolean checkFile(String name) { + return ((name != null) && name.toUpperCase().endsWith(".JPG")); + } + + + private static final long serialVersionUID = -1137199371724546343L; + + class Discripter { + static final int NEXT = 0; + static final int CONTINUE = -1; + static final int BREAK = 1; + + public boolean ret; + public int control; + public Discripter(boolean ret) { + this.ret = ret; + this.control = Discripter.NEXT; + } + } + + /** + * ファイル名の順序に並び替えるためのソートクラス + * + * @author hayashi + */ + static class FileSort implements Comparator { + @Override + public int compare(File src, File target){ + int diff = src.getName().compareTo(target.getName()); + return diff; + } + } + + /** + * JPEGファイルフィルター + * @author yuu + */ + class JpegFileFilter implements FilenameFilter { + @Override + public boolean accept(File dir, String name) { + return name.toUpperCase().matches(".*\\.JPG$"); + } + } + +} diff --git a/src/main/java/osm/jp/gpx/ImportPicture.java b/src/main/java/osm/jp/gpx/ImportPicture.java index 3728821..9cacf81 100644 --- a/src/main/java/osm/jp/gpx/ImportPicture.java +++ b/src/main/java/osm/jp/gpx/ImportPicture.java @@ -1,17 +1,11 @@ package osm.jp.gpx; import java.io.*; -import java.nio.channels.FileChannel; import java.text.DateFormat; -import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Comparator; import java.util.Date; -import java.util.Map; import java.util.ResourceBundle; import java.util.TimeZone; import java.util.logging.LogManager; @@ -22,16 +16,6 @@ import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.ImageWriteException; -import org.apache.commons.imaging.Imaging; -import org.apache.commons.imaging.common.ImageMetadata; -import org.apache.commons.imaging.common.RationalNumber; -import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; -import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter; -import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; -import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants; -import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants; -import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory; -import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet; import org.xml.sax.SAXException; public class ImportPicture extends Thread { @@ -100,99 +84,36 @@ } public File gpxDir; - public File imgDir; - public File outDir; - public long delta = 0; - public boolean exif = false; - public boolean exifBase = false; + public ImgFolder imgFolder; + //public File outDir; public ArrayList gpxFiles = new ArrayList<>(); public AppParameters params; - public boolean param_GpxSplit = false; - public static boolean param_GpxNoFirstNode = false; - public boolean param_GpxReuse = false; - public boolean param_GpxOutputWpt = true; - public boolean param_ImgOutputAll = false; - public String param_GpxSourceFolder = "."; - public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'"; private static final String EXIF_DATE_TIME_FORMAT_STRING = "yyyy:MM:dd HH:mm:ss"; - public ResourceBundle i18n = ResourceBundle.getBundle("i18n"); + public static final ResourceBundle i18n = ResourceBundle.getBundle("i18n"); public void setUp(String paramFilePath) throws Exception { System.out.println("Param File = '"+ paramFilePath +"'"); this.params = new AppParameters(paramFilePath); - - Date imgtime; - - System.out.println(" - param: "+ AppParameters.IMG_TIME +"="+ this.params.getProperty(AppParameters.IMG_TIME) ); - System.out.println(" - param: "+ AppParameters.IMG_BASE_FILE +"="+ this.params.getProperty(AppParameters.IMG_BASE_FILE) ); - System.out.println(" - param: "+ AppParameters.GPX_BASETIME +"="+ this.params.getProperty(AppParameters.GPX_BASETIME) ); - System.out.println(" - param: "+ AppParameters.IMG_SOURCE_FOLDER +"="+ this.params.getProperty(AppParameters.IMG_SOURCE_FOLDER) ); - System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_FOLDER +"="+ this.params.getProperty(AppParameters.IMG_OUTPUT_FOLDER) ); - System.out.println(" - param: "+ AppParameters.IMG_OUTPUT +"="+ this.params.getProperty(AppParameters.IMG_OUTPUT)); - System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_ALL +"="+ this.param_ImgOutputAll); - System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_EXIF +"= "+ String.valueOf(this.exif)); - System.out.println(" - param: "+ AppParameters.GPX_SOURCE_FOLDER +"="+ this.params.getProperty(AppParameters.GPX_SOURCE_FOLDER) ); - System.out.println(" - param: "+ AppParameters.GPX_OVERWRITE_MAGVAR +"="+ Complementation.param_GpxOverwriteMagvar); - System.out.println(" - param: "+ AppParameters.GPX_OUTPUT_SPEED +"="+ Complementation.param_GpxOutputSpeed); - System.out.println(" - param: "+ AppParameters.GPX_GPXSPLIT +"="+ this.param_GpxSplit); - System.out.println(" - param: "+ AppParameters.GPX_NO_FIRST_NODE +"="+ ImportPicture.param_GpxNoFirstNode); + params.printout(); this.ex = null; - // argv[0] --> AppParameters.IMG_SOURCE_FOLDER に置き換え - this.imgDir = new File(this.params.getProperty(AppParameters.IMG_SOURCE_FOLDER)); - - // 基準時刻(ファイル更新日時 | EXIF撮影日時) - this.exifBase = (this.params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")); - - // 基準時刻ファイルの「更新日時」を使って時刻合わせを行う。 - // argv[1] --> AppParameters.IMG_BASE_FILE に置き換え - imgtime = this.adjustTime(new File(this.imgDir, this.params.getProperty(AppParameters.IMG_BASE_FILE))); - - // 出力ファイル - // argv[3] --> AppParameters.IMG_OUTPUT に置き換え - this.outDir = new File(this.params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); - - // その他のパラメータを読み取る - String paramStr = this.params.getProperty(AppParameters.GPX_GPXSPLIT); - if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { - this.param_GpxSplit = true; - } - paramStr = this.params.getProperty(AppParameters.GPX_NO_FIRST_NODE); - if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { - ImportPicture.param_GpxNoFirstNode = true; - } - - paramStr = this.params.getProperty(AppParameters.IMG_OUTPUT_ALL); - if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { - this.param_ImgOutputAll = true; - } - - paramStr = this.params.getProperty(AppParameters.GPX_OVERWRITE_MAGVAR); - if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { - Complementation.param_GpxOverwriteMagvar = true; - } - - paramStr = this.params.getProperty(AppParameters.GPX_OUTPUT_SPEED); - if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { - Complementation.param_GpxOutputSpeed = true; - } - - paramStr = this.params.getProperty(AppParameters.GPX_SOURCE_FOLDER); - if (paramStr != null) { - this.param_GpxSourceFolder = paramStr; - this.gpxDir = new File(this.param_GpxSourceFolder); + // AppParameters.IMG_SOURCE_FOLDER に置き換え + imgFolder = new ImgFolder(params); + + this.gpxDir = params.getGpxSourceFolder(); + if (this.gpxDir != null) { if (!this.gpxDir.exists()) { // GPXファイルまたはディレクトリが存在しません。('%s') System.out.println( - String.format(i18n.getString("msg.100"), paramStr) + String.format(i18n.getString("msg.100"), gpxDir.getAbsolutePath()) ); return; } } else { - this.gpxDir = this.imgDir; + this.gpxDir = imgFolder.getImgDir(); } // 指定されたディレクトリ内のGPXファイルすべてを対象とする @@ -205,7 +126,7 @@ ); return; } - if (this.param_ImgOutputAll && (files.length > 1)) { + if (params.isImgOutputAll() && (files.length > 1)) { // "複数のGPXファイルがあるときには、'IMG.OUTPUT_ALL'オプションは指定できません。" System.out.println( i18n.getString("msg.120") @@ -225,7 +146,7 @@ if (file.isFile()) { String filename = file.getName().toUpperCase(); if (filename.toUpperCase().endsWith(".GPX")) { - if (!filename.toUpperCase().endsWith("_.GPX") || this.param_GpxReuse) { + if (!filename.toUpperCase().endsWith("_.GPX") || params.isGpxReuse()) { this.gpxFiles.add(file); } } @@ -235,28 +156,17 @@ else { this.gpxFiles.add(this.gpxDir); } - - paramStr = this.params.getProperty(AppParameters.IMG_OUTPUT_EXIF); - if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { - this.exif = true; - } - - String timeStr = this.params.getProperty(AppParameters.IMG_TIME); - try { - Date t = toUTCDate(timeStr); - this.delta = t.getTime() - imgtime.getTime(); + + // 出力ファイル + // AppParameters.IMG_OUTPUT に置き換え + File outDir = new File(params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)); + if (params.isImgOutput()) { + outDir = new File(outDir, imgFolder.getImgDir().getName()); } - catch (ParseException e) { - // "'%s'の書式が違います(%s)" - System.out.println( - String.format( - i18n.getString("msg.130"), - timeStr, - TIME_FORMAT_STRING - ) - ); - return; + else { + outDir = gpxDir; } + imgFolder.setOutDir(outDir); this.start(); try { @@ -285,14 +195,8 @@ @Override public void run() { try { - if (params.getProperty(AppParameters.IMG_OUTPUT).equals(Boolean.toString(true))) { - outDir = new File(outDir, imgDir.getName()); - } - else { - outDir = gpxDir; - } for (File gpxFile : this.gpxFiles) { - procGPXfile(new GpxFile(gpxFile)); + imgFolder.procGPXfile(new GpxFile(params, gpxFile)); } } catch(ParserConfigurationException | SAXException | IOException | ParseException | ImageReadException | ImageWriteException | IllegalArgumentException | TransformerException e) { @@ -301,317 +205,25 @@ } } - /** - * 個別のGPXファイルを処理する - * - * @throws ParserConfigurationException - * @throws IOException - * @throws SAXException - * @throws ParseException - * @throws ImageWriteException - * @throws ImageReadException - * @throws TransformerException - */ - void procGPXfile(GpxFile gpxFile) throws ParserConfigurationException, SAXException, IOException, ParseException, ImageReadException, ImageWriteException, TransformerException { - System.gc(); - - ElementMapTRKSEG seg = gpxFile.parse(); + + + + + public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - System.out.println("time difference: "+ (delta / 1000) +"(sec)"); - System.out.println(" Target GPX: ["+ gpxFile.getAbsolutePath() +"]"); - System.out.println(" EXIF: "+ (exif ? ("convert to '" + outDir.getAbsolutePath() +"'") : "off")); - System.out.println(); + public static Date toUTCDate(String timeStr) throws ParseException { + DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); + dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); + return dfUTC.parse(timeStr); + } - // imgDir内の画像ファイルを処理する - System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); - System.out.println("| name | Camera Time | GPStime | Latitude | Longitude | ele |magvar| km/h |"); - System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); - proc(imgDir, delta, seg, exif, gpxFile); - System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); + public static String toUTCString(Date localdate) { + DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); + dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); + return dfUTC.format(localdate); } /** - * 再帰メソッド - * @throws ParseException - * @throws IOException - * @throws ImageReadException - * @throws ImageWriteException - */ - boolean proc(File imgDir, long delta, ElementMapTRKSEG mapTRKSEG, boolean exifWrite, GpxFile gpxFile) throws ParseException, ImageReadException, IOException, ImageWriteException { - boolean ret = false; - File[] imgfiles = imgDir.listFiles(new JpegFileFilter()); - Arrays.sort(imgfiles, new FileSort()); - for (File image : imgfiles) { - System.out.print(String.format("|%-32s|", image.getName())); - if (image.isDirectory()) { - ret = proc(image, delta, mapTRKSEG, exifWrite, gpxFile); - continue; - } - - String imageName = image.getName(); - if (!checkFile(imageName)) { - System.out.println(String.format("%20s ", "it is not image file.")); - continue; - } - - Discripter result = procImageFile(image, delta, mapTRKSEG, exifWrite, gpxFile); - ret |= result.ret; - switch (result.control) { - case Discripter.CONTINUE: - continue; - case Discripter.BREAK: - break; - } - } - return ret; - } - - class Discripter { - static final int NEXT = 0; - static final int CONTINUE = -1; - static final int BREAK = 1; - - public boolean ret; - public int control; - public Discripter(boolean ret) { - this.ret = ret; - this.control = Discripter.NEXT; - } - } - - Discripter procImageFile(File imageFile, long delta, ElementMapTRKSEG mapTRKSEG, boolean exifWrite, GpxFile gpxFile) throws ParseException, ImageReadException, IOException, ImageWriteException { - Discripter result = new Discripter(false); - - // itime <-- 画像ファイルの撮影時刻 - // ファイルの更新日時/EXIFの撮影日時 - Date itime = new Date(imageFile.lastModified()); - if (this.exifBase) { - ImageMetadata meta = Imaging.getMetadata(imageFile); - JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; - if (jpegMetadata == null) { - // "'%s'にEXIF情報がありません" - System.out.println( - String.format( - i18n.getString("msg.140"), - imageFile.getAbsolutePath() - ) - ); - result.control = Discripter.CONTINUE; - return result; - } - TiffImageMetadata exif = jpegMetadata.getExif(); - if (exif == null) { - // "'%s'にEXIF情報がありません" - System.out.println( - String.format( - i18n.getString("msg.140"), - imageFile.getAbsolutePath() - ) - ); - result.control = Discripter.CONTINUE; - return result; - } - String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]; - itime = ImportPicture.toEXIFDate(dateTimeOriginal); - } - System.out.print(String.format("%20s|", toUTCString(itime))); - - // uktime <-- 画像撮影時刻に対応するGPX時刻(補正日時) - Date correctedtime = new Date(itime.getTime() + delta); - System.out.print(String.format("%20s|", toUTCString(correctedtime))); - - // 時刻uktimeにおけるをtrkptに追加する - String eleStr = "-"; - String magvarStr = "-"; - String speedStr = "-"; - TagTrkpt trkptT = null; - - for (Map.Entry map : mapTRKSEG.entrySet()) { - ElementMapTRKPT mapTRKPT = map.getValue(); - trkptT = mapTRKPT.getValue(correctedtime); - if (trkptT != null) { - break; - } - } - - if (trkptT == null) { - System.out.print(String.format("%-14s|%-14s|", "", "")); - System.out.println(String.format("%8s|%6s|%6s|", "", "", "")); - if (!this.param_ImgOutputAll) { - result.control = Discripter.CONTINUE; - return result; - } - } - else { - double latitude = trkptT.lat; - double longitude = trkptT.lon; - - if (trkptT.eleStr != null) { - eleStr = trkptT.eleStr; - } - - if (trkptT.magvarStr != null) { - magvarStr = trkptT.magvarStr; - } - - if (trkptT.speedStr != null) { - speedStr = trkptT.speedStr; - } - System.out.print(String.format("%14.10f|%14.10f|", latitude, longitude)); - System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); - } - - result.ret = true; - outDir.mkdir(); - - if (exifWrite) { - exifWrite(imageFile, correctedtime, trkptT); - } - else { - if (this.param_ImgOutputAll) { - // EXIFの変換を伴わない単純なファイルコピー - FileInputStream sStream = new FileInputStream(imageFile); - FileInputStream dStream = new FileInputStream(new File(outDir, imageFile.getName())); - FileChannel srcChannel = sStream.getChannel(); - FileChannel destChannel = dStream.getChannel(); - try { - srcChannel.transferTo(0, srcChannel.size(), destChannel); - } - finally { - srcChannel.close(); - destChannel.close(); - sStream.close(); - dStream.close(); - } - } - } - result.control = Discripter.NEXT; - return result; - } - - void exifWrite(File imageFile, Date correctedtime, TagTrkpt trkptT) throws ImageReadException, IOException, ImageWriteException { - DecimalFormat yearFormatter = new DecimalFormat("0000"); - DecimalFormat monthFormatter = new DecimalFormat("00"); - DecimalFormat dayFormatter = new DecimalFormat("00"); - - TiffOutputSet outputSet = null; - - ImageMetadata meta = Imaging.getMetadata(imageFile); - JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; - if (jpegMetadata != null) { - TiffImageMetadata exif = jpegMetadata.getExif(); - if (exif != null) { - outputSet = exif.getOutputSet(); - } - } - - if (outputSet == null) { - outputSet = new TiffOutputSet(); - } - - //---- EXIF_TAG_DATE_TIME_ORIGINAL / 「撮影日時/オリジナル画像の生成日時」---- - TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory(); - { - Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("UTC")); - cal.setTime(correctedtime); - exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); - exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, ImportPicture.toEXIFString(cal.getTime())); - } - - //---- EXIF GPS_TIME_STAMP ---- - TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory(); - { - Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - cal.setTimeZone(TimeZone.getTimeZone("GMT+00")); - cal.setTime(correctedtime); - final String yearStr = yearFormatter.format(cal.get(Calendar.YEAR)); - final String monthStr = monthFormatter.format(cal.get(Calendar.MONTH) + 1); - final String dayStr = dayFormatter.format(cal.get(Calendar.DAY_OF_MONTH)); - final String dateStamp = yearStr +":"+ monthStr +":"+ dayStr; - - gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_TIME_STAMP); - gpsDir.add( - GpsTagConstants.GPS_TAG_GPS_TIME_STAMP, - RationalNumber.valueOf(cal.get(Calendar.HOUR_OF_DAY)), - RationalNumber.valueOf(cal.get(Calendar.MINUTE)), - RationalNumber.valueOf(cal.get(Calendar.SECOND)) - ); - gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP); - gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, dateStamp); - } - - if (trkptT != null) { - //---- EXIF GPS elevation/ALTITUDE ---- - if (trkptT.eleStr != null) { - final double altitude = Double.parseDouble(trkptT.eleStr); - gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); - gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, RationalNumber.valueOf(altitude)); - } - - //---- EXIF GPS magvar/IMG_DIRECTION ---- - if (trkptT.magvarStr != null) { - final double magvar = Double.parseDouble(trkptT.magvarStr); - gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); - gpsDir.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(magvar)); - } - - //---- EXIF GPS_ ---- - outputSet.setGPSInDegrees(trkptT.lon, trkptT.lat); - } - - ExifRewriter rewriter = new ExifRewriter(); - try (FileOutputStream fos = new FileOutputStream(new File(outDir, imageFile.getName()))) { - rewriter.updateExifMetadataLossy(imageFile, fos, outputSet); - } - } - - // 基準時刻ファイルの「更新日時」を使って時刻合わせを行う。 - // argv[1] --> AppParameters.IMG_BASE_FILE に置き換え - // File baseFile = new File(this.imgDir, this.params.getProperty(AppParameters.IMG_BASE_FILE)); - private Date adjustTime(File baseFile) throws ImageReadException, IOException, ParseException { - if (exifBase) { - ImageMetadata meta = Imaging.getMetadata(baseFile); - JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; - if (jpegMetadata == null) { - // "'%s'にEXIF情報がありません" - System.out.println( - String.format( - i18n.getString("msg.140"), - baseFile.getAbsolutePath() - ) - ); - return null; - } - TiffImageMetadata exif = jpegMetadata.getExif(); - if (exif == null) { - // "'%s'にEXIF情報がありません" - System.out.println( - String.format( - i18n.getString("msg.140"), - baseFile.getAbsolutePath() - ) - ); - return null; - } - String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]; - return new Date(ImportPicture.toEXIFDate(dateTimeOriginal).getTime()); - } - else { - return new Date(baseFile.lastModified()); - } - } - - /** - * 対象は '*.JPG' のみ対象とする - * @return - * @param name - */ - public static boolean checkFile(String name) { - return ((name != null) && name.toUpperCase().endsWith(".JPG")); - } - - /** * DateをEXIFの文字列に変換する。 * 注意:EXiFの撮影時刻はUTC時間ではない * @param localdate @@ -635,18 +247,6 @@ return dfUTC.parse(timeStr); } - public static String toUTCString(Date localdate) { - DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); - dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.format(localdate); - } - - public static Date toUTCDate(String timeStr) throws ParseException { - DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); - dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.parse(timeStr); - } - static String getShortPathName(File dir, File iFile) { String dirPath = dir.getAbsolutePath(); String filePath = iFile.getAbsolutePath(); @@ -657,28 +257,4 @@ return filePath; } } - - /** - * ファイル名の順序に並び替えるためのソートクラス - * - * @author hayashi - */ - static class FileSort implements Comparator { - @Override - public int compare(File src, File target){ - int diff = src.getName().compareTo(target.getName()); - return diff; - } - } - - /** - * JPEGファイルフィルター - * @author yuu - */ - class JpegFileFilter implements FilenameFilter { - @Override - public boolean accept(File dir, String name) { - return name.toUpperCase().matches(".*\\.JPG$"); - } - } } \ No newline at end of file diff --git a/src/test/java/osm/jp/gpx/ElementMapTRKPTTest.java b/src/test/java/osm/jp/gpx/ElementMapTRKPTTest.java index e99a9e1..f034fda 100644 --- a/src/test/java/osm/jp/gpx/ElementMapTRKPTTest.java +++ b/src/test/java/osm/jp/gpx/ElementMapTRKPTTest.java @@ -32,7 +32,7 @@ @Before public void setUp() throws Exception { timeL = (sdf.parse("2018-10-25 08:00:00.000")).getTime(); - map = new ElementMapTRKPT(); + map = new ElementMapTRKPT(new AppParameters(AppParameters.FILE_PATH)); map.put(new Date(timeL), null); // 5-6: 2018-10-25 08:00:00.000 map.put(new Date(timeL + 1L), null); // 7: 2018-10-25 08:00:00.001 map.put(new Date(timeL - 1L), null); // 4: 2018-10-25 07:59:59.999 @@ -97,9 +97,10 @@ @Before public void setUp() throws Exception { - Complementation.param_GpxOverwriteMagvar = true; + AppParameters params = new AppParameters(AppParameters.FILE_PATH); + params.setGpxOverwriteMagvar(true); - map = new ElementMapTRKPT(); + map = new ElementMapTRKPT(params); for (int cnt = values.length; cnt > 0; cnt--) { map.put(createElement(values[cnt - 1])); } diff --git a/src/test/java/osm/jp/gpx/ElementMapTRKSEGTest.java b/src/test/java/osm/jp/gpx/ElementMapTRKSEGTest.java index 691ec14..ec41464 100644 --- a/src/test/java/osm/jp/gpx/ElementMapTRKSEGTest.java +++ b/src/test/java/osm/jp/gpx/ElementMapTRKSEGTest.java @@ -56,7 +56,7 @@ public void TRKSEGを読み込む(Fixture dataset) { try { System.out.println("GPX file: "+ dataset.gpxSourcePath); - GpxFile gpx = new GpxFile(new File(dataset.gpxSourcePath)); + GpxFile gpx = new GpxFile(new AppParameters(AppParameters.FILE_PATH), new File(dataset.gpxSourcePath)); gpx.parse(); assertThat(gpx.gpx.trkseg.size(), is(dataset.segCount)); for (Date key : gpx.gpx.trkseg.keySet()) { @@ -73,7 +73,7 @@ String gpxSourcePath = "src/test/data/2020-02-29 13.35.58 Day.gpx"; try { System.out.println("GPX file: "+ gpxSourcePath); - GpxFile gpx = new GpxFile(new File(gpxSourcePath)); + GpxFile gpx = new GpxFile(new AppParameters(AppParameters.FILE_PATH), new File(gpxSourcePath)); gpx.parse(); ElementMapTRKSEG seg = gpx.gpx.trkseg; assertTrue(seg.size() == 1);