KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > databinding > repeater > pad > PadContext


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.databinding.repeater.pad;
19
20 import org.apache.beehive.netui.util.internal.InternalStringBuilder;
21
22 /**
23  * A JavaBean that encapsulates the data needed to pad a Repeater with
24  * text. The PadContext is needed if the given consttraints, the
25  * minRepeat and maxRepeat attributes, require that the data rendered
26  * in the repeater be padded.
27  */

28 public class PadContext {
29
30     private static final String JavaDoc EMPTY_STRING = "";
31
32     /**
33      * @exclude
34      */

35     static final int DEFAULT_VALUE = -1;
36
37     private int _maxRepeat = DEFAULT_VALUE;
38     private int _minRepeat = DEFAULT_VALUE;
39     private String JavaDoc _padText = EMPTY_STRING;
40
41     /**
42      * @param padText the text that will be used to pad the Repeater content, if necessary
43      * @param minRepeat the minimum number of items that must be rendered in the repeater's body
44      * @param maxRepeat the maximum number of items to render in the repeater's body
45      */

46     public PadContext(String JavaDoc padText, int minRepeat, int maxRepeat) {
47         _padText = (padText != null ? padText : EMPTY_STRING);
48         _minRepeat = minRepeat;
49         _maxRepeat = maxRepeat;
50     }
51
52     /**
53      * Get the text to use when padding the {@link org.apache.beehive.netui.tags.databinding.repeater.Repeater}
54      *
55      * @return the pad text
56      */

57     public String JavaDoc getPadText() {
58         return _padText;
59     }
60
61     /**
62      * Get the minimum number of times to render an item in the repeater's body.
63      *
64      * @return the minimum number of items that must be rendered in the repeater's body
65      */

66     public int getMinRepeat() {
67         return _minRepeat;
68     }
69
70     /**
71      * Get the maximum number of times to render items in the repeater's body.
72      *
73      * @return the maximum number of items to render items in the repeater's body
74      */

75     public int getMaxRepeat() {
76         return _maxRepeat;
77     }
78
79     /**
80      * @param currCount the count of the number of items rendered.
81      * @return <code>true</code> if the minimum number of items have been rendered; <code>false</code> otherwise
82      */

83     public boolean checkMinRepeat(int currCount) {
84         if(_minRepeat == DEFAULT_VALUE)
85             return true;
86         else if(currCount >= _minRepeat)
87             return true;
88         else return false;
89     }
90
91     /**
92      * @param currCount the count of the number of items rendered so far
93      * @return <code>true</code> if the maximum number of items have been rendered; <code>false</code> otherwise
94      */

95     public boolean checkMaxRepeat(int currCount) {
96         if(_maxRepeat == DEFAULT_VALUE)
97             return false;
98         else if(currCount < _maxRepeat)
99             return false;
100         else return true;
101     }
102
103     /**
104      * Get a debugging String that represents a PadContext.
105      *
106      * @return a String representation of the PadContext
107      */

108     public String JavaDoc toString() {
109         InternalStringBuilder buf = new InternalStringBuilder(32);
110         buf.append("\nPadContext: ");
111         buf.append("padText: " + _padText + "\n");
112         buf.append("minRepeat: " + _minRepeat + "\n");
113         buf.append("maxRepeat: " + _maxRepeat + "\n");
114         return buf.toString();
115     }
116 }
117
Popular Tags