]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/function/gpsies/TrackListModel.java
Version 18.1, September 2015
[GpsPrune.git] / tim / prune / function / gpsies / TrackListModel.java
index 904dd8bc62248d49fe4e5669ee37fccc19a643a3..94ce503e41da2498ce36beb7c2d51dd7d04f1b14 100644 (file)
@@ -2,12 +2,14 @@ package tim.prune.function.gpsies;
 
 import java.text.NumberFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 
 import javax.swing.table.AbstractTableModel;
 
 import tim.prune.I18nManager;
 import tim.prune.config.Config;
 import tim.prune.data.Unit;
+import tim.prune.function.search.SearchResult;
 
 /**
  * Model for list of tracks from gpsies.com
@@ -15,7 +17,7 @@ import tim.prune.data.Unit;
 public class TrackListModel extends AbstractTableModel
 {
        /** List of tracks */
-       private ArrayList<GpsiesTrack> _trackList = null;
+       private ArrayList<SearchResult> _trackList = null;
        /** Column heading for track name */
        private String _nameColLabel = null;
        /** Column heading for length */
@@ -57,6 +59,12 @@ public class TrackListModel extends AbstractTableModel
                return _trackList.size();
        }
 
+       /** @return true if there are no rows */
+       public boolean isEmpty()
+       {
+               return getRowCount() == 0;
+       }
+
        /**
         * @param inColNum column number
         * @return column label for given column
@@ -74,7 +82,7 @@ public class TrackListModel extends AbstractTableModel
         */
        public Object getValueAt(int inRowNum, int inColNum)
        {
-               GpsiesTrack track = _trackList.get(inRowNum);
+               SearchResult track = _trackList.get(inRowNum);
                if (inColNum == 0) {return track.getTrackName();}
                double lengthM = track.getLength();
                // convert to current distance units
@@ -88,12 +96,26 @@ public class TrackListModel extends AbstractTableModel
         * Add a list of tracks to this model
         * @param inList list of tracks to add
         */
-       public void addTracks(ArrayList<GpsiesTrack> inList)
+       public void addTracks(ArrayList<SearchResult> inList)
+       {
+               addTracks(inList, false);
+       }
+
+       /**
+        * Add a list of tracks to this model and optionally sort them
+        * @param inList list of tracks to add
+        * @param inSort true to sort results after adding
+        */
+       public void addTracks(ArrayList<SearchResult> inList, boolean inSort)
        {
-               if (_trackList == null) {_trackList = new ArrayList<GpsiesTrack>();}
+               if (_trackList == null) {_trackList = new ArrayList<SearchResult>();}
                final int prevCount = _trackList.size();
-               if (inList != null && inList.size() > 0) {
+               if (inList != null && inList.size() > 0)
+               {
                        _trackList.addAll(inList);
+                       if (inSort) {
+                               Collections.sort(_trackList);
+                       }
                }
                final int updatedCount = _trackList.size();
                if (prevCount <= 0)
@@ -106,7 +128,7 @@ public class TrackListModel extends AbstractTableModel
         * @param inRowNum row number from 0
         * @return track object for this row
         */
-       public GpsiesTrack getTrack(int inRowNum)
+       public SearchResult getTrack(int inRowNum)
        {
                return _trackList.get(inRowNum);
        }