001: package com.icesoft.openajax.beans;
002:
003: import java.text.DateFormat;
004: import java.util.Calendar;
005: import java.util.TimeZone;
006:
007: /**
008: * Bean holding time zone specific information.
009: * Checking a selectBooleanCheckbox in the UI will cause instances of this class to populate the checkedTimeZoneList ArrayList in <code>TimeZoneBean</code>.
010: * That ArrayList is used to create a DataTable of checked time zones in the UI.
011: */
012: public class TimeZoneWrapper {
013: /* Variables */
014: /**
015: * {@link TimeZone} id used to identify the time zone. This id can be passed
016: * to <code>TimeZone.getTimeZone(String)</code>, to get the appropriate
017: * {@link TimeZone} object.
018: */
019: private String id;
020:
021: /**
022: * The component id of the commandButton, in the map UI, corresponding to
023: * this time zone.
024: */
025: private String mapCommandButtonId;
026:
027: /**
028: * The component id of the selectBooleanCheckbox, under the map UI,
029: * corresponding to this time zone.
030: */
031: private String checkboxId;
032:
033: /**
034: * A cached {@link DateFormat} used to describe what the time is for this
035: * {@link TimeZone}
036: */
037: private DateFormat dateFormat;
038:
039: /* Constructors */
040: /**
041: * @param id id used to identify the time zone.
042: * @param mapId map button component id in web page
043: * @param checkId checkbox component id in web page
044: */
045: public TimeZoneWrapper(String id, String mapId, String checkId) {
046: this .id = id;
047: this .mapCommandButtonId = mapId;
048: this .checkboxId = checkId;
049: this .dateFormat = TimeZoneBean
050: .buildDateFormatForTimeZone(TimeZone.getTimeZone(id));
051: }
052:
053: /* Getters */
054: /**
055: * Gets the name of this time zone to be displayed in the UI.
056: *
057: * @return String
058: */
059: public String getDisplayName() {
060: String displayName = null;
061: TimeZone timeZone = TimeZone.getTimeZone(id);
062: synchronized (TimeZone.class) {
063: displayName = TimeZoneBean.displayNameTokenizer(timeZone
064: .getDisplayName());
065: }
066: return displayName;
067: }
068:
069: /**
070: * Gets the {@link TimeZone} id used to identify this time zone in the Java
071: * code.
072: *
073: * @return String
074: */
075: public String getId() {
076: return id;
077: }
078:
079: /**
080: * Gets the dynamic time through the <code>formatCurrentTime</code> method
081: * in the <code>TimeZoneBean</code>.
082: *
083: * @return String
084: */
085: public String getTime() {
086: return TimeZoneBean.formatCurrentTime(dateFormat);
087: }
088:
089: /**
090: * Gets whether or not this time zone uses DayLight time.
091: *
092: * @return Returns the useDaylightTime.
093: */
094: public String getUseDaylightTime() {
095: TimeZone timeZone = TimeZone.getTimeZone(id);
096: if (timeZone.useDaylightTime()) {
097: return "Yes";
098: }
099:
100: return "No";
101: }
102:
103: /**
104: * Gets the state of DayLight Time in this time zone.
105: *
106: * @return Returns the inDaylightTime.
107: */
108: public String getInDaylightTime() {
109: TimeZone timeZone = TimeZone.getTimeZone(id);
110: Calendar cal = Calendar.getInstance(timeZone);
111: if (timeZone.inDaylightTime(cal.getTime())) {
112: return "Yes";
113: }
114:
115: return "No";
116: }
117:
118: /**
119: * Gets the {@link TimeZone} location used to identify this time zone.
120: *
121: * @return String
122: */
123: public String getLocation() {
124: return id;
125: }
126:
127: /**
128: * Ascertains whether mapCommandButtonId or checkboxId are a part of
129: * componentId. componentId might be a fully qualified id, with a prefix
130: * corresponding to container component(s).
131: *
132: * @param componentId Id of some component that may be related to this time
133: * zone
134: */
135: public boolean isRelevantComponentId(String componentId) {
136: boolean relevant = (componentId.endsWith(mapCommandButtonId) || componentId
137: .endsWith(checkboxId));
138: return relevant;
139: }
140:
141: /**
142: * Gets the component id of the commandButton, in the map UI, corresponding
143: * to this time zone.
144: */
145: public String getMapCommandButtonId() {
146: return mapCommandButtonId;
147: }
148:
149: /**
150: * Gets the component id of the selectBooleanCheckbox, under the map UI,
151: * corresponding to this time zone.
152: */
153: public String getCheckboxId() {
154: return checkboxId;
155: }
156: }
|