X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2Fgpsies%2FTrackListModel.java;h=94ce503e41da2498ce36beb7c2d51dd7d04f1b14;hb=ff33ebba6b7c62834f6dae16ce33eb2c710b160e;hp=904dd8bc62248d49fe4e5669ee37fccc19a643a3;hpb=4d5796d02a15808311c09448d79e6e7d1de9d636;p=GpsPrune.git diff --git a/tim/prune/function/gpsies/TrackListModel.java b/tim/prune/function/gpsies/TrackListModel.java index 904dd8b..94ce503 100644 --- a/tim/prune/function/gpsies/TrackListModel.java +++ b/tim/prune/function/gpsies/TrackListModel.java @@ -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 _trackList = null; + private ArrayList _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 inList) + public void addTracks(ArrayList 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 inList, boolean inSort) { - if (_trackList == null) {_trackList = new ArrayList();} + if (_trackList == null) {_trackList = new ArrayList();} 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); }