-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test.java
executable file
·154 lines (138 loc) · 4.95 KB
/
Test.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
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
// Group project for Bob Japundza, Perry Cameron, Dante Gearring
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
// class that is used to test calendar controls
public class Test extends JFrame implements ItemListener {
static JPanel calendarContainer;
static int yearSelected = 2018; // this will set the year for the calendar
static int monthSelected = 0; // this will be the month of interest
static int viewSelected = 0; // this will be the monthy view your calendar is on
private static final int BORDER = 2;
private static final int NOBORDER = 0;
private ForwardButtonHandler fbHandler;
private ReverseButtonHandler rbHandler;
// constructor
public Test () {
fbHandler = new ForwardButtonHandler(); // forward button
rbHandler = new ReverseButtonHandler();
calendarContainer = new JPanel();
SidePanel sidePanel = new SidePanel();
setTitle("Test Calendar Object");
calendarContainer.setLayout(new BorderLayout());
writeCalendar();
setLayout(new BorderLayout());
sidePanel.setPreferredSize(new Dimension(250,800));
sidePanel.setVisible(true);
calendarContainer.setPreferredSize(new Dimension(800,800));
add(sidePanel, BorderLayout.LINE_START);
add(calendarContainer, BorderLayout.CENTER);
pack();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// item listeners
SidePanel.oneMonthRadioButton.addItemListener(this);
SidePanel.threeMonthsRadioButton.addItemListener(this);
SidePanel.twelveMonthsRadioButton.addItemListener(this);
SidePanel.monthListComboBox.addItemListener(this);
// action listeners
SidePanel.forward.addActionListener(fbHandler);
SidePanel.reverse.addActionListener(rbHandler);
}
// main entry point
public static void main(String[] args) {
Test thisTest = new Test();
}
// method to set up three calendar view
public static void threeCalendarView() {
calendarContainer.setLayout(new GridLayout(2,2));
for(int i = 0; i < 3; i++) {
if(monthSelected + i == 12) {
calendarContainer.add(new CalendarPanel(0,BORDER, new GregorianCalendar(Test.yearSelected)));
} else if(monthSelected + i == 13) {
calendarContainer.add(new CalendarPanel(1,BORDER, new GregorianCalendar(Test.yearSelected)));
} else {
calendarContainer.add(new CalendarPanel(monthSelected + i,BORDER, new GregorianCalendar(Test.yearSelected)));
}
}
calendarContainer.add(new DayPanel("",0,Color.GRAY,new Theme(1).getPanelColor()));
}
// method to set up single calendar view
public static void oneCalendarView() {
calendarContainer.setLayout(new BorderLayout());
calendarContainer.add(new CalendarPanel(monthSelected, NOBORDER, new GregorianCalendar(Test.yearSelected)), BorderLayout.CENTER);
}
// method to set up full year view
public static void twelveCalendarView() {
calendarContainer.setLayout(new GridLayout(4,3));
for(int i = 0;i < 12; i++) {
calendarContainer.add(new CalendarPanel(i,BORDER, new GregorianCalendar(Test.yearSelected)));
}
}
// does the work of displaying a calendar view
public static void writeCalendar() {
calendarContainer.removeAll();
switch(viewSelected) {
case 0:
oneCalendarView();
break;
case 1:
threeCalendarView();
break;
case 2:
twelveCalendarView();
break;
}
calendarContainer.updateUI();
System.out.println("Updating UI"); //temp
}
// handles selections
@Override
public void itemStateChanged(ItemEvent e) {
if(SidePanel.oneMonthRadioButton.isSelected()) {
viewSelected = 0;
}
if(SidePanel.threeMonthsRadioButton.isSelected()) {
viewSelected = 1;
}
if(SidePanel.twelveMonthsRadioButton.isSelected()) {
viewSelected = 2;
}
selectMonth();
writeCalendar();
}
// handles month selection
public static void selectMonth() {
for(int i = 0; i < SidePanel.monthList.length ; i++) {
if(SidePanel.monthList[i].equals(SidePanel.monthListComboBox.getSelectedItem())) {
monthSelected = i;
System.out.println("Changed Monthyly selection to " + monthSelected); //temp
}
}
}
}
// forward button handler
class ForwardButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Test.yearSelected++;
SidePanel.yearDisplay.setText("" + Test.yearSelected);
Test.writeCalendar();
System.out.println("Forward one year"); //temp
}
}
// back button handler
class ReverseButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Test.yearSelected--;
SidePanel.yearDisplay.setText("" + Test.yearSelected);
Test.writeCalendar();
System.out.println("Reverse one year"); //temp
}
}