source: josm/trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java@ 12279

Last change on this file since 12279 was 12279, checked in by Don-vip, 7 years ago

sonar - squid:S3878 - Arrays should not be created for varargs parameters

  • Property svn:eol-style set to native
File size: 48.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.geoimage;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.awt.BorderLayout;
8import java.awt.Cursor;
9import java.awt.Dimension;
10import java.awt.FlowLayout;
11import java.awt.GraphicsEnvironment;
12import java.awt.GridBagConstraints;
13import java.awt.GridBagLayout;
14import java.awt.event.ActionEvent;
15import java.awt.event.ActionListener;
16import java.awt.event.FocusEvent;
17import java.awt.event.FocusListener;
18import java.awt.event.ItemEvent;
19import java.awt.event.ItemListener;
20import java.awt.event.WindowAdapter;
21import java.awt.event.WindowEvent;
22import java.io.File;
23import java.io.FileInputStream;
24import java.io.IOException;
25import java.io.InputStream;
26import java.text.DateFormat;
27import java.text.ParseException;
28import java.text.SimpleDateFormat;
29import java.util.ArrayList;
30import java.util.Collection;
31import java.util.Collections;
32import java.util.Comparator;
33import java.util.Date;
34import java.util.Dictionary;
35import java.util.Hashtable;
36import java.util.List;
37import java.util.Optional;
38import java.util.TimeZone;
39import java.util.concurrent.TimeUnit;
40import java.util.zip.GZIPInputStream;
41
42import javax.swing.AbstractAction;
43import javax.swing.AbstractListModel;
44import javax.swing.BorderFactory;
45import javax.swing.JButton;
46import javax.swing.JCheckBox;
47import javax.swing.JFileChooser;
48import javax.swing.JLabel;
49import javax.swing.JList;
50import javax.swing.JOptionPane;
51import javax.swing.JPanel;
52import javax.swing.JScrollPane;
53import javax.swing.JSeparator;
54import javax.swing.JSlider;
55import javax.swing.ListSelectionModel;
56import javax.swing.MutableComboBoxModel;
57import javax.swing.SwingConstants;
58import javax.swing.event.ChangeEvent;
59import javax.swing.event.ChangeListener;
60import javax.swing.event.DocumentEvent;
61import javax.swing.event.DocumentListener;
62import javax.swing.filechooser.FileFilter;
63
64import org.openstreetmap.josm.Main;
65import org.openstreetmap.josm.actions.DiskAccessAction;
66import org.openstreetmap.josm.data.gpx.GpxConstants;
67import org.openstreetmap.josm.data.gpx.GpxData;
68import org.openstreetmap.josm.data.gpx.GpxTrack;
69import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
70import org.openstreetmap.josm.data.gpx.WayPoint;
71import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
72import org.openstreetmap.josm.gui.ExtendedDialog;
73import org.openstreetmap.josm.gui.layer.GpxLayer;
74import org.openstreetmap.josm.gui.layer.Layer;
75import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
76import org.openstreetmap.josm.gui.widgets.JosmComboBox;
77import org.openstreetmap.josm.gui.widgets.JosmTextField;
78import org.openstreetmap.josm.io.GpxReader;
79import org.openstreetmap.josm.io.JpgImporter;
80import org.openstreetmap.josm.tools.ExifReader;
81import org.openstreetmap.josm.tools.GBC;
82import org.openstreetmap.josm.tools.ImageProvider;
83import org.openstreetmap.josm.tools.JosmRuntimeException;
84import org.openstreetmap.josm.tools.Pair;
85import org.openstreetmap.josm.tools.Utils;
86import org.openstreetmap.josm.tools.date.DateUtils;
87import org.xml.sax.SAXException;
88
89/**
90 * This class displays the window to select the GPX file and the offset (timezone + delta).
91 * Then it correlates the images of the layer with that GPX file.
92 */
93public class CorrelateGpxWithImages extends AbstractAction {
94
95 private static List<GpxData> loadedGpxData = new ArrayList<>();
96
97 private final transient GeoImageLayer yLayer;
98 private transient Timezone timezone;
99 private transient Offset delta;
100
101 /**
102 * Constructs a new {@code CorrelateGpxWithImages} action.
103 * @param layer The image layer
104 */
105 public CorrelateGpxWithImages(GeoImageLayer layer) {
106 super(tr("Correlate to GPX"), ImageProvider.get("dialogs/geoimage/gpx2img"));
107 this.yLayer = layer;
108 }
109
110 private final class SyncDialogWindowListener extends WindowAdapter {
111 private static final int CANCEL = -1;
112 private static final int DONE = 0;
113 private static final int AGAIN = 1;
114 private static final int NOTHING = 2;
115
116 private int checkAndSave() {
117 if (syncDialog.isVisible())
118 // nothing happened: JOSM was minimized or similar
119 return NOTHING;
120 int answer = syncDialog.getValue();
121 if (answer != 1)
122 return CANCEL;
123
124 // Parse values again, to display an error if the format is not recognized
125 try {
126 timezone = Timezone.parseTimezone(tfTimezone.getText().trim());
127 } catch (ParseException e) {
128 JOptionPane.showMessageDialog(Main.parent, e.getMessage(),
129 tr("Invalid timezone"), JOptionPane.ERROR_MESSAGE);
130 return AGAIN;
131 }
132
133 try {
134 delta = Offset.parseOffset(tfOffset.getText().trim());
135 } catch (ParseException e) {
136 JOptionPane.showMessageDialog(Main.parent, e.getMessage(),
137 tr("Invalid offset"), JOptionPane.ERROR_MESSAGE);
138 return AGAIN;
139 }
140
141 if (lastNumMatched == 0 && new ExtendedDialog(
142 Main.parent,
143 tr("Correlate images with GPX track"),
144 tr("OK"), tr("Try Again")).
145 setContent(tr("No images could be matched!")).
146 setButtonIcons("ok", "dialogs/refresh").
147 showDialog().getValue() == 2)
148 return AGAIN;
149 return DONE;
150 }
151
152 @Override
153 public void windowDeactivated(WindowEvent e) {
154 int result = checkAndSave();
155 switch (result) {
156 case NOTHING:
157 break;
158 case CANCEL:
159 if (yLayer != null) {
160 if (yLayer.data != null) {
161 for (ImageEntry ie : yLayer.data) {
162 ie.discardTmp();
163 }
164 }
165 yLayer.updateBufferAndRepaint();
166 }
167 break;
168 case AGAIN:
169 actionPerformed(null);
170 break;
171 case DONE:
172 Main.pref.put("geoimage.timezone", timezone.formatTimezone());
173 Main.pref.put("geoimage.delta", delta.formatOffset());
174 Main.pref.put("geoimage.showThumbs", yLayer.useThumbs);
175
176 yLayer.useThumbs = cbShowThumbs.isSelected();
177 yLayer.startLoadThumbs();
178
179 // Search whether an other layer has yet defined some bounding box.
180 // If none, we'll zoom to the bounding box of the layer with the photos.
181 boolean boundingBoxedLayerFound = false;
182 for (Layer l: Main.getLayerManager().getLayers()) {
183 if (l != yLayer) {
184 BoundingXYVisitor bbox = new BoundingXYVisitor();
185 l.visitBoundingBox(bbox);
186 if (bbox.getBounds() != null) {
187 boundingBoxedLayerFound = true;
188 break;
189 }
190 }
191 }
192 if (!boundingBoxedLayerFound) {
193 BoundingXYVisitor bbox = new BoundingXYVisitor();
194 yLayer.visitBoundingBox(bbox);
195 Main.map.mapView.zoomTo(bbox);
196 }
197
198 if (yLayer.data != null) {
199 for (ImageEntry ie : yLayer.data) {
200 ie.applyTmp();
201 }
202 }
203
204 yLayer.updateBufferAndRepaint();
205
206 break;
207 default:
208 throw new IllegalStateException();
209 }
210 }
211 }
212
213 private static class GpxDataWrapper {
214 private final String name;
215 private final GpxData data;
216 private final File file;
217
218 GpxDataWrapper(String name, GpxData data, File file) {
219 this.name = name;
220 this.data = data;
221 this.file = file;
222 }
223
224 @Override
225 public String toString() {
226 return name;
227 }
228 }
229
230 private ExtendedDialog syncDialog;
231 private final transient List<GpxDataWrapper> gpxLst = new ArrayList<>();
232 private JPanel outerPanel;
233 private JosmComboBox<GpxDataWrapper> cbGpx;
234 private JosmTextField tfTimezone;
235 private JosmTextField tfOffset;
236 private JCheckBox cbExifImg;
237 private JCheckBox cbTaggedImg;
238 private JCheckBox cbShowThumbs;
239 private JLabel statusBarText;
240
241 // remember the last number of matched photos
242 private int lastNumMatched;
243
244 /** This class is called when the user doesn't find the GPX file he needs in the files that have
245 * been loaded yet. It displays a FileChooser dialog to select the GPX file to be loaded.
246 */
247 private class LoadGpxDataActionListener implements ActionListener {
248
249 @Override
250 public void actionPerformed(ActionEvent arg0) {
251 FileFilter filter = new FileFilter() {
252 @Override
253 public boolean accept(File f) {
254 return f.isDirectory() || Utils.hasExtension(f, "gpx", "gpx.gz");
255 }
256
257 @Override
258 public String getDescription() {
259 return tr("GPX Files (*.gpx *.gpx.gz)");
260 }
261 };
262 AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, JFileChooser.FILES_ONLY, null);
263 if (fc == null)
264 return;
265 File sel = fc.getSelectedFile();
266
267 try {
268 outerPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
269
270 for (int i = gpxLst.size() - 1; i >= 0; i--) {
271 GpxDataWrapper wrapper = gpxLst.get(i);
272 if (sel.equals(wrapper.file)) {
273 cbGpx.setSelectedIndex(i);
274 if (!sel.getName().equals(wrapper.name)) {
275 JOptionPane.showMessageDialog(
276 Main.parent,
277 tr("File {0} is loaded yet under the name \"{1}\"", sel.getName(), wrapper.name),
278 tr("Error"),
279 JOptionPane.ERROR_MESSAGE
280 );
281 }
282 return;
283 }
284 }
285 GpxData data = null;
286 try (InputStream iStream = createInputStream(sel)) {
287 GpxReader reader = new GpxReader(iStream);
288 reader.parse(false);
289 data = reader.getGpxData();
290 data.storageFile = sel;
291
292 } catch (SAXException ex) {
293 Main.error(ex);
294 JOptionPane.showMessageDialog(
295 Main.parent,
296 tr("Error while parsing {0}", sel.getName())+": "+ex.getMessage(),
297 tr("Error"),
298 JOptionPane.ERROR_MESSAGE
299 );
300 return;
301 } catch (IOException ex) {
302 Main.error(ex);
303 JOptionPane.showMessageDialog(
304 Main.parent,
305 tr("Could not read \"{0}\"", sel.getName())+'\n'+ex.getMessage(),
306 tr("Error"),
307 JOptionPane.ERROR_MESSAGE
308 );
309 return;
310 }
311
312 MutableComboBoxModel<GpxDataWrapper> model = (MutableComboBoxModel<GpxDataWrapper>) cbGpx.getModel();
313 loadedGpxData.add(data);
314 if (gpxLst.get(0).file == null) {
315 gpxLst.remove(0);
316 model.removeElementAt(0);
317 }
318 GpxDataWrapper elem = new GpxDataWrapper(sel.getName(), data, sel);
319 gpxLst.add(elem);
320 model.addElement(elem);
321 cbGpx.setSelectedIndex(cbGpx.getItemCount() - 1);
322 } finally {
323 outerPanel.setCursor(Cursor.getDefaultCursor());
324 }
325 }
326
327 private InputStream createInputStream(File sel) throws IOException {
328 if (Utils.hasExtension(sel, "gpx.gz")) {
329 return new GZIPInputStream(new FileInputStream(sel));
330 } else {
331 return new FileInputStream(sel);
332 }
333 }
334 }
335
336 /**
337 * This action listener is called when the user has a photo of the time of his GPS receiver. It
338 * displays the list of photos of the layer, and upon selection displays the selected photo.
339 * From that photo, the user can key in the time of the GPS.
340 * Then values of timezone and delta are set.
341 * @author chris
342 *
343 */
344 private class SetOffsetActionListener implements ActionListener {
345
346 @Override
347 public void actionPerformed(ActionEvent arg0) {
348 SimpleDateFormat dateFormat = (SimpleDateFormat) DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
349
350 JPanel panel = new JPanel(new BorderLayout());
351 panel.add(new JLabel(tr("<html>Take a photo of your GPS receiver while it displays the time.<br>"
352 + "Display that photo here.<br>"
353 + "And then, simply capture the time you read on the photo and select a timezone<hr></html>")),
354 BorderLayout.NORTH);
355
356 ImageDisplay imgDisp = new ImageDisplay();
357 imgDisp.setPreferredSize(new Dimension(300, 225));
358 panel.add(imgDisp, BorderLayout.CENTER);
359
360 JPanel panelTf = new JPanel(new GridBagLayout());
361
362 GridBagConstraints gc = new GridBagConstraints();
363 gc.gridx = gc.gridy = 0;
364 gc.gridwidth = gc.gridheight = 1;
365 gc.weightx = gc.weighty = 0.0;
366 gc.fill = GridBagConstraints.NONE;
367 gc.anchor = GridBagConstraints.WEST;
368 panelTf.add(new JLabel(tr("Photo time (from exif):")), gc);
369
370 JLabel lbExifTime = new JLabel();
371 gc.gridx = 1;
372 gc.weightx = 1.0;
373 gc.fill = GridBagConstraints.HORIZONTAL;
374 gc.gridwidth = 2;
375 panelTf.add(lbExifTime, gc);
376
377 gc.gridx = 0;
378 gc.gridy = 1;
379 gc.gridwidth = gc.gridheight = 1;
380 gc.weightx = gc.weighty = 0.0;
381 gc.fill = GridBagConstraints.NONE;
382 gc.anchor = GridBagConstraints.WEST;
383 panelTf.add(new JLabel(tr("Gps time (read from the above photo): ")), gc);
384
385 JosmTextField tfGpsTime = new JosmTextField(12);
386 tfGpsTime.setEnabled(false);
387 tfGpsTime.setMinimumSize(new Dimension(155, tfGpsTime.getMinimumSize().height));
388 gc.gridx = 1;
389 gc.weightx = 1.0;
390 gc.fill = GridBagConstraints.HORIZONTAL;
391 panelTf.add(tfGpsTime, gc);
392
393 gc.gridx = 2;
394 gc.weightx = 0.2;
395 panelTf.add(new JLabel(" ["+dateFormat.toLocalizedPattern()+']'), gc);
396
397 gc.gridx = 0;
398 gc.gridy = 2;
399 gc.gridwidth = gc.gridheight = 1;
400 gc.weightx = gc.weighty = 0.0;
401 gc.fill = GridBagConstraints.NONE;
402 gc.anchor = GridBagConstraints.WEST;
403 panelTf.add(new JLabel(tr("I am in the timezone of: ")), gc);
404
405 String[] tmp = TimeZone.getAvailableIDs();
406 List<String> vtTimezones = new ArrayList<>(tmp.length);
407
408 for (String tzStr : tmp) {
409 TimeZone tz = TimeZone.getTimeZone(tzStr);
410
411 String tzDesc = tzStr + " (" +
412 new Timezone(((double) tz.getRawOffset()) / TimeUnit.HOURS.toMillis(1)).formatTimezone() +
413 ')';
414 vtTimezones.add(tzDesc);
415 }
416
417 Collections.sort(vtTimezones);
418
419 JosmComboBox<String> cbTimezones = new JosmComboBox<>(vtTimezones.toArray(new String[vtTimezones.size()]));
420
421 String tzId = Main.pref.get("geoimage.timezoneid", "");
422 TimeZone defaultTz;
423 if (tzId.isEmpty()) {
424 defaultTz = TimeZone.getDefault();
425 } else {
426 defaultTz = TimeZone.getTimeZone(tzId);
427 }
428
429 cbTimezones.setSelectedItem(defaultTz.getID() + " (" +
430 new Timezone(((double) defaultTz.getRawOffset()) / TimeUnit.HOURS.toMillis(1)).formatTimezone() +
431 ')');
432
433 gc.gridx = 1;
434 gc.weightx = 1.0;
435 gc.gridwidth = 2;
436 gc.fill = GridBagConstraints.HORIZONTAL;
437 panelTf.add(cbTimezones, gc);
438
439 panel.add(panelTf, BorderLayout.SOUTH);
440
441 JPanel panelLst = new JPanel(new BorderLayout());
442
443 JList<String> imgList = new JList<>(new AbstractListModel<String>() {
444 @Override
445 public String getElementAt(int i) {
446 return yLayer.data.get(i).getFile().getName();
447 }
448
449 @Override
450 public int getSize() {
451 return yLayer.data != null ? yLayer.data.size() : 0;
452 }
453 });
454 imgList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
455 imgList.getSelectionModel().addListSelectionListener(evt -> {
456 int index = imgList.getSelectedIndex();
457 Integer orientation = ExifReader.readOrientation(yLayer.data.get(index).getFile());
458 imgDisp.setImage(yLayer.data.get(index).getFile(), orientation);
459 Date date = yLayer.data.get(index).getExifTime();
460 if (date != null) {
461 DateFormat df = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
462 lbExifTime.setText(df.format(date));
463 tfGpsTime.setText(df.format(date));
464 tfGpsTime.setCaretPosition(tfGpsTime.getText().length());
465 tfGpsTime.setEnabled(true);
466 tfGpsTime.requestFocus();
467 } else {
468 lbExifTime.setText(tr("No date"));
469 tfGpsTime.setText("");
470 tfGpsTime.setEnabled(false);
471 }
472 });
473 panelLst.add(new JScrollPane(imgList), BorderLayout.CENTER);
474
475 JButton openButton = new JButton(tr("Open another photo"));
476 openButton.addActionListener(ae -> {
477 AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null,
478 JpgImporter.FILE_FILTER_WITH_FOLDERS, JFileChooser.FILES_ONLY, "geoimage.lastdirectory");
479 if (fc == null)
480 return;
481 File sel = fc.getSelectedFile();
482
483 Integer orientation = ExifReader.readOrientation(sel);
484 imgDisp.setImage(sel, orientation);
485
486 Date date = ExifReader.readTime(sel);
487 if (date != null) {
488 lbExifTime.setText(DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM).format(date));
489 tfGpsTime.setText(DateUtils.getDateFormat(DateFormat.SHORT).format(date)+' ');
490 tfGpsTime.setEnabled(true);
491 } else {
492 lbExifTime.setText(tr("No date"));
493 tfGpsTime.setText("");
494 tfGpsTime.setEnabled(false);
495 }
496 });
497 panelLst.add(openButton, BorderLayout.PAGE_END);
498
499 panel.add(panelLst, BorderLayout.LINE_START);
500
501 boolean isOk = false;
502 while (!isOk) {
503 int answer = JOptionPane.showConfirmDialog(
504 Main.parent, panel,
505 tr("Synchronize time from a photo of the GPS receiver"),
506 JOptionPane.OK_CANCEL_OPTION,
507 JOptionPane.QUESTION_MESSAGE
508 );
509 if (answer == JOptionPane.CANCEL_OPTION)
510 return;
511
512 long delta;
513
514 try {
515 delta = dateFormat.parse(lbExifTime.getText()).getTime()
516 - dateFormat.parse(tfGpsTime.getText()).getTime();
517 } catch (ParseException e) {
518 JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing the date.\n"
519 + "Please use the requested format"),
520 tr("Invalid date"), JOptionPane.ERROR_MESSAGE);
521 continue;
522 }
523
524 String selectedTz = (String) cbTimezones.getSelectedItem();
525 int pos = selectedTz.lastIndexOf('(');
526 tzId = selectedTz.substring(0, pos - 1);
527 String tzValue = selectedTz.substring(pos + 1, selectedTz.length() - 1);
528
529 Main.pref.put("geoimage.timezoneid", tzId);
530 tfOffset.setText(Offset.milliseconds(delta).formatOffset());
531 tfTimezone.setText(tzValue);
532
533 isOk = true;
534
535 }
536 statusBarUpdater.updateStatusBar();
537 yLayer.updateBufferAndRepaint();
538 }
539 }
540
541 @Override
542 public void actionPerformed(ActionEvent ae) {
543 // Construct the list of loaded GPX tracks
544 Collection<Layer> layerLst = Main.getLayerManager().getLayers();
545 GpxDataWrapper defaultItem = null;
546 for (Layer cur : layerLst) {
547 if (cur instanceof GpxLayer) {
548 GpxLayer curGpx = (GpxLayer) cur;
549 GpxDataWrapper gdw = new GpxDataWrapper(curGpx.getName(), curGpx.data, curGpx.data.storageFile);
550 gpxLst.add(gdw);
551 if (cur == yLayer.gpxLayer) {
552 defaultItem = gdw;
553 }
554 }
555 }
556 for (GpxData data : loadedGpxData) {
557 gpxLst.add(new GpxDataWrapper(data.storageFile.getName(),
558 data,
559 data.storageFile));
560 }
561
562 if (gpxLst.isEmpty()) {
563 gpxLst.add(new GpxDataWrapper(tr("<No GPX track loaded yet>"), null, null));
564 }
565
566 JPanel panelCb = new JPanel();
567
568 panelCb.add(new JLabel(tr("GPX track: ")));
569
570 cbGpx = new JosmComboBox<>(gpxLst.toArray(new GpxDataWrapper[gpxLst.size()]));
571 if (defaultItem != null) {
572 cbGpx.setSelectedItem(defaultItem);
573 }
574 cbGpx.addActionListener(statusBarUpdaterWithRepaint);
575 panelCb.add(cbGpx);
576
577 JButton buttonOpen = new JButton(tr("Open another GPX trace"));
578 buttonOpen.addActionListener(new LoadGpxDataActionListener());
579 panelCb.add(buttonOpen);
580
581 JPanel panelTf = new JPanel(new GridBagLayout());
582
583 try {
584 timezone = Timezone.parseTimezone(Optional.ofNullable(Main.pref.get("geoimage.timezone", "0:00")).orElse("0:00"));
585 } catch (ParseException e) {
586 timezone = Timezone.ZERO;
587 }
588
589 tfTimezone = new JosmTextField(10);
590 tfTimezone.setText(timezone.formatTimezone());
591
592 try {
593 delta = Offset.parseOffset(Main.pref.get("geoimage.delta", "0"));
594 } catch (ParseException e) {
595 delta = Offset.ZERO;
596 }
597
598 tfOffset = new JosmTextField(10);
599 tfOffset.setText(delta.formatOffset());
600
601 JButton buttonViewGpsPhoto = new JButton(tr("<html>Use photo of an accurate clock,<br>"
602 + "e.g. GPS receiver display</html>"));
603 buttonViewGpsPhoto.setIcon(ImageProvider.get("clock"));
604 buttonViewGpsPhoto.addActionListener(new SetOffsetActionListener());
605
606 JButton buttonAutoGuess = new JButton(tr("Auto-Guess"));
607 buttonAutoGuess.setToolTipText(tr("Matches first photo with first gpx point"));
608 buttonAutoGuess.addActionListener(new AutoGuessActionListener());
609
610 JButton buttonAdjust = new JButton(tr("Manual adjust"));
611 buttonAdjust.addActionListener(new AdjustActionListener());
612
613 JLabel labelPosition = new JLabel(tr("Override position for: "));
614
615 int numAll = getSortedImgList(true, true).size();
616 int numExif = numAll - getSortedImgList(false, true).size();
617 int numTagged = numAll - getSortedImgList(true, false).size();
618
619 cbExifImg = new JCheckBox(tr("Images with geo location in exif data ({0}/{1})", numExif, numAll));
620 cbExifImg.setEnabled(numExif != 0);
621
622 cbTaggedImg = new JCheckBox(tr("Images that are already tagged ({0}/{1})", numTagged, numAll), true);
623 cbTaggedImg.setEnabled(numTagged != 0);
624
625 labelPosition.setEnabled(cbExifImg.isEnabled() || cbTaggedImg.isEnabled());
626
627 boolean ticked = yLayer.thumbsLoaded || Main.pref.getBoolean("geoimage.showThumbs", false);
628 cbShowThumbs = new JCheckBox(tr("Show Thumbnail images on the map"), ticked);
629 cbShowThumbs.setEnabled(!yLayer.thumbsLoaded);
630
631 int y = 0;
632 GBC gbc = GBC.eol();
633 gbc.gridx = 0;
634 gbc.gridy = y++;
635 panelTf.add(panelCb, gbc);
636
637 gbc = GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 12);
638 gbc.gridx = 0;
639 gbc.gridy = y++;
640 panelTf.add(new JSeparator(SwingConstants.HORIZONTAL), gbc);
641
642 gbc = GBC.std();
643 gbc.gridx = 0;
644 gbc.gridy = y;
645 panelTf.add(new JLabel(tr("Timezone: ")), gbc);
646
647 gbc = GBC.std().fill(GBC.HORIZONTAL);
648 gbc.gridx = 1;
649 gbc.gridy = y++;
650 gbc.weightx = 1.;
651 panelTf.add(tfTimezone, gbc);
652
653 gbc = GBC.std();
654 gbc.gridx = 0;
655 gbc.gridy = y;
656 panelTf.add(new JLabel(tr("Offset:")), gbc);
657
658 gbc = GBC.std().fill(GBC.HORIZONTAL);
659 gbc.gridx = 1;
660 gbc.gridy = y++;
661 gbc.weightx = 1.;
662 panelTf.add(tfOffset, gbc);
663
664 gbc = GBC.std().insets(5, 5, 5, 5);
665 gbc.gridx = 2;
666 gbc.gridy = y-2;
667 gbc.gridheight = 2;
668 gbc.gridwidth = 2;
669 gbc.fill = GridBagConstraints.BOTH;
670 gbc.weightx = 0.5;
671 panelTf.add(buttonViewGpsPhoto, gbc);
672
673 gbc = GBC.std().fill(GBC.BOTH).insets(5, 5, 5, 5);
674 gbc.gridx = 2;
675 gbc.gridy = y++;
676 gbc.weightx = 0.5;
677 panelTf.add(buttonAutoGuess, gbc);
678
679 gbc.gridx = 3;
680 panelTf.add(buttonAdjust, gbc);
681
682 gbc = GBC.eol().fill(GBC.HORIZONTAL).insets(0, 12, 0, 0);
683 gbc.gridx = 0;
684 gbc.gridy = y++;
685 panelTf.add(new JSeparator(SwingConstants.HORIZONTAL), gbc);
686
687 gbc = GBC.eol();
688 gbc.gridx = 0;
689 gbc.gridy = y++;
690 panelTf.add(labelPosition, gbc);
691
692 gbc = GBC.eol();
693 gbc.gridx = 1;
694 gbc.gridy = y++;
695 panelTf.add(cbExifImg, gbc);
696
697 gbc = GBC.eol();
698 gbc.gridx = 1;
699 gbc.gridy = y++;
700 panelTf.add(cbTaggedImg, gbc);
701
702 gbc = GBC.eol();
703 gbc.gridx = 0;
704 gbc.gridy = y;
705 panelTf.add(cbShowThumbs, gbc);
706
707 final JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
708 statusBar.setBorder(BorderFactory.createLoweredBevelBorder());
709 statusBarText = new JLabel(" ");
710 statusBarText.setFont(statusBarText.getFont().deriveFont(8));
711 statusBar.add(statusBarText);
712
713 tfTimezone.addFocusListener(repaintTheMap);
714 tfOffset.addFocusListener(repaintTheMap);
715
716 tfTimezone.getDocument().addDocumentListener(statusBarUpdater);
717 tfOffset.getDocument().addDocumentListener(statusBarUpdater);
718 cbExifImg.addItemListener(statusBarUpdaterWithRepaint);
719 cbTaggedImg.addItemListener(statusBarUpdaterWithRepaint);
720
721 statusBarUpdater.updateStatusBar();
722
723 outerPanel = new JPanel(new BorderLayout());
724 outerPanel.add(statusBar, BorderLayout.PAGE_END);
725
726 if (!GraphicsEnvironment.isHeadless()) {
727 syncDialog = new ExtendedDialog(
728 Main.parent,
729 tr("Correlate images with GPX track"),
730 new String[] {tr("Correlate"), tr("Cancel")},
731 false
732 );
733 syncDialog.setContent(panelTf, false);
734 syncDialog.setButtonIcons("ok", "cancel");
735 syncDialog.setupDialog();
736 outerPanel.add(syncDialog.getContentPane(), BorderLayout.PAGE_START);
737 syncDialog.setContentPane(outerPanel);
738 syncDialog.pack();
739 syncDialog.addWindowListener(new SyncDialogWindowListener());
740 syncDialog.showDialog();
741 }
742 }
743
744 private final transient StatusBarUpdater statusBarUpdater = new StatusBarUpdater(false);
745 private final transient StatusBarUpdater statusBarUpdaterWithRepaint = new StatusBarUpdater(true);
746
747 private class StatusBarUpdater implements DocumentListener, ItemListener, ActionListener {
748 private final boolean doRepaint;
749
750 StatusBarUpdater(boolean doRepaint) {
751 this.doRepaint = doRepaint;
752 }
753
754 @Override
755 public void insertUpdate(DocumentEvent ev) {
756 updateStatusBar();
757 }
758
759 @Override
760 public void removeUpdate(DocumentEvent ev) {
761 updateStatusBar();
762 }
763
764 @Override
765 public void changedUpdate(DocumentEvent ev) {
766 // Do nothing
767 }
768
769 @Override
770 public void itemStateChanged(ItemEvent e) {
771 updateStatusBar();
772 }
773
774 @Override
775 public void actionPerformed(ActionEvent e) {
776 updateStatusBar();
777 }
778
779 public void updateStatusBar() {
780 statusBarText.setText(statusText());
781 if (doRepaint) {
782 yLayer.updateBufferAndRepaint();
783 }
784 }
785
786 private String statusText() {
787 try {
788 timezone = Timezone.parseTimezone(tfTimezone.getText().trim());
789 delta = Offset.parseOffset(tfOffset.getText().trim());
790 } catch (ParseException e) {
791 return e.getMessage();
792 }
793
794 // The selection of images we are about to correlate may have changed.
795 // So reset all images.
796 if (yLayer.data != null) {
797 for (ImageEntry ie: yLayer.data) {
798 ie.discardTmp();
799 }
800 }
801
802 // Construct a list of images that have a date, and sort them on the date.
803 List<ImageEntry> dateImgLst = getSortedImgList();
804 // Create a temporary copy for each image
805 for (ImageEntry ie : dateImgLst) {
806 ie.createTmp();
807 ie.tmp.setPos(null);
808 }
809
810 GpxDataWrapper selGpx = selectedGPX(false);
811 if (selGpx == null)
812 return tr("No gpx selected");
813
814 final long offsetMs = ((long) (timezone.getHours() * TimeUnit.HOURS.toMillis(1))) + delta.getMilliseconds(); // in milliseconds
815 lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, offsetMs);
816
817 return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>",
818 "<html>Matched <b>{0}</b> of <b>{1}</b> photos to GPX track.</html>",
819 dateImgLst.size(), lastNumMatched, dateImgLst.size());
820 }
821 }
822
823 private final transient RepaintTheMapListener repaintTheMap = new RepaintTheMapListener();
824
825 private class RepaintTheMapListener implements FocusListener {
826 @Override
827 public void focusGained(FocusEvent e) { // do nothing
828 }
829
830 @Override
831 public void focusLost(FocusEvent e) {
832 yLayer.updateBufferAndRepaint();
833 }
834 }
835
836 /**
837 * Presents dialog with sliders for manual adjust.
838 */
839 private class AdjustActionListener implements ActionListener {
840
841 @Override
842 public void actionPerformed(ActionEvent arg0) {
843
844 final Offset offset = Offset.milliseconds(
845 delta.getMilliseconds() + Math.round(timezone.getHours() * TimeUnit.HOURS.toMillis(1)));
846 final int dayOffset = offset.getDayOffset();
847 final Pair<Timezone, Offset> timezoneOffsetPair = offset.withoutDayOffset().splitOutTimezone();
848
849 // Info Labels
850 final JLabel lblMatches = new JLabel();
851
852 // Timezone Slider
853 // The slider allows to switch timezon from -12:00 to 12:00 in 30 minutes steps. Therefore the range is -24 to 24.
854 final JLabel lblTimezone = new JLabel();
855 final JSlider sldTimezone = new JSlider(-24, 24, 0);
856 sldTimezone.setPaintLabels(true);
857 Dictionary<Integer, JLabel> labelTable = new Hashtable<>();
858 // CHECKSTYLE.OFF: ParenPad
859 for (int i = -12; i <= 12; i += 6) {
860 labelTable.put(i * 2, new JLabel(new Timezone(i).formatTimezone()));
861 }
862 // CHECKSTYLE.ON: ParenPad
863 sldTimezone.setLabelTable(labelTable);
864
865 // Minutes Slider
866 final JLabel lblMinutes = new JLabel();
867 final JSlider sldMinutes = new JSlider(-15, 15, 0);
868 sldMinutes.setPaintLabels(true);
869 sldMinutes.setMajorTickSpacing(5);
870
871 // Seconds slider
872 final JLabel lblSeconds = new JLabel();
873 final JSlider sldSeconds = new JSlider(-600, 600, 0);
874 sldSeconds.setPaintLabels(true);
875 labelTable = new Hashtable<>();
876 // CHECKSTYLE.OFF: ParenPad
877 for (int i = -60; i <= 60; i += 30) {
878 labelTable.put(i * 10, new JLabel(Offset.seconds(i).formatOffset()));
879 }
880 // CHECKSTYLE.ON: ParenPad
881 sldSeconds.setLabelTable(labelTable);
882 sldSeconds.setMajorTickSpacing(300);
883
884 // This is called whenever one of the sliders is moved.
885 // It updates the labels and also calls the "match photos" code
886 class SliderListener implements ChangeListener {
887 @Override
888 public void stateChanged(ChangeEvent e) {
889 timezone = new Timezone(sldTimezone.getValue() / 2.);
890
891 lblTimezone.setText(tr("Timezone: {0}", timezone.formatTimezone()));
892 lblMinutes.setText(tr("Minutes: {0}", sldMinutes.getValue()));
893 lblSeconds.setText(tr("Seconds: {0}", Offset.milliseconds(100L * sldSeconds.getValue()).formatOffset()));
894
895 delta = Offset.milliseconds(100L * sldSeconds.getValue()
896 + TimeUnit.MINUTES.toMillis(sldMinutes.getValue())
897 + TimeUnit.DAYS.toMillis(dayOffset));
898
899 tfTimezone.getDocument().removeDocumentListener(statusBarUpdater);
900 tfOffset.getDocument().removeDocumentListener(statusBarUpdater);
901
902 tfTimezone.setText(timezone.formatTimezone());
903 tfOffset.setText(delta.formatOffset());
904
905 tfTimezone.getDocument().addDocumentListener(statusBarUpdater);
906 tfOffset.getDocument().addDocumentListener(statusBarUpdater);
907
908 lblMatches.setText(statusBarText.getText() + "<br>" + trn("(Time difference of {0} day)",
909 "Time difference of {0} days", Math.abs(dayOffset), Math.abs(dayOffset)));
910
911 statusBarUpdater.updateStatusBar();
912 yLayer.updateBufferAndRepaint();
913 }
914 }
915
916 // Put everything together
917 JPanel p = new JPanel(new GridBagLayout());
918 p.setPreferredSize(new Dimension(400, 230));
919 p.add(lblMatches, GBC.eol().fill());
920 p.add(lblTimezone, GBC.eol().fill());
921 p.add(sldTimezone, GBC.eol().fill().insets(0, 0, 0, 10));
922 p.add(lblMinutes, GBC.eol().fill());
923 p.add(sldMinutes, GBC.eol().fill().insets(0, 0, 0, 10));
924 p.add(lblSeconds, GBC.eol().fill());
925 p.add(sldSeconds, GBC.eol().fill());
926
927 // If there's an error in the calculation the found values
928 // will be off range for the sliders. Catch this error
929 // and inform the user about it.
930 try {
931 sldTimezone.setValue((int) (timezoneOffsetPair.a.getHours() * 2));
932 sldMinutes.setValue((int) (timezoneOffsetPair.b.getSeconds() / 60));
933 final long deciSeconds = timezoneOffsetPair.b.getMilliseconds() / 100;
934 sldSeconds.setValue((int) (deciSeconds % 60));
935 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
936 Main.warn(e);
937 JOptionPane.showMessageDialog(Main.parent,
938 tr("An error occurred while trying to match the photos to the GPX track."
939 +" You can adjust the sliders to manually match the photos."),
940 tr("Matching photos to track failed"),
941 JOptionPane.WARNING_MESSAGE);
942 }
943
944 // Call the sliderListener once manually so labels get adjusted
945 new SliderListener().stateChanged(null);
946 // Listeners added here, otherwise it tries to match three times
947 // (when setting the default values)
948 sldTimezone.addChangeListener(new SliderListener());
949 sldMinutes.addChangeListener(new SliderListener());
950 sldSeconds.addChangeListener(new SliderListener());
951
952 // There is no way to cancel this dialog, all changes get applied
953 // immediately. Therefore "Close" is marked with an "OK" icon.
954 // Settings are only saved temporarily to the layer.
955 new ExtendedDialog(Main.parent,
956 tr("Adjust timezone and offset"),
957 tr("Close")).
958 setContent(p).setButtonIcons("ok").showDialog();
959 }
960 }
961
962 static class NoGpxTimestamps extends Exception {
963 }
964
965 /**
966 * Tries to auto-guess the timezone and offset.
967 *
968 * @param imgs the images to correlate
969 * @param gpx the gpx track to correlate to
970 * @return a pair of timezone and offset
971 * @throws IndexOutOfBoundsException when there are no images
972 * @throws NoGpxTimestamps when the gpx track does not contain a timestamp
973 */
974 static Pair<Timezone, Offset> autoGuess(List<ImageEntry> imgs, GpxData gpx) throws NoGpxTimestamps {
975
976 // Init variables
977 long firstExifDate = imgs.get(0).getExifTime().getTime();
978
979 long firstGPXDate = -1;
980 // Finds first GPX point
981 outer: for (GpxTrack trk : gpx.tracks) {
982 for (GpxTrackSegment segment : trk.getSegments()) {
983 for (WayPoint curWp : segment.getWayPoints()) {
984 final Date parsedTime = curWp.setTimeFromAttribute();
985 if (parsedTime != null) {
986 firstGPXDate = parsedTime.getTime();
987 break outer;
988 }
989 }
990 }
991 }
992
993 if (firstGPXDate < 0) {
994 throw new NoGpxTimestamps();
995 }
996
997 return Offset.milliseconds(firstExifDate - firstGPXDate).splitOutTimezone();
998 }
999
1000 private class AutoGuessActionListener implements ActionListener {
1001
1002 @Override
1003 public void actionPerformed(ActionEvent arg0) {
1004 GpxDataWrapper gpxW = selectedGPX(true);
1005 if (gpxW == null)
1006 return;
1007 GpxData gpx = gpxW.data;
1008
1009 List<ImageEntry> imgs = getSortedImgList();
1010
1011 try {
1012 final Pair<Timezone, Offset> r = autoGuess(imgs, gpx);
1013 timezone = r.a;
1014 delta = r.b;
1015 } catch (IndexOutOfBoundsException ex) {
1016 Main.debug(ex);
1017 JOptionPane.showMessageDialog(Main.parent,
1018 tr("The selected photos do not contain time information."),
1019 tr("Photos do not contain time information"), JOptionPane.WARNING_MESSAGE);
1020 return;
1021 } catch (NoGpxTimestamps ex) {
1022 Main.debug(ex);
1023 JOptionPane.showMessageDialog(Main.parent,
1024 tr("The selected GPX track does not contain timestamps. Please select another one."),
1025 tr("GPX Track has no time information"), JOptionPane.WARNING_MESSAGE);
1026 return;
1027 }
1028
1029 tfTimezone.getDocument().removeDocumentListener(statusBarUpdater);
1030 tfOffset.getDocument().removeDocumentListener(statusBarUpdater);
1031
1032 tfTimezone.setText(timezone.formatTimezone());
1033 tfOffset.setText(delta.formatOffset());
1034 tfOffset.requestFocus();
1035
1036 tfTimezone.getDocument().addDocumentListener(statusBarUpdater);
1037 tfOffset.getDocument().addDocumentListener(statusBarUpdater);
1038
1039 statusBarUpdater.updateStatusBar();
1040 yLayer.updateBufferAndRepaint();
1041 }
1042 }
1043
1044 private List<ImageEntry> getSortedImgList() {
1045 return getSortedImgList(cbExifImg.isSelected(), cbTaggedImg.isSelected());
1046 }
1047
1048 /**
1049 * Returns a list of images that fulfill the given criteria.
1050 * Default setting is to return untagged images, but may be overwritten.
1051 * @param exif also returns images with exif-gps info
1052 * @param tagged also returns tagged images
1053 * @return matching images
1054 */
1055 private List<ImageEntry> getSortedImgList(boolean exif, boolean tagged) {
1056 if (yLayer.data == null) {
1057 return Collections.emptyList();
1058 }
1059 List<ImageEntry> dateImgLst = new ArrayList<>(yLayer.data.size());
1060 for (ImageEntry e : yLayer.data) {
1061 if (!e.hasExifTime()) {
1062 continue;
1063 }
1064
1065 if (e.getExifCoor() != null && !exif) {
1066 continue;
1067 }
1068
1069 if (!tagged && e.isTagged() && e.getExifCoor() == null) {
1070 continue;
1071 }
1072
1073 dateImgLst.add(e);
1074 }
1075
1076 dateImgLst.sort(Comparator.comparing(ImageEntry::getExifTime));
1077
1078 return dateImgLst;
1079 }
1080
1081 private GpxDataWrapper selectedGPX(boolean complain) {
1082 Object item = cbGpx.getSelectedItem();
1083
1084 if (item == null || ((GpxDataWrapper) item).file == null) {
1085 if (complain) {
1086 JOptionPane.showMessageDialog(Main.parent, tr("You should select a GPX track"),
1087 tr("No selected GPX track"), JOptionPane.ERROR_MESSAGE);
1088 }
1089 return null;
1090 }
1091 return (GpxDataWrapper) item;
1092 }
1093
1094 /**
1095 * Match a list of photos to a gpx track with a given offset.
1096 * All images need a exifTime attribute and the List must be sorted according to these times.
1097 * @param images images to match
1098 * @param selectedGpx selected GPX data
1099 * @param offset offset
1100 * @return number of matched points
1101 */
1102 static int matchGpxTrack(List<ImageEntry> images, GpxData selectedGpx, long offset) {
1103 int ret = 0;
1104
1105 for (GpxTrack trk : selectedGpx.tracks) {
1106 for (GpxTrackSegment segment : trk.getSegments()) {
1107
1108 long prevWpTime = 0;
1109 WayPoint prevWp = null;
1110
1111 for (WayPoint curWp : segment.getWayPoints()) {
1112 final Date parsedTime = curWp.setTimeFromAttribute();
1113 if (parsedTime != null) {
1114 final long curWpTime = parsedTime.getTime() + offset;
1115 ret += matchPoints(images, prevWp, prevWpTime, curWp, curWpTime, offset);
1116
1117 prevWp = curWp;
1118 prevWpTime = curWpTime;
1119 continue;
1120 }
1121 prevWp = null;
1122 prevWpTime = 0;
1123 }
1124 }
1125 }
1126 return ret;
1127 }
1128
1129 private static Double getElevation(WayPoint wp) {
1130 String value = wp.getString(GpxConstants.PT_ELE);
1131 if (value != null && !value.isEmpty()) {
1132 try {
1133 return Double.valueOf(value);
1134 } catch (NumberFormatException e) {
1135 Main.warn(e);
1136 }
1137 }
1138 return null;
1139 }
1140
1141 static int matchPoints(List<ImageEntry> images, WayPoint prevWp, long prevWpTime,
1142 WayPoint curWp, long curWpTime, long offset) {
1143 // Time between the track point and the previous one, 5 sec if first point, i.e. photos take
1144 // 5 sec before the first track point can be assumed to be take at the starting position
1145 long interval = prevWpTime > 0 ? Math.abs(curWpTime - prevWpTime) : TimeUnit.SECONDS.toMillis(5);
1146 int ret = 0;
1147
1148 // i is the index of the timewise last photo that has the same or earlier EXIF time
1149 int i = getLastIndexOfListBefore(images, curWpTime);
1150
1151 // no photos match
1152 if (i < 0)
1153 return 0;
1154
1155 Double speed = null;
1156 Double prevElevation = null;
1157
1158 if (prevWp != null) {
1159 double distance = prevWp.getCoor().greatCircleDistance(curWp.getCoor());
1160 // This is in km/h, 3.6 * m/s
1161 if (curWpTime > prevWpTime) {
1162 speed = 3600 * distance / (curWpTime - prevWpTime);
1163 }
1164 prevElevation = getElevation(prevWp);
1165 }
1166
1167 Double curElevation = getElevation(curWp);
1168
1169 // First trackpoint, then interval is set to five seconds, i.e. photos up to five seconds
1170 // before the first point will be geotagged with the starting point
1171 if (prevWpTime == 0 || curWpTime <= prevWpTime) {
1172 while (i >= 0) {
1173 final ImageEntry curImg = images.get(i);
1174 long time = curImg.getExifTime().getTime();
1175 if (time > curWpTime || time < curWpTime - interval) {
1176 break;
1177 }
1178 if (curImg.tmp.getPos() == null) {
1179 curImg.tmp.setPos(curWp.getCoor());
1180 curImg.tmp.setSpeed(speed);
1181 curImg.tmp.setElevation(curElevation);
1182 curImg.tmp.setGpsTime(new Date(curImg.getExifTime().getTime() - offset));
1183 curImg.flagNewGpsData();
1184 ret++;
1185 }
1186 i--;
1187 }
1188 return ret;
1189 }
1190
1191 // This code gives a simple linear interpolation of the coordinates between current and
1192 // previous track point assuming a constant speed in between
1193 while (i >= 0) {
1194 ImageEntry curImg = images.get(i);
1195 long imgTime = curImg.getExifTime().getTime();
1196 if (imgTime < prevWpTime) {
1197 break;
1198 }
1199
1200 if (prevWp != null && curImg.tmp.getPos() == null) {
1201 // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless variable
1202 double timeDiff = (double) (imgTime - prevWpTime) / interval;
1203 curImg.tmp.setPos(prevWp.getCoor().interpolate(curWp.getCoor(), timeDiff));
1204 curImg.tmp.setSpeed(speed);
1205 if (curElevation != null && prevElevation != null) {
1206 curImg.tmp.setElevation(prevElevation + (curElevation - prevElevation) * timeDiff);
1207 }
1208 curImg.tmp.setGpsTime(new Date(curImg.getExifTime().getTime() - offset));
1209 curImg.flagNewGpsData();
1210
1211 ret++;
1212 }
1213 i--;
1214 }
1215 return ret;
1216 }
1217
1218 private static int getLastIndexOfListBefore(List<ImageEntry> images, long searchedTime) {
1219 int lstSize = images.size();
1220
1221 // No photos or the first photo taken is later than the search period
1222 if (lstSize == 0 || searchedTime < images.get(0).getExifTime().getTime())
1223 return -1;
1224
1225 // The search period is later than the last photo
1226 if (searchedTime > images.get(lstSize - 1).getExifTime().getTime())
1227 return lstSize-1;
1228
1229 // The searched index is somewhere in the middle, do a binary search from the beginning
1230 int curIndex;
1231 int startIndex = 0;
1232 int endIndex = lstSize-1;
1233 while (endIndex - startIndex > 1) {
1234 curIndex = (endIndex + startIndex) / 2;
1235 if (searchedTime > images.get(curIndex).getExifTime().getTime()) {
1236 startIndex = curIndex;
1237 } else {
1238 endIndex = curIndex;
1239 }
1240 }
1241 if (searchedTime < images.get(endIndex).getExifTime().getTime())
1242 return startIndex;
1243
1244 // This final loop is to check if photos with the exact same EXIF time follows
1245 while ((endIndex < (lstSize-1)) && (images.get(endIndex).getExifTime().getTime()
1246 == images.get(endIndex + 1).getExifTime().getTime())) {
1247 endIndex++;
1248 }
1249 return endIndex;
1250 }
1251}
Note: See TracBrowser for help on using the repository browser.