/* ImageWidget.java

	Purpose:
		
	Description:
		
	History:
		Apr 16, 2008 5:40:26 PM     2008, Created by Dennis.Chen

Copyright (C) 2008 Potix Corporation. All Rights Reserved.
 */
package org.zkoss.zssex.ui.widget;

import org.zkoss.poi.ss.util.AreaReference;
import org.zkoss.zk.ui.Component;
import org.zkoss.zss.model.SPicture;
import org.zkoss.zss.model.SSheet;
import org.zkoss.zul.Image;

/**
 * A ImageWiget to show image in spreadsheet.
 * The implementation of this widget is {@link Image}, 
 * you can get {@link Image} component by call {@link #getComponent()}
 * 
 * @author Dennis.Chen
 * 
 */
public class ImageWidget extends BaseWidget {
	private static final long serialVersionUID = -3653947286915790167L;
	Image _imageComp;
	
	synchronized private Image inner() {
		if (_imageComp == null) {
			_imageComp = new Image();
			_imageComp.setSclass("zswidget-img");
		}
		return _imageComp;
	}
	
	public ImageWidget(SSheet sheet, SPicture pic, String panel) {
		super(panel);
		setId(pic.getId());
		setSizable(true);
		setMovable(true);
		setCtrlKeys("#del");
	}

	protected Component getInnerComponent() {
		return inner();
	}
	
	public String getSrc() {
		return inner().getSrc();
	}

	public void setSrc(String src) {
		inner().setSrc(src);
	}

	public org.zkoss.image.Image getContent() {
		return inner().getContent();
	}
	
	public void setWidth(String w){
		inner().setWidth(w);
	}
	
	public String getWidth(){
		return inner().getWidth();
	}
	
	public void setHeight(String h){
		inner().setHeight(h);
	}
	
	public String getHeight(){
		return inner().getHeight();
	}
	
	public void setBorder(String border){
		inner().setBorder(border);
	}
	
	public String getBorder(){
		return inner().getBorder();
	}

	public void setContent(org.zkoss.image.Image image) {
		inner().setContent(image);
	}

	protected WidgetCtrl newCtrl() {
		WidgetCtrl ctrl = super.newCtrl();
		//ZSS491, append widget when mark it on client
//		inner().setParent(ctrl);
		return ctrl;
	}
	
	void setInClient(boolean inClient) {
		super.setInClient(inClient);
		//ZSS491 attach to ui when set to client (render it)
		if(inClient){
			inner().setParent(getCtrl());
		}else if(!inClient && _imageComp!=null){
			_imageComp.setParent(null);
		}
	}

	@Override
	public void invalidate() {
		inner().invalidate();
	}


	@Override
	public String getWidgetType() {
		return "image";
	}

}
