001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.gpx;
003
004import java.awt.Color;
005import java.util.Collection;
006
007import org.openstreetmap.josm.data.Bounds;
008
009/**
010 * Gpx track. Implementations don't have to be immutable, but should always be thread safe.
011 * @since 15496
012 */
013public interface IGpxTrack extends IWithAttributes {
014
015    /**
016     * Returns the track segments.
017     * @return the track segments
018     */
019    Collection<IGpxTrackSegment> getSegments();
020
021    /**
022     * Returns the track bounds.
023     * @return the track bounds
024     */
025    Bounds getBounds();
026
027    /**
028     * Returns the track length.
029     * @return the track length
030     */
031    double length();
032
033    /**
034     * Gets the color of this track.
035     * @return The color, <code>null</code> if not set or not supported by the implementation.
036     * @since 15496
037     */
038    default Color getColor() {
039        return null;
040    }
041
042    /**
043     * Sets the color of this track. Not necessarily supported by all implementations.
044     * @param color color of this track
045     * @since 15496
046     */
047    default void setColor(Color color) {}
048
049    /**
050     * Add a listener that listens to changes in the GPX track.
051     * @param l The listener
052     */
053    default void addListener(GpxTrackChangeListener l) {
054        // nop
055    }
056
057    /**
058     * Remove a listener that listens to changes in the GPX track.
059     * @param l The listener
060     */
061    default void removeListener(GpxTrackChangeListener l) {
062        // nop
063    }
064
065    /**
066     * A listener that listens to GPX track changes.
067     * @author Michael Zangl
068     * @since 15496
069     */
070    @FunctionalInterface
071    interface GpxTrackChangeListener {
072        /**
073         * Called when the gpx data changed.
074         * @param e The event
075         */
076        void gpxDataChanged(GpxTrackChangeEvent e);
077    }
078
079    /**
080     * A track change event for the current track.
081     * @author Michael Zangl
082     * @since 15496
083     */
084    class GpxTrackChangeEvent {
085        private final IGpxTrack source;
086
087        GpxTrackChangeEvent(IGpxTrack source) {
088            super();
089            this.source = source;
090        }
091
092        /**
093         * Get the track that was changed.
094         * @return The track.
095         */
096        public IGpxTrack getSource() {
097            return source;
098        }
099    }
100}