package nc.ui.wa.ruleex.action;

import java.awt.Font;

import nc.ui.pub.bill.BillItem;
import nc.ui.pub.print.gen.PrintActionUtil;
import nc.ui.pub.print.version55.directprint.PrintDirectForm;
import nc.ui.pub.print.version55.directprint.PrintDirectSeperator;
import nc.ui.pub.print.version55.print.template.cell.style.Style;
import nc.ui.uif2.actions.SingleTemplateDirectPrintAction;

/**
 * @author xueliang1
 * 薪资规则的卡片打印
 * */
public class RuleCardPrintAction extends SingleTemplateDirectPrintAction {

	private static final long serialVersionUID = -2097898101474562254L;
	
///////////////////////////////////////////
	private Font defaultFont = new java.awt.Font("宋体"/* -=notranslate=- */, java.awt.Font.PLAIN, 14);//字体与平台一致，与UE不符合
	private float height = 20f;//高度定为20
	private float vlength=100f;//value长度为100
	private float nlength=100f;//item长度为100
	private int align=Style.LEFT;
	
	/////////////////////////////////////////////
	
	@Override
	public String getTitle() {
		if(getBillCardPanel() != null)
		{
			title = getBillCardPanel().getTitle();
		}
		return title;
	}
	@Override
	protected void processHead() {
		BillItem[] items = getHeadShowItems();
		if(items == null || items.length == 0)
			return ; 
		getPrint().addSection(new PrintDirectSeperator());
		processForm(items);
		
	}

	/**
	 * @author xueliang1
	 * 处理审计信息，也是每行三个
	 * */
	@Override
	protected void processTail() {
		BillItem[] items = getTailShowItems();
		if(items == null || items.length == 0)
			return ;
		getPrint().addSeperator(new PrintDirectSeperator());
		processForm(items);
	}
	
	/**
	 * @author xueliang1
	 * 对PrintDirectForm进行构造处理
	 * */
    private void processForm(BillItem[] items){
    	PrintDirectForm form = new PrintDirectForm();
		int i=0;
		for(BillItem item : items)
		{
			i++;
			form.addItem(item.getName(),PrintActionUtil.getItemPrintValue(item),getAlign(),getNlength(),getVlength(),getHeight(),getDefaultFont());
			//每三个占据一行，据中显示
			if(i%3==0){
				getPrint().addFormSection(form);
				getPrint().addSection(new PrintDirectSeperator());
				form=new PrintDirectForm();
				i=0;
			}
			
		}
		//不满三个的不能忘记添加
		if(i!=0){
			getPrint().addFormSection(form);
			getPrint().addSection(new PrintDirectSeperator());
		}
    }

	public Font getDefaultFont() {
		return defaultFont;
	}

	public void setDefaultFont(Font defaultFont) {
		this.defaultFont = defaultFont;
	}

	public float getHeight() {
		return height;
	}

	public void setHeight(float height) {
		this.height = height;
	}

	public float getVlength() {
		return vlength;
	}

	public void setVlength(float vlength) {
		this.vlength = vlength;
	}

	public float getNlength() {
		return nlength;
	}

	public void setNlength(float nlength) {
		this.nlength = nlength;
	}

	public int getAlign() {
		return align;
	}

	public void setAlign(int align) {
		this.align = align;
	}

}
