]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/function/gpsies/TrackListModel.java
Version 19, May 2018
[GpsPrune.git] / tim / prune / function / gpsies / TrackListModel.java
index 298578c4330c5dab8eccf8f86da4cff19b33187f..850921303801d33878c6b429ec2709087ed7fd6a 100644 (file)
@@ -2,6 +2,7 @@ package tim.prune.function.gpsies;
 
 import java.text.NumberFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 
 import javax.swing.table.AbstractTableModel;
 
@@ -11,7 +12,7 @@ import tim.prune.data.Unit;
 import tim.prune.function.search.SearchResult;
 
 /**
- * Model for list of tracks from gpsies.com
+ * Model for list of tracks from a search result (eg gpsies.com, geonames, overpass)
  */
 public class TrackListModel extends AbstractTableModel
 {
@@ -23,6 +24,8 @@ public class TrackListModel extends AbstractTableModel
        private String _lengthColLabel = null;
        /** Number of columns */
        private int _numColumns = 2;
+       /** Normally this model shows distances / lengths, except when this flag is true */
+       private boolean _showPointTypes = false;
        /** Formatter for distances */
        private NumberFormat _distanceFormatter = NumberFormat.getInstance();
 
@@ -74,6 +77,14 @@ public class TrackListModel extends AbstractTableModel
                return _lengthColLabel;
        }
 
+       /**
+        * @param inShowTypes true to show point types, false for distances
+        */
+       public void setShowPointTypes(boolean inShowTypes)
+       {
+               _showPointTypes = inShowTypes;
+       }
+
        /**
         * @param inRowNum row number
         * @param inColNum column number
@@ -82,7 +93,13 @@ public class TrackListModel extends AbstractTableModel
        public Object getValueAt(int inRowNum, int inColNum)
        {
                SearchResult track = _trackList.get(inRowNum);
-               if (inColNum == 0) {return track.getTrackName();}
+               if (inColNum == 0) {
+                       return track.getTrackName();
+               }
+               if (_showPointTypes)
+               {
+                       return track.getPointType();
+               }
                double lengthM = track.getLength();
                // convert to current distance units
                Unit distUnit = Config.getUnitSet().getDistanceUnit();
@@ -96,11 +113,25 @@ public class TrackListModel extends AbstractTableModel
         * @param inList list of tracks to add
         */
        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<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)