/*
 * Created on Dec 23, 2003
 *
 */
package LumiSoft.UI.Controls;

import java.util.*;

/**
 * WTabBar items collection.
 */
public class WTabBarItems implements Iterable<WTabBarItem>
{
	private WTabBar                m_pWTabBar = null;
	private ArrayList<WTabBarItem> m_pTabs    = null;
	
	/**
	 * Default constructor.
	 * @param tabBar
	 */
	protected WTabBarItems(WTabBar tabBar)
	{
		m_pWTabBar = tabBar;
			
		m_pTabs = new ArrayList<WTabBarItem>();
	}
	
	/**
	 * Adds new tab to tabs collection.
	 * @param caption Tab caption.
	 * @return
	 */
	public WTabBarItem Add(String caption)
	{
		return Add(caption,null,-1);
	}

	/**
	 * Adds new tab to tabs collection.
	 * @param caption Tab caption.
	 * @param tag User data.
	 * @return
	 */
	public WTabBarItem Add(String caption,Object tag)
	{
		return Add(caption,tag,-1);
	}

	/**
	 * Adds new tab to tabs collection.
	 * @param caption Tab caption.
	 * @param tag User data.
	 * @param imageIndex Image index.
	 * @return
	 */
	public WTabBarItem Add(String caption,Object tag,int imageIndex)
	{
		return Add(caption,"",tag,imageIndex);
	}
	
	/**
	 * Adds new tab to tabs collection.
	 * @param caption
	 * @param textID
	 * @param tag
	 * @param imageIndex
	 * @return
	 */
	public WTabBarItem Add(String caption,String textID,Object tag,int imageIndex)
	{
		WTabBarItem tab = new WTabBarItem(this);
		tab.setText(caption);
		tab.setTextID(textID);
		tab.setTag(tag);
		tab.setImageIndex(imageIndex);
		
		m_pTabs.add(tab);
	//	m_pTabBar.Invalidate();

		return tab;
	}
	
	/**
	 * Removes tab from tabs collection at specified index.
	 * @param index
	 */
	public void Remove(int index)
	{
		m_pTabs.remove(index);
	}
	
	/**
	 * Removes all tabs from tab collection.
	 *
	 */
	public void Clear()
	{
		m_pTabs.clear();
	}
	
	/**
	 * Gets specified tab index in tabs collection.
	 * @param tab
	 * @return
	 */
	public int IndexOf(WTabBarItem tab)
	{
		return m_pTabs.indexOf(tab);
	}
	
	/**
	 * Gets number of tabs in tab collection.
	 *
	 */
	public int getCount()
	{
		return m_pTabs.size();
	}
	
	/**
	 * Gets tab at specified index.
	 * @param index
	 * @return
	 */
	public WTabBarItem get(int index)
	{
		return m_pTabs.get(index);
	}
	
	/**
	 * Returns visible items (item.getVisible = true).
	 * @return
	 */
	public WTabBarItem[] getVisibleItems()
	{
		ArrayList<WTabBarItem> items = new ArrayList<WTabBarItem>();
		for(WTabBarItem item : this){
			if(item.getVisible()){
				items.add(item);
			}
		}
		
		WTabBarItem[] retVal = new WTabBarItem[items.size()];
		items.toArray(retVal);
		
		return retVal;
		
		// Won't work  for some reason
	//	return (Column[])visibleColumns.toArray();
	}
	
	/**
	 * Gets collection owner WTabBar.
	 * @return
	 */
	public WTabBar getWTabBar()
	{
		return m_pWTabBar;
	}
	
	
	/**
	 * Gets iterator.
	 */
	public Iterator<WTabBarItem> iterator()
	{
		return m_pTabs.iterator();
	}

}
