-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.java
More file actions
207 lines (178 loc) · 5.73 KB
/
Copy pathModel.java
File metadata and controls
207 lines (178 loc) · 5.73 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Comparator;
public class Model {
//Variables--------------------------------------------------
private ArrayList<Dates> days; //ArrayList of (tasks + associated dates)
private Dates selectedTask; //the task that is selected in the task frame
private Controller controller;
private GregorianCalendar selectedMonth;//used for displaying the calendar
private GregorianCalendar selectedDay; //used for keeping track of the highlighted day
private GregorianCalendar today; //today's date
//Methods----------------------------------------------------
public void addController(Controller c)
{
controller = c;
}
public int getSelectedYear()
{
return selectedMonth.get(Calendar.YEAR);
}
public GregorianCalendar getSelectedMonth()
{
return (GregorianCalendar) selectedMonth.clone();
}
public void setSelectedMonth(GregorianCalendar g)
{
selectedMonth = g;
}
public GregorianCalendar getToday()
{
return (GregorianCalendar) today.clone();
}
public void setSelectedDay(GregorianCalendar g)
{
selectedDay = g;
}
public GregorianCalendar getSelectedDay()
{
return (GregorianCalendar) selectedDay.clone();
}
public ArrayList<Dates> getTasks(){
ArrayList<Dates> taskList = new ArrayList<Dates>();
Dates task = new Dates("", selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH)+1, selectedDay.get(Calendar.DATE));
for(Dates d : days) {
if(task.compareTo(d) == 0)
taskList.add(d);
}
return taskList;
}
public void addTask(String name)
{
//Dates d = new Dates(name, year, month, day);
Dates d = new Dates(name, selectedDay.get(Calendar.YEAR), (selectedDay.get(Calendar.MONTH)+1), selectedDay.get(Calendar.DAY_OF_MONTH));
//days.add(d);
//Comparator<Dates> byDate = (Dates o1, Dates o2)->{return o1.compareTo(o2);};
//days.sort(byDate);
this.addTask(d);
//THIS IS WHERE WE'RE GOING TO WANT TO ADD THE CODE TO NOTIFY THE CONTROLLER TO UPDATE THE TASKVIEW FRAME
}
public void addTask(String name, int year, int month, int day)
{
Dates d = new Dates(name, year, month, day);
//Dates today's date = new Dates("", selectedDay.get(Calendar.YEAR), (selectedDay.get(Calendar.MONTH)+1), selectedDay.get(Calendar.DAY_OF_MONTH));
this.addTask(d);
}
public void addTask(Dates d)
{
//Dates d = new Dates(name, year, month, day);
//Dates today's date = new Dates("", selectedDay.get(Calendar.YEAR), (selectedDay.get(Calendar.MONTH)+1), selectedDay.get(Calendar.DAY_OF_MONTH));
days.add(d);
Comparator<Dates> byDate = (Dates o1, Dates o2)->{return o1.compareTo(o2);};
days.sort(byDate);
//**THIS IS WHERE WE'RE GOING TO WANT TO ADD THE CODE TO NOTIFY THE CONTROLLER TO UPDATE THE TASKVIEW FRAME
controller.updateTF();
}
public void removeTask()
{
//Dates d = new Dates(name, year, month, day);
//search the ArrayList ------ we could make this faster
if(selectedTask == null)
{
return;
}
for(int i = 0; i < days.size();i++)
{
if(days.get(i).equals(selectedTask))
{
days.remove(i);
selectedTask = null;
break;
}
}
//**THIS IS WHERE WE'RE GOING TO WANT TO ADD THE CODE TO NOTIFY THE CONTROLLER TO UPDATE THE TASKVIEW FRAME
controller.updateTF();
}
public void removeTask(String s)
{
Dates d = new Dates(s, selectedDay.get(Calendar.YEAR), (selectedDay.get(Calendar.MONTH)+1), selectedDay.get(Calendar.DAY_OF_MONTH));
for(int i = 0; i< days.size(); i++)
{
if(days.get(i).equals(d))
{
days.remove(i);
return;
}
}
}
public void removeTask(String name, int year, int month, int day)
{
Dates d = new Dates(name, year, month, day);
//search the arraylist ------ we could make this faster
for(int i = 0; i < days.size();i++)
{
if(days.get(i).equals(d))
{
days.remove(i);
break;
}
}
//**THIS IS WHERE WE'RE GOING TO WANT TO ADD THE CODE TO NOTIFY THE CONTROLLER TO UPDATE THE TASKVIEW FRAME
}
public void editTask(String newName, String oldName, int year, int month, int day)
{
Dates d = new Dates(oldName, year, month, day);
for(int i = 0; i < days.size(); i++)
{
if(days.get(i).equals(d))
{
days.get(i).setTask(newName);
break;
}
}
//**THIS IS WHERE WE'RE GOING TO WANT TO ADD THE CODE TO NOTIFY THE CONTROLLER TO UPDATE THE TASKVIEW FRAME
}
public void editTask(String newName)
{
selectedTask.setTask(newName);
//**THIS IS WHERE WE'RE GOING TO WANT TO ADD THE CODE TO NOTIFY THE CONTROLLER TO UPDATE THE TASKVIEW FRAME
controller.updateTF();
}
public ArrayList<String> exportList() //export the tasks in the selected day's month
{
Dates startDate = new Dates("", selectedDay.get(Calendar.YEAR), (selectedDay.get(Calendar.MONTH)+1), 1);
Dates endDate = new Dates("", selectedDay.get(Calendar.YEAR), (selectedDay.get(Calendar.MONTH)+1), selectedDay.getActualMaximum(Calendar.DAY_OF_MONTH));
ArrayList<String> s = new ArrayList<>();
//speed could be improved by keeping track of the first task in a month and the last when a new date is selected in the calendar frame
for(int i = 0; i < days.size(); i++)
{
Dates read = days.get(i);
if(read.compareTo(startDate)>=0 && read.compareTo(endDate)<=0)
{
s.add(read.toString());
}
}
return s;
}
public void selectTask(String s)
{
Dates task = new Dates(s, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH)+1, selectedDay.get(Calendar.DATE));
for(Dates d: days)
{
if (task.equals(d))
{
selectedTask = d;
}
}
}
//Constructors-----------------------------------------------
public Model()
{
days = new ArrayList<>();
controller = null;
selectedMonth = new GregorianCalendar();
selectedDay = new GregorianCalendar();
today = new GregorianCalendar();
}
}