/*
 * Created on Jan 5, 2004
 *
 */
package LumiSoft.UI.Controls;

import java.util.*;

/**
 * Combobox items collection.
 */
public class WComboItems implements Iterable<WComboItem>
{
	private ArrayList<WComboItem> m_pItems = null;
	
	/**
	 * Default constructor.
	 *
	 */
	protected WComboItems()
	{
		m_pItems = new ArrayList<WComboItem>();
	}
	
	
	/**
	 * Adds item to items collection.
	 * @param text Item text.
	 */
	public void Add(String text)
	{
		Add(text,null);
	}
	
	/**
	 * Adds item to items collection.
	 * @param text Items text.
	 * @param tag Item tag.
	 */
	public void Add(String text,Object tag)
	{
		WComboItem it = new WComboItem(text);
		it.setTag(tag);
		m_pItems.add(it);
	}
	
	/**
	 * Gets if collection contains specified item.
	 * @param item Item to check.
	 * @return Returns true if collection contains specified item.
	 */
	public boolean Contains(WComboItem item)
	{
		return m_pItems.contains(item);
	}
	
	/**
	 * Gets item index in collection or -1 if item won't belong to this collection.
	 * @param item
	 * @return
	 */
	public int IndexOf(WComboItem item)
	{
		return m_pItems.indexOf(item);
	}
	
	/**
	 * Removes specified item from collection.
	 * @param item
	 */
	public void Remove(WComboItem item)
	{
		m_pItems.remove(item);
	}
	
	/**
	 * Removes all items from collection.
	 *
	 */
	public void Clear()
	{
		m_pItems.clear();
	}
	
	
	/**
	 * Gets item from specified index.
	 * @param index
	 * @return
	 */
	public WComboItem get(int index)
	{
		return m_pItems.get(index);
	}
	
	/**
	 * Gets number of items in collection.
	 * @return
	 */
	public int getCount()
	{
		return m_pItems.size();
	}
	
	
	/**
	 * Gets iterator.
	 */
	public Iterator<WComboItem> iterator()
	{
		return m_pItems.iterator();
	}
}
