01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.examples.ajax.builtin;
18:
19: import java.text.DateFormat;
20: import java.util.Date;
21: import java.util.TimeZone;
22:
23: import org.apache.wicket.markup.html.basic.Label;
24: import org.apache.wicket.model.AbstractReadOnlyModel;
25:
26: /**
27: * A simple component that displays current time
28: *
29: * @author Igor Vaynberg (ivaynberg)
30: */
31: public class Clock extends Label {
32: /**
33: * Constructor
34: *
35: * @param id
36: * Component id
37: * @param tz
38: * Timezone
39: */
40: public Clock(String id, TimeZone tz) {
41: super (id, new ClockModel(tz));
42:
43: }
44:
45: /**
46: * A model that returns current time in the specified timezone via a
47: * formatted string
48: *
49: * @author Igor Vaynberg (ivaynberg)
50: */
51: private static class ClockModel extends AbstractReadOnlyModel {
52: private DateFormat df;
53:
54: /**
55: * @param tz
56: */
57: public ClockModel(TimeZone tz) {
58: df = DateFormat.getDateTimeInstance(DateFormat.FULL,
59: DateFormat.LONG);
60: df.setTimeZone(tz);
61: }
62:
63: /**
64: * @see org.apache.wicket.model.AbstractReadOnlyModel#getObject()
65: */
66: public Object getObject() {
67: return df.format(new Date());
68: }
69: }
70: }
|