Changeset 3052 in josm
- Timestamp:
- 2010-02-27T14:25:57+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r2931 r3052 16 16 import java.awt.event.ActionEvent; 17 17 import java.awt.event.ActionListener; 18 import java.awt.event.FocusEvent; 19 import java.awt.event.FocusListener; 18 20 import java.awt.event.ItemEvent; 19 21 import java.awt.event.ItemListener; … … 120 122 JCheckBox cbShowThumbs; 121 123 JLabel statusBarText; 122 StatusBarListener statusBarListener;123 124 124 125 // remember the last number of matched photos … … 216 217 } 217 218 218 /** This action listener is called when the user has a photo of the time of his GPS receiver. It 219 /** 220 * This action listener is called when the user has a photo of the time of his GPS receiver. It 219 221 * displays the list of photos of the layer, and upon selection displays the selected photo. 220 222 * From that photo, the user can key in the time of the GPS. … … 433 435 434 436 } 435 statusBar Listener.updateStatusBar();437 statusBarUpdater.updateStatusBar(); 436 438 yLayer.updateBufferAndRepaint(); 437 439 } … … 446 448 Layer cur = iterLayer.next(); 447 449 if (cur instanceof GpxLayer) { 448 GpxDataWrapper gdw = new GpxDataWrapper(((GpxLayer) cur).getName(), 449 ((GpxLayer) cur).data, 450 ((GpxLayer) cur).data.storageFile); 450 GpxLayer curGpx = (GpxLayer) cur; 451 GpxDataWrapper gdw = new GpxDataWrapper(curGpx.getName(), curGpx.data, curGpx.data.storageFile); 451 452 gpxLst.add(gdw); 452 453 if (cur == yLayer.gpxLayer) { … … 473 474 cbGpx.setSelectedItem(defaultItem); 474 475 } 476 cbGpx.addActionListener(statusBarUpdaterWithRepaint); 475 477 panelCb.add(cbGpx); 476 478 … … 500 502 delta = 0; 501 503 } 502 delta = delta / 1000; 504 delta = delta / 1000; // milliseconds -> seconds 503 505 504 506 tfOffset = new JTextField(10); … … 625 627 statusBar.add(statusBarText); 626 628 627 statusBarListener = new StatusBarListener() { 628 @Override 629 public void updateStatusBar() { 630 statusBarText.setText(statusText()); 631 } 632 private String statusText() { 633 try { 634 timezone = parseTimezone(tfTimezone.getText().trim()); 635 delta = parseOffset(tfOffset.getText().trim()); 636 } catch (ParseException e) { 637 return e.getMessage(); 638 } 639 640 // Construct a list of images that have a date, and sort them on the date. 641 ArrayList<ImageEntry> dateImgLst = getSortedImgList(); 642 for (ImageEntry ie : dateImgLst) { 643 ie.cleanTmp(); 644 } 645 646 GpxDataWrapper selGpx = selectedGPX(false); 647 if (selGpx == null) 648 return tr("No gpx selected"); 649 650 final long offset_ms = ((long) (timezone * 3600) + delta) * 1000; // in milliseconds 651 lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, offset_ms); 652 653 return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>", 654 "<html>Matched <b>{0}</b> of <b>{1}</b> photos to GPX track.</html>", 655 dateImgLst.size(), lastNumMatched, dateImgLst.size()); 656 } 657 }; 658 659 tfTimezone.getDocument().addDocumentListener(statusBarListener); 660 tfOffset.getDocument().addDocumentListener(statusBarListener); 661 cbExifImg.addItemListener(statusBarListener); 662 cbTaggedImg.addItemListener(statusBarListener); 663 664 statusBarListener.updateStatusBar(); 629 tfTimezone.addFocusListener(repaintTheMap); 630 tfOffset.addFocusListener(repaintTheMap); 631 632 tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 633 tfOffset.getDocument().addDocumentListener(statusBarUpdater); 634 cbExifImg.addItemListener(statusBarUpdaterWithRepaint); 635 cbTaggedImg.addItemListener(statusBarUpdaterWithRepaint); 636 637 statusBarUpdater.updateStatusBar(); 665 638 666 639 outerPanel = new JPanel(); … … 784 757 } 785 758 786 private static abstract class StatusBarListener implements DocumentListener, ItemListener { 759 StatusBarUpdater statusBarUpdater = new StatusBarUpdater(false); 760 StatusBarUpdater statusBarUpdaterWithRepaint = new StatusBarUpdater(true); 761 762 private class StatusBarUpdater implements DocumentListener, ItemListener, ActionListener { 763 private boolean doRepaint; 764 765 public StatusBarUpdater(boolean doRepaint) { 766 this.doRepaint = doRepaint; 767 } 768 787 769 public void insertUpdate(DocumentEvent ev) { 788 770 updateStatusBar(); … … 796 778 updateStatusBar(); 797 779 } 798 abstract public void updateStatusBar(); 780 public void actionPerformed(ActionEvent e) { 781 updateStatusBar(); 782 } 783 784 public void updateStatusBar() { 785 statusBarText.setText(statusText()); 786 if (doRepaint) { 787 yLayer.updateBufferAndRepaint(); 788 } 789 } 790 791 private String statusText() { 792 try { 793 timezone = parseTimezone(tfTimezone.getText().trim()); 794 delta = parseOffset(tfOffset.getText().trim()); 795 } catch (ParseException e) { 796 return e.getMessage(); 797 } 798 799 // The selection of images we are about to correlate may have changed. 800 // So reset all images. 801 for (ImageEntry ie: yLayer.data) { 802 ie.tmp = null; 803 } 804 805 // Construct a list of images that have a date, and sort them on the date. 806 ArrayList<ImageEntry> dateImgLst = getSortedImgList(); 807 // Create a temporary copy for each image 808 for (ImageEntry ie : dateImgLst) { 809 ie.cleanTmp(); 810 } 811 812 GpxDataWrapper selGpx = selectedGPX(false); 813 if (selGpx == null) 814 return tr("No gpx selected"); 815 816 final long offset_ms = ((long) (timezone * 3600) + delta) * 1000; // in milliseconds 817 lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, offset_ms); 818 819 return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>", 820 "<html>Matched <b>{0}</b> of <b>{1}</b> photos to GPX track.</html>", 821 dateImgLst.size(), lastNumMatched, dateImgLst.size()); 822 } 823 } 824 825 RepaintTheMapListener repaintTheMap = new RepaintTheMapListener(); 826 private class RepaintTheMapListener implements FocusListener { 827 public void focusGained(FocusEvent e) { // do nothing 828 } 829 830 public void focusLost(FocusEvent e) { 831 yLayer.updateBufferAndRepaint(); 832 } 799 833 } 800 834 … … 875 909 delta = sldMinutes.getValue()*60 + sldSeconds.getValue(); 876 910 877 tfTimezone.getDocument().removeDocumentListener(statusBar Listener);878 tfOffset.getDocument().removeDocumentListener(statusBar Listener);911 tfTimezone.getDocument().removeDocumentListener(statusBarUpdater); 912 tfOffset.getDocument().removeDocumentListener(statusBarUpdater); 879 913 880 914 tfTimezone.setText(formatTimezone(timezone)); 881 915 tfOffset.setText(Long.toString(delta + 24*60*60L*dayOffset)); // add the day offset to the offset field 882 916 883 tfTimezone.getDocument().addDocumentListener(statusBar Listener);884 tfOffset.getDocument().addDocumentListener(statusBar Listener);917 tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 918 tfOffset.getDocument().addDocumentListener(statusBarUpdater); 885 919 886 920 lblMatches.setText(statusBarText.getText() + "<br>" + trn("(Time difference of {0} day)", "Time difference of {0} days", Math.abs(dayOffset), Math.abs(dayOffset))); 887 921 888 statusBar Listener.updateStatusBar();922 statusBarUpdater.updateStatusBar(); 889 923 yLayer.updateBufferAndRepaint(); 890 924 } … … 1009 1043 System.out.println("offt " + delta);*/ 1010 1044 1011 tfTimezone.getDocument().removeDocumentListener(statusBar Listener);1012 tfOffset.getDocument().removeDocumentListener(statusBar Listener);1045 tfTimezone.getDocument().removeDocumentListener(statusBarUpdater); 1046 tfOffset.getDocument().removeDocumentListener(statusBarUpdater); 1013 1047 1014 1048 tfTimezone.setText(formatTimezone(timezone)); … … 1016 1050 tfOffset.requestFocus(); 1017 1051 1018 tfTimezone.getDocument().addDocumentListener(statusBar Listener);1019 tfOffset.getDocument().addDocumentListener(statusBar Listener);1020 1021 statusBar Listener.updateStatusBar();1052 tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 1053 tfOffset.getDocument().addDocumentListener(statusBarUpdater); 1054 1055 statusBarUpdater.updateStatusBar(); 1022 1056 yLayer.updateBufferAndRepaint(); 1023 1057 }
Note:
See TracChangeset
for help on using the changeset viewer.