/*
 * Created on Jan 11, 2004
 *
 */
package LumiSoft.UI.Controls;

import java.awt.*;

/**
 * Menu item.
 */
public class WMenuItem 
{
	private Object       m_pParent    = null;
	private String       m_Text       = "";
	private String       m_TextID     = "";
	private boolean      m_Visible    = true;
	private boolean      m_Enabled    = true;
	private boolean      m_Separator  = false;
	private int          m_ImageIndex = -1;
	private Object       m_Tag        = null;
	private WContextMenu m_pSubMenu   = null;
	private Rectangle    m_Bounds     = null; 
	
	/**
	 * Default constructor.
	 * @param parent
	 */
	protected WMenuItem(Object parent)
	{
		m_pParent = parent;
	}
	
	
	/**
	 * Gets menuitem text.
	 * @return
	 */
	public String getText()
	{
		WText wText = null;
		if(m_pParent.getClass() == WContextMenu.class){
			wText = ((WContextMenu)m_pParent).getWText();
		}
		else if(m_pParent.getClass() == WMenuBar.class){
			wText = ((WMenuBar)m_pParent).getWText();
		}
		
		if(wText != null && getTextID().length() > 0){
			return wText.get(getTextID());
		}
		else{
			return m_Text;
		}
	}
	/**
	 * Sets menuitem text.
	 * @param value
	 */
	public void setText(String value)
	{
		if(m_Text != value){
			m_Text = value;
		}
	}
	
	/**
	 * Gets column text ID.
	 * @return
	 */
	public String getTextID()
	{
		return m_TextID;
	}
	/**
	 * Sets column text ID.
	 * @param value
	 */
	public void setTextID(String value)
	{
		m_TextID = value;
	}
	
	/**
	 * Gets if menuitem visible.
	 * @return
	 */
	public boolean getVisible()
	{
		return m_Visible;
	}
	/**
	 * Sets if menuitem visible.
	 * @param value
	 */
	public void setVisible(boolean value)
	{
		if(m_Visible != value){
			m_Visible = value;
		}
	}
	
	/**
	 * Gets if menuitem enabled.
	 * @return
	 */
	public boolean getEnabled()
	{
		return m_Enabled;
	}
	/**
	 * Sets if menuitem enabled.
	 * @param value
	 */
	public void setEnabled(boolean value)
	{
		if(m_Enabled != value){
			m_Enabled = value;
		}
	}
	
	/**
	 * Gets if menuitem is separator.
	 * @return
	 */
	public boolean getSeparator()
	{
		return m_Separator;
	}
	/**
	 * Sets if menuitem is separator.
	 * @param value
	 */
	public void setSeparator(boolean value)
	{
		if(m_Separator != value){
			m_Separator = value;
		}
	}
	
	/**
	 * Gets menuitem image index.
	 * @return
	 */
	public int getImageIndex()
	{
		return m_ImageIndex;
	}
	/**
	 * Sets menuitem image index.
	 * @param value
	 */
	public void setImageIndex(int value)
	{
		if(m_ImageIndex != value){
			m_ImageIndex = value;
		}
	}
	
	/**
	 * Gets menuitem tag.
	 * @return
	 */
	public Object getTag()
	{
		return m_Tag;
	}
	/**
	 * Sets menuitem tag.
	 * @param value
	 */
	public void setTag(Object value)
	{
		m_Tag = value;		
	}
	
	/**
	 * Gets menuitem sub menu.
	 * @return
	 */
	public WContextMenu getSubMenu()
	{
		return m_pSubMenu;
	}
	/**
	 * Sets menuitem sub menu.
	 * @param value
	 */
	public void setSubMenu(WContextMenu value)
	{
		m_pSubMenu = value;		
	}
	
	
	/**
	 * Gets if menuitem bounds.
	 * @return
	 */
	protected Rectangle getBounds()
	{
		return m_Bounds;
	}
	/**
	 * Sets if menuitem bounds.
	 * @param value
	 */
	protected void setBounds(Rectangle value)
	{
		if(m_Bounds != value){
			m_Bounds = value;
		}
	}
	
	/**
	 * Gets item text rectangle.
	 * @return
	 */
	protected Rectangle getTextRect()
	{
		return new Rectangle(m_Bounds.x + 27,m_Bounds.y,m_Bounds.width - 2,m_Bounds.height);
	}

}
