Newer
Older
Harry Linrui XU
committed
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package no.ntnu.idatt1002.demo.controller;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.Optional;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.text.Text;
import no.ntnu.idatt1002.demo.data.Budget.FileHandlingBudget;
import no.ntnu.idatt1002.demo.data.Budget.GeneralBudget;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseRegister;
import no.ntnu.idatt1002.demo.data.Economics.FileHandling;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.IncomeCategory;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
public class IncomeExpenseController implements FinanceController {
@FXML
private TableColumn<Expense, Double> expAmountCol;
@FXML
private TableColumn<Expense, ExpenseCategory> expCategoryCol;
@FXML
private TableColumn<Expense, String> expDateCol;
@FXML
private TableColumn<Expense, String> expDescriptionCol;
@FXML
private TableColumn<Expense, Boolean> expRecurringCol;
@FXML
private TableColumn<Income, Double> inAmountCol;
@FXML
private TableColumn<Income, IncomeCategory> inCategoryCol;
@FXML
private TableColumn<Income, String> inDateCol;
@FXML
private TableColumn<Income, String> inDescriptionCol;
@FXML
private TableColumn<Income, Boolean> inRecurringCol;
@FXML
private TableView<Expense> expenseTableView;
@FXML
private TableView<Income> incomeTableView;
@FXML
private Text inSum;
@FXML
private Text expSum;
@FXML
private Button addBtn;
@FXML
private Button deleteBtn;
@FXML
private Button editBtn;
@FXML
private ProgressBar budgetProgress;
@FXML
private DatePicker date;
@FXML
private Label daysLeftLbl;
@FXML
private ComboBox<?> filter;
@FXML
private Button returnBtn;
@FXML
private Label title;
private FinanceMode financeMode;
private IncomeRegister incomeRegister;
private ExpenseRegister expenseRegister;
private GeneralBudget generalBudget;
private ObservableList<Income> income;
private ObservableList<Expense> expenses;
FileHandling fileHandling;
@FXML
public void initialize() throws IOException {
//Initialize columns
inDateCol.setCellValueFactory(new PropertyValueFactory<Income, String>("date"));
inAmountCol.setCellValueFactory(new PropertyValueFactory<Income, Double>("amount"));
inCategoryCol.setCellValueFactory(new PropertyValueFactory<Income, IncomeCategory>("category"));
inDescriptionCol.setCellValueFactory(new PropertyValueFactory<Income, String>("description"));
inRecurringCol.setCellValueFactory(new PropertyValueFactory<Income, Boolean>("recurring"));
expDateCol.setCellValueFactory(new PropertyValueFactory<Expense, String>("date"));
expAmountCol.setCellValueFactory(new PropertyValueFactory<Expense, Double>("amount"));
expCategoryCol.setCellValueFactory(new PropertyValueFactory<Expense, ExpenseCategory>("category"));
expDescriptionCol.setCellValueFactory(new PropertyValueFactory<Expense, String>("description"));
expRecurringCol.setCellValueFactory(new PropertyValueFactory<Expense, Boolean>("recurring"));
//Initialize registers and tableview
incomeRegister = loadIncomeDataFromFile("Income");
income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
expenseRegister = loadExpenseDataFromFile("Expense");
expenses = FXCollections.observableArrayList(expenseRegister.getItems());
expenseTableView.setItems(expenses);
//Initialize sum field under the tableview
inSum.setText(String.valueOf(incomeRegister.getTotalSum()));
expSum.setText(String.valueOf(expenseRegister.getTotalSum()));
fileHandling = new FileHandling();
}
/**
* Method for handling the adding of new entries in the tableview.
* @param event A button click on the add button.
*/
@Override
public void handleAddBtn(ActionEvent event) {
handleEditBtn(event);
}
/**
* Method for handling the editing of a chosen entry in the tableview.
*
* @param event A button click on the edit button.
*/
@Override
public void handleEditBtn(ActionEvent event) {
}
/**
* Deletes an entry from the tableview, if an entry has been selected. The method brings up a
* popup window, asking for confirmation for deleting the entry.
*
* @param event A button click on the delete button
*/
@Override
public void handleDeleteBtn(ActionEvent event) {
}
/**
* Method for synching the register with the tableview. The observable list to which the tableview
* is set, is being refilled with all the entries in the register, keeping it updated with new
* changes.
*/
@Override
public void refreshTableView() {
}
/**
* Returns an optional, which is a popup alert box, asking for confirmation for deleting an
* entry.
*
* @return An alert box, asking for confirmation for deleting the selected entry of the tableview.
*/
@Override
public Optional<ButtonType> showConfirmationDialog() {
return Optional.empty();
}
/**
* Saves the changes made to the tableview by writing the information to a file.
*
* @param fileName The name of the file that is written to.
* @throws IOException If an error occurs while writing to the file.
*/
@Override
public void saveDataToFile(String fileName) throws IOException {
}
/**
* Method that either reads data from a file with which it fills an income register, if older changes exist, or instantiates an income register if the file is empty.
* @param fileName The name of the file that is being read from.
* @return An object of type IncomeRegister.
* @throws IOException If an error occurs while reading from the file.
*/
public IncomeRegister loadIncomeDataFromFile(String fileName) throws IOException {
//Instantiate new incomeRegister
if (fileHandling.isEmpty(fileName)) {
incomeRegister = new IncomeRegister();
} else { //Load previous income register
try {
incomeRegister = fileHandling.readIncomeRegisterFromFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
return incomeRegister;
}
/**
* Method that either reads data from a file with which it fills an expense register, if older changes exist, or instantiates an expense register if the file is empty.
* @param fileName The name of the file that is being read from.
* @return An object of type IncomeRegister.
* @throws IOException If an error occurs while reading from the file.
*/
public ExpenseRegister loadExpenseDataFromFile(String fileName) throws IOException {
//ItemRegister<T extends Item>
if (fileHandling.isEmpty(fileName)) {
expenseRegister = new ExpenseRegister();
} else {
try {
expenseRegister = fileHandling.readExpenseRegisterFromFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
return expenseRegister;
}
/**
* Method that either reads data from a file with which it fills a budget register, if this is an old budget, or instantiates a budget register if this is a new budget.
* @param fileName The name of the file that is being read from.
* @return An object of type GeneralBudget.
* @throws IOException If an error occurs while reading from the file.
*/
public GeneralBudget loadBudgetDataFromFile(String fileName) throws IOException {
FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
//Instantiate new budget
if (fileHandlingBudget.isEmpty(fileName)) {
generalBudget = new GeneralBudget(31, 1000);
} else { //Load previous budget
try {
generalBudget = fileHandlingBudget.readGeneralBudgetFromFile(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
return generalBudget;
}
/**
* Switches the scene to the Main Menu scene.
*/
private void returnToMainMenu() {
}
}