]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/WaypointListModel.java
e5b41865e739a0cb08dc95382fc82eb692472ffd
[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                 if (inIndex < 0 || inIndex >= getSize()) return "";
42                 return _waypoints.get(inIndex).getWaypointName();
43         }
44
45         /**
46          * Get the waypoint at the given index
47          * @param inIndex index number, starting at 0
48          * @return DataPoint object
49          */
50         public DataPoint getWaypoint(int inIndex)
51         {
52                 return _waypoints.get(inIndex);
53         }
54
55         /**
56          * Fire event to notify that contents have changed
57          */
58         public void fireChanged()
59         {
60                 _track.getWaypoints(_waypoints);
61                 this.fireContentsChanged(this, 0, getSize()-1);
62         }
63 }