.write("-fl\"><div class=\"").write(zcls).write("-fr\"><div class=\"")
.write(zcls).write("-fm\"></div></div></div></div>");
}
private void getMonthView(Calendars self, Writer out) throws IOException{
final SmartWriter wh = new SmartWriter(out);
final Locale locale = Locales.getCurrent();
final TimeZone timezone = self.getDefaultTimeZone();
final Date begin = self.getBeginDate();
final Date end = self.getEndDate();
// day view
final String uuid = self.getUuid();
// CSS ClassNamefinal
String zcls = self.getZclass();
final String month = zcls + "-month-cnt";
final String inner = month + "-inner";
final String month_header = zcls + "-month-header";
final String month_body = zcls + "-month-body";
final String month_week = zcls + "-month-week";
final String month_date = zcls + "-month-date";
final String month_date_off = zcls + "-month-date-off";
final String month_date_cnt = month_date + "-cnt";
final String month_date_evt = month_date + "-evt";
final String week_weekend = zcls + "-week-weekend";
final String week_today = zcls + "-week-today";
final String day_of_week = zcls + "-day-of-week";
final String day_of_month_bg = zcls + "-day-of-month-bg";
final String day_of_month_body = zcls + "-day-of-month-body";
final String week_of_year = zcls + "-week-of-year";
final String week_of_year_text = zcls + "-week-of-year-text";
wh.write("<div id=\"").write(uuid).write("!inner\" class=\"")
.write(month).write("\">");
wh.write("<div class=\"").write(inner).write("\">");
// title
wh.write("<table class=\"").write(month_header).write("\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr>");
Calendar cal = Calendar.getInstance(timezone);
Calendar btmp = Calendar.getInstance(timezone);
Calendar etmp = Calendar.getInstance(timezone);
cal.setTime(begin);
final DateFormatter dfhandler = self.getDateFormatter();
int[] weekend = new int[]{-1, -1};
// day-of-week
for (int index = 0, k = 0; k < 7; ++k) {
String content = dfhandler.getCaptionByDayOfWeek(cal.getTime(), locale, timezone);
wh.write("<th title=\"").write(content).write("\" class=\"")
.write(day_of_week);
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
weekend[index++] = k;
wh.write(" ").write(week_weekend);
}
wh.write("\">").write(content).write("</th>");
cal.add(Calendar.DAY_OF_MONTH, 1);
}
wh.write("</tr></tbody></table>");
// calculate how many weeks we should display
int weeks = self.getWeekOfMonth();
float number = 100F /weeks;
if (self.isWeekOfYear()) {
cal.setTime(begin);
wh.write("<div id=\"").write(uuid).write("!woy\" class=\"").write(
week_of_year).write("\">");
for (int j = 0; j < weeks; j++) {
cal.set(Calendar.MILLISECOND, 0);
wh.write("<div class=\"").write(month_week).write(
"\" style=\"top:").write((number * j)).write(
"%; height:").write(number).write("%;\"><span z.time=\"")
.write(String.valueOf(cal.getTimeInMillis())).write("\" class=\"")
.write(week_of_year_text).write("\">").write(
dfhandler.getCaptionByWeekOfYear(cal.getTime(), locale,
timezone)).write("</span></div>");
cal.add(Calendar.DAY_OF_MONTH, 7);
}
wh.write("</div>");
}
//events content
wh.write("<div id=\"").write(uuid).write("!cnt\" class=\"").write(month_body)
.write("\">");
// reset date
cal.setTime(begin);
Calendar current = Calendar.getInstance(timezone);
int today_year = current.get(Calendar.YEAR);
int today_day = current.get(Calendar.DAY_OF_YEAR);
// current date
current.setTime(self.getCurrentDate());
int curMonth = current.get(Calendar.MONTH);
final EventRender render = self.getEventRender();
Map<String, List<CalendarEvent>> dayMap = new HashMap<String, List<CalendarEvent>>();
for (int j = 0; j < weeks; j++) {
wh.write("<div class=\"").write(month_week).write("\" style=\"top:")
.write((number * j)).write("%; height:").write(number).write("%;\">");
// the background of day of month
wh.write("<table class=\"").write(day_of_month_bg)
.write("\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr>");
for (int i = 0; i < 7; i++) {
wh.write("<td class=\"");
if (weekend[0] == i || weekend[1] == i)
wh.write(" ").write(week_weekend);
if (today_year == cal.get(Calendar.YEAR) &&
today_day == cal.get(Calendar.DAY_OF_YEAR))
wh.write(" ").write(week_today);
wh.write("\"> </td>");
cal.add(Calendar.DAY_OF_MONTH, 1);
}
wh.write("</tr></tbody></table>");
// the body of day of month
wh.write("<table class=\"").write(day_of_month_body)
.write("\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr>");
// reset date
cal.add(Calendar.DAY_OF_MONTH, -7);
// the title of day of week
for (int i = 0; i < 7; i++) {
wh.write("<td class=\"").write(month_date);
if (weekend[0] == i || weekend[1] == i)
wh.write(" ").write(week_weekend);
if (today_year == cal.get(Calendar.YEAR) &&
today_day == cal.get(Calendar.DAY_OF_YEAR)) {
wh.write(" ").write(week_today);
}
if (curMonth != cal.get(Calendar.MONTH))
wh.write(" ").write(month_date_off);
cal.set(Calendar.MILLISECOND, 0);
Date d = cal.getTime();
wh.write("\" z.bd=\"").write(String.valueOf(d.getTime())).write("\" z.pt=\"")
.write(dfhandler.getCaptionByPopup(d, locale, timezone))
.write("\"><span class=\"")
.write(month_date_cnt).write("\">")
.write(dfhandler.getCaptionByDateOfMonth(d, locale, timezone))
.write("</span></td>");
cal.add(Calendar.DAY_OF_MONTH, 1);
}
wh.write("</tr>");
// the content of day of week
// reset date
cal.add(Calendar.DAY_OF_MONTH, -7);
SimpleDateFormat sdfKey = new SimpleDateFormat("yyyy/MM/dd");
sdfKey.setTimeZone(timezone);
//List daylongList = new LinkedList();
int[] daylongCnt = new int[7];
// get current begin date of the week.
cal.set(Calendar.MILLISECOND, 0);
Date beginDate = cal.getTime();
current.setTime(beginDate);
current.add(Calendar.DAY_OF_WEEK, 7);
current.set(Calendar.MILLISECOND, 0);
Date endDate = current.getTime();
for (int day = 0; day < 7; ++day) {
cal.set(Calendar.MILLISECOND, 0);
Date curDate = cal.getTime();
List<CalendarEvent> evts = self.getEvent(curDate);
String key = sdfKey.format(curDate);
List<CalendarEvent> list = null;
if (day + j * 7 < dayMap.size()) {
list = dayMap.get(key);
if (list != null) {
// due to the evts is an unmodifiable list.
evts = new LinkedList<CalendarEvent>(evts);
// the list has some cross events, we need to re-calculate it.
evts.addAll(0, list);
// reset the list
list.clear();
}
}
if (list == null) {
list = new LinkedList<CalendarEvent>();
dayMap.put(key, list);
}
List<CalendarEvent> perDay = new LinkedList<CalendarEvent>();
for (CalendarEvent ce : evts) {
Date ed = ce.getEndDate();
double rests = (ed.getTime() - curDate.getTime())/ 1000;
Date bd = ce.getBeginDate();
daylongCnt[day]++;
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)) {
for (double y = 1, x = rests/ONE_DAY; y < x; y++) {
if (y + day >= 7) {
// in current view page
if (ed.after(endDate)) {
String nextkey = sdfKey.format(new Date(endDate.getTime() + (long)ONE_DAY));
List<CalendarEvent> nextList = dayMap.get(nextkey);
if (nextList == null) {
nextList = new LinkedList<CalendarEvent>();
dayMap.put(nextkey, nextList);
}
nextList.add(ce);
}
break; // jump out the loop
}
int size = day+(int)y;
daylongCnt[size]++;
}
list.add(ce);
} else
perDay.add(ce);
}
list.addAll(perDay);
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
current.setTime(beginDate);
wh.write("<tr>");
for (int total = 7, i = 0; i < 7; i++) {
current.set(Calendar.MILLISECOND, 0);
Date curDate = current.getTime();
List<CalendarEvent> evts = dayMap.get(sdfKey.format(curDate));
wh.write("<td class=\"").write(month_date_evt).write("\"");
if (evts.size() > 0) {
CalendarEvent ce = (CalendarEvent)evts.remove(0);
Date bd = ce.getBeginDate();
Date ed = ce.getEndDate();
double rests = (ed.getTime() - curDate.getTime())/ 1000 / ONE_DAY;
int colspan = 1;
for (double y = 1; y < rests && y + i < 7; y++)
colspan++;
total -= colspan;
if (total < 0) colspan += total;
wh.write(" colspan=\"").write(colspan).write("\"").write(">");
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 >= 1))
wh.write(render.drawAllDayByMonth(self, ce, self.getCalendarEventId(ce), beginDate, endDate));
else
wh.write(render.drawDayByMonth(self, ce, self.getCalendarEventId(ce)));
while(--colspan > 0 && ++i < 7)
current.add(Calendar.DAY_OF_WEEK, 1);
} else {
total--;
wh.write("> ");
}
wh.write("</td>");
current.add(Calendar.DAY_OF_WEEK, 1);
}
wh.write("</tr>");
}
// the end of the body
wh.write("</tbody></table>");
wh.write("</div>");
}
wh.write("</div></div></div>");
}