001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/utils/mvc/intf/ListScroll.java $
003: * $Id: ListScroll.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.utils.mvc.intf;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: public class ListScroll {
026: protected final transient Log logger = LogFactory
027: .getLog(getClass());
028:
029: public static final String STARTING_INDEX_TAG = "listScroll_startingIndex";
030: public static final String ENSURE_VISIBLE_TAG = "listScroll_ensureVisibleIndex";
031:
032: private int total;
033: private int perPage;
034: private int startingIndex;
035:
036: public ListScroll(int perPage, int total, int startingIndex) {
037: this .perPage = perPage;
038: this .total = total;
039: this .startingIndex = startingIndex;
040: }
041:
042: public int getNextIndex() {
043: int nextIndex = startingIndex + perPage;
044:
045: if (nextIndex >= total) {
046: return -1;
047: }
048:
049: return nextIndex;
050: }
051:
052: public int getPerPage() {
053: return perPage;
054: }
055:
056: public void setPerPage(int perPage) {
057: this .perPage = perPage;
058: }
059:
060: public int getPrevIndex() {
061: int prevIndex = startingIndex - perPage;
062:
063: if (prevIndex < 0) {
064: return -1;
065: }
066:
067: return prevIndex;
068: }
069:
070: public int getStartingIndex() {
071: return startingIndex;
072: }
073:
074: public void setStartingIndex(int startingIndex) {
075: this .startingIndex = startingIndex;
076: }
077:
078: public int getTotal() {
079: return total;
080: }
081:
082: public void setTotal(int total) {
083: this .total = total;
084: }
085:
086: public int getFirstItem() {
087: if (total == 0) {
088: return 0;
089: }
090: return startingIndex + 1;
091: }
092:
093: public int getLastItem() {
094: int lastItem = startingIndex + perPage;
095:
096: if (lastItem > total) {
097: return total;
098: }
099: return lastItem;
100: }
101: }
|