www.pudn.com > SSPP.rar > PageSeparator.java


package edu.neu.sspp; 
 
 
public class PageSeparator { 
	private int count; 
	private int totalPage; 
	private int size; 
	private int currentPage; 
	private boolean isEnd; 
	private boolean isBegin; 
	 
	public PageSeparator(int count, int size) { 
		this.count = count; 
		this.size = size; 
		 
		init(); 
	 
	} 
	 
	private void init() { 
		if(count % size != 0) 
			totalPage = count / size + 1; 
		else 
			totalPage = count / size; 
		 
		currentPage = 1; 
		refresh(); 
	} 
	 
	private void refresh() { 
		if(totalPage == 1) { 
			isBegin = true; 
			isEnd = true; 
		} 
		else if(currentPage == 1) { 
			isBegin = true; 
			isEnd = false; 
		} 
		else if(currentPage == totalPage) { 
			isBegin = false; 
			isEnd = true; 
		} 
		else { 
			isBegin = false; 
			isEnd = false; 
		}		 
	} 
	 
	public void setCurrentPage(int currentPage) throws Exception { 
		if(currentPage > totalPage || currentPage < 1) 
			throw new Exception("current page error!"); 
		else 
			this.currentPage = currentPage; 
		refresh(); 
	} 
	 
	public int getCurrentPage() { 
		return currentPage; 
	} 
	 
	public int getTotalPage() { 
		return totalPage; 
	} 
	 
	public boolean getIsBegin() { 
		return isBegin; 
	} 
	 
	public boolean getIsEnd() { 
		return isEnd; 
	} 
	 
	public void setToBegin() { 
		currentPage = 1; 
		refresh(); 
	} 
	 
	public void setToEnd() { 
		currentPage = totalPage; 
		refresh(); 
	} 
	 
	public int getSize() { 
		return size; 
	} 
	 
	public int getCurrentPageBegin() { 
		return (currentPage - 1) * size; 
	} 
	 
	public int getCurrentPageEnd() { 
		if(!isEnd || count % size == 0) 
			return currentPage * size; 
		else 
			return (currentPage - 1) * size + count % size; 
	} 
	 
	public int getCurrentPageCount() { 
		if(!isEnd || count % size == 0) 
			return size; 
		else 
			return count % size; 
	} 
	 
	public int getNextPage() { 
		return currentPage + 1; 
	} 
	 
	public int getBackPage() { 
		return currentPage - 1; 
	} 
	 
	public int getCount() { 
		return count; 
	} 
}