01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.integration.app1.components;
16:
17: import org.apache.tapestry.annotations.AfterRender;
18: import org.apache.tapestry.annotations.Parameter;
19: import org.apache.tapestry.annotations.SetupRender;
20: import org.apache.tapestry.internal.util.IntegerRange;
21:
22: /**
23: * A component that can count up or count down.
24: * <p>
25: * This is useful as a demonstration; now that the prop binding supports
26: * {@link IntegerRange integer ranges}, it's much less necessary.
27: */
28: public class Count {
29: @Parameter
30: private int _start = 1;
31:
32: @Parameter(required=true)
33: private int _end;
34:
35: @Parameter
36: private int _value;
37:
38: private boolean _increment;
39:
40: @SetupRender
41: void initializeValue() {
42: _value = _start;
43:
44: _increment = _start < _end;
45: }
46:
47: @AfterRender
48: boolean next() {
49: if (_increment) {
50: int newValue = _value + 1;
51:
52: if (newValue <= _end) {
53: _value = newValue;
54: return false; // re-render body
55: }
56: } else {
57: int newValue = _value - 1;
58:
59: if (newValue >= _end) {
60: _value = newValue;
61: return false; // re-render body
62: }
63: }
64:
65: return true;
66: }
67: }
|