﻿package TableWidget{
	
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.geom.ColorTransform;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.utils.setInterval;
	import flash.text.TextFormat;
	import flash.events.KeyboardEvent;
	import flash.ui.Mouse;
	import fl.containers.ScrollPane;
	import TableWidget.comp.textformatter.TextPropertiesComponent;
	
	/**
	* This class contains all the properties and methods of a cell.
	* ColumnReference and RowReference classes will use CellClass to make the update.
	* Any update made in the column or row will update the cell class variables and properties.
	*
	* @author Vivek Kumar
	*/
	public class CellClass extends MovieClip
	{
		private var cellContent:String = " ";
		public var isHeader:Boolean;
		private var headerStyle;
		public var columnRef:Object;
		public var rowRef:Object;
		private var editorRef:Object;
		private var isInFocus:Boolean;
		private var cellWidth:Number;
		private var rootRef:MovieClip;
		private var cellHeight:Number;
		private var objCellEditor:CellEditor;
		private var cellBGMC:Sprite;
		
		private var selectionMC:MovieClip;
		private var cellGraphicMC:Sprite;
		private var cellBorderMC:Sprite;
		public var cellText:TextField;
		private var mc:MovieClip;
		public const UPDATEHEIGHT = "updateHeight";
		public const UPDATEWIDTH = "updateWidth"
		public const SELECTED = "selected"
		public const COLUMNSELECTED = "columnselected"

		private var objWidgetController:WidgetController;
		private var objConfigXML:XML;
		private var xmlCaptivateParams:XML;
		public var isSelected:Boolean;
		public var enableIt:Boolean = true;
		private var dragBtn:Sprite;
		private var lineShape:Sprite;
		private var format:TextFormat;
		private var isDrawing;
		private var objCursor:mcCursor;
		private var objLeftArrow:mcArrwLeft;
		private var objRightArrow:mcArrwRight;
		private var objMcBox:mcBox;
		private var objTextPropertiesComponent:TextPropertiesComponent;
		public var xmlTextFormat:String;
		private var bgColor:String
		private var borderColor:String
		public function CellClass()
		{
			rootRef = this;
			objWidgetController = WidgetController.getInstance();
			objConfigXML = objWidgetController.objConfigXML;
			xmlCaptivateParams = objWidgetController.xmlCaptivateParams;
			objTextPropertiesComponent = objWidgetController.objTextPropertiesComponent;
			
			xmlTextFormat = String(objConfigXML.textProperties);;
		}
		
		/**
		* This function sets the width for the cell.
		* 
		*/
		public function set Width(inCellWidth:Number):void
		{
			if(inCellWidth < 60)
			{
				inCellWidth = 60;
			}
			cellWidth = inCellWidth;
			cellGraphicMC.width = cellWidth;
			selectionMC.width = cellWidth;
			cellText.width = cellWidth;
		}
		/**
		* This function sets the bgColor for the cell.
		* 
		*/
		public function set BgColor(val):void
		{
			//trace("BgColor");
			bgColor=val
		}
		/**
		* This function used to get the width of the selected cell.
		* 
		*/
		public function get Width():Number
		{
			return cellWidth;
		}
		
		/**
		* This function sets the height for the cell.
		* 
		*/
		public function set Height(inCellHeight:Number):void
		{
			
			if(inCellHeight < objConfigXML.row.@height){
				inCellHeight = objConfigXML.row.@height
			}
			if(inCellHeight >= cellGraphicMC.height){
				cellHeight = inCellHeight;
				cellGraphicMC.height = cellHeight;
				selectionMC.height = cellHeight;
				cellText.height = cellHeight;
				if(dragBtn != null){
					dragBtn.height = cellHeight
				}
			}
				
			
		}
		
		/**
		* This function used to get the height of the selected cell.
		* 
		*/
		public function get Height():Number
		{
			return cellGraphicMC.height//cellHeight;
		}
		//Current cell Format
		public function getCurrentCellFormat():String {
			//trace("cellText.type"+cellText.type);
			var cellFormat:TextFormat;
			if(cellText.type=="input" && cellText.text!="")
			{
				
				if(HasTextSelected())
				{
					//trace("in if>>>>"+cellText.selectionBeginIndex);
					
					cellFormat=cellText.getTextFormat(cellText.selectionBeginIndex)
				}
				else
				{
					//trace("in else>>>>"+cellText.selectionBeginIndex);
					cellFormat=cellText.getTextFormat(0,1)
				}
				xmlTextFormat=String(GetUpdatedFormattingForSelectedText(cellFormat));
			}
			else if(cellText.type=="dynamic" && cellText.text!="")
			{
				cellFormat=cellText.getTextFormat(0,1)
				xmlTextFormat=String(GetUpdatedFormattingForSelectedText(cellFormat));
			}
			//trace("xmlTextFormat??????????????"+xmlTextFormat);
				
			return xmlTextFormat;
		}
		//get format for selcted text
		private function GetUpdatedFormattingForSelectedText(cellFormat):XML
		{
			var tempCellTextFormatXml:XML= new XML(xmlTextFormat);
				
				
				tempCellTextFormatXml.textDecoration[0].@bold = cellFormat.bold
				tempCellTextFormatXml.textDecoration[0].@italic = cellFormat.italic
				tempCellTextFormatXml.textDecoration[0].@underline = cellFormat.underline
				tempCellTextFormatXml.textDecoration[0].@align = cellFormat.align
				tempCellTextFormatXml.font[0].@face=cellFormat.font
				//tempCellTextFormatXml.textProperties[0].font[0].@style=cellText.size
				tempCellTextFormatXml.font[0].@size=cellFormat.size
				
				if(cellFormat.color==0)
				{
					
					tempCellTextFormatXml.color[0].@textColor=0x000000
				}
				else
				{
					tempCellTextFormatXml.color[0].@textColor=cellFormat.color
				}
				
				tempCellTextFormatXml.color[0].@borderColor=borderColor
				tempCellTextFormatXml.color[0].@highlightColor=bgColor
				return tempCellTextFormatXml;
		}
		// chk for Selected text
		private function HasTextSelected():Boolean
		{
			var flag:Boolean=true
			//trace("cellText.selectionBeginIndex"+cellText.selectionBeginIndex);
			//trace("cellText.selectionEndIndex"+cellText.selectionEndIndex);
			if(cellText.selectionBeginIndex==cellText.selectionEndIndex)
			{
				flag=false
			}
			if(cellText.selectionBeginIndex==cellText.text.length-1)
			{
				flag=false
			}
			return flag
			
		}
		/**
		* This function sets the content for the cell.
		* 
		*/
		public function set txtContent(inContent:String):void
		{
			cellContent = inContent;
			
			if(cellText){
				cellText.htmlText = cellContent//objWidgetController.htmlize(cellContent, "text");
			}
			
		}
		
		/**
		* This function used to get the content of the selected cell.
		* 
		*/
		public function get txtContent():String
		{
			return cellText.htmlText;
		}
		
		/**
		* This function used to create a cell.
		* This function will be called from ColumnClass.
		* This function intializes the variables and properties for a cell.
		*/
		public function init(columnWidth:int):void
		{
			
			cellWidth = columnWidth//int(objConfigXML.column.@width);
			cellHeight = int(objConfigXML.row.@height);
			
			mc = new MovieClip();
			mc.name = "mc"
			mc.type = "data";
			
			cellGraphicMC = new Sprite();
			
			cellBGMC = new Sprite();
			cellBGMC.name = "cellBGMC";
			// changed by sneha
			//trace("init"+xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor);
			//bgColor=xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor
			//cellBGMC.graphics.beginFill(xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor);
			//ApplyBgColor(bgColor)
			if(xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor!="")
			{
				cellBGMC.graphics.beginFill(xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor);
				bgColor=xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor
			}
			else
			{
				cellBGMC.graphics.beginFill(objConfigXML.cell.@bgcolor);
				bgColor=objConfigXML.cell.@bgcolor
			}
			
			//cellBGMC.graphics.beginFill(objConfigXML.cell.@bgcolor);
			cellBGMC.graphics.drawRect(0, 0, cellWidth, cellHeight);
			cellBGMC.graphics.endFill();
			cellGraphicMC.addChild(cellBGMC);
			
			cellBorderMC = new Sprite();
			cellBorderMC.name = "cellBorderMC";
			if(xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@borderColor!="")
			{
				cellBorderMC.graphics.lineStyle(objConfigXML.cell.@borderThickness, xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@borderColor); 
				borderColor=xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@borderColor
			}
			else
			{
				cellBorderMC.graphics.lineStyle(objConfigXML.cell.@borderThickness, objConfigXML.cell.@borderColor); 
				borderColor=objConfigXML.cell.@borderColor
			}
			
			cellBorderMC.graphics.drawRect(0, 0, cellWidth-.25, cellHeight-.25);
			cellBorderMC.graphics.endFill();
			cellGraphicMC.addChild(cellBorderMC);
			
			mc.addChild(cellGraphicMC);
			
			drawSelection(mc);
			
			cellText = new TextField();
			
			cellText.selectable = false;
			cellText.multiline = false;
			cellText.wordWrap = true;
			cellText.width = cellWidth;
			cellText.height = cellHeight;
			//cellText.alwaysShowSelection=true
			//cellText.border=true
			//wrapText();
			
			mc.cellText = cellText;
			mc.addChild(cellText);
			
			objCellEditor = new CellEditor();
			objCellEditor.addEventListener(objCellEditor.KILLFOCUS, killCellFocus);
			objCellEditor.addEventListener(objCellEditor.UPDATEHEIGHT, setCellHeight);
			objCellEditor.init(mc);
			
			mc.cellText.doubleClickEnabled = true;
			mc.cellText.addEventListener(MouseEvent.CLICK, setSelectionEvent);
			mc.cellText.addEventListener(MouseEvent.DOUBLE_CLICK, callEditor);

			rootRef.addChild(mc);			
		}
		public function ApplyBgColor(val):void
		{
			var colorTransform:ColorTransform = new ColorTransform();
			colorTransform.color = val
			cellBGMC.transform.colorTransform = colorTransform;
			bgColor=val
		}
		public function wrapText(){
			if(cellText.textHeight > cellText.height){
				cellText.height = cellText.textHeight+5;
				cellGraphicMC.height = cellText.textHeight+5
				selectionMC.height = cellText.textHeight + 5;
			}else if(cellText.height > (cellText.textHeight+5)){
				var tentativeHeight = cellText.textHeight+5;
				if(tentativeHeight < int(objConfigXML.row.@height)){
					tentativeHeight = int(objConfigXML.row.@height)
				}
				cellText.height = tentativeHeight
				cellGraphicMC.height = tentativeHeight
				selectionMC.height = tentativeHeight;
			}
		}
		public function makeDraggable(){
			//Edited for colulmn resize functionality
			
			dragBtn = new Sprite();	
			dragBtn.graphics.beginFill(0xFFCC00);
			dragBtn.graphics.drawRect(0, 0, 10, 10);
			dragBtn.graphics.endFill();

			dragBtn.width = 4;
			dragBtn.height = cellBGMC.height;
			dragBtn.x = cellBGMC.x + cellBGMC.width - dragBtn.width;
			dragBtn.addEventListener(MouseEvent.MOUSE_OVER, enableCellOver);
			dragBtn.addEventListener(MouseEvent.MOUSE_OUT, enableCellOut);
			//dragBtn.addEventListener(MouseEvent.MOUSE_MOVE, enableCursor);
			
			dragBtn.addEventListener(MouseEvent.MOUSE_DOWN, enableCellDrag);
			dragBtn.addEventListener(MouseEvent.MOUSE_UP, disableCellDrag);		
			//mc.stage.addEventListener(MouseEvent.MOUSE_UP, disableCellDrag);

			mc.addChild(dragBtn);
			dragBtn.alpha = 0;
			
			objCursor = objWidgetController.objCursor
			
			
			objLeftArrow = new mcArrwLeft();
			mc.addChild(objLeftArrow);
			objLeftArrow.visible = false;
			objLeftArrow.y = objLeftArrow.height/2
			
			objRightArrow = new mcArrwRight();
			mc.addChild(objRightArrow);
			objRightArrow.visible = false;
			objRightArrow.y = objRightArrow.height/2
			
			objMcBox = new mcBox();
			mc.addChild(objMcBox);
			objMcBox.visible = false;
			objMcBox.x = objMcBox.width /2
			objMcBox.y = objMcBox.height/2
			//*******************************************
			
		}
		
		
		/**
		* This function draws the selection movieclip in the beginning.
		* Only the visibility needs to be true or false to see the clip. 
		*/
		private function drawSelection(mc)
		{
			selectionMC = new MovieClip;
			selectionMC.name = "selectionMC";
			//selectionMC.graphics.lineStyle(2, 0x76777E, 1, false, "none"); 
			selectionMC.graphics.lineStyle(objConfigXML.cell.@selectedBorderThickness, objConfigXML.cell.@selectedBorderColor);
			selectionMC.graphics.drawRect(0, 0, cellWidth, cellHeight);
			selectionMC.graphics.endFill();
			selectionMC.visible = false;
			mc.addChild(selectionMC);
		}
		
		
		/**
		* This function is used to set the header style.
		* This function will retrieve data from config XML.
		*/
		public function setHeaderStyle(inBlnVal:Boolean)
		{
			//trace("setHeaderStyle"+inBlnVal);
			var colorTransform:ColorTransform = new ColorTransform();
			isHeader = inBlnVal;
			var testContent:String;
			var str1;
			var str2;
			var captivateVarName;
			
			if (inBlnVal)
			{
					
				if(xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor=="")
				{
					colorTransform.color = objConfigXML.headerCell.@bgcolor;
				}
				else
				{
					colorTransform.color =xmlCaptivateParams.table.column[columnRef.index].row[rowRef.index].cell[0].@bgColor;
				}
				
				cellBGMC.transform.colorTransform = colorTransform;
				//cellText.textColor = objConfigXML.headerCell.@textColor;
				
				if (objWidgetController.wm != "Edit")
				{
					cellText.htmlText = cellContent;
					testContent = String(cellText.text);
					str1 = testContent.substring(0, 2);
					str2 = testContent.substr(testContent.length-2, 2);
				
					if (str1 == "$$" && str2 == "$$")
					{								
						captivateVarName = testContent.substring(2, testContent.length - 2);					
						cellContent = String(objWidgetController.rootRef.sendCaptivateVarValue(captivateVarName));
						cellText.htmlText = cellContent
					}
					else
					{					
						cellText.htmlText = cellContent
					}	
				}
				else
				{				
					cellText.htmlText =cellContent
				}
				
				format = new TextFormat();
				format.font = objConfigXML.text.@face;
				format.color = objConfigXML.headerCell.@textColor;
				format.size = objConfigXML.text.@size;
				cellText.defaultTextFormat=format
			}
			else 
			{
				format = new TextFormat();
				format.font = objConfigXML.text.@face;
				format.color = objConfigXML.text.@color;
				format.size = objConfigXML.text.@size;
				//format.align = objConfigXML.text.@align;
				
				if (objWidgetController.wm != "Edit")
				{
					cellText.htmlText = cellContent;
					testContent = String(cellText.text);
					str1 = testContent.substring(0, 2);
					str2 = testContent.substr(testContent.length-2, 2);
				
					if (str1 == "$$" && str2 == "$$")
					{								
						captivateVarName = testContent.substring(2, testContent.length - 2);					
						cellContent = String(objWidgetController.rootRef.sendCaptivateVarValue(captivateVarName));
						cellText.htmlText = cellContent
					}
					else
					{					
						cellText.htmlText = cellContent
					}	
				}
				else
				{				
					cellText.htmlText =cellContent
				}
				
				//cellText.htmlText =cellContent
				cellText.defaultTextFormat=format
			}
			
		}
		
		public function changeToSelection(inBlnVal:Boolean){
			var colorTransform:ColorTransform = new ColorTransform();
			if (inBlnVal)
			{
				isSelected = true
				if(isHeader){
					colorTransform.color = objConfigXML.cell.@multiSelectionHeaderColor
					cellBGMC.transform.colorTransform = colorTransform;
				}else{
					colorTransform.color = objConfigXML.cell.@multiSelectionColor
					cellBGMC.transform.colorTransform = colorTransform;
				}
				
			}
			else 
			{
				if(!selectionMC.visible){
					isSelected = false
				}
				if(isHeader){
					colorTransform.color = objConfigXML.headerCell.@bgcolor;
					cellBGMC.transform.colorTransform = colorTransform;
					cellText.textColor = objConfigXML.headerCell.@textColor;
				}else{
					colorTransform.color = objConfigXML.cell.@bgcolor;
					cellBGMC.transform.colorTransform = colorTransform;
					//cellText.textColor = objConfigXML.color.@textColor;
				}
			}
			
		}
		/*ApplyBorderColor */
		public function ApplyBorderColor(val)
		{
			var colorTransform:ColorTransform = new ColorTransform();
			colorTransform.color = val
			cellBorderMC.transform.colorTransform = colorTransform;
			borderColor=val
		}
		
		/*
		 * Edited for colulmn resize functionality
		 */
		private function enableCellOver(e:MouseEvent):void 
		{
			if(enableIt){
				objCursor.visible = true;
				objCursor.x = objWidgetController.mcGrid.mouseX;
				objCursor.y = objWidgetController.mcGrid.mouseY;
				Mouse.hide();
			}
		}
		
		private function enableCursor(e:MouseEvent):void 
		{
			if(enableIt){
				objCursor.visible = true;
				objCursor.x = objWidgetController.mcGrid.mouseX;
				objCursor.y = objWidgetController.mcGrid.mouseY;
			}
		}
		
		private function enableCellOut(e:MouseEvent):void 
		{
			if(enableIt){
				objCursor.visible = false;
				Mouse.show();
			}
		}
		
		private function enableCellDrag(e:MouseEvent):void 
		{
			if(enableIt){
				setSelectionEvent(e);
				rootRef.addEventListener(MouseEvent.MOUSE_UP, disableCellDrag);		
				rootRef.addEventListener(Event.ENTER_FRAME, drawDragLines);
				//mc.stage.addEventListener(MouseEvent.MOUSE_MOVE, fnNull);
				
				dragBtn.startDrag();
				objCursor.visible = true;
				objCursor.x = objWidgetController.mcGrid.mouseX;
				objCursor.y = objWidgetController.mcGrid.mouseY;			
				startDraw();
				Mouse.hide();
			}
		}
		
		private function fnNull(e:MouseEvent):void 
		{
			
		}
		
		private function disableCellDrag(e:MouseEvent):void 
		{
			//mc.stage.removeEventListener(MouseEvent.MOUSE_MOVE, fnNull);
			//mc.stage.removeEventListener(MouseEvent.MOUSE_UP, fnNull);
			if(enableIt){
				dragBtn.stopDrag();
				
				rootRef.removeEventListener(MouseEvent.MOUSE_UP, disableCellDrag);	
				rootRef.removeEventListener(Event.ENTER_FRAME, drawDragLines);
				
				if(cellText.x + dragBtn.x >= 60){
					cellText.width = cellText.x + dragBtn.x;
					cellGraphicMC.width = cellGraphicMC.x + dragBtn.x;
				}else{
					cellText.width = 60
					cellGraphicMC.width = 60
				}
				
				if (cellText.height > int(objConfigXML.row.@height))
				{
					cellGraphicMC.height = Math.ceil(cellText.height);	
				}
				else
				{
					cellGraphicMC.height = int(objConfigXML.row.@height);				
				}
				if (selectionMC.visible)
				{
					selectionMC.width = cellGraphicMC.width;
					selectionMC.height = cellGraphicMC.height;
				}
				endDraw();
				Mouse.show();
			}
		}
		
		private function startDraw()
		{
			
			
			lineShape = new Sprite();
			isDrawing = true;
			var optimizedWidth = mc.mouseX >= 60 ? mc.mouseX : 60
			lineShape.graphics.clear();
			lineShape.graphics.lineStyle(2, 0x47E3E9);
			lineShape.graphics.moveTo(optimizedWidth, -rootRef.y);
			lineShape.graphics.lineTo(optimizedWidth, 348);
			lineShape.graphics.moveTo(0, (cellGraphicMC.y+cellGraphicMC.height));
			lineShape.graphics.lineTo((cellGraphicMC.x + optimizedWidth), (cellGraphicMC.y+cellGraphicMC.height));
			lineShape.graphics.endFill();
			mc.addChild(lineShape);
			
			objRightArrow.visible = true;
			objLeftArrow.visible = true;
			
			objRightArrow.x = lineShape.width - objRightArrow.width;
			objRightArrow.y = cellGraphicMC.y + cellGraphicMC.height;
			
			objLeftArrow.x = 0;
			objLeftArrow.y = cellGraphicMC.y + cellGraphicMC.height;
			
			objMcBox.visible = true;
			objMcBox.x = lineShape.width / 2;
			objMcBox.y = cellGraphicMC.y + cellGraphicMC.height;
			objMcBox.txtMeasure.htmlText = String(lineShape.width / 72) + "\"";
			mc.setChildIndex(objMcBox,mc.numChildren-1);
			/*if(cellText.text != " "){
				if(cellText.getTextFormat().align){
					cellText.autoSize = cellText.getTextFormat().align
				}else if(isHeader){
					cellText.autoSize = objConfigXML.
				}else{
				}
				
			}*/
		}
		
		private function drawDragLines(e)
		{
			if (isDrawing == true)
			{
				var optimizedWidth = mc.mouseX >= 60 ? mc.mouseX : 60
				if(lineShape != null){
					mc.removeChild(lineShape);
				}
				lineShape = new Sprite();	
				lineShape.graphics.clear();
				lineShape.graphics.lineStyle(2, 0x47E3E9); 
				
				lineShape.graphics.moveTo(optimizedWidth, -rootRef.y);
				lineShape.graphics.lineTo(optimizedWidth, 348);
				lineShape.graphics.moveTo(0, (cellGraphicMC.y+cellGraphicMC.height));
				lineShape.graphics.lineTo((cellGraphicMC.x + optimizedWidth), (cellGraphicMC.y+cellGraphicMC.height));
				lineShape.graphics.endFill();
				mc.addChild(lineShape);
				
				objCursor.visible = true;
				objCursor.x = objWidgetController.mcGrid.mouseX;;
				objCursor.y = objWidgetController.mcGrid.mouseY;
				
				objRightArrow.visible = true;
				objLeftArrow.visible = true;
				
				objRightArrow.x = lineShape.width - objRightArrow.width;
				objRightArrow.y = cellGraphicMC.y + cellGraphicMC.height;
				
				objLeftArrow.x = 0;
				objLeftArrow.y = cellGraphicMC.y + cellGraphicMC.height;
				
				objMcBox.visible = true;
				objMcBox.x = lineShape.width / 2;
				objMcBox.y = cellGraphicMC.y + cellGraphicMC.height;
				objMcBox.txtMeasure.htmlText = String(lineShape.width / 72) + "\"";
				mc.setChildIndex(objMcBox,mc.numChildren-1);
				Mouse.hide();
			}
		}
		
		private function endDraw()
		{
			isDrawing = false;
			dragBtn.height = cellGraphicMC.height;
			dragBtn.x = cellGraphicMC.x + cellGraphicMC.width - dragBtn.width;
			dragBtn.y = 0;
			lineShape.graphics.clear();
			mc.removeChild(lineShape);
			objCursor.visible = false;
			objRightArrow.visible = false;
			objLeftArrow.visible = false;
			objMcBox.visible = false;			
			cellText.autoSize = "none"
			cellWidth = cellGraphicMC.width
			
			dispatchEvent(new Event(UPDATEWIDTH));
			//dispatchEvent(new Event(UPDATEHEIGHT));
		}
		
		//*****************************************************
		
		/**
		* This function is used to get the header style.
		* This function will return the header style properties.
		*/
		public function getHeaderStyle()
		{
			
		}
		
		private function setReferences():void
		{

		}
		
		/**
		* This function is used to set the column reference.
		* Column reference will be used to create the cell in a particular column.
		* Cell Properties will be updated as per the Row reference received.
		*/
		public function setColumnReference(inColumnRef:Object)
		{
			columnRef = inColumnRef;
		}
		
		/**
		* This function is used to set the row reference.
		* Row reference will be used to create the cell in a particular row.
		* Cell Properties will be updated as per the Row reference received.
		*/
		public function setRowReference(inRowRef:Object)
		{
			rowRef = inRowRef;
		}
		
		/**
		* This function call the selection function.
		* 
		*/
		public function setSelectionEvent(evt:MouseEvent)
		{
			if(enableIt){
				mc.cellText.addEventListener(MouseEvent.MOUSE_UP, setTextSelectionEvent);
				setSelection(true);
			}
		}
		
		/**
		* This function set the selection of a cell.
		* 
		*/
		public function setSelection(inBlnVal:Boolean)
		{
			//selectionMC.width = cellWidth//cellGraphicMC.width;
			//selectionMC.height = cellHeight//cellGraphicMC.height;
			selectionMC.visible = inBlnVal;
			applyFilter(mc, 0);
			if(inBlnVal){
				isSelected = true;
				dispatchEvent(new Event(SELECTED));
				dispatchEvent(new Event(COLUMNSELECTED));
			}else{
				killEditor();
				isSelected = false;
			}
			
		}
		
		/**
		* This function set the isInFocus to true if the cell is selected.
		* 
		*/
		public function setFocus(inFocusVal)
		{
			isInFocus = inFocusVal;
		}
		
		/**
		* This function returns the name of the selected cell.
		* 
		*/
		public function getFocus()
		{
			return this.isInFocus;
		}
		
		/**
		* This function enables the cell to be edited.
		* 
		*/
		public function callEditor(evt:MouseEvent)
		{
			/*if(cellText.text == "")
			{
				objTextPropertiesComponent.initializeFormatter();
			}*/
			if(enableIt){
				mc.cellText.removeEventListener(MouseEvent.CLICK, setSelectionEvent);
				//mc.cellText.addEventListener(MouseEvent.MOUSE_UP, setTextSelectionEvent);
				var index = -1;
				var prevFormat = cellText.getTextFormat()
				if(evt==null){
					cellText.text = "";
					index = cellText.text.length;
				}else{
					index = cellText.getCharIndexAtPoint(evt.localX, evt.localY);
				}
				
				if(cellText.text != " "){
					if(prevFormat.align != null){
						cellText.defaultTextFormat = prevFormat
						cellText.autoSize = prevFormat.align;
					}else{
						cellText.autoSize = objConfigXML.text.@align;
					}
				}
				applyFilter(mc, 1)
				objCellEditor.enableEditor(rootRef, index);
				
				var mcRef = objWidgetController.mcRef;
				mcRef.cellBlocker.width = mcRef.width
				mcRef.cellBlocker.height = mcRef.parent.height;
				mcRef.cellBlocker.visible = true;
				mcRef.setChildIndex(mcRef.cellBlocker, 0);				
				mcRef.cellBlocker.addEventListener(MouseEvent.CLICK, forceKillEditor);
			}
			dispatchEvent(new Event('DisplayTextFormatter'));
		}
		
		private function forceKillEditor(evt:MouseEvent){
			killEditor();
			hideCellBlocker();
			setSelection(true);
		}
		
		private function hideCellBlocker()
		{
			var mcRef = objWidgetController.mcRef;
			mcRef.cellBlocker.width = 0
			mcRef.cellBlocker.height = 0;
			mcRef.cellBlocker.visible = false;
		}
		
		private function setTextSelectionEvent(evt:Event):void
		{
			dispatchEvent(new Event('SetTextSelectionEvent'));
		}
		
		private function killEditor(){
			if(cellText.type == "input"){
				cellText.type = "dynamic";
				cellText.setSelection(0,0)
				cellText.selectable = false;
				cellContent = cellText.htmlText;
				if(cellText.height >= cellHeight){
					cellHeight = cellGraphicMC.height
				}
				if(dragBtn != null){
					dragBtn.height = cellHeight
				}
				isSelected = false
				cellText.autoSize = "none"
				
				
				if(cellText.height < objConfigXML.row.@height){
					cellText.height = int(objConfigXML.row.@height);
				}
				if(cellText.width < cellGraphicMC.width){
					cellText.height = cellGraphicMC.width;
				}
				//cellText.alwaysShowSelection=false
				/*if (isHeader)
				{
					cellText.textColor = objConfigXML.headerCell.@textColor;
				}
				else 
				{
					cellText.textColor = xmlCaptivateParams.textProperties.color.@textColor;
				}*/
				dispatchEvent(new Event(UPDATEHEIGHT));
				ScrollPane(this.parent.parent.parent.parent).update();
				mc.cellText.removeEventListener(MouseEvent.MOUSE_UP, setTextSelectionEvent);
				mc.cellText.addEventListener(MouseEvent.CLICK, setSelectionEvent);
				hideCellBlocker();
				//cellText.setTextFormat(format);
			}
			dispatchEvent(new Event('HideTextFormatter'));
		}
		
		/**
		* This function catches the event dispatched from cell editor class to kill the focus from current cell
		* when user presses ENTER key.
		* 
		*/
		public function killCellFocus(evt:Event)
		{
			if(cellText.type == "input"){
				cellText.type = "dynamic";
				cellText.setSelection(0,0)
				cellText.selectable = false;
				selectionMC.visible = false;
				objWidgetController.currentSelectedCell = null;
				
				//cellText.alwaysShowSelection=false
				
				cellContent = cellText.htmlText;			
				cellText.autoSize = "none"
				
				
				
				if(cellText.height < int(objConfigXML.row.@height)){
					cellText.height = int(objConfigXML.row.@height);
				}
				if(cellText.width < cellGraphicMC.width){
					cellText.width = cellGraphicMC.width;
				}
				if(cellText.height >= cellHeight){
					cellHeight = cellGraphicMC.height
				}
				
				if(dragBtn != null){
					dragBtn.height = cellHeight
				}
				
				isSelected = false
				
				applyFilter(mc, 0);
				dispatchEvent(new Event(UPDATEHEIGHT));
				ScrollPane(this.parent.parent.parent.parent).update();
				mc.cellText.addEventListener(MouseEvent.CLICK, setSelectionEvent);
				hideCellBlocker()
				dispatchEvent(new Event('HideTextFormatter'));
			}
		}
		public function updateTableOnFontSizeChange():void
		{
			cellContent = cellText.htmlText;			
				cellText.autoSize = "none"
			if(cellText.height < int(objConfigXML.row.@height)){
				cellText.height = int(objConfigXML.row.@height);
			}
			if(cellText.width < cellGraphicMC.width){
				cellText.width = cellGraphicMC.width;
			}
			if(cellText.height >= cellHeight){
				cellHeight = cellGraphicMC.height
			}
			dispatchEvent(new Event(UPDATEHEIGHT));
			ScrollPane(this.parent.parent.parent.parent).update();
		}
		private function applyFilter(inObj, inAlphaVal:Number)
		{
			if(inAlphaVal == 0){
				inObj.filters = new Array(); 
			}else{
				var dropShadow:DropShadowFilter = new DropShadowFilter(); 
				dropShadow.distance = 2; 
				dropShadow.angle = 45; 
				dropShadow.color = 0x9C9DA2; 
				dropShadow.alpha = 1; 
				dropShadow.blurX = 5; 
				dropShadow.blurY = 5; 
				dropShadow.strength = 2; 
				dropShadow.quality = 3; 
				dropShadow.inner = false; 
				dropShadow.knockout = false; 
				dropShadow.hideObject = false; 
				inObj.filters = new Array(dropShadow); 
			}
		}
		
		/**
		* This function catches the event dispatched from cell editor class on every keystroke pressed
		* by the user which in turn effects the height of the cell.
		*/
		public function setCellHeight(e:Event):void 
		{
			var resultHight = Math.ceil(cellText.height)
			if(resultHight > objConfigXML.row.@height){
				cellGraphicMC.height = resultHight;
				selectionMC.height = resultHight;
			}else{
				cellGraphicMC.height = int(objConfigXML.row.@height)
				selectionMC.height = int(objConfigXML.row.@height)
			}
			ScrollPane(this.parent.parent.parent.parent).update();
			//trace("this.parent:::"+this.parent.parent.parent.parent);
		}
	}
}