KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > ScarabPaginatedList


1 package org.tigris.scarab.util;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.List JavaDoc;
50
51 /*
52  *
53  * @author <a HREF="mailto:tenersen@collab.net">Todd Enersen</a>
54  * @version $Id: ScarabPaginatedList.java 8532 2003-08-26 17:54:35Z elicia $
55  */

56 public class ScarabPaginatedList
57 {
58     /**
59      * The total size of the list, not just the window which is
60      * the displayable region.
61      */

62     private int totalListSize;
63     
64     /**
65      * The number of items per page, including the current
66      * displayable region.
67      */

68     private int resultsPerPage;
69
70     /**
71      * The current page number that is being displayed.
72      */

73     private int currentPageNumber;
74
75     /**
76      * The current viewable list window, as a List
77      */

78     private List JavaDoc window;
79
80
81     /**
82      * Constructor
83      */

84     public ScarabPaginatedList()
85     {
86         window = null;
87         currentPageNumber = 0;
88         resultsPerPage = 0;
89         totalListSize = 0;
90     }
91
92     /**
93      * Constructor which sets things up for a 'ready' list.
94      */

95     public ScarabPaginatedList(List JavaDoc l, int size, int pageNum, int perPage)
96     {
97         window = l;
98         totalListSize = size;
99         currentPageNumber = pageNum;
100         resultsPerPage = perPage;
101     }
102
103     /**
104      * Method to return the size of the entire list, not
105      * just the part that is currently 'to be' displayed.
106      */

107     public int getTotalListSize()
108     {
109         return totalListSize;
110     }
111
112     /**
113      * Method to return the total number of pages in this list.
114      */

115     public int getNumberOfPages()
116     {
117         int r = 0;
118
119         if (resultsPerPage != 0)
120         {
121             r = (int)Math.ceil((float)totalListSize / resultsPerPage);
122         }
123
124         return r;
125     }
126
127     /**
128      * Method to get the current page number.
129      */

130     public int getPageNumber()
131     {
132         return currentPageNumber;
133     }
134
135     /**
136      * Method to return the previous page number.
137      */

138     public int getPrevPageNumber()
139     {
140         int r = getPageNumber() - 1;
141         if (r < 0)
142         {
143             r = 0;
144         }
145         return r;
146     }
147
148     /**
149      * Method to return the next page number
150      */

151     public int getNextPageNumber()
152     {
153         int r = getPageNumber() + 1;
154         if (r > getNumberOfPages())
155         {
156             r = 0;
157         }
158         return r;
159     }
160     
161     /**
162      * Method to get the number of results per page.
163      */

164     public int getResultsPerPage()
165     {
166         return resultsPerPage;
167     }
168
169     /**
170      * Method to get the portion of the list that is currently
171      * viewable (inside the window)
172      */

173     public List JavaDoc getList()
174     {
175         return window;
176     }
177
178
179     /**
180      * Method to set the TotalListSize.
181      */

182     public void setTotalListSize(int size)
183     {
184         totalListSize = size;
185     }
186
187     /**
188      * Method to set the current page number.
189      */

190     public void setCurrentPageNumber(int pageNum)
191     {
192         currentPageNumber = pageNum;
193     }
194
195     /**
196      * Method to set the current list window.
197      */

198     public void setList(List JavaDoc list)
199     {
200         window = list;
201     }
202
203
204 }
205
Popular Tags