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

import java.awt.*;

import LumiSoft.UI.Controls.*;
import LumiSoft.UI.Controls.Grid.Editors.*;

/**
 * Grid column.
 */
public class WGridColumn 
{
	private WGridColumns m_pColumns        = null;
	private String       m_ColumnName      = "";
	private String       m_Text            = "";
	private String       m_TextID          = "";	
	private int          m_TextAlign       = HorizontalAlignment.Right;	
	private Font         m_pFont           = null;
//	private Font         m_pCellsFont      = null;
	private int          m_CellsTextAlign  = HorizontalAlignment.Left;
	private String       m_CellTextFormat  = "";
	private String       m_MappingName     = "";
	private boolean      m_Visible         = true; 
	private boolean      m_AllowEdit       = true;
	private boolean      m_AllowSort       = true;
	private boolean      m_AllowResize     = true;
	private int          m_Width           = 20;
	private Object       m_pTag            = null;
	private String       m_FooterText      = "";
	private int          m_FooterTextAlign = HorizontalAlignment.Right;
	private int          m_FooterType      = WGridViewFooterType.Text;
	private Rectangle    m_pBounds         = null;	
	private WBaseEditor  m_pEditor         = null;
	
	/**
	 * Default constructor.
	 * @param columns
	 */
	protected WGridColumn(WGridColumns columns,String name)
	{				
		m_pColumns   = columns;
		m_ColumnName = name;
		m_pFont      = new Font("SansSerif",Font.PLAIN,12);
		m_pBounds    = new Rectangle(-1,-1,0,0);		
		m_pEditor    = new WTextEditor();
	}
	
	
	/**
	 * Gets column name.
	 * @return
	 */
	public String getColumnName()
	{
		return m_ColumnName;
	}	
	
	/**
	 * Gets column caption.
	 * @return
	 */
	public String getText()
	{
		if(m_pColumns.getView().getGrid().getWText() != null && getTextID().length() > 0){
			return m_pColumns.getView().getGrid().getWText().get(getTextID());
		}
		else{
			return m_Text;
		}
	}
	/**
	 * Sets column caption.
	 * @param value
	 */
	public void setText(String value)
	{
		if(m_Text != value){
			m_Text = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * 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;
		
		// Notify owner view about Column change.
		m_pColumns.getView().OnColumnChanged(this);
	}
	
	/**
	 * Gets column text horiontal alignment.
	 * @return
	 */
	public int getTextAlign()
	{
		return m_TextAlign;
	}
	/**
	 * Sets column text horiontal alignment.
	 * @param value
	 */
	public void setTextAlign(int value)
	{
		if(m_TextAlign != value){
			m_TextAlign = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column cells text horizontal alignment.
	 * @return
	 */
	public int getCellsTextAlign()
	{
		return m_CellsTextAlign;
	}
	/**
	 * Sets column cells text horizontal alignment.
	 * @param value
	 */
	public void setCellsTextAlign(int value)
	{
		if(m_CellsTextAlign != value){
			m_CellsTextAlign = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column cells text display format.
	 * @return
	 */
	public String getCellTextFormat()
	{
		return m_CellTextFormat;
	}
	/**
	 * Sets column cells text display format.
	 * @param value
	 */
	public void setCellTextFormat(String value)
	{
		if(m_CellTextFormat != value){
			m_CellTextFormat = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets datasource DataTable mapping column.
	 * @return
	 */
	public String getMappingName()
	{
		return m_MappingName;
	}
	/**
	 * Sets datasource DataTable mapping column.
	 * @param value
	 */
	public void setMappingName(String value)
	{
		if(m_MappingName != value){
			m_MappingName = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column caption text font.
	 * @return
	 */
	public Font getFont()
	{
		return m_pFont;
	}
	/**
	 * Sets column caption text font.
	 * @param value
	 */
	public void setFont(Font value)
	{
		if(m_pFont != value){
			m_pFont = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets if column is visible.
	 * @return
	 */
	public boolean getVisible()
	{
		return m_Visible;
	}
	/**
	 * Sets if column is visible.
	 * @param value
	 */
	public void setVisible(boolean value)
	{
		if(m_Visible != value){
			m_Visible = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets if column is editable.
	 * @return
	 */
	public boolean getAllowEdit()
	{
		return m_AllowEdit;
	}
	/**
	 * Sets if column is editable.
	 * @param value
	 */
	public void setAllowEdit(boolean value)
	{
		if(m_AllowEdit != value){
			m_AllowEdit = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets if column can be sorted.
	 * @return
	 */
	public boolean getAllowSort()
	{
		return m_AllowSort;
	}
	/**
	 * Sets if column can be sorted.
	 * @param value
	 */
	public void setAllowSort(boolean value)
	{
		if(m_AllowSort != value){
			m_AllowSort = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets if column can be resized.
	 * @return
	 */
	public boolean getAllowResize()
	{
		return m_AllowResize;
	}
	/**
	 * Sets if column can be resized.
	 * @param value
	 */
	public void setAllowResize(boolean value)
	{
		if(m_AllowResize != value){
			m_AllowResize = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column width.
	 * @return
	 */
	public int getWidth()
	{
		return m_Width;
	}
	/**
	 * Sets column width.
	 * @param value
	 */
	public void setWidth(int value)
	{
		if(m_Width != value && value > 0){
			m_Width = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column tag.
	 * @return
	 */
	public Object getTag()
	{
		return m_pTag;		
	}
	/**
	 * Sets colum tag.
	 * @param value
	 */
	public void setTag(Object value)
	{
		m_pTag = value;
	}	
	
	/**
	 * Gets column bounding rectangle.
	 * @return
	 */
	public Rectangle getBounds()
	{
		return m_pBounds;
	}
	protected void setBounds(Rectangle value)
	{
		if(m_pBounds != value){
			m_pBounds = value;
		}
	}
	
	/**
	 * Gets column footer text.
	 * @return
	 */
	public String getFooterText()
	{
		return m_FooterText;
	}
	/**
	 * Sets column footer text.
	 * @param value
	 */
	public void setFooterText(String value)
	{
		if(m_FooterText != value){
			m_FooterText = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column column footer text horiontal alignment.
	 * @return
	 */
	public int getFooterTextAlign()
	{
		return m_FooterTextAlign;
	}
	/**
	 * Sets column column footer text horiontal alignment.
	 * @param value
	 */
	public void setFooterTextAlign(int value)
	{
		if(m_FooterTextAlign != value){
			m_FooterTextAlign = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column column footer type.
	 * @return
	 */
	public int getFooterType()
	{
		return m_FooterType;
	}
	/**
	 * Sets column column footer type.
	 * @param value
	 */
	public void setFooterType(int value)
	{
		if(m_FooterType != value){
			m_FooterType = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets column editor.
	 * @return
	 */
	public WBaseEditor getEditor()
	{
		if(m_pEditor == null){
			m_pEditor = new WTextEditor();
		}
		
		return m_pEditor;
	}
	/**
	 * Sets column editor.
	 * @param value
	 */
	public void setEditor(WBaseEditor value)
	{
		if(m_pEditor != value){
			m_pEditor = value;
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets physical column index. Invisible columns are included.
	 * @return
	 */
	public int getIndex()
	{
		return m_pColumns.indexOf(this);
	}
	/**
	 * Sets physical column index. Invisible columns are included.
	 * @param value
	 */
	public void setIndex(int value)
	{
		if(getIndex() != value){
			m_pColumns.MoveColumn(this,value);
			
			// Notify owner view about Column change.
			m_pColumns.getView().OnColumnChanged(this);
		}
	}
	
	/**
	 * Gets reference to columns collection.
	 * @return
	 */
	public WGridColumns getColumns()
	{
		return m_pColumns;
	}
}
