X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fload%2FJpegLoader.java;h=a2453bec57a071d8e7abb4c85c1e4b623c31bf64;hp=e6917c1a48c2500f846e78cdd1338a97f000e3c0;hb=da0b1f449260a0b4a94318006382a9039726ef3e;hpb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b diff --git a/tim/prune/load/JpegLoader.java b/tim/prune/load/JpegLoader.java index e6917c1..a2453be 100644 --- a/tim/prune/load/JpegLoader.java +++ b/tim/prune/load/JpegLoader.java @@ -3,7 +3,7 @@ package tim.prune.load; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; -import java.util.ArrayList; +import java.util.TreeSet; import javax.swing.BorderFactory; import javax.swing.BoxLayout; @@ -45,7 +45,7 @@ public class JpegLoader implements Runnable private JProgressBar _progressBar = null; private int[] _fileCounts = null; private boolean _cancelled = false; - private ArrayList _photos = null; + private TreeSet _photos = null; /** @@ -128,7 +128,7 @@ public class JpegLoader implements Runnable { // Initialise arrays, errors, summaries _fileCounts = new int[4]; // files, jpegs, exifs, gps - _photos = new ArrayList(); + _photos = new TreeSet(new PhotoSorter()); File[] files = _fileChooser.getSelectedFiles(); // Loop recursively over selected files/directories to count files int numFiles = countFileList(files, true, _subdirCheckbox.isSelected()); @@ -244,9 +244,9 @@ public class JpegLoader implements Runnable {_fileCounts[2]++;} // exif found if (jpegData.isValid()) { - if (jpegData.getDatestamp() != null && jpegData.getTimestamp() != null) + if (jpegData.getGpsDatestamp() != null && jpegData.getGpsTimestamp() != null) { - photo.setTimestamp(createTimestamp(jpegData.getDatestamp(), jpegData.getTimestamp())); + photo.setTimestamp(createTimestamp(jpegData.getGpsDatestamp(), jpegData.getGpsTimestamp())); } // Make DataPoint and attach to Photo DataPoint point = createDataPoint(jpegData); @@ -255,6 +255,12 @@ public class JpegLoader implements Runnable photo.setOriginalStatus(PhotoStatus.TAGGED); _fileCounts[3]++; } + // Use exif timestamp if gps timestamp not available + if (photo.getTimestamp() == null && jpegData.getOriginalTimestamp() != null) + { + photo.setTimestamp(createTimestamp(jpegData.getOriginalTimestamp())); + } + photo.setExifThumbnail(jpegData.getThumbnailImage()); } catch (JpegException jpe) { // don't list errors, just count them } @@ -367,6 +373,28 @@ public class JpegLoader implements Runnable } + /** + * Use the given String value to create a timestamp + * @param inStamp timestamp from exif + * @return Timestamp object corresponding to input + */ + private static Timestamp createTimestamp(String inStamp) + { + Timestamp stamp = null; + try + { + stamp = new Timestamp(Integer.parseInt(inStamp.substring(0, 4)), + Integer.parseInt(inStamp.substring(5, 7)), + Integer.parseInt(inStamp.substring(8, 10)), + Integer.parseInt(inStamp.substring(11, 13)), + Integer.parseInt(inStamp.substring(14, 16)), + Integer.parseInt(inStamp.substring(17))); + } + catch (NumberFormatException nfe) {} + return stamp; + } + + /** * Check whether to accept the given filename * @param inName name of file