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

import java.awt.*;

/**
 * WTabBar item.
 */
public class WTabBarItem 
{
	private String       m_Text       = "";
	private String       m_TextID     = "";
	private Object       m_Tag        = null;
	private int          m_ImageIndex = -1;
	private boolean      m_Enabled    = true;
	private boolean      m_Visible    = true;
	private WTabBarItems m_pTabs      = null;
	private Rectangle    m_Bounds;

	/**
	 * Default constructor.
	 * @param tabs
	 */
	public WTabBarItem(WTabBarItems tabs)
	{	
		m_pTabs = tabs;
		m_Bounds = new Rectangle(-1,-1,0,0);
	}

	
	public void OnItemNeedsUpdate()
	{
	//	m_pTabs.WTabBar.Invalidate();
	}
	
	
	/**
	 * Gets tab text.
	 * @return
	 */
	public String getText()
	{
		if(m_pTabs.getWTabBar().getWText() != null && getTextID().length() > 0){			
			return m_pTabs.getWTabBar().getWText().get(getTextID());
		}
		else{
			return m_Text;
		}
	}
	/**
	 * Sets tab text.
	 * @param value
	 */
	public void setText(String value)
	{
		if(m_Text != value){
			m_Text = value;
			OnItemNeedsUpdate();
		}
	}
	
	/**
	 * Gets tab text ID.
	 * @return
	 */
	public String getTextID()
	{
		return m_TextID;
	}
	/**
	 * Sets tab text ID.
	 * @param value
	 */
	public void setTextID(String value)
	{
		if(m_TextID != value){
			m_TextID = value;
	//		OnItemNeedsUpdate();
		}
	}
	
	/**
	 * Gets tab tag.
	 * @return
	 */
	public Object getTag()
	{
		return m_Tag;
	}
	/**
	 * Sets tab tag.
	 * @param value
	 */
	public void setTag(Object value)
	{
		if(m_Tag != value){
			m_Tag = value;
		}
	}
	
	/**
	 * Gets tab index in tabs collection.
	 * @return
	 */
	public int getIndex()
	{
		return (m_pTabs != null ? m_pTabs.IndexOf(this) : -1);
	}
	
	/**
	 * Gets tab image index.
	 * @return
	 */
	public int getImageIndex()
	{
		return m_ImageIndex;
	}
	/**
	 * Sets tab image index.
	 * @param value
	 */
	public void setImageIndex(int value)
	{
		if(m_ImageIndex != value){
			m_ImageIndex = value;
			OnItemNeedsUpdate();
		}
	}
	
	/**
	 * Gets if tab is enabled.
	 * @return
	 */
	public boolean getEnabled()
	{
		return m_Enabled;
	}
	/**
	 * Sets if tab enebled.
	 * @param value
	 */
	public void setEnabled(boolean value)
	{
		if(m_Enabled != value){
			m_Enabled = value;
			OnItemNeedsUpdate();
		}
	}
	
	/**
	 * Gets if tab is visible.
	 * @return
	 */
	public boolean getVisible()
	{
		return m_Visible;
	}
	/**
	 * Sets if tab is visble.
	 * @param value
	 */
	public void setVisible(boolean value)
	{
		if(m_Visible != value){
			m_Visible = value;
			OnItemNeedsUpdate();
		}
	}
	
	
	protected Rectangle getBounds()
	{
		return m_Bounds;
	}
	protected void setBounds(Rectangle value)
	{
		if(m_Bounds != value){
			m_Bounds = value;
		}
	}
	
	protected Rectangle getImageRect()
	{
		return new Rectangle(this.getBounds().x + 3,this.getBounds().y + 3,16,16);
	}
	
	protected Rectangle getTextRect()
	{
		if(this.getImageIndex() == -1){
			return new Rectangle(this.getBounds().x + 3,this.getBounds().y,this.getBounds().width - 3,this.getBounds().height);
		}
		else{
			return new Rectangle(this.getBounds().x + 20,this.getBounds().y,this.getBounds().width - 18,this.getBounds().height);
		}
	}
}
