import java.util.Date;

import com.smartgwt.client.types.TimeDisplayFormat;
import com.smartgwt.client.widgets.calendar.Calendar;
import com.smartgwt.client.widgets.layout.VLayout;


public class CalendarPanel extends VLayout {
  private static final int ONE_MINUTE = 1000 * 60 ;
  private static final int DURATION_IN_MINUTES = 15;
  private Calendar calendar;

  public CalendarPanel() {
    setWidth100();
    setHeight100();
    addMember(setupCalendar());
  }
  
  private Calendar setupCalendar() {
    calendar = new Calendar();
    calendar.setHeight(2000);
    calendar.setCanEditEvents(false);
    calendar.setCanCreateEvents(false);
    calendar.setCanDeleteEvents(false);
    calendar.setAutoFetchData(false);
    calendar.setEventOverlap(true);
    calendar.setTimeFormatter(TimeDisplayFormat.TOSHORT24HOURTIME);
    calendar.setEventOverlapIdenticalStartTimes(true);
    calendar.setRowHeight(20);
    calendar.setFirstDayOfWeek(1);

    Date startDate = new Date(1349265818267L);
    for (int i = 0; i < 24; i++) {
      createEventAt(i, startDate);
      startDate = new Date(startDate.getTime() + (ONE_MINUTE * 60));
    }
    
    return calendar;
  }

  private void createEventAt(int id, Date startDate) {
    Date endDate = new Date(startDate.getTime() + DURATION_IN_MINUTES * ONE_MINUTE);
    calendar.addEvent(startDate, endDate , id + "1", "description " + id);
    calendar.addEvent(startDate, endDate , id + "2", "description " + id) ;
  }
}