X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fsettings%2FMapSourceListModel.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fsettings%2FMapSourceListModel.java;h=dc7954aa9b4b47dd6169583b2103d936d7ba4fdb;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/settings/MapSourceListModel.java b/src/tim/prune/function/settings/MapSourceListModel.java new file mode 100644 index 0000000..dc7954a --- /dev/null +++ b/src/tim/prune/function/settings/MapSourceListModel.java @@ -0,0 +1,47 @@ +package tim.prune.function.settings; + +import javax.swing.AbstractListModel; + +import tim.prune.gui.map.MapSource; +import tim.prune.gui.map.MapSourceLibrary; + +/** + * Class to act as list model for the map source list + */ +public class MapSourceListModel extends AbstractListModel +{ + /** + * @see javax.swing.ListModel#getSize() + */ + public int getSize() + { + return MapSourceLibrary.getNumSources(); + } + + /** + * @see javax.swing.ListModel#getElementAt(int) + */ + public String getElementAt(int inIndex) + { + if (inIndex < 0 || inIndex >= getSize()) return ""; + return MapSourceLibrary.getSource(inIndex).getName(); + } + + /** + * @param inIndex index in list + * @return corresponding map source object + */ + public MapSource getSource(int inIndex) + { + if (inIndex < 0 || inIndex >= getSize()) return null; + return MapSourceLibrary.getSource(inIndex); + } + + /** + * Fire event to notify that contents have changed + */ + public void fireChanged() + { + this.fireContentsChanged(this, 0, getSize()-1); + } +}