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