TOC PREV NEXT INDEX

Modifying TimeZoneWrapper.java


Each row in the dataTable is populated by a TimeZoneWrapper bean. Each cell in the dataTable is then populated by properties of the TimeZoneWrapper beans. So, we have to modify TimeZoneWrapper to add the requisite properties and accessor methods.

1. Add imports for the utility classes we use for calculating times with.
import java.util.TimeZone;
 
import java.util.Calendar;
 
import java.text.DateFormat;
 

 
2. Declare a helper DateFormat instance for the time bean property.
private DateFormat dateFormat;
 
3. Alter the constructor to initialize the new fields; checkboxId and dateFormat.
/**
 
 * @param id      id used to identify the time zone.
 
 * @param mapId   map button component id in web page
 
 * @param xCoords array of X-coordinates for the image map object.
 
 * @param yCoords array of Y-coordinates for the image map object.
 
 * @param coords  number of coordinates in the image map object.
 
 */
 
public TimeZoneWrapper(String id, String mapId, int[] xCoords,
 
                       int[] yCoords, int coords) {
 
    this.id = id;
 
    this.mapCommandButtonId = mapId;
 
    this.dateFormat =
 
            TimeZoneBean.buildDateFormatForTimeZone(
 
                    TimeZone.getTimeZone(id));
 
    mapPolygon = new Polygon(xCoords, yCoords, coords);
 
}
 

 
4. Add getter accessor methods for the displayName, time, useDaylightTime, inDaylightTime, location properties.
public String getDisplayName() {
 
		TimeZone timeZone = TimeZone.getTimeZone(id); 
 
		return TimeZoneBean.displayNameTokenizer( timeZone.getDisplayName() );
 
}
 
...
 
public String getTime() {
 
		return TimeZoneBean.formatCurrentTime( dateFormat );
 
}
 
...
 
public String getUseDaylightTime() {
 
		TimeZone timeZone = TimeZone.getTimeZone(id); 
 
		if( timeZone.useDaylightTime() )
 
				return "Yes"; 
 
		return "No";
 
}
 
...
 
public String getInDaylightTime() {
 
		TimeZone timeZone = TimeZone.getTimeZone(id);
 
		Calendar cal = Calendar.getInstance(timeZone); 
 
		if( timeZone.inDaylightTime(cal.getTime()) )
 
				return "Yes"; 
 
		return "No";
 
}
 
...
 
public String getLocation() {
 
		return id;
 
}
 

 


Copyright 2005-2009. ICEsoft Technologies, Inc.
TOC PREV NEXT INDEX