/*
 * Created on 18.12.2003
 *
 */

package LumiSoft.UI.Controls.WOutlookBar;

import java.awt.*;

/**
 * 
 */
public class HitInfo 
{
	private int  m_HittedObject = HittedObject.None;
	private Bar  m_HittedBar    = null;
	private Item m_HittedItem   = null;

	/**
	 * 
	 * @param hitPoint
	 * @param outlookBar
	 */
	public HitInfo(Point hitPoint,WOutlookBar outlookBar)
	{
		Bar activeBar = outlookBar.getActiveBar();

		//--- First look if bar was hitted -------//
		for(Bar bar : outlookBar.getBars()){
			if(bar.getBarRect().contains(hitPoint)){
				m_HittedObject = HittedObject.Bar;
				m_HittedBar    = bar;				
				return;
			}			
		}
		//----------------------------------------//

		//--- look if scroll buttons hitted ------//
		if(outlookBar.getIsUpScrollBtnVisible() && outlookBar.getUpScrollBtnRect().contains(hitPoint)){
			m_HittedObject = HittedObject.UpScrollButton;
			return;
		}

		if(outlookBar.getIsDownScrollBtnVisible() && outlookBar.getDownScrollBtnRect().contains(hitPoint)){
			m_HittedObject = HittedObject.DownScrollButton;
			return;
		}
		//----------------------------------------//

		//--- look if bar item hitted -----------//
		if(activeBar != null){
			for(int it = activeBar.getFirstVisibleIndex();it<activeBar.getItems().getCount();it++){
				Item item = (Item)activeBar.getItems().get(it);
				
				if(item.getBounds().contains(hitPoint) && activeBar.getBarClientRect().contains(hitPoint)){
					m_HittedObject = HittedObject.Item;
					m_HittedItem   = item;
					return;
				}
			}
		}
		//----------------------------------------//
		
		m_HittedObject = HittedObject.None;
	}


	/**
	 * 
	 * @param hitInfo
	 * @return
	 */
	public boolean Compare(HitInfo hitInfo)
	{
		if(hitInfo == null){
			return false;
		}
		
		switch(hitInfo.getHittedObject())
		{
			case HittedObject.Bar:
				if(m_HittedBar != null && hitInfo.getHittedBar() != null && hitInfo.getHittedBar().equals(m_HittedBar)){
					return true;
				}
				break;
				
			case HittedObject.Item:
				if(m_HittedItem != null && hitInfo.getHittedItem() != null && hitInfo.getHittedItem().equals(m_HittedItem)){
					return true;
				}
				break;
						
			case HittedObject.None:
				if(m_HittedObject == HittedObject.None){
					return true;				
				}
				break;
				
		//	default:
		//		return false;			
		}
		
		return false;
	}


	/**
	 * 
	 * @return
	 */
	public int getHittedObject()
	{
		return m_HittedObject;
	}

	/**
	 * 
	 * @return
	 */
	public Bar getHittedBar()
	{
		return m_HittedBar;
	}

	/**
	 * 
	 * @return
	 */	
	public Item getHittedItem()
	{
		return m_HittedItem;
	}

}
