Package org.zkoss.calendar.api

Examples of org.zkoss.calendar.api.EventRender


    // 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("\">&nbsp;</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 {
View Full Code Here


    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("\">&nbsp;</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(">&nbsp;");
        }

        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("\">&nbsp;</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("\">&nbsp;</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);
    }

View Full Code Here

TOP

Related Classes of org.zkoss.calendar.api.EventRender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.