1 package org.apache.tapestry.pets.presentation.components; 2 3 public class PagedModel 4 { 5 private int pageSize; 6 private int nextPageNumber; 7 private int previousPageNumber; 8 private int pageToShow; 9 private int itemCount; 10 private int pageCount; 11 12 public boolean getHasNextPage() 13 { 14 return (getPageToShow() < getPageCount()) ? true : false; 15 } 16 17 public boolean getHasPreviousPage() 18 { 19 return (getPageToShow() > 1) ? true : false; 20 } 21 22 public int getNextPageNumber() 23 { 24 return nextPageNumber; 25 } 26 27 public int getPageSize() 28 { 29 return (pageSize == 0) ? 4 : pageSize; 31 } 32 33 public int getPageToShow() 34 { 35 return (pageToShow == 0) ? 1 : pageToShow; 36 } 37 38 public int getPreviousPageNumber() 39 { 40 return previousPageNumber; 41 } 42 43 public void setNextPageNumber(int nextPageNumber) 44 { 45 this.nextPageNumber = nextPageNumber; 46 } 47 48 public void setPageSize(int pageSize) 49 { 50 this.pageSize = pageSize; 51 } 52 53 public void setPageToShow(int pageToShow) 54 { 55 this.pageToShow = jumpToPage(pageToShow, getPageCount()); 56 } 57 58 public void setPreviousPageNumber(int previousPageNumber) 59 { 60 this.previousPageNumber = previousPageNumber; 61 } 62 63 public int getItemCount() 64 { 65 return itemCount; 66 } 67 68 public int getPageCount() 69 { 70 if (pageCount != 0) 71 { 72 return pageCount; 73 } 74 else 75 { 76 return (int) Math.ceil(((double) getItemCount() / (double) getPageSize())); 77 } 78 } 79 80 public void setItemCount(int itemCount) 81 { 82 this.itemCount = itemCount; 83 } 84 85 public void setPageCount(int pageCount) 86 { 87 this.pageCount = pageCount; 88 } 89 90 private static int jumpToPage(int page, int pCount) 91 { 92 if (page < 2) 93 { 94 return 1; 95 } 96 else 97 if (page > pCount) 98 { 99 return pCount; 100 } 101 else 102 { 103 return page; 104 } 105 } 106 } 107 | Popular Tags |