01: /*
02: * $Id: Clock.java 460265 2006-04-16 13:36:52Z jdonnerstag $ $Revision: 460265 $ $Date:
03: * 2006-02-12 03:04:38 +0100 (So, 12 Feb 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.text.DateFormat;
21: import java.util.Date;
22: import java.util.TimeZone;
23:
24: import wicket.Component;
25: import wicket.markup.html.basic.Label;
26: import wicket.model.AbstractReadOnlyModel;
27:
28: /**
29: * A simple component that displays current time
30: *
31: * @author Igor Vaynberg (ivaynberg)
32: */
33: public class Clock extends Label {
34: /**
35: * Constructor
36: *
37: * @param id
38: * Component id
39: * @param tz
40: * Timezone
41: */
42: public Clock(String id, TimeZone tz) {
43: super (id, new ClockModel(tz));
44:
45: }
46:
47: /**
48: * A model that returns current time in the specified timezone via a
49: * formatted string
50: *
51: * @author Igor Vaynberg (ivaynberg)
52: */
53: private static class ClockModel extends AbstractReadOnlyModel {
54: private DateFormat df;
55:
56: /**
57: * @param tz
58: */
59: public ClockModel(TimeZone tz) {
60: df = DateFormat.getDateTimeInstance(DateFormat.FULL,
61: DateFormat.FULL);
62: df.setTimeZone(tz);
63: }
64:
65: /**
66: * @see wicket.model.AbstractReadOnlyModel#getObject(wicket.Component)
67: */
68: public Object getObject(Component component) {
69: return df.format(new Date());
70: }
71: }
72: }
|