-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerStatistic.java
More file actions
126 lines (106 loc) · 3.98 KB
/
ControllerStatistic.java
File metadata and controls
126 lines (106 loc) · 3.98 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
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.Pane;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Button;
import java.net.URL;
import java.util.ResourceBundle;
import java.io.IOException;
import javafx.scene.control.DatePicker;
import java.time.LocalDate;
import java.util.NoSuchElementException;
import javafx.scene.control.Label;
import java.util.Observable;
import java.util.Observer;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane; // Assuming rightPane is of type AnchorPane
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.time.format.DateTimeFormatter;
import javafx.scene.control.Alert;
public class ControllerStatistic {
// Singleton pattern
private static ControllerStatistic instance;
// Declare other controllers
ControllerSubStat controllerSubStat;
// Declare the models (Source of data)
ModelMain modelMain;
// Declare the statistics class generator
Statistics statistics;
// Panels
@FXML
private Pane statisticsMiniPanel;
// Constructor to set the ModelMain instance
public ControllerStatistic() {}
// Singleton getInstance() method
public static ControllerStatistic getInstance() {
if (instance == null) {
instance = new ControllerStatistic();
}
return instance;
}
/**
* This update method will accessed by ControllerMain
*/
public void updateCurrentPanel() {
this.modelMain = modelMain.getInstance();
panelCycler(modelMain.getStatIndex());
}
/**
* This sets the chosen pane and makes it load the chosen fxmlFile
*/
private <T> T loadPanel(String fxmlFile, Pane pane) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
Node panel = loader.load();
pane.getChildren().setAll(panel);
return loader.getController();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
private void panelCycler(int counter) {
if(counter == 0){handlePanelOne(null);}
else if(counter==1){handlePanelTwo(null);}
else if(counter==2){handlePanelThree(null);}
}
@FXML
private void incrementPanel(ActionEvent event) {
modelMain.increaseStatIndex();
if(modelMain.getStatIndex()>2){
modelMain.resetStatIndex();
}
panelCycler(modelMain.getStatIndex());
}
@FXML
private void decrementPanel(ActionEvent event) {
modelMain.decreaseStatIndex();
if(modelMain.getStatIndex()<0){
modelMain.setStatIndex(2);
}
panelCycler(modelMain.getStatIndex());
}
@FXML
private void handlePanelOne(ActionEvent event) {
statistics = statistics.getInstance();
controllerSubStat = (ControllerSubStat) loadPanel("StatisticsOne.fxml", statisticsMiniPanel);
controllerSubStat.updateStatistic("(Page 1) Total deaths in this period: " + statistics.totalDeath());
}
@FXML
private void handlePanelTwo(ActionEvent event) {
statistics = statistics.getInstance();
controllerSubStat = (ControllerSubStat) loadPanel("StatisticsTwo.fxml", statisticsMiniPanel);
controllerSubStat.updateStatistic("(Page 2) Average cases per day in this period: " + statistics.averageCases());
}
@FXML
private void handlePanelThree(ActionEvent event) {
statistics = statistics.getInstance();
controllerSubStat = (ControllerSubStat) loadPanel("StatisticsThree.fxml", statisticsMiniPanel);
controllerSubStat.updateStatistic("(Page 3) Average mobility: " + statistics.averageTransit());
}
}