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

import java.awt.*;
import java.util.*;

/**
 * Tab page collection.
 */
public class WTabControlPages implements Iterable<WTabControlPage>
{
//	private WTabControl                m_pWTab   = null;
	private WTabBar                    m_pTabBar = null;
	private ArrayList<WTabControlPage> m_pItems  = null;
	
	/**
	 * Default constructor.
	 * @param tab This collection owner TabControl.
	 * @param tabBar 
	 */
	protected WTabControlPages(WTabControl tab,WTabBar tabBar)
	{
//		m_pWTab = tab;
		m_pTabBar = tabBar;
		
		m_pItems = new ArrayList<WTabControlPage>();
	}
	
	
	/**
	 * Adds new tab page to collection.
	 * @param text Tab caption text.
	 * @param tabPage Control what fills tab area.
	 */
	public void Add(String text,Component tabPage)
	{
		Add(text,tabPage,-1,null);
	}
	
	/**Adds new tab page to collection.
	 * 
	 * @param text Tab caption text.
	 * @param textID TextID.
	 * @param tabPage Control what fills tab area.
	 */
	public void Add(String text,String textID,Component tabPage)
	{
		Add(text,textID,tabPage,-1,null);
	}
	
	/**
	 * Adds new tab page to collection.
	 * @param text Tab caption text.
	 * @param tabPage Control what fills tab area.
	 * @param imageIndex Tab image index.
	 * @param tag User data.
	 */
	public void Add(String text,Component tabPage,int imageIndex,Object tag)
	{
		Add(text,"",tabPage,imageIndex,tag);
	}
	
	/**
	 * Adds new tab page to collection.
	 * @param text Tab caption text.
	 * @param textID TextID.
	 * @param tabPage Control what fills tab area.
	 * @param imageIndex Tab image index.
	 * @param tag User data.
	 */
	public void Add(String text,String textID,Component tabPage,int imageIndex,Object tag)
	{
		WTabBarItem tab = m_pTabBar.getTabs().Add(text,textID,null,imageIndex);
		
		WTabControlPage page = new WTabControlPage(tab,tabPage);
		page.setTag(tag);
		
		tab.setTag(page);
		m_pItems.add(page);
	}
	
	/**
	 * Removes specified tab from collection.
	 * @param page
	 */
	public void Remove(WTabControlPage page)
	{
		m_pItems.remove(page);
	}
	
	/**
	 * Removes all tabs from tab collection.
	 *
	 */
	public void Clear()
	{
		m_pItems.clear();
	}
	
	/**
	 * Gets specified item index in collection.
	 * @param page
	 * @return
	 */
	public int IndexOf(WTabControlPage page)
	{
		return m_pItems.indexOf(page);
	}
	
	
	/**
	 * Gets number of tabs in tab collection.
	 * @return
	 */
	public int getCount()
	{
		return m_pItems.size();
	}
	
	/**
	 * Gets item at specified index.
	 * @param index
	 * @return
	 */
	public WTabControlPage get(int index)
	{
		return m_pItems.get(index);
	}
	
	
	/**
	 * Gets iterator.
	 * @return
	 */
	public Iterator<WTabControlPage> iterator()
	{
		return m_pItems.iterator();
	}
		
}
