1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
package tim.prune.function;
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 Object 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);
}
}
|