01: /*
02: * $Id: WorldClockPage.java 460265 2006-04-16 13:36:52Z jdonnerstag $ $Revision: 460265 $
03: * $Date: 2006-04-16 15:36:52 +0200 (Sun, 16 Apr 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples.ajax.builtin;
19:
20: import java.util.TimeZone;
21:
22: import wicket.ajax.AbstractAjaxTimerBehavior;
23: import wicket.ajax.AjaxRequestTarget;
24: import wicket.util.time.Duration;
25:
26: /**
27: * A world clock example page. Demonstrates timer behavior as well as multiple
28: * component update.
29: *
30: * @author Igor Vaynberg (ivaynberg)
31: */
32: public class WorldClockPage extends BasePage {
33: /**
34: * Constructor
35: */
36: public WorldClockPage() {
37: // create clock components for different timezones
38: final Clock la = new Clock("la", TimeZone
39: .getTimeZone("America/Los_Angeles"));
40: final Clock ny = new Clock("ny", TimeZone
41: .getTimeZone("America/New_York"));
42: final Clock moscow = new Clock("moscow", TimeZone
43: .getTimeZone("Europe/Moscow"));
44: final Clock prague = new Clock("prague", TimeZone
45: .getTimeZone("Europe/Prague"));
46: final Clock london = new Clock("london", TimeZone
47: .getTimeZone("Europe/London"));
48:
49: // make components print out id attrs so they can be updated via ajax
50: la.setOutputMarkupId(true);
51: ny.setOutputMarkupId(true);
52: moscow.setOutputMarkupId(true);
53: prague.setOutputMarkupId(true);
54: london.setOutputMarkupId(true);
55:
56: // add the components to the container and add a markup id setter to
57: // each component.
58: add(la);
59: add(ny);
60: add(moscow);
61: add(prague);
62: add(london);
63:
64: // add the timer behavior to the la component and make it update all
65: // other components as well
66: la.add(new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
67: /**
68: * @see wicket.ajax.AbstractAjaxTimerBehavior#onTimer(wicket.ajax.AjaxRequestTarget)
69: */
70: protected void onTimer(AjaxRequestTarget target) {
71: target.addComponent(la);
72: target.addComponent(ny);
73: target.addComponent(moscow);
74: target.addComponent(prague);
75: target.addComponent(london);
76: }
77: });
78: }
79: }
|