/**
 * 功能：类似于java中的StringBuffer类的功能，用于字符串的拼接
 *       这种方式比直接用"+"性能要高出很多
 */
package("com.henry.ui");
com.henry.ui.Label = function(aText, aImage, aId) {		
	//扩展定义
	var self = new com.henry.ui.HTML("span", aId);
	var labelInstance = this.constructor.extendInstance(self);
	var $super = labelInstance.$super;				//防止死循环


	//私有变量定义区
	var _image = aImage;
	
	//方法定义区 
	{
		labelInstance.setTag = function() {
			throw new Error("tag can't be changed!");
		}
		
		labelInstance.buildImage = function() {
			var image = new com.henry.ui.SPAN();
			if (_image) {
				image.setClass("item", "image");
				image.setClass("image", _image);
			}
			return image;
		}
		
		labelInstance.buildText = function() {			
			var text = new com.henry.ui.SPAN();	
			text.setClass("item","text");
			text.addChild("html",this.getControlText());
			return text;
		}

	
		labelInstance.setId = function(theId) {
			$super.setId(theId);					//不能使用self.$super, 否则可能导致死循环
			return this;
		} 
		
		labelInstance.setControlText = function(theText, noRefresh) {
			$super.setControlText(theText, true);					//不能使用self.$super, 否则可能导致死循环
			if (!noRefresh) {
				var text = this.getChild("box.text");
				text.setControlText(theText);
			}
			return this;
		}
		
		labelInstance.getControlImage = function() {
			return _image;
		}
		
		labelInstance.setControlImage = function(theImage) {
			_image = theImage;
			
			var image = self.getChild("box.image");
			
			image.setClass("image", theImage);
			if (!theImage) {
				image.setClass("item", null);
			}
			else {
				image.setClass("item", "image");
			}
			
			return this;
		}
	}
	
	//初始化区
	(function() {
		$super.setId(aId);
	
		$super.setControlText(aText, true);
				
		$super.setTag("span");
		self.setClass("system", "control");
		self.setClass("item", "control");
		self.setClass("ui", "label");
		self.setClass("text", "expand");
		self.setAttribute("onselectstart", "return false;");
				
		var box = self.buildBox();
		self.addChild("box", box);	
	})();
				
	return labelInstance;
}
