Changeset 9742 in josm for trunk/src/org
- Timestamp:
- 2016-02-05T00:31:52+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r9741 r9742 35 35 import java.util.Hashtable; 36 36 import java.util.List; 37 import java.util.Locale; 37 38 import java.util.Objects; 38 39 import java.util.TimeZone; … … 869 870 public void actionPerformed(ActionEvent arg0) { 870 871 871 long diff = delta.getSeconds() + Math.round(timezone.getHours() * 60 * 60); 872 873 double diffInH = (double) diff/(60*60); // hours 874 875 // Find day difference 876 final int dayOffset = (int) Math.round(diffInH / 24); // days 877 double tmz = diff - dayOffset*24*60*60L; // seconds 878 879 // In hours, rounded to two decimal places 880 tmz = (double) Math.round(tmz*100/(60*60)) / 100; 881 882 // Due to imprecise clocks we might get a "+3:28" timezone, which should obviously be 3:30 with 883 // -2 minutes offset. This determines the real timezone and finds offset. 884 double fixTimezone = (double) Math.round(tmz * 2)/2; // hours, rounded to one decimal place 885 int offset = (int) Math.round(diff - fixTimezone*60*60) - dayOffset*24*60*60; // seconds 872 final Offset offset = Offset.milliseconds( 873 delta.getMilliseconds() + Math.round(timezone.getHours() * 60 * 60 * 1000)); 874 final int dayOffset = offset.getDayOffset(); 875 final Pair<Timezone, Offset> timezoneOffsetPair = offset.withoutDayOffset().splitOutTimezone(); 886 876 887 877 // Info Labels … … 895 885 Dictionary<Integer, JLabel> labelTable = new Hashtable<>(); 896 886 // CHECKSTYLE.OFF: ParenPad 897 labelTable.put(-24, new JLabel("-12:00")); 898 labelTable.put(-12, new JLabel( "-6:00")); 899 labelTable.put( 0, new JLabel( "0:00")); 900 labelTable.put( 12, new JLabel( "6:00")); 901 labelTable.put( 24, new JLabel( "12:00")); 887 for (int i = -12; i <= 12; i += 6) { 888 labelTable.put(i * 2, new JLabel(new Timezone(i).formatTimezone())); 889 } 902 890 // CHECKSTYLE.ON: ParenPad 903 891 sldTimezone.setLabelTable(labelTable); … … 911 899 // Seconds slider 912 900 final JLabel lblSeconds = new JLabel(); 913 final JSlider sldSeconds = new JSlider(-60 , 60, 0);901 final JSlider sldSeconds = new JSlider(-600, 600, 0); 914 902 sldSeconds.setPaintLabels(true); 915 sldSeconds.setMajorTickSpacing(30); 903 labelTable = new Hashtable<>(); 904 // CHECKSTYLE.OFF: ParenPad 905 for (int i = -60; i <= 60; i += 30) { 906 labelTable.put(i * 10, new JLabel(Offset.seconds(i).formatOffset())); 907 } 908 // CHECKSTYLE.ON: ParenPad 909 sldSeconds.setLabelTable(labelTable); 910 sldSeconds.setMajorTickSpacing(300); 916 911 917 912 // This is called whenever one of the sliders is moved. … … 920 915 @Override 921 916 public void stateChanged(ChangeEvent e) { 922 // parse slider position into real timezone 923 double tz = Math.abs(sldTimezone.getValue()); 924 String zone = tz % 2 == 0 925 ? (int) Math.floor(tz/2) + ":00" 926 : (int) Math.floor(tz/2) + ":30"; 927 if (sldTimezone.getValue() < 0) { 928 zone = '-' + zone; 929 } 930 931 lblTimezone.setText(tr("Timezone: {0}", zone)); 917 timezone = new Timezone(sldTimezone.getValue() / 2.); 918 919 lblTimezone.setText(tr("Timezone: {0}", timezone.formatTimezone())); 932 920 lblMinutes.setText(tr("Minutes: {0}", sldMinutes.getValue())); 933 lblSeconds.setText(tr("Seconds: {0}", sldSeconds.getValue())); 934 935 try { 936 timezone = Timezone.parseTimezone(zone); 937 } catch (ParseException pe) { 938 throw new RuntimeException(pe); 939 } 940 delta = Offset.seconds(sldMinutes.getValue() * 60 + sldSeconds.getValue() + 24 * 60 * 60L * dayOffset); // add the day offset 921 lblSeconds.setText(tr("Seconds: {0}", Offset.milliseconds(100 * sldSeconds.getValue()).formatOffset())); 922 923 delta = Offset.milliseconds(100 * sldSeconds.getValue() 924 + 1000L * 60 * sldMinutes.getValue() 925 + 1000L * 60 * 60 * 24 * dayOffset); 941 926 942 927 tfTimezone.getDocument().removeDocumentListener(statusBarUpdater); … … 972 957 // and inform the user about it. 973 958 try { 974 sldTimezone.setValue((int) (fixTimezone*2)); 975 sldMinutes.setValue(offset / 60); 976 sldSeconds.setValue(offset % 60); 959 sldTimezone.setValue((int) (timezoneOffsetPair.a.getHours() * 2)); 960 sldMinutes.setValue((int) (timezoneOffsetPair.b.getSeconds() / 60)); 961 final long deciSeconds = timezoneOffsetPair.b.getMilliseconds() / 100; 962 sldSeconds.setValue((int) (deciSeconds % 60)); 977 963 } catch (Exception e) { 978 964 JOptionPane.showMessageDialog(Main.parent, … … 1016 1002 1017 1003 // Init variables 1018 long firstExifDate = imgs.get(0).getExifTime().getTime() / 1000;1004 long firstExifDate = imgs.get(0).getExifTime().getTime(); 1019 1005 1020 1006 long firstGPXDate = -1; … … 1026 1012 final Date parsedTime = curWp.setTimeFromAttribute(); 1027 1013 if (parsedTime != null) { 1028 firstGPXDate = parsedTime.getTime() / 1000;1014 firstGPXDate = parsedTime.getTime(); 1029 1015 break outer; 1030 1016 } … … 1040 1026 } 1041 1027 1042 // seconds 1043 long diff = firstExifDate - firstGPXDate; 1044 1045 double diffInH = (double) diff / (60 * 60); // hours 1046 1047 // Find day difference 1048 int dayOffset = (int) Math.round(diffInH / 24); // days 1049 double tz = diff - dayOffset * 24 * 60 * 60L; // seconds 1050 1051 // In hours, rounded to two decimal places 1052 tz = (double) Math.round(tz * 100 / (60 * 60)) / 100; 1053 1054 // Due to imprecise clocks we might get a "+3:28" timezone, which should obviously be 3:30 with 1055 // -2 minutes offset. This determines the real timezone and finds offset. 1056 final double timezone = (double) Math.round(tz * 2) / 2; // hours, rounded to one decimal place 1057 final long delta = Math.round(diff - timezone * 60 * 60); // seconds 1058 return Pair.create(new Timezone(timezone), Offset.seconds(delta)); 1028 return Offset.milliseconds(firstExifDate - firstGPXDate).splitOutTimezone(); 1059 1029 } 1060 1030 … … 1470 1440 1471 1441 String formatOffset() { 1472 return Long.toString(milliseconds / 1000); 1442 if (milliseconds % 1000 == 0) { 1443 return Long.toString(milliseconds / 1000); 1444 } else if (milliseconds % 100 == 0) { 1445 return String.format(Locale.ENGLISH, "%.1f", milliseconds / 1000.); 1446 } else { 1447 return String.format(Locale.ENGLISH, "%.3f", milliseconds / 1000.); 1448 } 1473 1449 } 1474 1450 … … 1481 1457 offset = offset.substring(1); 1482 1458 } 1483 return Offset. seconds(Long.parseLong(offset));1459 return Offset.milliseconds(Math.round(Double.parseDouble(offset) * 1000)); 1484 1460 } catch (NumberFormatException nfe) { 1485 1461 throw new ParseException(error, 0); … … 1488 1464 return Offset.ZERO; 1489 1465 } 1466 } 1467 1468 int getDayOffset() { 1469 final double diffInH = (double) getMilliseconds() / 1000. / 60 / 60; // hours 1470 1471 // Find day difference 1472 return (int) Math.round(diffInH / 24); 1473 } 1474 1475 Offset withoutDayOffset() { 1476 return milliseconds(getMilliseconds() - getDayOffset() * 24 * 60 * 60 * 1000); 1477 } 1478 1479 Pair<Timezone, Offset> splitOutTimezone() { 1480 // In hours, rounded to two decimal places 1481 double tz = (double) Math.round(withoutDayOffset().getSeconds() * 100 / (60 * 60)) / 100; 1482 1483 // Due to imprecise clocks we might get a "+3:28" timezone, which should obviously be 3:30 with 1484 // -2 minutes offset. This determines the real timezone and finds offset. 1485 final double timezone = (double) Math.round(tz * 2) / 2; // hours, rounded to one decimal place 1486 final long delta = Math.round(getMilliseconds() - timezone * 60 * 60 * 1000); // milliseconds 1487 return Pair.create(new Timezone(timezone), Offset.milliseconds(delta)); 1490 1488 } 1491 1489
Note:
See TracChangeset
for help on using the changeset viewer.