Update of /cvsroot/displaytag/display09/src/org/displaytag/pagination
In directory sc8-pr-cvs1:/tmp/cvs-serv553/src/org/displaytag/pagination
Modified Files:
Pagination.java SmartListHelper.java NumberedPage.java
Log Message:
formatted code, some javadoc improvements and small fixes
Index: Pagination.java
===================================================================
RCS file: /cvsroot/displaytag/display09/src/org/displaytag/pagination/Pagination.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Pagination.java 21 Jun 2003 12:34:50 -0000 1.1
--- Pagination.java 9 Aug 2003 19:54:07 -0000 1.2
***************
*** 16,22 ****
/**
! * Field mLog
*/
! private static Log mLog= LogFactory.getLog(Pagination.class);
/**
--- 16,22 ----
/**
! * logger
*/
! private static Log mLog = LogFactory.getLog(Pagination.class);
/**
***************
*** 24,43 ****
*/
private MessageFormat mUrlFormat;
!
/**
* first page
*/
private Integer mFirst;
!
/**
* last page
*/
private Integer mLast;
!
/**
* previous page
*/
private Integer mPrevious;
!
/**
* next page
--- 24,43 ----
*/
private MessageFormat mUrlFormat;
!
/**
* first page
*/
private Integer mFirst;
!
/**
* last page
*/
private Integer mLast;
!
/**
* previous page
*/
private Integer mPrevious;
!
/**
* next page
***************
*** 46,52 ****
/**
! * Field mPages
*/
! private ArrayList mPages= new ArrayList();
/**
--- 46,53 ----
/**
! * ArrayList containg NumberedPage objects
! * @see org.displaytag.pagination.NumberedPage
*/
! private ArrayList mPages = new ArrayList();
/**
***************
*** 56,66 ****
public Pagination(String pUrlFormatString)
{
! mUrlFormat= new MessageFormat(pUrlFormatString);
}
/**
* add a page
! * @param pNumber int
! * @param pSelected boolean
*/
public void addPage(int pNumber, boolean pSelected)
--- 57,67 ----
public Pagination(String pUrlFormatString)
{
! mUrlFormat = new MessageFormat(pUrlFormatString);
}
/**
* add a page
! * @param pNumber int page number
! * @param pSelected is the page selected?
*/
public void addPage(int pNumber, boolean pSelected)
***************
*** 112,116 ****
public void setFirst(Integer pFirst)
{
! mFirst= pFirst;
}
--- 113,117 ----
public void setFirst(Integer pFirst)
{
! mFirst = pFirst;
}
***************
*** 130,134 ****
public void setLast(Integer pLast)
{
! mLast= pLast;
}
--- 131,135 ----
public void setLast(Integer pLast)
{
! mLast = pLast;
}
***************
*** 148,152 ****
public void setPrevious(Integer pPrevious)
{
! mPrevious= pPrevious;
}
--- 149,153 ----
public void setPrevious(Integer pPrevious)
{
! mPrevious = pPrevious;
}
***************
*** 166,179 ****
public void setNext(Integer pNext)
{
! mNext= pNext;
}
/**
! * Method getFormattedBanner
! * @param pNumberedPageFormat String
! * @param pNumberedPageSelectedFormat String
! * @param pNumberedPageSeparator String
! * @param pFullBanner String
! * @return String
*/
public String getFormattedBanner(
--- 167,180 ----
public void setNext(Integer pNext)
{
! mNext = pNext;
}
/**
! * returns the appropriate banner for the pagination
! * @param pNumberedPageFormat String to be used for a not selected page
! * @param pNumberedPageSelectedFormat String to be used for a selected page
! * @param pNumberedPageSeparator separator beetween pages
! * @param pFullBanner String basic banner
! * @return String formatted banner whith pages
*/
public String getFormattedBanner(
***************
*** 184,191 ****
{
! StringBuffer lBuffer= new StringBuffer(100);
// numbered page list
! Iterator lPageIterator= mPages.iterator();
while (lPageIterator.hasNext())
--- 185,192 ----
{
! StringBuffer lBuffer = new StringBuffer(100);
// numbered page list
! Iterator lPageIterator = mPages.iterator();
while (lPageIterator.hasNext())
***************
*** 193,204 ****
// get NumberedPage from iterator
! NumberedPage lPage= (NumberedPage) lPageIterator.next();
! Integer lPageNumber= new Integer(lPage.getNumber());
! String lUrlString= mUrlFormat.format(new Object[] {
lPageNumber });
// needed for MessageFormat : page number/url
! Object[] lPageObjects= { lPageNumber, lUrlString };
// selected page need a different formatter
--- 194,205 ----
// get NumberedPage from iterator
! NumberedPage lPage = (NumberedPage) lPageIterator.next();
! Integer lPageNumber = new Integer(lPage.getNumber());
! String lUrlString = mUrlFormat.format(new Object[] {
lPageNumber });
// needed for MessageFormat : page number/url
! Object[] lPageObjects = { lPageNumber, lUrlString };
// selected page need a different formatter
***************
*** 220,224 ****
// String for numbered pages
! String lNumberedPageString= lBuffer.toString();
// Object array
--- 221,225 ----
// String for numbered pages
! String lNumberedPageString = lBuffer.toString();
// Object array
***************
*** 228,232 ****
// {3} next page url
// {4} last page url
! Object[] lPageObjects=
{
lNumberedPageString,
--- 229,233 ----
// {3} next page url
// {4} last page url
! Object[] lPageObjects =
{
lNumberedPageString,
Index: SmartListHelper.java
===================================================================
RCS file:
/cvsroot/displaytag/display09/src/org/displaytag/pagination/SmartListHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SmartListHelper.java 15 Jul 2003 21:47:12 -0000 1.2
--- SmartListHelper.java 9 Aug 2003 19:54:07 -0000 1.3
***************
*** 12,19 ****
/**
* <p>
! * Utility class that chops up a List of objects into small bite size pieces
* that are more suitable for display.
* </p>
- *
* <p>
* This class is a stripped down version of the WebListHelper from Tim Dawson
([EMAIL PROTECTED])
--- 12,18 ----
/**
* <p>
! * Utility class that chops up a List of objects into small bite size pieces
* that are more suitable for display.
* </p>
* <p>
* This class is a stripped down version of the WebListHelper from Tim Dawson
([EMAIL PROTECTED])
***************
*** 26,62 ****
/**
! * Field mLog
*/
! private static Log mLog= LogFactory.getLog(SmartListHelper.class);
/**
! * Field mFullList
*/
private List mFullList;
/**
! * Field mFullListSize
*/
private int mFullListSize;
/**
! * Field mPageSize
*/
private int mPageSize;
/**
! * Field mPageCount
*/
private int mPageCount;
/**
! * Field mCurrentPage
*/
private int mCurrentPage;
/**
! * Field mProp
*/
! private TableProperties mProp= null;
/**
--- 25,61 ----
/**
! * logger
*/
! private static Log mLog = LogFactory.getLog(SmartListHelper.class);
/**
! * full list
*/
private List mFullList;
/**
! * sixe of the full list
*/
private int mFullListSize;
/**
! * number of items in a page
*/
private int mPageSize;
/**
! * number of pages
*/
private int mPageCount;
/**
! * index of current page
*/
private int mCurrentPage;
/**
! * TableProperties
*/
! private TableProperties mProp = null;
/**
***************
*** 64,68 ****
* into bite size pieces that are suitable for display.
* @param pList List
! * @param pPageSize int
* @param pProperties TableProperties
*/
--- 63,67 ----
* into bite size pieces that are suitable for display.
* @param pList List
! * @param pPageSize number of items in a page
* @param pProperties TableProperties
*/
***************
*** 85,103 ****
}
! mProp= pProperties;
! mPageSize= pPageSize;
! mFullList= pList;
if (mFullList != null)
{
! mFullListSize= pList.size();
}
else
{
! mFullListSize= 0;
}
! mPageCount= computedPageCount();
! mCurrentPage= 1;
}
--- 84,102 ----
}
! mProp = pProperties;
! mPageSize = pPageSize;
! mFullList = pList;
if (mFullList != null)
{
! mFullListSize = pList.size();
}
else
{
! mFullListSize = 0;
}
! mPageCount = computedPageCount();
! mCurrentPage = 1;
}
***************
*** 105,121 ****
* Returns the computed number of pages it would take to show all the
* elements in the list given the pageSize we are working with.
! * @return int
*/
protected int computedPageCount()
{
! int lResult= 0;
if ((mFullList != null) && (mPageSize > 0))
{
! int lSize= mFullListSize;
! int lDiv= lSize / mPageSize;
! int lMod= lSize % mPageSize;
! lResult= (lMod == 0) ? lDiv : lDiv + 1;
}
--- 104,120 ----
* Returns the computed number of pages it would take to show all the
* elements in the list given the pageSize we are working with.
! * @return int computed number of pages
*/
protected int computedPageCount()
{
! int lResult = 0;
if ((mFullList != null) && (mPageSize > 0))
{
! int lSize = mFullListSize;
! int lDiv = lSize / mPageSize;
! int lMod = lSize % mPageSize;
! lResult = (lMod == 0) ? lDiv : lDiv + 1;
}
***************
*** 127,135 ****
* Returns the index into the master list of the first object that
* should appear on the current page that the user is viewing.
! * @return int
*/
protected int getFirstIndexForCurrentPage()
{
-
return getFirstIndexForPage(mCurrentPage);
}
--- 126,133 ----
* Returns the index into the master list of the first object that
* should appear on the current page that the user is viewing.
! * @return int index of the first object that should appear on the current page
*/
protected int getFirstIndexForCurrentPage()
{
return getFirstIndexForPage(mCurrentPage);
}
***************
*** 149,154 ****
* Returns the index into the master list of the first object that
* should appear on the given page.
! * @param pPage int
! * @return int
*/
protected int getFirstIndexForPage(int pPage)
--- 147,152 ----
* Returns the index into the master list of the first object that
* should appear on the given page.
! * @param pPage page number
! * @return int index of the first object that should appear on the given page
*/
protected int getFirstIndexForPage(int pPage)
***************
*** 161,173 ****
* Returns the index into the master list of the last object that should
* appear on the given page.
! * @param pPage int
! * @return int
*/
protected int getLastIndexForPage(int pPage)
{
! int lFirstIndex= getFirstIndexForPage(pPage);
! int lPageIndex= mPageSize - 1;
! int lLastIndex= mFullListSize - 1;
return Math.min(lFirstIndex + lPageIndex, lLastIndex);
--- 159,171 ----
* Returns the index into the master list of the last object that should
* appear on the given page.
! * @param pPage page number
! * @return int index of the last object that should appear on the given page
*/
protected int getLastIndexForPage(int pPage)
{
! int lFirstIndex = getFirstIndexForPage(pPage);
! int lPageIndex = mPageSize - 1;
! int lLastIndex = mFullListSize - 1;
return Math.min(lFirstIndex + lPageIndex, lLastIndex);
***************
*** 177,181 ****
* Returns a subsection of the list that contains just the elements that
* are supposed to be shown on the current page the user is viewing.
! * @return List
*/
--- 175,179 ----
* Returns a subsection of the list that contains just the elements that
* are supposed to be shown on the current page the user is viewing.
! * @return List subsection of the list that contains the elements that are
supposed to be shown on the current page
*/
***************
*** 189,194 ****
* Returns a subsection of the list that contains just the elements that
* are supposed to be shown on the given page.
! * @param pPage int
! * @return List
*/
protected List getListForPage(int pPage)
--- 187,193 ----
* Returns a subsection of the list that contains just the elements that
* are supposed to be shown on the given page.
! * @param pPage page number
! * @return List subsection of the list that contains just the elements that
! * are supposed to be shown on the given page
*/
protected List getListForPage(int pPage)
***************
*** 197,212 ****
mLog.debug("getListForPage page=" + pPage);
! List lList= new ArrayList(mPageSize + 1);
! int lFirstIndex= getFirstIndexForPage(pPage);
! int lLastIndex= getLastIndexForPage(pPage);
! Iterator lIterator= mFullList.iterator();
! int lCount= 0;
while (lIterator.hasNext())
{
! Object lObject= lIterator.next();
if (lCount > lLastIndex)
--- 196,211 ----
mLog.debug("getListForPage page=" + pPage);
! List lList = new ArrayList(mPageSize + 1);
! int lFirstIndex = getFirstIndexForPage(pPage);
! int lLastIndex = getLastIndexForPage(pPage);
! Iterator lIterator = mFullList.iterator();
! int lCount = 0;
while (lIterator.hasNext())
{
! Object lObject = lIterator.next();
if (lCount > lLastIndex)
***************
*** 227,232 ****
/**
* Set's the page number that the user is viewing.
! *
! * @param pPage int
*/
public void setCurrentPage(int pPage)
--- 226,230 ----
/**
* Set's the page number that the user is viewing.
! * @param pPage page number
*/
public void setCurrentPage(int pPage)
***************
*** 243,247 ****
else
{
! mCurrentPage= pPage;
}
}
--- 241,245 ----
else
{
! mCurrentPage = pPage;
}
}
***************
*** 252,256 ****
* are currently positioned. The message looks like:
*
! * nnn <item(s)> found, displaying nnn to nnn.
*
* <item(s)> is replaced by either itemName or itemNames depending on if
--- 250,254 ----
* are currently positioned. The message looks like:
*
! * nnn <item(s)> found, displaying nnn to nnn.
*
* <item(s)> is replaced by either itemName or itemNames depending on if
***************
*** 264,279 ****
{
mLog.debug("returning paging.banner.no_items_found");
!
! Object[] lObjs= { mProp.getPagingItemsName()};
return MessageFormat.format(mProp.getPagingFoundNoItems(),
lObjs);
!
}
else if (mFullListSize == 1)
{
!
mLog.debug("returning paging.banner.one_item_found");
!
! Object[] lObjs= { mProp.getPagingItemName()};
return MessageFormat.format(mProp.getPagingFoundOneItem(),
lObjs);
--- 262,277 ----
{
mLog.debug("returning paging.banner.no_items_found");
!
! Object[] lObjs = { mProp.getPagingItemsName()};
return MessageFormat.format(mProp.getPagingFoundNoItems(),
lObjs);
!
}
else if (mFullListSize == 1)
{
!
mLog.debug("returning paging.banner.one_item_found");
!
! Object[] lObjs = { mProp.getPagingItemName()};
return MessageFormat.format(mProp.getPagingFoundOneItem(),
lObjs);
***************
*** 281,285 ****
else if (computedPageCount() == 1)
{
! Object[] lObjs= { new Integer(mFullListSize),
mProp.getPagingItemsName(), mProp.getPagingItemsName()};
mLog.debug("returning paging.banner.all_items_found");
--- 279,283 ----
else if (computedPageCount() == 1)
{
! Object[] lObjs = { new Integer(mFullListSize),
mProp.getPagingItemsName(), mProp.getPagingItemsName()};
mLog.debug("returning paging.banner.all_items_found");
***************
*** 289,293 ****
else
{
! Object[] lObjs=
{
new Integer(mFullListSize),
--- 287,291 ----
else
{
! Object[] lObjs =
{
new Integer(mFullListSize),
***************
*** 315,328 ****
mLog.debug("getPageNavigationBar");
! int lMaxPages= 8;
! lMaxPages= mProp.getPagingGroupSize(lMaxPages);
! int lCurrentPage= mCurrentPage;
! int lPageCount= mPageCount;
! int lStartPage= 1;
! int lEndPage= lMaxPages;
! Pagination lPagination= new Pagination(pUrlFormatString);
mLog.debug("mPageCount=" + mPageCount);
--- 313,326 ----
mLog.debug("getPageNavigationBar");
! int lMaxPages = 8;
! lMaxPages = mProp.getPagingGroupSize(lMaxPages);
! int lCurrentPage = mCurrentPage;
! int lPageCount = mPageCount;
! int lStartPage = 1;
! int lEndPage = lMaxPages;
! Pagination lPagination = new Pagination(pUrlFormatString);
mLog.debug("mPageCount=" + mPageCount);
***************
*** 336,349 ****
if (lCurrentPage < lMaxPages)
{
! lStartPage= 1;
! lEndPage= lMaxPages;
if (lPageCount < lEndPage)
{
! lEndPage= lPageCount;
}
}
else
{
! lStartPage= lCurrentPage;
while (lStartPage + lMaxPages > (lPageCount + 1))
{
--- 334,347 ----
if (lCurrentPage < lMaxPages)
{
! lStartPage = 1;
! lEndPage = lMaxPages;
if (lPageCount < lEndPage)
{
! lEndPage = lPageCount;
}
}
else
{
! lStartPage = lCurrentPage;
while (lStartPage + lMaxPages > (lPageCount + 1))
{
***************
*** 351,355 ****
}
! lEndPage= lStartPage + (lMaxPages - 1);
}
--- 349,353 ----
}
! lEndPage = lStartPage + (lMaxPages - 1);
}
***************
*** 360,364 ****
}
! for (int lCounter= lStartPage; lCounter <= lEndPage; lCounter++)
{
mLog.debug("adding page " + lCounter);
--- 358,362 ----
}
! for (int lCounter = lStartPage; lCounter <= lEndPage; lCounter++)
{
mLog.debug("adding page " + lCounter);
***************
*** 379,395 ****
if (lPagination.isOnePage())
{
! lBannerFormat= mProp.getPagingBannerOnePage();
}
else if (lPagination.isFirst())
{
! lBannerFormat= mProp.getPagingBannerFirst();
}
else if (lPagination.isLast())
{
! lBannerFormat= mProp.getPagingBannerLast();
}
else
{
! lBannerFormat= mProp.getPagingBannerFull();
}
--- 377,393 ----
if (lPagination.isOnePage())
{
! lBannerFormat = mProp.getPagingBannerOnePage();
}
else if (lPagination.isFirst())
{
! lBannerFormat = mProp.getPagingBannerFirst();
}
else if (lPagination.isLast())
{
! lBannerFormat = mProp.getPagingBannerLast();
}
else
{
! lBannerFormat = mProp.getPagingBannerFull();
}
Index: NumberedPage.java
===================================================================
RCS file:
/cvsroot/displaytag/display09/src/org/displaytag/pagination/NumberedPage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NumberedPage.java 21 Jun 2003 12:34:50 -0000 1.1
--- NumberedPage.java 9 Aug 2003 19:54:07 -0000 1.2
***************
*** 1,4 ****
--- 1,6 ----
package org.displaytag.pagination;
+ import org.apache.commons.lang.builder.ToStringBuilder;
+
/**
* <p>Object representing a page</p>
***************
*** 20,36 ****
/**
! * Constructor for NumberedPage
! * @param pNumber int
! * @param pSelected boolean
*/
public NumberedPage(int pNumber, boolean pSelected)
{
! mNumber= pNumber;
! mSelected= pSelected;
}
/**
! *
! * @return the int value of mNumber.
*/
public int getNumber()
--- 22,38 ----
/**
! * Creates a new page with the specified number
! * @param pNumber page number
! * @param pSelected is the page selected?
*/
public NumberedPage(int pNumber, boolean pSelected)
{
! mNumber = pNumber;
! mSelected = pSelected;
}
/**
! * return the page number
! * @return the page number
*/
public int getNumber()
***************
*** 40,45 ****
/**
! *
! * @return true if mSelected is set to true.
*/
public boolean getSelected()
--- 42,47 ----
/**
! * is the page selected?
! * @return true if the page is slected
*/
public boolean getSelected()
***************
*** 49,58 ****
/**
! * Method toString
! * @return String
*/
public String toString()
{
! return "[Page number=" + mNumber + ", selected=" + mSelected + "]";
}
--- 51,60 ----
/**
! * return a String representation of the page
! * @return String representation of the page
*/
public String toString()
{
! return new ToStringBuilder(this).append("number",
mNumber).append("selected", mSelected).toString();
}
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel