Changeset 17845 in josm for trunk/src/org
- Timestamp:
- 2021-05-01T14:00:25+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r17748 r17845 33 33 import org.openstreetmap.josm.tools.ListenerList; 34 34 import org.openstreetmap.josm.tools.ListeningCollection; 35 import org.openstreetmap.josm.tools.date.Interval; 35 36 36 37 /** … … 718 719 * returns minimum and maximum timestamps in the track 719 720 * @param trk track to analyze 720 * @return minimum and maximum dates in array of 2 elements721 */ 722 public static Instant[]getMinMaxTimeForTrack(IGpxTrack trk) {721 * @return minimum and maximum as interval 722 */ 723 public static Optional<Interval> getMinMaxTimeForTrack(IGpxTrack trk) { 723 724 final LongSummaryStatistics statistics = trk.getSegments().stream() 724 725 .flatMap(seg -> seg.getWayPoints().stream()) … … 726 727 .summaryStatistics(); 727 728 return statistics.getCount() == 0 || (statistics.getMin() == 0 && statistics.getMax() == 0) 728 ? null729 : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())};729 ? Optional.empty() 730 : Optional.of(new Interval(Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax()))); 730 731 } 731 732 … … 734 735 * Warning: there are lot of track with broken timestamps, 735 736 * so we just ignore points from future and from year before 1970 in this method 736 * @return minimum and maximum dates in array of 2 elements737 * @return minimum and maximum as interval 737 738 * @since 7319 738 739 */ 739 public synchronized Instant[]getMinMaxTimeForAllTracks() {740 public synchronized Optional<Interval> getMinMaxTimeForAllTracks() { 740 741 long now = System.currentTimeMillis(); 741 742 final LongSummaryStatistics statistics = tracks.stream() … … 746 747 .summaryStatistics(); 747 748 return statistics.getCount() == 0 748 ? new Instant[0]749 : new Instant[]{Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax())};749 ? Optional.empty() 750 : Optional.of(new Interval(Instant.ofEpochMilli(statistics.getMin()), Instant.ofEpochMilli(statistics.getMax()))); 750 751 } 751 752 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r17842 r17845 40 40 import org.openstreetmap.josm.tools.Logging; 41 41 import org.openstreetmap.josm.tools.Utils; 42 import org.openstreetmap.josm.tools.date. DateUtils;42 import org.openstreetmap.josm.tools.date.Interval; 43 43 44 44 import javax.swing.AbstractAction; … … 53 53 import java.io.File; 54 54 import java.time.Instant; 55 import java.time.format.DateTimeFormatter;56 import java.time.format.FormatStyle;57 55 import java.util.ArrayList; 58 56 import java.util.Arrays; … … 157 155 */ 158 156 public static String getTimespanForTrack(IGpxTrack trk) { 159 Instant[] bounds = GpxData.getMinMaxTimeForTrack(trk); 160 return bounds != null ? formatTimespan(bounds) : ""; 161 } 162 163 /** 164 * Formats the timespan of the given track as a human readable string 165 * @param bounds The bounds to format, i.e., an array containing the min/max date 166 * @return The timespan as a string 167 */ 168 public static String formatTimespan(Instant[] bounds) { 169 String ts = ""; 170 DateTimeFormatter df = DateUtils.getDateFormatter(FormatStyle.SHORT); 171 String earliestDate = df.format(bounds[0]); 172 String latestDate = df.format(bounds[1]); 173 174 if (earliestDate.equals(latestDate)) { 175 DateTimeFormatter tf = DateUtils.getTimeFormatter(FormatStyle.SHORT); 176 ts += earliestDate + ' '; 177 ts += tf.format(bounds[0]) + " \u2013 " + tf.format(bounds[1]); 178 } else { 179 DateTimeFormatter dtf = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.MEDIUM); 180 ts += dtf.format(bounds[0]) + " \u2013 " + dtf.format(bounds[1]); 181 } 182 183 ts += String.format(" (%s)", Utils.getDurationString(bounds[1].toEpochMilli() - bounds[0].toEpochMilli())); 184 return ts; 157 return GpxData.getMinMaxTimeForTrack(trk).map(Interval::format).orElse(""); 185 158 } 186 159 … … 354 327 long to = toDate.toEpochMilli(); 355 328 for (IGpxTrack trk : data.getTracks()) { 356 In stant[] t = GpxData.getMinMaxTimeForTrack(trk);329 Interval t = GpxData.getMinMaxTimeForTrack(trk).orElse(null); 357 330 358 331 if (t == null) continue; 359 long tm = t [1].toEpochMilli();332 long tm = t.getEnd().toEpochMilli(); 360 333 trackVisibility[i] = (tm == 0 && showWithoutDate) || (from <= tm && tm <= to); 361 334 i++; -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
r17841 r17845 54 54 import org.openstreetmap.josm.tools.ImageProvider; 55 55 import org.openstreetmap.josm.tools.OpenBrowser; 56 import org.openstreetmap.josm.tools.date.Interval; 56 57 57 58 /** … … 88 89 String name = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_NAME)).orElse(""); 89 90 String desc = (String) Optional.ofNullable(attr.get(GpxConstants.GPX_DESC)).orElse(""); 90 In stant[] time = GpxData.getMinMaxTimeForTrack(trk);91 Interval time = GpxData.getMinMaxTimeForTrack(trk).orElse(null); 91 92 String url = (String) Optional.ofNullable(attr.get("url")).orElse(""); 92 93 tracks[i] = new Object[]{name, desc, time, trk.length(), url, trk}; … … 140 141 t.setRowSorter(rowSorter); 141 142 rowSorter.setModel(model); 142 rowSorter.setComparator(2, Comparator.comparing((In stant[] d) -> d == null ? Instant.MIN : d[0]));143 rowSorter.setComparator(2, Comparator.comparing((Interval d) -> d == null ? Instant.MIN : d.getStart())); 143 144 rowSorter.setComparator(3, Comparator.comparingDouble(length -> (double) length)); 144 145 // default column widths … … 150 151 public Component getTableCellRendererComponent( 151 152 JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 152 if (value instanceof In stant[]) {153 value = GpxLayer.formatTimespan(((Instant[]) value));153 if (value instanceof Interval) { 154 value = ((Interval) value).format(); 154 155 } 155 156 return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); … … 327 328 JComponent jc = (JComponent) c; 328 329 Object value = getValueAt(row, col); 329 jc.setToolTipText( col == 2 ? Arrays.toString((Instant[]) value) :String.valueOf(value));330 jc.setToolTipText(String.valueOf(value)); 330 331 if (content.length > row 331 332 && content[row].length > 5 -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DateFilterPanel.java
r17842 r17845 20 20 import org.openstreetmap.josm.spi.preferences.Config; 21 21 import org.openstreetmap.josm.tools.GBC; 22 import org.openstreetmap.josm.tools.date.Interval; 22 23 23 24 /** … … 51 52 this.layer = layer; 52 53 53 final Instant startTime, endTime; 54 Instant[] bounds = layer.data.getMinMaxTimeForAllTracks(); 55 if (bounds.length == 0) { 56 startTime = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant(); 57 endTime = Instant.now(); 58 } else { 59 startTime = bounds[0]; 60 endTime = bounds[1]; 61 } 62 63 dateFrom.setDate(startTime); 64 dateTo.setDate(endTime); 65 dateFrom.setRange(startTime, endTime); 66 dateTo.setRange(startTime, endTime); 54 Interval interval = layer.data.getMinMaxTimeForAllTracks() 55 .orElseGet(() -> new Interval(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant(), Instant.now())); 56 dateFrom.setDate(interval.getStart()); 57 dateTo.setDate(interval.getEnd()); 58 dateFrom.setRange(interval.getStart(), interval.getEnd()); 59 dateTo.setRange(interval.getStart(), interval.getEnd()); 67 60 68 61 add(noTimestampCb, GBC.std().grid(1, 1).insets(0, 0, 5, 0)); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r17715 r17845 60 60 import org.openstreetmap.josm.tools.Stopwatch; 61 61 import org.openstreetmap.josm.tools.Utils; 62 import org.openstreetmap.josm.tools.date.Interval; 62 63 63 64 /** … … 565 566 double now = System.currentTimeMillis()/1000.0; 566 567 if (colored == ColorMode.TIME) { 567 Instant[] bounds = data.getMinMaxTimeForAllTracks(); 568 if (bounds.length >= 2) { 569 minval = bounds[0].getEpochSecond(); 570 maxval = bounds[1].getEpochSecond(); 571 } else { 572 minval = 0; 573 maxval = now; 574 } 568 Interval interval = data.getMinMaxTimeForAllTracks().orElse(new Interval(Instant.EPOCH, Instant.now())); 569 minval = interval.getStart().getEpochSecond(); 570 maxval = interval.getEnd().getEpochSecond(); 575 571 dateScale.setRange(minval, maxval); 576 572 }
Note:
See TracChangeset
for help on using the changeset viewer.