-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendarDay.java
More file actions
62 lines (47 loc) · 1.9 KB
/
CalendarDay.java
File metadata and controls
62 lines (47 loc) · 1.9 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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;
import java.text.SimpleDateFormat;
//CalendarDay is a button that displays information about the events of that day when clicked.
//TODO: add functionality to open new window/panel when clicked
public class CalendarDay extends Button{
private static SimpleDateFormat df = new SimpleDateFormat("EEE, MMM dd, yyyy");
private CDActionListener listener;
public CalendarDay(Calendar date, TodoList list, Color color){
super.setFocusable(false);
super.setBackground(color);
this.listener = new CDActionListener(date, list);
super.addActionListener(this.listener);
}
public void changeDate(Calendar date){
//update the internal date and labelp
this.listener.date = date;
super.setLabel(date.get(Calendar.DAY_OF_MONTH)+"");
}
private class CDActionListener implements ActionListener{
private Calendar date;
private TodoList list;
public CDActionListener(Calendar date, TodoList list){
this.date = date;
this.list = list;
}
public void actionPerformed(ActionEvent e){
Calendar start = (Calendar)date.clone();
start.set(Calendar.HOUR, 0);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
start.set(Calendar.MILLISECOND, 0);
Calendar end = (Calendar)start.clone();
end.add(Calendar.DATE, 1);
TodoList filteredList = list.filterByDate(start,end);
if(filteredList.size() == 0) return;
JFrame window = new JFrame();
window.add(new ListView(filteredList));
window.setTitle("To-Do Items for "+df.format(date.getTime()));
window.setSize(800,600);
window.revalidate();
window.setVisible(true);
}
}
}