$package("js.ui.list");

js.ui.list.IconListItemRenderer = function (owner){
	this.owner = owner;
}

js.ui.list.IconListItemRenderer.prototype = new js.ui.list.AbstractListItemRenderer();

js.ui.list.IconListItemRenderer.prototype.style = 1;//js.ui.list.AbstractListView.ViewType.BIGICON;

js.ui.list.IconListItemRenderer.prototype.getNativeClass = function (){
	if(this.style==0)
		return "js.ui.list.IconListItemRenderer_Report";
	else
		return "js.ui.list.IconListItemRenderer";
}

js.ui.list.IconListItemRenderer.prototype.getCSS = function (){
	if(this.isSelected())
		return this.baseCSS + " Panel_selected";
	if(this.state==1)
		return this.baseCSS + " Panel_over";
	return this.baseCSS;
}

js.ui.list.IconListItemRenderer.prototype.bindUI = function (){
	this.__superBindUI = js.ui.list.AbstractListItemRenderer.prototype.bindUI;
	this.__superBindUI();
	this.edit = this.ui.getElementsByTagName("textarea")[0];
	this.textDiv = this.ui.getElementsByTagName("div")[3];
	this.text = this.ui.getElementsByTagName("a")[0];
	var icon = this.ui.getElementsByTagName("img")[0];
	this.iconDiv = icon.parentNode;
	this.icon = new js.ui.Img();
	this.icon.ui = icon;
	this.bindEvents();
}

js.ui.list.IconListItemRenderer.prototype.bindEvents = function (){
	var __this = this;
	this.ui.onmouseover = function(){
		__this.state = 1;
		this.className = __this.getCSS();
	}
	this.ui.onkeydown = function(event){
		if(!event) event=window.event;
		if (event.which==113 || event.keyCode==113)
			__this.rename();
	};
	this.ui.ondblclick = function(event){
			__this.__mouseClickTimer.stop();
			if (__this.onopen)
				__this.onopen();
	};
	
	this.__mouseClickTimer = new js.util.Timer();
	this.__mouseClickTimer.setInterval(500);
	this.__mouseClickTimer.ontimer = function(){
		__this.rename();
		this.stop();
	};
	this.text.onclick = function(){
		if(__this.isSelected())
			__this.__mouseClickTimer.setActive(true);
		return js.ui.Component.eventCancelBubble(event);
	};
	this.edit.onkeydown = function(event){
		if(!event) event=window.event;
		if (event.which==13 || event.keyCode==13)
			__this.toTextView();
		if (event.which==27 || event.keyCode==27)
			__this.cancelEdit();
	}	
}

js.ui.list.IconListItemRenderer.prototype.rename = function(){
	if(this.readOnly) return;
	if(this.edit.style.display=="block") return;
	var value = this.text.innerHTML;
	this.edit.value = value;
	this.edit.style.width = this.textDiv.offsetWidth+2;
	this.edit.style.height = this.textDiv.offsetHeight+2;
	this.edit.style.display = "block";
	this.textDiv.style.display = "none";
	this.edit.focus();
	this.edit.select();
	var __this = this;
	this.edit.onblur = function(){
		__this.toTextView();
	}
//	this.__OldValue = value;
}
js.ui.list.IconListItemRenderer.prototype.toTextView = function (){
//	this.SetText(this.Edit.value);
//	this.UserObject.Text = this.Edit.value;
	this.text.innerHTML = this.edit.value;
	this.textDiv.style.display = "";
	this.edit.style.display = "none";
	if(this.onchange) this.onchange(this.edit.value);
//	this.onmousedown = js.ui.list.IconListBoxCellRenderer.prototype.__onmousedown;
//	this.SetOpenType(this.OpenType);
}

js.ui.list.IconListItemRenderer.prototype.cancelEdit = function (){
	var func = this.edit.onblur;
	this.edit.onblur = null;
	this.textDiv.style.display = "";
	this.edit.style.display = "none";
}

js.ui.list.IconListItemRenderer.prototype.setIcon = function (url){
//	js.util.Utils.prototype.setImage(this.icon, url);
//	if(!this.ui) this.getUI();
	this.icon.setSrc(url);
}

js.ui.list.IconListItemRenderer.prototype.paintSelect = function(){
	this.getUI().className = this.getCSS();
}
js.ui.list.IconListItemRenderer.prototype.paintText = function(){
	var text = this.userObject.text;
	if(text=='') text = "&nbsp";
	this.text.innerHTML = text;
	this.edit.value = text;
}

js.ui.list.IconListItemRenderer.prototype.paintIcon = function (){
	var icon = this.userObject.icon;
	this.setIcon(icon);
}

js.ui.list.IconListItemRenderer.prototype.paint = function(){
	this.paintText();
	this.paintIcon();
	this.paintSelect();
}


