Changeset 2676 in josm for trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
- Timestamp:
- 2009-12-24T08:48:40+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r2662 r2676 40 40 import javax.swing.AbstractListModel; 41 41 import javax.swing.BorderFactory; 42 import javax.swing.ButtonGroup;43 42 import javax.swing.JButton; 44 43 import javax.swing.JCheckBox; … … 49 48 import javax.swing.JOptionPane; 50 49 import javax.swing.JPanel; 51 import javax.swing.JRadioButton;52 50 import javax.swing.JScrollPane; 53 51 import javax.swing.JSeparator; … … 90 88 double timezone; 91 89 long delta; 92 90 93 91 public CorrelateGpxWithImages(GeoImageLayer layer) { 94 92 this.yLayer = layer; … … 123 121 JLabel statusBarText; 124 122 StatusBarListener statusBarListener; 125 123 126 124 // remember the last number of matched photos 127 125 int lastNumMatched = 0; … … 440 438 public void actionPerformed(ActionEvent arg0) { 441 439 // Construct the list of loaded GPX tracks 442 Collection<Layer> layerLst = Main.ma in.map.mapView.getAllLayers();440 Collection<Layer> layerLst = Main.map.mapView.getAllLayers(); 443 441 GpxDataWrapper defaultItem = null; 444 442 Iterator<Layer> iterLayer = layerLst.iterator(); … … 491 489 timezone = 0; 492 490 } 493 491 494 492 tfTimezone = new JTextField(10); 495 493 tfTimezone.setText(formatTimezone(timezone)); 496 494 497 495 try { 498 delta = parseOffset(Main.pref.get("geoimage.delta", "0"));496 delta = parseOffset(Main.pref.get("geoimage.delta", "0")); 499 497 } catch (ParseException e) { 500 498 delta = 0; 501 499 } 502 500 delta = delta / 1000; 503 501 504 502 tfOffset = new JTextField(10); 505 503 tfOffset.setText(Long.toString(delta)); 506 507 JPanel panelBtn = new JPanel(); 508 504 509 505 JButton buttonViewGpsPhoto = new JButton(tr("<html>Use photo of an accurate clock,<br>" 510 506 + "e.g. GPS receiver display</html>")); … … 519 515 520 516 JLabel labelPosition = new JLabel(tr("Override position for: ")); 521 517 522 518 int numAll = getSortedImgList(true, true).size(); 523 519 int numExif = numAll - getSortedImgList(false, true).size(); … … 529 525 cbTaggedImg = new JCheckBox(tr("Images that are already tagged ({0}/{1})", numTagged, numAll), true); 530 526 cbTaggedImg.setEnabled(numTagged != 0); 531 527 532 528 labelPosition.setEnabled(cbExifImg.isEnabled() || cbTaggedImg.isEnabled()); 533 529 … … 540 536 yLayer.loadThumbs(); 541 537 } else { 542 } 538 } 543 539 } 544 540 });*/ … … 549 545 gbc.gridy = y++; 550 546 panelTf.add(panelCb, gbc); 551 552 547 548 553 549 gbc = GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,12); 554 550 gbc.gridx = 0; … … 578 574 gbc.weightx = 1.; 579 575 panelTf.add(tfOffset, gbc); 580 576 581 577 gbc = GBC.std().insets(5,5,5,5); 582 578 gbc.gridx = 2; … … 593 589 gbc.weightx = 0.5; 594 590 panelTf.add(buttonAutoGuess, gbc); 595 591 596 592 gbc.gridx = 3; 597 593 panelTf.add(buttonAdjust, gbc); … … 628 624 statusBarText.setFont(statusBarText.getFont().deriveFont(8)); 629 625 statusBar.add(statusBarText); 630 626 631 627 statusBarListener = new StatusBarListener() { 632 628 @Override … … 639 635 delta = parseOffset(tfOffset.getText().trim()); 640 636 } catch (ParseException e) { 641 642 } 643 637 return e.getMessage(); 638 } 639 644 640 // Construct a list of images that have a date, and sort them on the date. 645 641 ArrayList<ImageEntry> dateImgLst = getSortedImgList(); … … 647 643 ie.cleanTmp(); 648 644 } 649 645 650 646 GpxDataWrapper selGpx = selectedGPX(false); 651 647 if (selGpx == null) 652 648 return tr("No gpx selected"); 653 649 654 650 lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, (long) (timezone * 3600) + delta); 655 651 … … 657 653 } 658 654 }; 659 655 660 656 tfTimezone.getDocument().addDocumentListener(statusBarListener); 661 657 tfOffset.getDocument().addDocumentListener(statusBarListener); 662 658 cbExifImg.addItemListener(statusBarListener); 663 659 cbTaggedImg.addItemListener(statusBarListener); 664 660 665 661 statusBarListener.updateStatusBar(); 666 662 … … 683 679 syncDialog.pack(); 684 680 syncDialog.addWindowListener(new WindowAdapter() { 685 final int CANCEL = -1;686 final int DONE = 0;687 final int AGAIN = 1;688 final int NOTHING = 2;681 final static int CANCEL = -1; 682 final static int DONE = 0; 683 final static int AGAIN = 1; 684 final static int NOTHING = 2; 689 685 private int checkAndSave() { 690 if (syncDialog.isVisible()) {686 if (syncDialog.isVisible()) 691 687 // nothing happened: JOSM was minimized or similar 692 return NOTHING; 693 } 688 return NOTHING; 694 689 int answer = syncDialog.getValue(); 695 690 if(answer != 1) … … 704 699 return AGAIN; 705 700 } 706 701 707 702 try { 708 703 delta = parseOffset(tfOffset.getText().trim()); 709 704 } catch (ParseException e) { 710 711 705 JOptionPane.showMessageDialog(Main.parent, e.getMessage(), 706 tr("Invalid offset"), JOptionPane.ERROR_MESSAGE); 712 707 return AGAIN; 713 708 } 714 709 715 710 if (lastNumMatched == 0) { 716 711 if (new ExtendedDialog( … … 718 713 tr("Correlate images with GPX track"), 719 714 new String[] { tr("OK"), tr("Try Again") }). 720 setContent(tr("No images could be matched!")).721 setButtonIcons(new String[] { "ok.png", "dialogs/refresh.png"}).722 showDialog().getValue() == 2)723 715 setContent(tr("No images could be matched!")). 716 setButtonIcons(new String[] { "ok.png", "dialogs/refresh.png"}). 717 showDialog().getValue() == 2) 718 return AGAIN; 724 719 } 725 720 return DONE; 726 721 } 727 722 723 @Override 728 724 public void windowDeactivated(WindowEvent e) { 729 725 int result = checkAndSave(); 730 726 switch (result) { 731 case NOTHING: 732 break; 733 case CANCEL: 734 { 735 for (ImageEntry ie : yLayer.data) { 736 ie.tmp = null; 737 } 738 yLayer.updateBufferAndRepaint(); 739 break; 727 case NOTHING: 728 break; 729 case CANCEL: 730 { 731 for (ImageEntry ie : yLayer.data) { 732 ie.tmp = null; 740 733 } 741 case AGAIN: 742 actionPerformed(null); 743 break; 744 case DONE: 745 { 746 Main.pref.put("geoimage.timezone", formatTimezone(timezone)); 747 Main.pref.put("geoimage.delta", Long.toString(delta * 1000)); 748 Main.pref.put("geoimage.showThumbs", yLayer.useThumbs); 749 750 yLayer.useThumbs = cbShowThumbs.isSelected();//FIXME 751 yLayer.loadThumbs(); 752 753 // Search whether an other layer has yet defined some bounding box. 754 // If none, we'll zoom to the bounding box of the layer with the photos. 755 boolean boundingBoxedLayerFound = false; 756 for (Layer l: Main.map.mapView.getAllLayers()) { 757 if (l != yLayer) { 758 BoundingXYVisitor bbox = new BoundingXYVisitor(); 759 l.visitBoundingBox(bbox); 760 if (bbox.getBounds() != null) { 761 boundingBoxedLayerFound = true; 762 break; 763 } 734 yLayer.updateBufferAndRepaint(); 735 break; 736 } 737 case AGAIN: 738 actionPerformed(null); 739 break; 740 case DONE: 741 { 742 Main.pref.put("geoimage.timezone", formatTimezone(timezone)); 743 Main.pref.put("geoimage.delta", Long.toString(delta * 1000)); 744 Main.pref.put("geoimage.showThumbs", yLayer.useThumbs); 745 746 yLayer.useThumbs = cbShowThumbs.isSelected();//FIXME 747 yLayer.loadThumbs(); 748 749 // Search whether an other layer has yet defined some bounding box. 750 // If none, we'll zoom to the bounding box of the layer with the photos. 751 boolean boundingBoxedLayerFound = false; 752 for (Layer l: Main.map.mapView.getAllLayers()) { 753 if (l != yLayer) { 754 BoundingXYVisitor bbox = new BoundingXYVisitor(); 755 l.visitBoundingBox(bbox); 756 if (bbox.getBounds() != null) { 757 boundingBoxedLayerFound = true; 758 break; 764 759 } 765 760 } 766 if (! boundingBoxedLayerFound) {767 BoundingXYVisitor bbox = new BoundingXYVisitor();768 yLayer.visitBoundingBox(bbox);769 Main.map.mapView.recalculateCenterScale(bbox);770 }771 772 773 for (ImageEntry ie : yLayer.data) {774 ie.applyTmp();775 }776 777 yLayer.updateBufferAndRepaint();778 779 780 break;781 761 } 782 default: 783 throw new IllegalStateException(); 762 if (! boundingBoxedLayerFound) { 763 BoundingXYVisitor bbox = new BoundingXYVisitor(); 764 yLayer.visitBoundingBox(bbox); 765 Main.map.mapView.recalculateCenterScale(bbox); 766 } 767 768 769 for (ImageEntry ie : yLayer.data) { 770 ie.applyTmp(); 771 } 772 773 yLayer.updateBufferAndRepaint(); 774 775 776 break; 777 } 778 default: 779 throw new IllegalStateException(); 784 780 } 785 781 } … … 807 803 */ 808 804 private class AdjustActionListener implements ActionListener { 809 805 810 806 public void actionPerformed(ActionEvent arg0) { 811 807 812 808 long diff = delta + Math.round(timezone*60*60); 813 809 814 810 double diffInH = (double)diff/(60*60); // hours 815 811 816 812 // Find day difference 817 813 final int dayOffset = (int)Math.round(diffInH / 24); // days 818 double tmz = diff - dayOffset*24*60*60 ; // seconds814 double tmz = diff - dayOffset*24*60*60l; // seconds 819 815 820 816 // In hours, rounded to two decimal places … … 881 877 tfTimezone.getDocument().removeDocumentListener(statusBarListener); 882 878 tfOffset.getDocument().removeDocumentListener(statusBarListener); 883 879 884 880 tfTimezone.setText(formatTimezone(timezone)); 885 tfOffset.setText(Long.toString(delta + dayOffset*24*60*60 )); // add the day offset to the offset field881 tfOffset.setText(Long.toString(delta + dayOffset*24*60*60l)); // add the day offset to the offset field 886 882 887 883 tfTimezone.getDocument().addDocumentListener(statusBarListener); … … 937 933 tr("Adjust timezone and offset"), 938 934 new String[] { tr("Close")}). 939 setContent(p).setButtonIcons(new String[] {"ok.png"}).showDialog();935 setContent(p).setButtonIcons(new String[] {"ok.png"}).showDialog(); 940 936 } 941 937 } 942 938 943 939 private class AutoGuessActionListener implements ActionListener { 944 940 945 941 public void actionPerformed(ActionEvent arg0) { 946 942 GpxDataWrapper gpxW = selectedGPX(true); … … 948 944 return; 949 945 GpxData gpx = gpxW.data; 950 946 951 947 ArrayList<ImageEntry> imgs = getSortedImgList(); 952 948 PrimaryDateParser dateParser = new PrimaryDateParser(); … … 996 992 // Find day difference 997 993 int dayOffset = (int)Math.round(diffInH / 24); // days 998 double tz = diff - dayOffset*24*60*60 ; // seconds994 double tz = diff - dayOffset*24*60*60l; // seconds 999 995 1000 996 // In hours, rounded to two decimal places … … 1004 1000 // -2 minutes offset. This determines the real timezone and finds offset. 1005 1001 timezone = (double)Math.round(tz * 2)/2; // hours, rounded to one decimal place 1006 delta = (long)Math.round(diff - timezone*60*60); // seconds1002 delta = Math.round(diff - timezone*60*60); // seconds 1007 1003 1008 1004 /*System.out.println("phto " + firstExifDate); … … 1017 1013 tfTimezone.getDocument().removeDocumentListener(statusBarListener); 1018 1014 tfOffset.getDocument().removeDocumentListener(statusBarListener); 1019 1015 1020 1016 tfTimezone.setText(formatTimezone(timezone)); 1021 1017 tfOffset.setText(Long.toString(delta)); … … 1024 1020 tfTimezone.getDocument().addDocumentListener(statusBarListener); 1025 1021 tfOffset.getDocument().addDocumentListener(statusBarListener); 1026 1022 1027 1023 statusBarListener.updateStatusBar(); 1028 1024 yLayer.updateBufferAndRepaint(); … … 1033 1029 return getSortedImgList(cbExifImg.isSelected(), cbTaggedImg.isSelected()); 1034 1030 } 1035 1031 1036 1032 /** 1037 1033 * Returns a list of images that fulfill the given criteria. 1038 1034 * Default setting is to return untagged images, but may be overwritten. 1039 1035 * @param boolean all -- returns all available images 1040 * @param boolean noexif -- returns untagged images without EXIF-GPS coords 1036 * @param boolean noexif -- returns untagged images without EXIF-GPS coords 1041 1037 * this parameter is irrelevant if <code>all</code> is true 1042 1038 * @param boolean exif -- also returns images with exif-gps info … … 1047 1043 ArrayList<ImageEntry> dateImgLst = new ArrayList<ImageEntry>(yLayer.data.size()); 1048 1044 for (ImageEntry e : yLayer.data) { 1049 if (e.time == null) 1045 if (e.time == null) { 1050 1046 continue; 1051 1047 } 1048 1052 1049 if (e.exifCoor != null) { 1053 if (!exif) 1050 if (!exif) { 1054 1051 continue; 1055 } 1056 1052 } 1053 } 1054 1057 1055 if (e.isTagged() && e.exifCoor == null) { 1058 if (!tagged) 1056 if (!tagged) { 1059 1057 continue; 1060 } 1061 1058 } 1059 } 1060 1062 1061 dateImgLst.add(e); 1063 1062 } 1064 1063 1065 1064 Collections.sort(dateImgLst, new Comparator<ImageEntry>() { 1066 1065 public int compare(ImageEntry arg0, ImageEntry arg1) { … … 1251 1250 1252 1251 private double parseTimezone(String timezone) throws ParseException { 1253 1252 1254 1253 String error = tr("Error while parsing timezone.\nExpected format: {0}", "+H:MM"); 1255 1256 1254 1255 1257 1256 if (timezone.length() == 0) 1258 1257 return 0; … … 1324 1323 private long parseOffset(String offset) throws ParseException { 1325 1324 String error = tr("Error while parsing offset.\nExpected format: {0}", "number"); 1326 1325 1327 1326 if (offset.length() > 0) { 1328 1327 try { … … 1334 1333 throw new ParseException(error,0); 1335 1334 } 1336 } else {1335 } else 1337 1336 return 0; 1338 }1339 1337 } 1340 1338 }
Note:
See TracChangeset
for help on using the changeset viewer.