X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2Fgpsies%2FTrackListModel.java;fp=tim%2Fprune%2Ffunction%2Fgpsies%2FTrackListModel.java;h=275ae83ab715117841efc47dae90d0bf18160354;hb=112bb0c9b46894adca9a33ed8c99ea712b253185;hp=0000000000000000000000000000000000000000;hpb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;p=GpsPrune.git diff --git a/tim/prune/function/gpsies/TrackListModel.java b/tim/prune/function/gpsies/TrackListModel.java new file mode 100644 index 0000000..275ae83 --- /dev/null +++ b/tim/prune/function/gpsies/TrackListModel.java @@ -0,0 +1,108 @@ +package tim.prune.function.gpsies; + +import java.text.NumberFormat; +import java.util.ArrayList; + +import javax.swing.table.AbstractTableModel; + +import tim.prune.Config; +import tim.prune.I18nManager; +import tim.prune.data.Distance; + +/** + * Model for list of tracks from gpsies.com + */ +public class TrackListModel extends AbstractTableModel +{ + /** List of tracks */ + private ArrayList _trackList = null; + /** Column heading for track name */ + private static final String _nameColLabel = I18nManager.getText("dialog.gpsies.column.name"); + /** Column heading for length */ + private static final String _lengthColLabel = I18nManager.getText("dialog.gpsies.column.length"); + /** Formatter for distances */ + private NumberFormat _distanceFormatter = NumberFormat.getInstance(); + + /** + * Constructor + */ + public TrackListModel() + { + _distanceFormatter.setMaximumFractionDigits(1); + } + + /** + * @return column count + */ + public int getColumnCount() + { + return 2; + } + + /** + * @return number of rows + */ + public int getRowCount() + { + if (_trackList == null) return 0; + return _trackList.size(); + } + + /** + * @param inColNum column number + * @return column label for given column + */ + public String getColumnName(int inColNum) + { + if (inColNum == 0) {return _nameColLabel;} + return _lengthColLabel; + } + + /** + * @param inRowNum row number + * @param inColNum column number + * @return cell entry at given row and column + */ + public Object getValueAt(int inRowNum, int inColNum) + { + GpsiesTrack track = _trackList.get(inRowNum); + if (inColNum == 0) {return track.getTrackName();} + double lengthM = track.getLength(); + if (Config.getConfigBoolean(Config.KEY_METRIC_UNITS)) { + return _distanceFormatter.format(lengthM / 1000.0) + " " + I18nManager.getText("units.kilometres.short"); + } + // must be imperial + return _distanceFormatter.format(Distance.convertMetresToMiles(lengthM)) + + " " + I18nManager.getText("units.miles.short"); + } + + /** + * Add a list of tracks to this model + * @param inList list of tracks to add + */ + public void addTracks(ArrayList inList) + { + if (_trackList == null) {_trackList = new ArrayList();} + if (inList != null && inList.size() > 0) { + _trackList.addAll(inList); + } + fireTableDataChanged(); + } + + /** + * @param inRowNum row number from 0 + * @return track object for this row + */ + public GpsiesTrack getTrack(int inRowNum) + { + return _trackList.get(inRowNum); + } + + /** + * Clear the list of tracks + */ + public void clear() + { + _trackList = null; + } +}