/*
 * Created on 17.12.2003
 *
 */
package LumiSoft.UI.Controls.WOutlookBar;

import java.util.*;

/**
 * Outlookbar bars collection.
 */
public class Bars implements Iterable<Bar>
{
	private WOutlookBar    m_pOutlookBar = null;
	private ArrayList<Bar> m_pBars       = null;
	
	/**
	 * Default constructor.
	 * @param outlookBar
	 */
	protected Bars(WOutlookBar outlookBar)
	{
		m_pOutlookBar = outlookBar;
		m_pBars       = new ArrayList<Bar>();
	}
	
	
	/**
	 * Add new bar with specified text to bars collection.
	 * @param text
	 * @return
	 */
	public Bar Add(String text)
	{
		return Add(text,"");
	}
	/**
	 * Add new bar with specified text and textID to bars collection.
	 * @param text
	 * @param textID
	 * @return
	 */
	public Bar Add(String text,String textID)
	{
		Bar bar = new Bar(this);
		bar.setText(text);
		bar.setTextID(textID);
		m_pBars.add(bar);
		
		return bar;
	}
	
	/**
	 * Removes bar from specified index.
	 * @param index
	 */
	public void remove(int index)
	{
		m_pBars.remove(index);
	}
	
	/**
	 * Removes specified bar.
	 * @param bar
	 */
	public void remove(Bar bar)
	{
		m_pBars.remove(bar);
	}
	
	/**
	 * Gets specified bar index.
	 * @param bar
	 * @return
	 */
	public int indexOf(Bar bar)
	{
		return m_pBars.indexOf(bar);
	}
	
	/**
	 * Gets bar from specified index.
	 * @param index
	 * @return
	 */
	public Bar get(int index)
	{
		return m_pBars.get(index);
	}
	
	/**
	 * Gets bars count in collection.
	 * @return
	 */
	public int getCount()
	{
		return m_pBars.size();
	}
	
	/**
	 * Gets visible bars.
	 * @return
	 */
	public Bar[] getVisibleBars()
	{
		ArrayList<Bar> visibleItems = new ArrayList<Bar>();
		for(Bar item : this){
			if(item.getVisible()){
				visibleItems.add(item);
			}
		}
		
		Bar[] retVal = new Bar[visibleItems.size()];
		visibleItems.toArray(retVal);
		
		return retVal;
		
		// Won't work  for some reason
	//	return (Column[])visibleColumns.toArray();
	}
	
	/**
	 * Gets reference to bars owner outlookbar. 
	 * @return
	 */
	public WOutlookBar getWOutlookBar()
	{
		return m_pOutlookBar;
	}
	
	
	/**
	 * Gets iterator.
	 * @return
	 */
	public Iterator<Bar> iterator()
	{
		return m_pBars.iterator();
	}
}
