]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/WaypointListModel.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / gui / WaypointListModel.java
1 package tim.prune.gui;
2
3 import java.util.ArrayList;
4 import javax.swing.AbstractListModel;
5
6 import tim.prune.data.DataPoint;
7 import tim.prune.data.Track;
8
9 /**
10  * Class to act as list model for the waypoint list
11  */
12 public class WaypointListModel extends AbstractListModel
13 {
14         Track _track = null;
15         ArrayList<DataPoint> _waypoints = null;
16
17         /**
18          * Constructor giving Track object
19          * @param inTrack Track object
20          */
21         public WaypointListModel(Track inTrack)
22         {
23                 _track = inTrack;
24                 _waypoints = new ArrayList<DataPoint>();
25                 _track.getWaypoints(_waypoints);
26         }
27
28         /**
29          * @see javax.swing.ListModel#getSize()
30          */
31         public int getSize()
32         {
33                 return _waypoints.size();
34         }
35
36         /**
37          * @see javax.swing.ListModel#getElementAt(int)
38          */
39         public Object getElementAt(int inIndex)
40         {
41                 DataPoint p = null;
42                 if (inIndex < 0 || inIndex >= getSize()
43                         || _waypoints == null || (p = _waypoints.get(inIndex)) == null)
44                         return "";
45                 return p.getWaypointName();
46         }
47
48         /**
49          * Get the waypoint at the given index
50          * @param inIndex index number, starting at 0
51          * @return DataPoint object
52          */
53         public DataPoint getWaypoint(int inIndex)
54         {
55                 return _waypoints.get(inIndex);
56         }
57
58         /**
59          * Fire event to notify that contents have changed
60          */
61         public void fireChanged()
62         {
63                 _track.getWaypoints(_waypoints);
64                 this.fireContentsChanged(this, 0, getSize()-1);
65         }
66 }