改ページプログラム(非共通版)簡単版

3037 ワード

package net.dbet.common;

import java.util.List;

/**
 *    ,  currPage,pageCount,pageCodeCount,pageRows
 * */
public class Pages {
	
	private int currPage;           //    
	private int pageCount;          //   
	private String pageBar;         //      
	
	private int pageCodeCount=10;   //       
	private int halfPageCode=5;     //       
	
	public int getHalfPageCode() {
		return halfPageCode;
	}
	public void setHalfPageCode(int halfPageCode) {
		this.halfPageCode = halfPageCode;
	}
	public int getPageCodeCount() {
		return pageCodeCount;
	}
	public void setPageCodeCount(int pageCodeCount) {
		this.pageCodeCount = pageCodeCount;
		if(pageCodeCount%2==0)
			halfPageCode=pageCodeCount/2;
		else
			halfPageCode=pageCodeCount/2+1;
	}
	public int getCurrPage() {
		return currPage;
	}
	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}
	public String getPageBar() {
		if(this.pageCount==0) return "";
		StringBuffer sResult=new StringBuffer();
		sResult.append("[<a href='javascript:jumpPage(1);'>  </a>]");
		if(this.currPage>1)
			sResult.append("[<a href='javascript:jumpPage("+(this.currPage-1)+");'>   </a>]");
		if(this.currPage-(halfPageCode-1)>1&&this.pageCount>pageCodeCount)
			sResult.append("...");
		int start=1;
		if(this.currPage>halfPageCode){
			if(this.pageCount-this.currPage<halfPageCode){
				start=this.pageCount-(pageCodeCount-1);
			}else{
				start=this.currPage-(halfPageCode-1);
			}
		}
		start=start<1?1:start;
		int end=this.pageCount;
		if(start+(pageCodeCount-1)<this.pageCount)
			end=start+(pageCodeCount-1);
		else
			end=this.pageCount;
		for(int i=start;i<=end;i++){
			if(this.currPage==i){
				sResult.append("<font color='red'>"+i+"</font>");
			}else{
				sResult.append("[<a href='javascript:jumpPage("+i+");'>"+i+"</a>]");
			}
		}
		if(end!=this.pageCount)
			sResult.append("...");
		if(this.currPage<this.pageCount)
			sResult.append("[<a href='javascript:jumpPage("+(this.currPage+1)+");'>   </a>]");
		sResult.append("[<a href='javascript:jumpPage("+this.pageCount+");'>  </a>]");
		return sResult.toString();
	}
	public void setPageBar(String pageBar) {
		this.pageBar = pageBar;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	
		
}