package calendar;
import java.util.Calendar;
import javax.swing.Icon;
public class Event extends CsvStructure{
public static final int NOT_REPEATING = 0;
public static final int REPEATING_DAILY = 1;
public static final int REPEATING_WEEKENDS = 2;
public static final int REPEATING_WORKING_DAYS = 3;
public static final int REPEATING_WEEKLY = 4;
public static final int REPEATING_TWO_WEEKS = 5;
public static final int REPEATING_FOUR_WEEKS = 6;
public static final int REPEATING_MONTHLY = 7;
public static final int REPEATING_YEARLY = 8;
public static final int GENERAL_EVENT = 0;
public static final int WORK_EVENT = 1;
public static final int SOCIAL_EVENT = 2;
public static final int BIRTHDAY_EVENT = 3;
public static final int NO_FIELDS = 7;
public static final int IDX_ID = 1;
public static final int IDX_TITLE = 2;
public static final int IDX_START_DATE = 3;
public static final int IDX_END_DATE = 4;
public static final int IDX_DESCRIPTION = 5;
public static final int IDX_REPETITION = 6;
protected int m_type;
protected int m_id;
protected String m_title;
protected Calendar m_start_date;
protected Calendar m_end_date;
protected String m_description;
protected int m_repetition;
protected Icon m_icon;
return m_description;
}
m_description = description;
return true;
}
return m_end_date;
}
m_end_date = end_date;
return true;
}
return m_id;
}
public boolean SetId(
int id) {
m_id = id;
return true;
}
return m_repetition;
}
m_repetition = repetition;
return true;
}
return m_start_date;
}
this.m_start_date = start_date;
return true;
}
return m_title;
}
public boolean SetTitle(String title)
throws Exception {
if (ValidTitle(title)==true){
m_title = title;
}
return true;
}
m_id = Data.AllocateEventId();
m_title = "Temp Event";
m_start_date = Calendar.getInstance();
m_end_date = Calendar.getInstance();
m_end_date.add(Calendar.HOUR_OF_DAY, 1);
m_description = "Dummy event";
m_repetition = Event.NOT_REPEATING;
m_type = Event.GENERAL_EVENT;
}
public Event(
int id, String title, Calendar start_date, Calendar end_date,
String description, int repetition) throws Exception {
m_id = id;
if(ValidTitle(title) == true){
m_title = title;
}
m_start_date = start_date;
if(validEnd(end_date) == true){
m_end_date = end_date;
}
if (ValidDescription(description) == true){
m_description = description;
}
m_repetition = repetition;
m_type = Event.GENERAL_EVENT;
}
String csv = m_type+","+m_id+","+"\""+m_title+"\",\""+
Data.FromDate(m_start_date)+"\",\""+Data.FromDate(m_end_date)+"\",\""
+m_description+"\","+m_repetition;
return csv;
}
public boolean ValidTitle(String title)
throws Exception{
if (title.equals("") || title.length() > 50){
throw new Exception("Please enter a valid title " +
"(Between 1 and 50 characters)");
}
return true;
}
public boolean validEnd(Calendar end)
throws Exception{
if(end.after(GetStart_date()) || end.equals(GetStart_date())){
return true;
}
throw new Exception("Invalid end date: Please make sure"
+ " the end is after the beginning of the event");
}
if (description.equals("") || description.length() > 250){
throw new Exception("Please enter a valid description " +
"(more than 1 and less than 250 characters)");
}
return true;
}
}