KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > helper > Goto


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under GPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portlet.forums.helper;
12
13
14 /**
15  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
16  * @version $Revision: 1.1.1.1 $
17  */

18 public class Goto
19    extends Range
20 {
21    private int postSize;
22    private int postsPerPage;
23    private int topicId;
24    private String JavaDoc imgUrl;
25    private String JavaDoc gotoText;
26
27    /**
28     * Creates a new {@link Goto} object.
29     *
30     * @param postsPerPage DOCUMENT_ME
31     * @param gotoText DOCUMENT_ME
32     */

33    public Goto(int postsPerPage,
34                String JavaDoc gotoText)
35    {
36       super(3, 0, 3);
37       this.postsPerPage = postsPerPage;
38       this.gotoText = gotoText;
39    }
40
41    /**
42     * DOCUMENT_ME
43     *
44     * @return DOCUMENT_ME
45     */

46    public int getPostSize()
47    {
48       return postSize;
49    }
50
51    /**
52     * DOCUMENT_ME
53     *
54     * @param postSize DOCUMENT_ME
55     */

56    public void setPostSize(int postSize)
57    {
58       this.postSize = postSize;
59    }
60
61    /**
62     * DOCUMENT_ME
63     *
64     * @return DOCUMENT_ME
65     */

66    public int getTopicId()
67    {
68       return topicId;
69    }
70
71    /**
72     * DOCUMENT_ME
73     *
74     * @param topicId DOCUMENT_ME
75     */

76    public void setTopicId(int topicId)
77    {
78       this.topicId = topicId;
79    }
80
81    /**
82     * DOCUMENT_ME
83     *
84     * @return DOCUMENT_ME
85     */

86    public String JavaDoc getImgUrl()
87    {
88       return imgUrl;
89    }
90
91    /**
92     * DOCUMENT_ME
93     *
94     * @param imgUrl DOCUMENT_ME
95     */

96    public void setImgUrl(String JavaDoc imgUrl)
97    {
98       this.imgUrl = imgUrl;
99    }
100
101    /**
102     * DOCUMENT_ME
103     *
104     * @return DOCUMENT_ME
105     */

106    public String JavaDoc generate()
107    {
108       if (postSize >= postsPerPage)
109       {
110          return build((int) Math.ceil((double) (postSize + 1) / (double) postsPerPage), -1);
111       }
112       else
113       {
114          return "";
115       }
116    }
117
118    /**
119     * DOCUMENT_ME
120     *
121     * @param buffer DOCUMENT_ME
122     */

123    protected void start(StringBuffer JavaDoc buffer)
124    {
125       buffer.append("[ <img SRC=\"").append(imgUrl).append("\" alt=\"" + gotoText + "\" title=\"" + gotoText
126                                                            + "\"/>" + gotoText + ": ");
127    }
128
129    /**
130     * DOCUMENT_ME
131     *
132     * @param buffer DOCUMENT_ME
133     */

134    protected final void end(StringBuffer JavaDoc buffer)
135    {
136       buffer.append(" ] ");
137    }
138
139    /**
140     * DOCUMENT_ME
141     *
142     * @param buffer DOCUMENT_ME
143     * @param index DOCUMENT_ME
144     */

145    protected final void normal(StringBuffer JavaDoc buffer,
146                                int index)
147    {
148       lastNormal(buffer, index);
149       buffer.append(", ");
150    }
151
152    /**
153     * DOCUMENT_ME
154     *
155     * @param buffer DOCUMENT_ME
156     * @param index DOCUMENT_ME
157     */

158    protected final void enhanced(StringBuffer JavaDoc buffer,
159                                  int index)
160    {
161       lastNormal(buffer, index);
162       buffer.append(", ");
163    }
164
165    /**
166     * DOCUMENT_ME
167     *
168     * @param buffer DOCUMENT_ME
169     * @param index DOCUMENT_ME
170     */

171    protected final void lastNormal(StringBuffer JavaDoc buffer,
172                                    int index)
173    {
174       buffer.append("<a HREF=\"index.html?module=bb&op=viewtopic&t=").append(topicId).append("&start=")
175             .append(index * postsPerPage).append("\">").append(index + 1).append("</a>");
176    }
177
178    /**
179     * DOCUMENT_ME
180     *
181     * @param buffer DOCUMENT_ME
182     * @param index DOCUMENT_ME
183     */

184    protected final void lastEnhanced(StringBuffer JavaDoc buffer,
185                                      int index)
186    {
187       lastNormal(buffer, index);
188    }
189 }
Popular Tags