From: Julien V. <vi...@us...> - 2004-05-15 23:21:48
|
User: vietj Date: 04/05/15 16:21:41 Added: common/src/main/org/jboss/nukes/common/format/range GotoWithOffset.java Log: moved out of the bb module Revision Changes Path 1.1 nukes/common/src/main/org/jboss/nukes/common/format/range/GotoWithOffset.java Index: GotoWithOffset.java =================================================================== /*************************************** * * * Nukes: The OpenSource CMS * * * * Distributable under GPL license. * * See terms of license at gnu.org. * * * ***************************************/ package org.jboss.nukes.common.format.range; /** * @author <a href="mailto:ju...@jb...">Julien Viet</a> * @version $Revision: 1.1 $ */ public class GotoWithOffset extends Range { private int perPage; private String URL; private int offset; private int size; private String gotoPageLabel; private String previousLabel; private String nextLabel; public GotoWithOffset(int size, int offset, int perPage, String URL, String gotoPageLabel, String previousLabel, String nextLabel) { super(3, 3, 3); this.size = size; this.offset = offset; this.perPage = perPage; this.URL = URL; this.gotoPageLabel = gotoPageLabel; this.previousLabel = previousLabel; this.nextLabel = nextLabel; } public void setOffset(int offset) { this.offset = offset; } protected final void start(StringBuffer buffer) { buffer.append(gotoPageLabel); int offset = (int)Math.floor((double)this.offset / (double)perPage); if (offset > 0) { offset = (offset - 1) * perPage; buffer.append(" <a href=\"").append(URL).append(offset).append("\">").append(previousLabel).append("</a> "); } } protected final void end(StringBuffer buffer) { int nextOffset = (int)(Math.floor((double)this.offset / (double)perPage) + 1) * perPage; if (nextOffset < size) { buffer.append(" <a href=\"").append(URL).append(nextOffset).append("\">").append(nextLabel).append("</a> "); } } protected final void normal(StringBuffer buffer, int index) { lastNormal(buffer, index); buffer.append(", "); } protected final void enhanced(StringBuffer buffer, int index) { lastEnhanced(buffer, index); buffer.append(", "); } protected final void lastNormal(StringBuffer buffer, int index) { buffer.append("<a href=\"").append(URL).append(index * perPage). append("\">").append(index + 1).append("</a>"); } protected final void lastEnhanced(StringBuffer buffer, int index) { buffer.append("<b>").append(index + 1).append("</b>"); } public String generate() { if (size >= perPage) { return build((int)Math.ceil(size / (double)perPage), (int)Math.floor(offset / (double)perPage)); } else { return ""; } } } |