?? baseband.java
字號:
/***********************************************************************
* Module: BaseBand.java
* Author: juny
* Created: 2006年7月13日 15:00:31
* Purpose: Defines the Class BaseBand
***********************************************************************/
package net.excel.report.base;
import java.util.ArrayList;
import java.util.List;
import net.excel.report.base.element.Templet;
import net.excel.report.config.ReportConfig.SheetConfig;
import net.excel.report.util.AnalyseTempletTool;
import jxl.Range;
import jxl.write.WritableImage;
import jxl.write.WritableSheet;
/**
* 所有帶的基類(組也是屬于帶的一種). 帶表示報表中的一個可重復輸出的區域,
* 該區域根據帶的不同類型會產生不同的輸出效果,如band它所對應的body區是根據band對應的數據源的記錄條數來進行輸出的,
* 在band中假設對應的數據源為5條記錄那么該band對應的body區也會打印5次。
*
* @author juny
*/
public abstract class BaseBand extends BaseElement implements ITempletContainer {
/**
* @param container 父容器對象。
*/
public BaseBand(ITempletContainer container) {
super(container);
}
/**
* 設置當前報表配置文件信息。這個函數以后可能會移掉,當前配置文件信息對象應該放在
* 參數對象中去給當前所有對象共享才比較合理,而無需要每個對象都去顯式的設置。
* @param sheetConfig
*/
public void setReportConfig(SheetConfig sheetConfig){
this.sheetConfig = sheetConfig;
}
protected SheetConfig sheetConfig = null;
/**
* 取得當前band對象在報表寫入數據的起始行
*/
public int getRealBeginRow(){
return realBeginRow;
}
protected int realBeginRow = 0;
/**
* 取得當前band對象總共寫入了多少行數據
*/
public int getRealRowCount(){
return realRowCount;
}
protected int realRowCount = 0;
/**
* 設置頭容器。
*/
public void setHearder() {
this.headTemplet = new Templet(this.getParentContainer());
curTemplet = this.headTemplet;
}
/**
* 設置明細容器
* @param beginCol
* @param beginRow
*/
public void setDetail(int beginCol, int beginRow) {
this.detailTemplet = new Templet(this.getParentContainer());
this.detailTemplet.setBegin(beginCol, beginRow);
this.curTemplet.setEnd(beginCol, beginRow);
this.curTemplet = this.detailTemplet;
}
/**
* 設置當前帶的結束位置
* @param beginCol
* @param beginRow
*/
public void setBottom(int beginCol, int beginRow) {
this.bottomTemplet = new Templet(this.getParentContainer());
this.bottomTemplet.setBegin(beginCol, beginRow);
this.curTemplet.setEnd(beginCol, beginRow);
this.curTemplet = this.bottomTemplet;
}
/* (non-Javadoc)
* @see excel.report.util.ITempletContainer#setBegin(int, int)
*/
public void setBegin(int beginCol, int beginRow) {
curTemplet.setBegin(beginCol, beginRow);
}
/* (non-Javadoc)
* @see excel.report.util.ITempletContainer#setEnd(int, int)
*/
public void setEnd(int endCol, int endRow) {
curTemplet.setEnd(endCol, endRow);
}
/**
* 判斷傳入模板信息是否是當前容器對象的頭。
* @param templet 模板定義內容
* @return true 當前傳入模板是當前帶對象的頭 false 表示不是
*/
public boolean isHead(String templet) {
return isSameBand(templet);
}
/**
* 判斷傳入模板信息是否是當前容器對象的body區。
* @param templet 模板定義內容
* @return true 當前傳入模板是當前帶對象的body區 false 表示不是
*/
public boolean isDetail(String templet) {
return isSameBand(templet);
}
/**
* 判斷傳入模板信息是否是當前容器對象的foot區。
* @param templet 模板定義內容
* @return true 當前傳入模板是當前帶對象的foot區 false 表示不是
*/
public boolean isBottom(String templet) {
return isSameBand(templet);
}
/**
* 判斷傳入模板信息是否是當前容器對象的結束位置。
* @param templet 模板定義內容
* @return true 當前傳入模板是當前帶對象的結束位置 false 表示不是
*/
public boolean isEnd(String templet) {
return isSameBand(templet);
}
private boolean isSameBand(String templet){
String name = AnalyseTempletTool.getPorperty(
templet,
AnalyseTempletTool.PROPERTY_NAME
);
if(this.getName().equals(name)){
return true;
}
return false;
}
/*
* @see excel.report.util.ITempletContainer#getContainElements()
*/
public List getContainElements() {
return null;
}
/*
* @see excel.report.util.ITempletContainer#getElement(java.lang.String)
*/
public BaseElement getElement(String name) {
BaseElement element = null;
if(null != headTemplet){
element = headTemplet.getElement(name);
if(null != element){
return element;
}
}
if(null != detailTemplet){
element = this.detailTemplet.getElement(name);
if(null != element){
return element;
}
}
if(null != bottomTemplet){
element = this.bottomTemplet.getElement(name);
if(null != element){
return element;
}
}
return null;
}
/*
* @see excel.report.util.ITempletContainer#addElement(excel.report.util.BaseElement)
*/
public void addElement(BaseElement element, int col, int row) {
this.curTemplet.addElement(element, col, row);
}
/*
* @see excel.report.util.ITempletContainer#getElement(int, int)
*/
public BaseElement getElement(int col, int row) {
BaseElement element = null;
if(null != headTemplet){
element = headTemplet.getElement(col, row);
if(null != element){
return element;
}
}
if(null != this.detailTemplet){
element = this.detailTemplet.getElement(col, row);
if(null != element){
return element;
}
}
if(null != this.bottomTemplet){
element = this.bottomTemplet.getElement(col, row);
if(null != element){
return element;
}
}
return null;
}
/*
* @see excel.report.util.ITempletContainer#getBeginCol()
*/
public int getBeginCol() {
return null == headTemplet ? 0 : headTemplet.getBeginCol();
}
/*
* @see excel.report.util.ITempletContainer#getBeginRow()
*/
public int getBeginRow() {
return null == headTemplet ? 0 : headTemplet.getBeginRow();
}
/*
* @see excel.report.util.ITempletContainer#getEndCol()
*/
public int getEndCol() {
return null == bottomTemplet ? 0 : bottomTemplet.getEndCol();
}
/*
* @see excel.report.util.ITempletContainer#getEndRow()
*/
public int getEndRow() {
return null == bottomTemplet ? 0 : bottomTemplet.getEndRow();
}
/* (non-Javadoc)
* 添加一個合并單元格信息到容器中。
*/
public boolean addMergedCell(Range range) {
if(null != headTemplet){
if(headTemplet.addMergedCell(range)){
return true;
}
}
if(null != detailTemplet){
if(detailTemplet.addMergedCell(range)){
return true;
}
}
if(null != bottomTemplet){
if(bottomTemplet.addMergedCell(range)){
return true;
}
}
return false;
}
/* (non-Javadoc)
* @see excel.report.util.ITempletContainer#getMergedCells()
*/
public List getMergedCells() {
//還未實現
return null;
}
/*
* (non-Javadoc)
* @see excel.report.base.ITempletContainer#getImages()
*/
public List getImages() {
if(images != null){
return images;
}
images = new ArrayList();
List tImages = null;
if(null != headTemplet){
tImages = headTemplet.getImages();
if(null != tImages){
images.addAll(tImages);
tImages = null;
}
}
if(null != detailTemplet){
tImages = detailTemplet.getImages();
if(null != tImages){
images.addAll(tImages);
tImages = null;
}
}
if(null != bottomTemplet){
tImages = bottomTemplet.getImages();
if(null != tImages){
images.addAll(tImages);
tImages = null;
}
}
return images;
}
private List images = null;
/*
* (non-Javadoc)
* @see excel.report.base.ITempletContainer#addImage(jxl.write.WritableImage)
*/
public boolean addImage(WritableImage image) {
if(null != headTemplet){
if(headTemplet.addImage(image)){
return true;
}
}
if(null != detailTemplet){
if(detailTemplet.addImage(image)){
return true;
}
}
if(null != bottomTemplet){
if(bottomTemplet.addImage(image)){
return true;
}
}
return false;
}
/*
* (non-Javadoc)
* @see excel.report.base.ITempletContainer#removeAllTempletImages(jxl.write.WritableSheet)
*/
public boolean removeAllTempletImages(WritableSheet sheet) {
if(null != headTemplet){
headTemplet.removeAllTempletImages(sheet);
}
if(null != detailTemplet){
detailTemplet.removeAllTempletImages(sheet);
}
if(null != bottomTemplet){
bottomTemplet.removeAllTempletImages(sheet);
}
return true;
}
/**
* 生成當前帶對象的頭部區的報表數據
* @param param 參數對象
* @throws Exception
*/
protected void writeHead(Parameter param) throws Exception{
if(null != this.headTemplet){
this.headTemplet.write(param);
}
}
/**
* 生成當前帶對象的body區的報表數據
* @param param 參數對象
* @throws Exception
*/
protected void writeBody(Parameter param) throws Exception{
if(null != this.detailTemplet){
this.detailTemplet.write(param);
}
}
/**
* 生成當前帶對象的foot區的報表數據
* @param param 參數對象
* @throws Exception
*/
protected void writeFoot(Parameter param) throws Exception{
if(null != this.bottomTemplet){
this.bottomTemplet.write(param);
}
}
protected ITempletContainer headTemplet = null; //頭部模板容器
protected ITempletContainer detailTemplet = null;//明細信息模板容器
protected ITempletContainer bottomTemplet = null;//尾部模板容器信息
protected ITempletContainer curTemplet = null;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -