📄 paginationsupport.java
字号:
package com.tcg.core;
import java.util.List;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* UserSession: Administrator
* Date: 2007-9-4
* Time: 16:07:50
* To change this template use File | Settings | File Templates.
*/
public class PaginationSupport {
public final static int PAGESIZE = 15;
private int pageSize = PAGESIZE;
private List items;
private int totalCount;
private int[] indexes = new int[0];
private int startIndex = 0;
public PaginationSupport(List items, int totalCount) {
this(items, totalCount, 0);
}
public PaginationSupport(List items, int totalCount, int startIndex) {
this(items, totalCount,PAGESIZE, startIndex);
}
public PaginationSupport(List items, int totalCount, int startIndex, int pageSize) {
setPageSize(pageSize);
setTotalCount(totalCount);
setItems(items);
setStartIndex(startIndex);
}
public List getItems() {
if(items == null) items = new ArrayList();
return items;
}
public void setItems(List items) {
this.items = items;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public int getTotalPage() {
int count = totalCount / pageSize;
if (totalCount % pageSize > 0)
count++;
return count;
}
public int getCurrentPage() {
int count = (startIndex+1) / pageSize;
if ((startIndex+1) % pageSize > 0)
count++;
if(count > getTotalPage()) count = getTotalPage();
return count;
}
public int getNextPage() {
int no = getCurrentPage();
if(no < getTotalPage()) no ++;
return no;
}
public int getPreviousPage() {
int no = getCurrentPage();
if(no > 1) no --;
return no;
}
public String getPreviousable() {
return getCurrentPage()==1?"disabled":"";
}
public String getNextable() {
return getCurrentPage()==getTotalPage()?"disabled":"";
}
public void setTotalCount(int totalCount) {
if (totalCount > 0) {
this.totalCount = totalCount;
int count = totalCount / pageSize;
if (totalCount % pageSize > 0)
count++;
indexes = new int[count];
for (int i = 0; i < count; i++) {
indexes[i] = pageSize * i;
}
} else {
this.totalCount = 0;
}
}
public int[] getIndexes() {
return indexes;
}
public void setIndexes(int[] indexes) {
this.indexes = indexes;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
if (totalCount <= 0)
this.startIndex = 0;
else if (startIndex >= totalCount)
this.startIndex = indexes[indexes.length - 1];
else if (startIndex < 0)
this.startIndex = 0;
else {
this.startIndex = indexes[startIndex / pageSize];
}
}
public int getNextIndex() {
int nextIndex = getStartIndex() + pageSize;
if (nextIndex >= totalCount)
return getStartIndex();
else
return nextIndex;
}
public int getPreviousIndex() {
int previousIndex = getStartIndex() - pageSize;
if (previousIndex < 0)
return 0;
else
return previousIndex;
}
public List getViewPageLabels() {
List list = new ArrayList();
int firstNo = (getCurrentPage()/10)*10+1;
int lastNo = (getCurrentPage()/10)*10+10;
if(lastNo > getTotalPage()){
lastNo = getTotalPage();
}
while(firstNo <= lastNo){
list.add(firstNo);
firstNo ++;
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -