-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreesView.java
More file actions
163 lines (114 loc) · 4.83 KB
/
Copy pathFreesView.java
File metadata and controls
163 lines (114 loc) · 4.83 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
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.ArrayList;
//Benjamin Smith
//Program Description:
//Oct 21, 2024
public class FreesView extends CustomPanel
{
private JScrollPane pane;
private int numRows;
private final Border b;
private String[] column;
protected BigDuty bd;
public FreesView(String panelName, Dimension d, BigDuty bd)
{
super(panelName, d);
b = BorderFactory.createLineBorder(Color.black);
this.bd = bd;
// Week creation, panels + layout
GridLayout week = new GridLayout(1, 5);
CustomPanel[] weekPanels = new CustomPanel[5];
this.setLayout(week);
String[] dayNames = {"M", "T", "W", "R", "F"};
for(int x = 0; x < 5; x++) {
weekPanels[x] = new CustomPanel(dayNames[x], new Dimension(100, 100));
GridLayout monday = new GridLayout(9, 1);
GridLayout other = new GridLayout(7, 1);
if(x == 0) weekPanels[x].setLayout(monday);
else weekPanels[x].setLayout(other);
this.add(weekPanels[x]);
weekPanels[x].setBorder(b);
}
column = new String[1];
column[0] = "";
//real input attempted
for(int x = 0; x < dayNames.length; x++) {
int offset = x == 0 ? 1 : 0;
for (int y = 1; y <= ((GridLayout) (weekPanels[x].getLayout())).getRows() - offset; y++) {
JTable table = createDylanTable(bd.getTeachersWithFreeInPeriod(new Period(y), dayNames[x]), new Period(y), dayNames[x]);
JScrollPane scroll = new JScrollPane(table);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
weekPanels[x].add(scroll);
if (x == 0 && y == 4) {
weekPanels[x].add(createDylanTable(bd.getTeachersWithFreeInPeriod(new Period("L"), dayNames[x]), new Period("L"), dayNames[x]));
}
}
}
}
@Override
public void refreshPanel() {
this.removeAll();
GridLayout week = new GridLayout(1, 5);
CustomPanel[] weekPanels = new CustomPanel[5];
this.setLayout(week);
String[] dayNames = {"M", "T", "W", "R", "F"};
for(int x = 0; x < 5; x++) {
weekPanels[x] = new CustomPanel(dayNames[x], new Dimension(100, 100));
GridLayout monday = new GridLayout(9, 1);
GridLayout other = new GridLayout(7, 1);
if(x == 0) weekPanels[x].setLayout(monday);
else weekPanels[x].setLayout(other);
this.add(weekPanels[x]);
weekPanels[x].setBorder(b);
}
column = new String[1];
column[0] = "Duties";
//real input attempted
for(int x = 0; x < dayNames.length; x++) {
int offset = x == 0 ? 1 : 0;
for (int y = 1; y <= ((GridLayout) (weekPanels[x].getLayout())).getRows() - offset; y++) {
JTable table = createDylanTable(bd.getTeachersWithFreeInPeriod(new Period(y), dayNames[x]), new Period(y), dayNames[x]);
JScrollPane scroll = new JScrollPane(table);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scroll.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0));
// System.out.println(Arrays.toString(scroll.getComponents()));
weekPanels[x].add(scroll);
if (x == 0 && y == 4) {
weekPanels[x].add(createDylanTable(bd.getTeachersWithFreeInPeriod(new Period("L"), dayNames[x]), new Period("L"), dayNames[x]));
}
}
}
super.refreshPanel();
}
//next class
public JTable createDylanTable(ArrayList<Teacher> teachers, Period p, String day) {
String[][] data = new String[teachers.size()][1];
for(int i = 0; i < teachers.size(); i++) {
data[i][0] = teachers.get(i).getName() + ", " + teachers.get(i).getAssignment(day, p).getName();
}
DefaultTableModel tm = new DefaultTableModel(data, column); //eventual data implementation, make data have things
JTable t = new JTable(tm);
t.setBorder(b);
t.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
return t;
}
public JTable createTable(Object[][] data) {
DefaultTableModel tm = new DefaultTableModel(data, column); //eventual data implementation, make data have things
JTable t = new JTable(tm);
t.setBorder(b);
t.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
return t;
}
public JScrollPane getPane()
{
return pane;
}
public void setPane(JScrollPane pane)
{
this.pane = pane;
}
}