-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFarmReportHandler.java
More file actions
133 lines (100 loc) · 3.44 KB
/
FarmReportHandler.java
File metadata and controls
133 lines (100 loc) · 3.44 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
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
/**
* FarmReportHandler.java created by Bo in ateam
*
* Author: Bo Li (bli379@wisc.edu) Date: @date
*
*
* Course: CS400 Semester: Spring 2020 Lecture: 001
*
* IDE: Eclipse IDE For Java Developers Version: 291942 (4.14.0)
*/
/**
* FarmReportHandler - TODO Describe purpose of this user-defined type
*
* @author Bo, zhang
*
*/
public class FarmReportHandler implements javafx.event.EventHandler<ActionEvent> {
private MilkData milkData;
private VBox root;
private TextField id;
private TextField year;
private ObservableList<FarmReport.Milk> tableitems =
FXCollections.observableArrayList();
/**
* Instantiates a new date range handler.
*
*
*/
public FarmReportHandler(MilkData milkData, VBox root, TextField id, TextField year) {
this.milkData = milkData;
this.root = root;
this.id = id;
this.year = year;
}
@Override
public void handle(ActionEvent arg0) {
// TODO Auto-generated method stub
// retrieve data
EventLog.getInstance().log("FarmReport Generated");
String farmid = id.getText().toString();
String farmyear = year.getText().toString();
Set<String> months = milkData.getMonths();
for (String month : months) {
// check year
String[] arrOfStr = month.split("-", 2);
if (arrOfStr[0].equals(year)) {
List<MilkItem> itemlist = milkData.getDataByMonth(month);
int totalofall = 0;
int totaloffarm = 0;
// find id
for (MilkItem item : itemlist) {
totalofall += item.getWeight();
if (item.getFarmID().equals(id)) {
totaloffarm += item.getWeight();
}
}
// find percentage
double percent = totaloffarm / totalofall;
// add to table
FarmReport.Milk tableitem =
new FarmReport.Milk(arrOfStr[1], (Integer) totaloffarm, (Double) percent);
tableitems.add(tableitem);
}
}
// add table
TableView table = new TableView<>();
table.setEditable(true);
// 1
TableColumn<FarmReport.Milk, String> col1 = new TableColumn<>("Month");
col1.setPrefWidth(250);
col1.setCellValueFactory(new PropertyValueFactory<FarmReport.Milk, String>("month"));
// 2
TableColumn<FarmReport.Milk, Integer> col2 = new TableColumn<>("Weight");
col2.setPrefWidth(250);
col2.setCellValueFactory(new PropertyValueFactory<FarmReport.Milk, Integer>("weight"));
// 3
TableColumn<FarmReport.Milk, Double> col3 =
new TableColumn<>("Percent of Total Weight of All Farms");
col3.setPrefWidth(250);
col3.setCellValueFactory(new PropertyValueFactory<FarmReport.Milk, Double>("percentage"));
table.setItems(tableitems);
table.getColumns().addAll(col1, col2, col3);
root.getChildren().add(table);
}
}