001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.gpx; 003 004import java.util.Collection; 005import java.util.Map; 006 007import org.openstreetmap.josm.data.Bounds; 008 009/** 010 * Read-only gpx track. Implementations doesn't have to be immutable, but should always be thread safe. 011 * @since 444 012 */ 013public interface GpxTrack extends IWithAttributes { 014 015 /** 016 * Returns the track segments. 017 * @return the track segments 018 */ 019 Collection<GpxTrackSegment> getSegments(); 020 021 /** 022 * Returns the track attributes. 023 * @return the track attributes 024 */ 025 Map<String, Object> getAttributes(); 026 027 /** 028 * Returns the track bounds. 029 * @return the track bounds 030 */ 031 Bounds getBounds(); 032 033 /** 034 * Returns the track length. 035 * @return the track length 036 */ 037 double length(); 038 039 /** 040 * Add a listener that listens to changes in the GPX track. 041 * @param l The listener 042 */ 043 default void addListener(GpxTrackChangeListener l) { 044 // nop 045 } 046 047 /** 048 * Remove a listener that listens to changes in the GPX track. 049 * @param l The listener 050 */ 051 default void removeListener(GpxTrackChangeListener l) { 052 // nop 053 } 054 055 /** 056 * A listener that listens to GPX track changes. 057 * @author Michael Zangl 058 * @since 12156 059 */ 060 @FunctionalInterface 061 interface GpxTrackChangeListener { 062 /** 063 * Called when the gpx data changed. 064 * @param e The event 065 */ 066 void gpxDataChanged(GpxTrackChangeEvent e); 067 } 068 069 /** 070 * A track change event for the current track. 071 * @author Michael Zangl 072 * @since 12156 073 */ 074 class GpxTrackChangeEvent { 075 private final GpxTrack source; 076 077 GpxTrackChangeEvent(GpxTrack source) { 078 super(); 079 this.source = source; 080 } 081 082 /** 083 * Get the track that was changed. 084 * @return The track. 085 */ 086 public GpxTrack getSource() { 087 return source; 088 } 089 } 090}