KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > openajax > beans > TimeZoneWrapper


1 package com.icesoft.openajax.beans;
2
3 import java.text.DateFormat JavaDoc;
4 import java.util.Calendar JavaDoc;
5 import java.util.TimeZone JavaDoc;
6
7 /**
8  * Bean holding time zone specific information.
9  * Checking a selectBooleanCheckbox in the UI will cause instances of this class to populate the checkedTimeZoneList ArrayList in <code>TimeZoneBean</code>.
10  * That ArrayList is used to create a DataTable of checked time zones in the UI.
11  */

12 public class TimeZoneWrapper
13 {
14     /* Variables */
15     /**
16      * {@link TimeZone} id used to identify the time zone. This id can be passed
17      * to <code>TimeZone.getTimeZone(String)</code>, to get the appropriate
18      * {@link TimeZone} object.
19      */

20     private String JavaDoc id;
21
22     /**
23      * The component id of the commandButton, in the map UI, corresponding to
24      * this time zone.
25      */

26     private String JavaDoc mapCommandButtonId;
27
28     /**
29      * The component id of the selectBooleanCheckbox, under the map UI,
30      * corresponding to this time zone.
31      */

32     private String JavaDoc checkboxId;
33
34
35     /**
36      * A cached {@link DateFormat} used to describe what the time is for this
37      * {@link TimeZone}
38      */

39     private DateFormat JavaDoc dateFormat;
40
41     /* Constructors */
42     /**
43      * @param id id used to identify the time zone.
44      * @param mapId map button component id in web page
45      * @param checkId checkbox component id in web page
46      */

47     public TimeZoneWrapper(String JavaDoc id, String JavaDoc mapId, String JavaDoc checkId) {
48         this.id = id;
49         this.mapCommandButtonId = mapId;
50         this.checkboxId = checkId;
51         this.dateFormat = TimeZoneBean.buildDateFormatForTimeZone(
52                 TimeZone.getTimeZone(id));
53     }
54
55     /* Getters */
56     /**
57      * Gets the name of this time zone to be displayed in the UI.
58      *
59      * @return String
60      */

61     public String JavaDoc getDisplayName() {
62         String JavaDoc displayName = null;
63         TimeZone JavaDoc timeZone = TimeZone.getTimeZone(id);
64         synchronized (TimeZone JavaDoc.class) {
65             displayName = TimeZoneBean.displayNameTokenizer(
66                     timeZone.getDisplayName());
67         }
68         return displayName;
69     }
70
71     /**
72      * Gets the {@link TimeZone} id used to identify this time zone in the Java
73      * code.
74      *
75      * @return String
76      */

77     public String JavaDoc getId() {
78         return id;
79     }
80
81     /**
82      * Gets the dynamic time through the <code>formatCurrentTime</code> method
83      * in the <code>TimeZoneBean</code>.
84      *
85      * @return String
86      */

87     public String JavaDoc getTime() {
88         return TimeZoneBean.formatCurrentTime(dateFormat);
89     }
90
91     /**
92      * Gets whether or not this time zone uses DayLight time.
93      *
94      * @return Returns the useDaylightTime.
95      */

96     public String JavaDoc getUseDaylightTime() {
97         TimeZone JavaDoc timeZone = TimeZone.getTimeZone(id);
98         if (timeZone.useDaylightTime()) {
99             return "Yes";
100         }
101
102         return "No";
103     }
104
105     /**
106      * Gets the state of DayLight Time in this time zone.
107      *
108      * @return Returns the inDaylightTime.
109      */

110     public String JavaDoc getInDaylightTime() {
111         TimeZone JavaDoc timeZone = TimeZone.getTimeZone(id);
112         Calendar JavaDoc cal = Calendar.getInstance(timeZone);
113         if (timeZone.inDaylightTime(cal.getTime())) {
114             return "Yes";
115         }
116
117         return "No";
118     }
119
120     /**
121      * Gets the {@link TimeZone} location used to identify this time zone.
122      *
123      * @return String
124      */

125     public String JavaDoc getLocation() {
126         return id;
127     }
128
129
130     /**
131      * Ascertains whether mapCommandButtonId or checkboxId are a part of
132      * componentId. componentId might be a fully qualified id, with a prefix
133      * corresponding to container component(s).
134      *
135      * @param componentId Id of some component that may be related to this time
136      * zone
137      */

138     public boolean isRelevantComponentId(String JavaDoc componentId) {
139         boolean relevant = (componentId.endsWith(mapCommandButtonId) ||
140                             componentId.endsWith(checkboxId));
141         return relevant;
142     }
143
144     /**
145      * Gets the component id of the commandButton, in the map UI, corresponding
146      * to this time zone.
147      */

148     public String JavaDoc getMapCommandButtonId() {
149         return mapCommandButtonId;
150     }
151
152     /**
153      * Gets the component id of the selectBooleanCheckbox, under the map UI,
154      * corresponding to this time zone.
155      */

156     public String JavaDoc getCheckboxId() {
157         return checkboxId;
158     }
159 }
160
Popular Tags