X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2FWaypointListModel.java;fp=src%2Ftim%2Fprune%2Fgui%2FWaypointListModel.java;h=3d5dd1fb62bafaa222df382109ead68756ad0605;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/gui/WaypointListModel.java b/src/tim/prune/gui/WaypointListModel.java new file mode 100644 index 0000000..3d5dd1f --- /dev/null +++ b/src/tim/prune/gui/WaypointListModel.java @@ -0,0 +1,66 @@ +package tim.prune.gui; + +import java.util.ArrayList; +import javax.swing.AbstractListModel; + +import tim.prune.data.DataPoint; +import tim.prune.data.Track; + +/** + * Class to act as list model for the waypoint list + */ +public class WaypointListModel extends AbstractListModel +{ + Track _track = null; + ArrayList _waypoints = null; + + /** + * Constructor giving Track object + * @param inTrack Track object + */ + public WaypointListModel(Track inTrack) + { + _track = inTrack; + _waypoints = new ArrayList(); + _track.getWaypoints(_waypoints); + } + + /** + * @see javax.swing.ListModel#getSize() + */ + public int getSize() + { + return _waypoints.size(); + } + + /** + * @see javax.swing.ListModel#getElementAt(int) + */ + public String getElementAt(int inIndex) + { + DataPoint p = null; + if (inIndex < 0 || inIndex >= getSize() + || _waypoints == null || (p = _waypoints.get(inIndex)) == null) + return ""; + return p.getWaypointName(); + } + + /** + * Get the waypoint at the given index + * @param inIndex index number, starting at 0 + * @return DataPoint object + */ + public DataPoint getWaypoint(int inIndex) + { + return _waypoints.get(inIndex); + } + + /** + * Fire event to notify that contents have changed + */ + public void fireChanged() + { + _track.getWaypoints(_waypoints); + this.fireContentsChanged(this, 0, getSize()-1); + } +}