]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/settings/MapSourceListModel.java
Version 18.6, December 2016
[GpsPrune.git] / tim / prune / function / settings / MapSourceListModel.java
1 package tim.prune.function.settings;
2
3 import javax.swing.AbstractListModel;
4
5 import tim.prune.gui.map.MapSource;
6 import tim.prune.gui.map.MapSourceLibrary;
7
8 /**
9  * Class to act as list model for the map source list
10  */
11 public class MapSourceListModel extends AbstractListModel<String>
12 {
13         /**
14          * @see javax.swing.ListModel#getSize()
15          */
16         public int getSize()
17         {
18                 return MapSourceLibrary.getNumSources();
19         }
20
21         /**
22          * @see javax.swing.ListModel#getElementAt(int)
23          */
24         public String getElementAt(int inIndex)
25         {
26                 if (inIndex < 0 || inIndex >= getSize()) return "";
27                 return MapSourceLibrary.getSource(inIndex).getName();
28         }
29
30         /**
31          * @param inIndex index in list
32          * @return corresponding map source object
33          */
34         public MapSource getSource(int inIndex)
35         {
36                 if (inIndex < 0 || inIndex >= getSize()) return null;
37                 return MapSourceLibrary.getSource(inIndex);
38         }
39
40         /**
41          * Fire event to notify that contents have changed
42          */
43         public void fireChanged()
44         {
45                 this.fireContentsChanged(this, 0, getSize()-1);
46         }
47 }