final int days = self.getDays();
final Locale locale = Locales.getCurrent();
final TimeZone timezone = self.getDefaultTimeZone();
final Date begin = self.getBeginDate();
final EventRender render = self.getEventRender();
wh.write("<div id=\"").write(uuid).write("!inner\" class=\"")
.write(week).write("\">");
// week header
wh.write("<div class=\"").write(week_header).write("\"><table class=\"").write(week_header_cnt)
.write("\" cellpadding=\"0\" cellspacing=\"0\"><tbody>");
// day's header
wh.write("<tr id=\"").write(uuid).write("!header\" class=\"").write(day_header).write("\">");
Map<TimeZone, String> zones = self.getTimeZones();
for (Iterator it = zones.entrySet().iterator(); it.hasNext();) {
Map.Entry me = (Map.Entry)it.next();
wh.write("<th rowspan=\"3\" class=\"").write(tzone);
if (!it.hasNext())
wh.write(" ").write(tzone_end);
wh.write("\">");
new Out((String)me.getValue()).render(out);
if (!it.hasNext())
wh.write("<div id=\"").write(uuid).write("!hdarrow\" class=\"")
.write(week_header_arrow).write("\"></div>");
wh.write("</th>");
}
Calendar cal = Calendar.getInstance(timezone);
Calendar current = Calendar.getInstance(timezone);
Calendar btmp = Calendar.getInstance(timezone);
Calendar etmp = Calendar.getInstance(timezone);
int today_year = current.get(Calendar.YEAR);
int today_day = current.get(Calendar.DAY_OF_YEAR);
cal.setTime(begin);
final DateFormatter dfhandler = self.getDateFormatter();
int[] weekend = new int[]{-1, -1, -1};
// day-of-week
for (int index = 0, j = 0; j < days; ++j) {
String content = dfhandler.getCaptionByDate(cal.getTime(), locale, timezone);
wh.write("<th z.time=\"").write(String.valueOf(cal.getTimeInMillis()))
.write("\" title=\"").write(content).write("\" class=\"").write(day_of_week).write("\"><div class=\"")
.write(day_of_week_inner);
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
weekend[index++] = j;
wh.write(" ").write(week_weekend);
}
if (weekend[2] == -1 && today_year == cal.get(Calendar.YEAR) &&
today_day == cal.get(Calendar.DAY_OF_YEAR)) {
weekend[2] = j;
wh.write(" ").write(week_today);
}
wh.write("\"><span class=\"").write(day_of_week_cnt).write("\">")
.write(content)
.write("</span></div></th>");
cal.add(Calendar.DAY_OF_WEEK, 1);
}
wh.write("<th class=\"").write(day_of_week_end).write("\"> </th>");
wh.write("</tr>");
// daylong
wh.write("<tr class=\"").write(daylong).write("\">")
.write("<td class=\"").write(daylong_body).write("\" colspan=\"")
.write(days).write("\"><div id=\"").write(uuid).write("!daylong\" class=\"")
.write(daylong_inner).write("\"><table class=\"").write(daylong_cnt)
.write("\" cellpadding=\"0\" cellspacing=\"0\"><tbody>");
// separator date
cal.setTime(begin);
SimpleDateFormat sdfKey = new SimpleDateFormat("yyyy/MM/dd");
sdfKey.setTimeZone(timezone);
List<List<CalendarEvent>> daylongList = new LinkedList<List<CalendarEvent>>();
Map<String, List<CalendarEvent>> dayMap = new HashMap<String, List<CalendarEvent>>();
int[] daylongCnt = new int[days];
for (int day = 0; day < days; ++day) {
cal.set(Calendar.MILLISECOND, 0);
Date curDate = cal.getTime();
List<CalendarEvent> evts = self.getEvent(curDate);
List<CalendarEvent> list = new LinkedList<CalendarEvent>();
for (CalendarEvent ce : evts) {
Date bd = ce.getBeginDate();
Date ed = ce.getEndDate();
double rests = (ed.getTime() - curDate.getTime())/ 1000;
btmp.setTime(bd);
etmp.setTime(ed);
if ((bd.before(curDate)) || btmp.get(Calendar.YEAR) != etmp.get(Calendar.YEAR)
|| (btmp.get(Calendar.DAY_OF_YEAR) != etmp.get(Calendar.DAY_OF_YEAR)
&& (etmp.get(Calendar.HOUR_OF_DAY) != 0 || etmp.get(Calendar.MINUTE) != 0))
|| (ed.getTime() - bd.getTime() >= ONE_DAY*1000 &&
rests >= ONE_DAY)) {
daylongCnt[day]++;
for (double y = 1, x = rests/ONE_DAY; y < x && y + day < days; y++) {
int size = day+(int)y;
daylongCnt[size]++;
}
list.add(ce);
} else {
String key = sdfKey.format(curDate);
List<CalendarEvent> dayList = dayMap.get(key);
if (dayList == null) {
dayList = new LinkedList<CalendarEvent>();
dayMap.put(key, dayList);
}
dayList.add(ce);
}
}
daylongList.add(list);
cal.add(Calendar.DAY_OF_WEEK, 1);
}
int maxSize = 0;
for (int i = 0; i < daylongCnt.length; i++)
if (maxSize < daylongCnt[i]) maxSize = daylongCnt[i];
// fill the event of the daylong
for (int r = 0; r < maxSize; r++) {
// reset date
cal.setTime(begin);
wh.write("<tr>");
int c = 0, total = days;
for (Iterator it = daylongList.iterator(); it.hasNext();c++) {
List<CalendarEvent> list = (List<CalendarEvent>)it.next();
cal.set(Calendar.MILLISECOND, 0);
Date curDate = cal.getTime();
wh.write("<td class=\"").write(daylong_evt).write("\"");
if (list.size() > 0) {
CalendarEvent ce = list.remove(0);
double rests = (ce.getEndDate().getTime() - curDate.getTime())/ 1000;
int colspan = 1;
for (double y = 1, x = rests/ONE_DAY; y < x && y + c < days; y++)
colspan++;
total -= colspan;
if (total < 0) colspan += total;
wh.write(" colspan=\"").write(colspan).write("\"").write(">");
wh.write(render.drawAllDay(self, ce, self.getCalendarEventId(ce)));
while(--colspan > 0 && it.hasNext()) {
it.next();
cal.add(Calendar.DAY_OF_WEEK, 1);
}
} else {
total--;
wh.write("> ");
}
cal.add(Calendar.DAY_OF_WEEK, 1);
wh.write("</td>");
}
wh.write("</tr>");
}
// the end of daylong
wh.write("<tr>");
for (int j = 0; j < days; ++j)
wh.write("<td class=\"").write(daylong_evt).write(' ').write(daylong_more).write("\"> </td>");
wh.write("</tr>");
wh.write("</tbody></table></div>")
.write("</td></tr>");
// the end of daylong
wh.write("<tr><td colspan=\"").write(days).write("\" class=\"").write(daylong_end).write("\"> </td></tr>");
// the end of week header
wh.write("</tbody></table></div>");
// week content
wh.write("<div id=\"").write(uuid).write("!cnt\" class=\"").write(week_body)
.write("\">");
boolean isIE = Executions.getCurrent().isBrowser("ie");
if (isIE)
wh.write("<table cellpadding=\"0\" cellspacing=\"0\" style=\"table-layout:fixed;\"><tbody><tr><td>");
wh.write("<table class=\"").write(week_cnt)
.write("\" cellpadding=\"0\" cellspacing=\"0\"><tbody>");
// hours separator
wh.write("<tr>");
for (int i = 0; i < zones.size(); i++) {
wh.write("<td class=\"").write(tzone);
if (i + 1 == zones.size())
wh.write(" ").write(tzone_end);
wh.write("\"></td>");
}
wh.write("<td colspan=\"").write(days).write("\"><div class=\"")
.write(hour).write("\"><div class=\"").write(hour_inner).write("\">");
for (int k = 0; k < 24; k++)
wh.write("<div class=\"").write(hour_sep).write("\"></div>");
// the end of hours separator
wh.write("</div></div></td></tr>");
// the content of day
wh.write("<tr>");
current.set(Calendar.MINUTE, 0);
for (Iterator it = zones.entrySet().iterator(); it.hasNext();) {
Map.Entry me = (Map.Entry)it.next();
wh.write("<td class=\"").write(tzone);
if (!it.hasNext())
wh.write(" ").write(tzone_end);
wh.write("\">");
for(int k = 0; k < 24; k++) {
current.set(Calendar.HOUR_OF_DAY, k);
wh.write("<div class=\"").write(hour_of_day).write("\">");
wh.write(dfhandler.getCaptionByTimeOfDay(current.getTime(), locale, (TimeZone)me.getKey()));
wh.write("</div>");
}
wh.write("</td>");
}
// reset date
cal.setTime(begin);
for (int j = 0; j < days; ++j) {
wh.write("<td class=\"").write(week_day);
if (weekend[0] == j || weekend[1] == j)
wh.write(" ").write(week_weekend);
if (weekend[2] == j)
wh.write(" ").write(week_today);
wh.write("\"><div class=\"").write(week_day_cnt).write("\">");
// TODO fill the content of day
cal.set(Calendar.MILLISECOND, 0);
Date curDate = cal.getTime();
List<CalendarEvent> evts = (List<CalendarEvent>) dayMap.get(sdfKey.format(curDate));
if (evts != null && !evts.isEmpty()) {
Collections.sort(evts, getDefaultEndDateComparator());
for (CalendarEvent ce : evts)
wh.write(render.drawDay(self, ce, self.getCalendarEventId(ce)));
}
wh.write("</div></td>");
cal.add(Calendar.DAY_OF_WEEK, 1);
}