-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowDetailsController.java
More file actions
177 lines (153 loc) · 5.97 KB
/
ShowDetailsController.java
File metadata and controls
177 lines (153 loc) · 5.97 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
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import java.util.*;
import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.*;
import javafx.scene.text.Text;
import java.time.LocalDate;
/**
* This class controls the window that pops up
* when you click on a borough on the Map panel of
* the application. It populates a table with CovidData
* objects filtered by borough and date range,
* and displays the borough name and date range in labels.
*
* @author Rayan Popat, James Coward and Shicheng Li.
*/
public class ShowDetailsController {
@FXML
private Label boroughDetailsLabel;
@FXML
private TableView tableView;
@FXML
private Label boroughNameLabel;
@FXML
private Label selectedDatesLabel;
private ArrayList<CovidData> filteredData;
private String boroughName;
private LocalDate startDate;
private LocalDate endDate;
/**
* Constructor for the class.
* Passes on the following parameters to the class:
* @param filteredData The filtered data.
* @param boroughName The borough name.
* @param startDate The start date.
* @param endDate The end date.
*
* The following parameters are passed on to the initialize method:
* @param boroughNameLabel The borough name label.
* @param selectedDatesLabel The selected dates label.
* @param tableView The table view.
*/
public ShowDetailsController(ArrayList<CovidData> filteredData, String boroughName, LocalDate startDate, LocalDate endDate,Label boroughNameLabel,Label selectedDatesLabel, TableView<CovidData> tableView) {
this.filteredData = filteredData;
this.boroughName = boroughName;
this.startDate = startDate;
this.endDate = endDate;
this.boroughNameLabel=boroughNameLabel;
this.selectedDatesLabel = selectedDatesLabel;
this.tableView = tableView;
}
/**
* This method is called when the window is opened.
* It sets the borough name label, the selected dates label,
* and the table view.
*/
public void initialize() {
setFilteredData(filteredData);
populateTable(filteredData, boroughName);
setBoroughNameText(boroughName);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
}
/**
* Sets the borough name label.
* @param buttonName The name of the borough.
*/
public void setBoroughNameText (String buttonName) {
boroughNameLabel.setText(buttonName);
}
/**
* Sets the filtered data.
* @param dataList The filtered data.
*/
public void setFilteredData (ArrayList<CovidData> dataList) {
filteredData = dataList;
}
/**
* Populates the table view with the filtered data.
* @param dataList The filtered data.
* @param svgName The name of the SVG (which is also the borough name).
*/
public void populateTable(ArrayList<CovidData> dataList, String svgName) {
// Define the columns for the TableView
TableColumn<CovidData, String> dateCol = new TableColumn<>("Date");
dateCol.setCellValueFactory(new PropertyValueFactory<>("date"));
TableColumn<CovidData, Integer> retailCol = new TableColumn<>("Retail/Recreation GMR");
retailCol.setCellValueFactory(new PropertyValueFactory<>("retailRecreationGMR"));
TableColumn<CovidData, Integer> groceryCol = new TableColumn<>("Grocery/Pharmacy GMR");
groceryCol.setCellValueFactory(new PropertyValueFactory<>("groceryPharmacyGMR"));
TableColumn<CovidData, Integer> parksCol = new TableColumn<>("Parks GMR");
parksCol.setCellValueFactory(new PropertyValueFactory<>("parksGMR"));
TableColumn<CovidData, Integer> transitCol = new TableColumn<>("Transit GMR");
transitCol.setCellValueFactory(new PropertyValueFactory<>("transitGMR"));
TableColumn<CovidData, Integer> workplacesCol = new TableColumn<>("Workplaces GMR");
workplacesCol.setCellValueFactory(new PropertyValueFactory<>("workplacesGMR"));
TableColumn<CovidData, Integer> residentialCol = new TableColumn<>("Residential GMR");
residentialCol.setCellValueFactory(new PropertyValueFactory<>("residentialGMR"));
TableColumn<CovidData, Integer> newCasesCol = new TableColumn<>("New Cases");
newCasesCol.setCellValueFactory(new PropertyValueFactory<>("newCases"));
TableColumn<CovidData, Integer> totalCasesCol = new TableColumn<>("Total Cases");
totalCasesCol.setCellValueFactory(new PropertyValueFactory<>("totalCases"));
TableColumn<CovidData, Integer> newDeathsCol = new TableColumn<>("New Death");
newDeathsCol.setCellValueFactory(new PropertyValueFactory<>("newDeaths"));
// Add the columns to the TableView
tableView.getColumns().addAll(dateCol, retailCol, groceryCol, parksCol, transitCol,
workplacesCol, residentialCol, newCasesCol, totalCasesCol,newDeathsCol);
for (CovidData data : filteredData) {
if (data.getBorough().contains(svgName)) {
tableView.getItems().add(data);
}
}
}
/**
* Returns the filtered data.
* @return The filtered data.
*/
public ArrayList<CovidData> getfilteredData() {
return filteredData;
}
/**
* Returns the borough name.
* @return The borough name.
*/
public Label getBoroughNameLabel()
{
return boroughNameLabel;
}
/**
* Returns the selected dates label.
* @return The selected dates label.
*/
public Label getboroughDetailsLabel()
{
return boroughDetailsLabel;
}
/**
* Returns the table view.
* @return The table view.
*/
public Label getselectedDatesLabel()
{
return selectedDatesLabel;
}
/**
* Returns the borough name label.
* @return The borough name label.
*/
public TableView gettableView()
{
return tableView;
}
}