-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarAppModel.java
109 lines (91 loc) · 2.78 KB
/
CalendarAppModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
/**
* This class defines the model for the calendar that is used to display to the user and allows the user to
* view the events on the date the user clicked on
* @author amalachirayil
*
*/
public class CalendarAppModel {
// Declaring the data and view that is used to store the calendar data and display the calendar, respectively
private CalendarData calendarData;
private CalendarAppView calendarAppView;
// Declaring an array list to retrieve the list of events
private ArrayList<Event> eventList;
private SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
/**
* Constructor that creates an CalendarAppModel object
* @param calendarAppView - calendar view
*/
public CalendarAppModel(CalendarAppView calendarAppView) {
this.calendarAppView = calendarAppView;
calendarData = new CalendarData();
eventList = new ArrayList<Event>();
calendarAppView.setData(this);
}
/**
* Sets the current Calendar
* @param calendarData - data that is used to set the current calendar
*/
public void setCalendar(CalendarData calendarData) {
this.calendarData = calendarData;
}
/**
* Retrieves the calendar data
* @return calendarData object
*/
public CalendarData getCalendarData() {
return calendarData;
}
/**
* Set the day that user selected to the current calendar
* @param day - day the user clicked on
*/
public void setDay(int day) {
calendarData.getGregorianCalendar().set(Calendar.DAY_OF_MONTH, day);
calendarAppView.setData(this);
}
/**
* Provides the functionality to move the calendar day by day either to the previous or next day
* depending on the current date
* @param i - day
*/
public void addDay(int i) {
calendarData.getGregorianCalendar().add(Calendar.DAY_OF_MONTH, i);
calendarAppView.setData(this);
}
/**
* Gets the date of an event
* @return
*/
public String getEventDate() {
return sdf.format(calendarData.getGregorianCalendar().getTime());
}
/**
* Adds an event to the existing list of events and also sets it up in the calendar view
* @param eventTitle - title of event
* @param date - date of event
* @param startTime - start time of event
* @param endTime - end time of event
*/
public void addEvent(String eventTitle, String date, String startTime, String endTime) {
Event event = new Event(eventTitle, date, startTime, endTime);
eventList.add(event);
calendarAppView.setData(this);
}
/**
* Sets list of events
* @param eventList - list of events to be set
*/
public void setEventList(ArrayList<Event> eventList) {
this.eventList = eventList;
}
/**
* Retrieves list of events
* @return list of events
*/
public ArrayList<Event> getEventList(){
return eventList;
}
}