Skip to content
Snippets Groups Projects
Commit 80a37e57 authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

"Added javadoc"

parent 10173a6f
No related branches found
No related tags found
8 merge requests!43Merging frontend-testing into master,!38"Made progressbar dynamic in accordance to spending. Added balance field....,!37Made the sub progress bars respond to changes in expense,!32Added input validation to add dialog boxes.,!30Redesigned scenes,!29Redesigned scenes,!28Redesigned scenes,!26Redesigned Main menu and expense/income windows
Pipeline #213194 passed
......@@ -16,6 +16,9 @@ import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
/**
* Class that represents the popup dialog box that appears whenever a budget item is to be added or edited.
* The dialog contains various fields that are used to create a new item or edit an existing item.
* @author Anders Emil Bergan
* @since 24.3.2023
*
*/
public class AddBudgetController {
......@@ -42,9 +45,12 @@ public class AddBudgetController {
*/
@FXML
public void initialize(){
//Set the possible values in a list.
ObservableList<ExpenseCategory> expenseCategories = FXCollections.observableArrayList(
ExpenseCategory.values());
//Set the values inside the dropbox
categoryVariable.setItems(expenseCategories);
//Set default value
categoryVariable.setPromptText("Category");
}
......@@ -56,6 +62,26 @@ public class AddBudgetController {
return this.newBudgetItem;
}
/**
* Binds the item that is taken in as the argument with a budget item declared in this class. The item of this class is instantiated
* as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes
* in the dialog window are then set to the values of the chosen item, as to not display empty values.
* @param item The item that is chosen to be edited.
*/
@FXML
public void setBudget(BudgetItem item){
//Deep copying item and then binding the two items
chosenBudgetItem = new BudgetItem(item.getBudgetAmount(), item.getBudgetDescription(), item.getBudgetCategory());
chosenBudgetItem.getAmountProperty().bindBidirectional(item.getAmountProperty());
chosenBudgetItem.getDescriptionProperty().bindBidirectional(item.getDescriptionProperty());
chosenBudgetItem.getCategoryProperty().bindBidirectional(item.getCategoryProperty());
//Set the values of the input fields of the dialog box
amountVariable.textProperty().set(String.valueOf(item.getBudgetAmount()));
descriptionVariable.textProperty().set(item.getBudgetDescription());
categoryVariable.setValue(item.getBudgetCategory());
}
/**
* Adds a new to the budget tableview or edits an existing entry in table if the OK button is pressed.
* An entry is edited as the selected entry of the table is bounded to another budget item in this class. If this budget item
......@@ -82,26 +108,6 @@ public class AddBudgetController {
stage.close();
}
/**
* Binds the item that is taken in as the argument with a budget item from this class. The item of this class is instantiated
* as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes
* in the dialog window are then set to the values of the chosen item, as to not display empty values.
* @param item The item that is chosen to be edited.
*/
@FXML
public void setBudget(BudgetItem item){
//Deep copying item and then binding the two items
chosenBudgetItem = new BudgetItem(item.getBudgetAmount(), item.getBudgetDescription(), item.getBudgetCategory());
chosenBudgetItem.getAmountProperty().bindBidirectional(item.getAmountProperty());
chosenBudgetItem.getDescriptionProperty().bindBidirectional(item.getDescriptionProperty());
chosenBudgetItem.getCategoryProperty().bindBidirectional(item.getCategoryProperty());
//Set the values of the input fields of the dialog box
amountVariable.textProperty().set(String.valueOf(item.getBudgetAmount()));
descriptionVariable.textProperty().set(item.getBudgetDescription());
categoryVariable.setValue(item.getBudgetCategory());
}
/**
* Closes the dialog box.
* @param actionEvent A button click on the close button.
......
......@@ -17,8 +17,14 @@ import javafx.scene.control.TextField;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
/**
* Class that represents the popup dialog box that appears whenever an expense is to be added or edited.
* The dialog contains various fields that are used to create a new expense or edit an existing expense.
* @author Harry Linrui Xu
* @since 13.3.2023
*/
public class AddExpenseController {
Expense newExpense = null; //the expense that is chosen when editing or the expense that is created when adding
......@@ -48,17 +54,26 @@ public class AddExpenseController {
@FXML
private ComboBox<Boolean> recurringBox;
/**
* Initializes the category and recurring drop boxes by filling them with all the values from the ExpenseCategory enum,
* and the boolean values respectively, and the datepicker calendar.
* It then sets them to the default values of GIFT, false and today respectively.
*/
@FXML
public void initialize() {
//Set the possible values in a list.
ObservableList<ExpenseCategory> expenseCategories = FXCollections.observableArrayList(
ExpenseCategory.values());
//Set the values inside the dropbox
categoryBox.setItems(expenseCategories);
//Set default value
categoryBox.setValue(ExpenseCategory.FOOD);
ObservableList<Boolean> recurring = FXCollections.observableArrayList(true, false);
recurringBox.setItems(recurring);
recurringBox.setValue(false);
//Set date to today
datePicker.setValue(LocalDate.now());
}
......@@ -70,7 +85,18 @@ public class AddExpenseController {
return recurringBox.getValue();//.equals("Yes");
}
public void setExpense(Expense expense) { //TODO NEED CANCEL BUTTON TO REMOVE THE CHANGES IF CANCEL IS PRESSED
public Expense getNewExpense() {
return this.newExpense;
}
/**
* Binds the expense that is taken in as the argument with an expense declared in this class. The expense of this class is instantiated
* as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes
* in the dialog window are then set to the values of the chosen expense, as to not display empty values.
* @param expense The expense that is chosen to be edited.
*/
public void setExpense(Expense expense) {
//Deep copying expense and then binding the two expenses
chosenExpense = new Expense(expense.getDescription(), expense.getAmount(), expense.isRecurring(), expense.getCategory(), expense.getDate());
chosenExpense.descriptionProperty().bindBidirectional(expense.descriptionProperty());
chosenExpense.amountProperty().bindBidirectional(expense.amountProperty());
......@@ -78,6 +104,7 @@ public class AddExpenseController {
chosenExpense.expenseCategoryObjectProperty().bindBidirectional(expense.expenseCategoryObjectProperty());
chosenExpense.dateProperty().bindBidirectional(expense.dateProperty());
//Set the values of the input fields of the dialog box
descriptionField.textProperty().set(expense.getDescription());
amountField.textProperty().setValue(String.valueOf(expense.getAmount()));
recurringBox.setValue(expense.isRecurring());
......@@ -85,8 +112,15 @@ public class AddExpenseController {
categoryBox.setValue(expense.getCategory());
}
/**
* Adds a new to the tableview or edits an existing entry in table if the OK button is pressed.
* An entry is edited as the selected entry of the table is bounded to another expense in this class. If this expense
* is altered, the expense in the tableview will automatically respond with the same changes.
* @param event If the OK button is pressed.
*/
@FXML
public void pressOkBtn(ActionEvent event) {
//Instantiates a new expense
if (newExpense == null) {
LocalDate date = datePicker.getValue();
double amount = Double.parseDouble(amountField.getText());
......@@ -95,6 +129,7 @@ public class AddExpenseController {
boolean recurring = isRecurring();
newExpense = new Expense(description, amount, recurring, category, date);
}
//Sets the value of the expense(chosen) that is bounded to the chosen expense (not chosenExpense) in the tableview
if (chosenExpense != null) {
chosenExpense.setDescription((descriptionField.getText()));
chosenExpense.setAmount(Double.parseDouble(amountField.getText()));
......@@ -107,6 +142,10 @@ public class AddExpenseController {
((Stage) source.getScene().getWindow()).close();
}
/**
* Closes the dialog box and cancels any pending changes.
* @param event A button click on the cancel button.
*/
@FXML
public void pressCancelBtn(ActionEvent event) {
final Node source = (Node) event.getSource();
......@@ -114,8 +153,4 @@ public class AddExpenseController {
stage.close();
}
public Expense getNewExpense() {
return this.newExpense;
}
}
\ No newline at end of file
......@@ -19,6 +19,12 @@ import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.Income;
import no.ntnu.idatt1002.demo.data.Economics.IncomeCategory;
/**
* Class that represents the popup dialog box that appears whenever an income is to be added or edited.
* The dialog contains various fields that are used to create a new income or edit an existing income.
* @author Harry Linrui Xu
* @since 24.3.2023
*/
public class AddIncomeController {
Income newIncome = null;
......@@ -45,17 +51,26 @@ public class AddIncomeController {
@FXML
private ComboBox<Boolean> recurringBox;
/**
* Initializes the category and recurring drop boxes by filling them with all the values from the IncomeCategory enum,
* and the boolean values respectively, and the datepicker calendar.
* It then sets them to the default values of GIFT, false and today respectively.
*/
@FXML
public void initialize() {
//Set the possible values in a list.
ObservableList<IncomeCategory> incomeCategories = FXCollections.observableArrayList(
IncomeCategory.values());
//Set the values inside the dropbox
categoryBox.setItems(incomeCategories);
//Set default value
categoryBox.setValue(IncomeCategory.GIFT);
ObservableList<Boolean> recurring = FXCollections.observableArrayList(true, false);
recurringBox.setItems(recurring);
recurringBox.setValue(false);
//Set date to today
datePicker.setValue(LocalDate.now());
}
......@@ -67,7 +82,18 @@ public class AddIncomeController {
return recurringBox.getValue();//.equals("Yes");
}
public void setIncome(Income income) { //TODO NEED CANCEL BUTTON TO REMOVE THE CHANGES IF CANCEL IS PRESSED
public Income getNewIncome() {
return this.newIncome;
}
/**
* Binds the income that is taken in as the argument with an income declared in this class. The income of this class is instantiated
* as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes
* in the dialog window are then set to the values of the chosen income, as to not display empty values.
* @param income The income that is chosen to be edited.
*/
public void setIncome(Income income) {
//Deep copying income and then binding the two incomes
chosenIncome = new Income(income.getDescription(), income.getAmount(), income.isRecurring(), income.getCategory(), income.getDate());
chosenIncome.descriptionProperty().bindBidirectional(income.descriptionProperty());
chosenIncome.amountProperty().bindBidirectional(income.amountProperty());
......@@ -78,6 +104,7 @@ public class AddIncomeController {
amountField.textProperty().setValue(String.valueOf(income.getAmount()));
recurringBox.setValue(income.isRecurring());
//Set the values of the input fields of the dialog box
descriptionField.textProperty().set(income.getDescription());
amountField.textProperty().setValue(String.valueOf(income.getAmount()));
recurringBox.setValue(income.isRecurring());
......@@ -85,8 +112,15 @@ public class AddIncomeController {
categoryBox.setValue(income.getCategory());
}
/**
* Adds a new to the tableview or edits an existing entry in table if the OK button is pressed.
* An entry is edited as the selected entry of the table is bounded to another income in this class. If this income
* is altered, the income in the tableview will automatically respond with the same changes.
* @param event If the OK button is pressed.
*/
@FXML
public void pressOkBtn(ActionEvent event) {
//Instantiates a new income
if (chosenIncome == null) {
LocalDate date = datePicker.getValue();
double amount = Double.parseDouble(amountField.getText());
......@@ -95,6 +129,7 @@ public class AddIncomeController {
boolean recurring = isRecurring();
newIncome = new Income(description, amount, recurring, category, date);
}
//Sets the value of the income(chosenIncome) that is bounded to the chosen income (not chosenIncome) in the tableview
if (chosenIncome != null) {
chosenIncome.setDescription((descriptionField.getText()));
chosenIncome.setAmount(Double.parseDouble(amountField.getText()));
......@@ -107,6 +142,11 @@ public class AddIncomeController {
((Stage) source.getScene().getWindow()).close();
}
/**
* Closes the dialog box and cancels any pending changes.
* @param event A button click on the cancel button.
*/
@FXML
public void pressCancelBtn(ActionEvent event) {
final Node source = (Node) event.getSource();
......@@ -114,8 +154,4 @@ public class AddIncomeController {
stage.close();
}
public Income getNewIncome() {
return this.newIncome;
}
}
\ No newline at end of file
......@@ -32,10 +32,13 @@ import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
import no.ntnu.idatt1002.demo.data.Economics.Item;
import no.ntnu.idatt1002.demo.data.Economics.ItemRegister;
enum DialogMode {
ADD, EDIT, DELETE
}
/**
* Controller for expense scene in the application. This controller manages all actions that relates to the expense tableview (add, edit and delete), the switching
* of scenes from the expense scene to another scene, and the saving of the table, whenever the user switches to another scene.
*
* @author Harry Linrui Xu
* @since 13.3.2023
*/
public class ExpensesController {
@FXML
......@@ -50,7 +53,7 @@ public class ExpensesController {
private ComboBox<String> show;
@FXML
private Button incomeBtn;
private Button expenseBtn;
@FXML
private Text sum;
......@@ -86,35 +89,54 @@ public class ExpensesController {
ObservableList<String> filter;
/**
* Initializes the expense register, the observable expense list and the tableview, along values of the dropbox used for filtering the tableview.
* The method is called each time the FXML of this scene is loaded.
* @throws IOException If there occurs any exception when loading the budget register from a file.
*/
@FXML
public void initialize() throws IOException {
//Initialize table columns
dateColumn.setCellValueFactory(new PropertyValueFactory<Expense, String>("date"));
amountColumn.setCellValueFactory(new PropertyValueFactory<Expense, Double>("amount"));
categoryColumn.setCellValueFactory(new PropertyValueFactory<Expense, ExpenseCategory>("category"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<Expense, String>("description"));
recurringColumn.setCellValueFactory(new PropertyValueFactory<Expense, Boolean>("recurring"));
//Initialize the filter box
filter = FXCollections.observableArrayList("All", "Food", "Clothes", "Books", "Other",
"Fixed expense");
show.setItems(filter);
show.setValue("All");
//Initialize registers and tableview
expenseRegister = loadExpenseDataFromFile("Expense");
expenses = FXCollections.observableArrayList(expenseRegister.getItems());
expenseTableView.setItems(expenses);
//Initialize sum field under the tableview
sum.setText(String.valueOf(expenseRegister.getTotalSum()));
}
/**
* Method for handling the adding of new entries in the tableview.
* @param event A button click on the add button.
*/
@FXML
protected void handleAddButton(ActionEvent event) {
handleEditButton(event);
}
/**
* Method for handling the editing of a chosen entry in the tableview.
* @param event A button click on the edit button.
*/
@FXML
protected void handleEditButton(ActionEvent event) {
//Instantiate FXML loader and loads the popup for adding expense
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/AddExpense.fxml"));
Expense newExpense = null;
String dialogTitle = "";
// Load the FXML file for your dialog box
......@@ -134,7 +156,8 @@ public class ExpensesController {
/**
* The mode of the dialog. NEW if new contact, EDIT if edit existing contact.
*/
DialogMode dialogMode;
DialogMode dialogMode;
//Sets the title of the dialog box
if (event.getSource().equals(addBtn)) {
dialogMode = DialogMode.ADD;
dialogTitle = "Add expense";
......@@ -144,25 +167,32 @@ public class ExpensesController {
&& expenseTableView.getSelectionModel().getSelectedItem() != null) {
dialogMode = DialogMode.EDIT;
dialogTitle = "Edit expense";
//Gets the selected item from the table
newExpense = expenseTableView.getSelectionModel().getSelectedItem();
//Binds the selected item to another item which is defined in the ItemController
dialogController.setExpense(newExpense);
} else {
return;
}
dialog.setTitle(dialogTitle);
dialog.showAndWait();
// Show the Dialog and wait for the user to close it
dialog.showAndWait();
//Get the newly created expense from the dialog pane
newExpense = dialogController.getNewExpense();
//Adds the new item to the register
if (newExpense != null && dialogMode == DialogMode.ADD) {
expenseRegister.addItem(newExpense);
}
//Updates the tableview using the register
refreshTableView();
}
//Only add the expense to the tableview, if the expense is not null
/**
* 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
*/
@FXML
public void handleDeleteBtn(ActionEvent event) {
Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem();
......@@ -176,12 +206,20 @@ public class ExpensesController {
}
}
/**
* 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.
*/
protected void refreshTableView() {
this.expenses.setAll(expenseRegister.getItems());
this.sum.setText(String.valueOf(expenseRegister.getTotalSum()));
}
/**
* 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.
*/
private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
......@@ -191,6 +229,12 @@ public class ExpensesController {
return alert.showAndWait();
}
/**
* 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>
FileHandling fileHandling = new FileHandling();
......@@ -206,16 +250,27 @@ public class ExpensesController {
return expenseRegister;
}
/**
* Saves the changes made to the expense 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.
*/
public void saveDataToFile(String fileName) throws IOException {
FileHandling fileHandling = new FileHandling();
fileHandling.writeItemRegisterToFile(expenseRegister, fileName);
}
/**
* Switches scenes from the expense scene to another, by loading a new FXML file and setting the scene to this location.
* The destination depends entirely on which button is pressed.
* @param event A button click on the buttons on the buttonbar or the next button
* @throws IOException If an error occurs with loading any of the FXML files.
*/
@FXML
public void switchScene(ActionEvent event) throws IOException {
saveDataToFile("Expense");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == incomeBtn) {
if (event.getSource() == expenseBtn) {
loader.setLocation(SceneController.class.getResource("/view/Income.fxml"));
} else if (event.getSource() == returnBtn) {
loader.setLocation(SceneController.class.getResource("/view/FirstMenu.fxml"));
......
......@@ -28,12 +28,15 @@ import no.ntnu.idatt1002.demo.data.Economics.IncomeCategory;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
import no.ntnu.idatt1002.demo.data.Economics.FileHandling;
/**
* Controller for income scene in the application. This controller manages all actions that relates to the income tableview (add, edit and delete), the switching
* of scenes from the income scene to another scene, and the saving of the table, whenever the user switches to another scene.
*
* @author Harry Linrui Xu
* @since 24.3.2023
*/
public class IncomeController {
/**
* The mode of the dialog. NEW if new contact, EDIT if edit existing contact.
*/
private DialogMode dialogMode;
@FXML
private Button addBtn;
@FXML
......@@ -81,35 +84,54 @@ public class IncomeController {
ObservableList<String> filter;
/**
* Initializes the income register, the observable income list and the tableview, along values of the dropbox used for filtering the tableview.
* The method is called each time the FXML of this scene is loaded.
* @throws IOException If there occurs any exception when loading the budget register from a file.
*/
@FXML
public void initialize() throws IOException {
//Initialize table columns
dateColumn.setCellValueFactory(new PropertyValueFactory<Income, String>("date"));
amountColumn.setCellValueFactory(new PropertyValueFactory<Income, Double>("amount"));
categoryColumn.setCellValueFactory(new PropertyValueFactory<Income, IncomeCategory>("category"));
descriptionColumn.setCellValueFactory(new PropertyValueFactory<Income, String>("description"));
recurringColumn.setCellValueFactory(new PropertyValueFactory<Income, Boolean>("recurring"));
//Initialize the filter box
filter = FXCollections.observableArrayList("All", "Gift", "Salary", "Student loan", "Fixed income");
show.setItems(filter);
show.setValue("All");
//Initialize registers and tableview
incomeRegister = loadIncomeDataFromFile("Income");
income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
//Initialize sum field under the tableview
sum.setText(String.valueOf(incomeRegister.getTotalSum()));
//if budget.register isEmpty -> disable expense
}
/**
* Method for handling the adding of new entries in the tableview.
* @param event A button click on the add button.
*/
@FXML
protected void handleAddButton(ActionEvent event) {
handleEditButton(event);
}
/**
* Method for handling the editing of a chosen entry in the tableview.
* @param event A button click on the edit button.
*/
@FXML
protected void handleEditButton(ActionEvent event) {
//Instantiate FXML loader and loads the popup for adding income
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/AddIncome.fxml"));
Income newIncome = null;
String dialogTitle = "";
// Load the FXML file for your dialog box
......@@ -126,16 +148,24 @@ public class IncomeController {
// Get the controller for the loaded FXML file
AddIncomeController dialogController = loader.getController();
/**
* The mode of the dialog. NEW if new contact, EDIT if edit existing contact.
*/
DialogMode dialogMode;
//Sets the title of the dialog box
if (event.getSource().equals(addBtn)) {
dialogMode = DialogMode.ADD;
dialogTitle = "Add income";
} else if (event.getSource().equals(editBtn)
&& incomeTableView.getSelectionModel().getSelectedItem() != null) {
}
else if (event.getSource().equals(editBtn) && incomeTableView.getSelectionModel().getSelectedItem() != null) {
dialogMode = DialogMode.EDIT;
dialogTitle = "Edit income";
//Gets the selected item from the table
newIncome = incomeTableView.getSelectionModel().getSelectedItem();
//Binds the selected item to another item which is defined in the ItemController
dialogController.setIncome(newIncome);
} else {
}
else {
return;
}
......@@ -145,19 +175,27 @@ public class IncomeController {
//Get the newly created income from the dialog pane
newIncome = dialogController.getNewIncome();
//Adds the new item to the register
if (newIncome != null && dialogMode == DialogMode.ADD) {
incomeRegister.addItem(newIncome);
}
//Updates the tableview using the register
refreshTableView();
}
//Only add the income to the tableview, if the income is not null
/**
* 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
*/
@FXML
public void handleDeleteBtn(ActionEvent event) {
//Gets the selected item from the tableview
Income chosenIncome = incomeTableView.getSelectionModel().getSelectedItem();
//Exits the method if nothing is selected
if (chosenIncome == null) {
return;
}
//Brings up a confirmation popup
Optional<ButtonType> isConfirmed = showConfirmationDialog();
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
incomeRegister.removeItem(chosenIncome);
......@@ -165,11 +203,19 @@ public class IncomeController {
}
}
/**
* 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.
*/
protected void refreshTableView() {
this.income.setAll(incomeRegister.getItems());
this.sum.setText(String.valueOf(incomeRegister.getTotalSum()));
}
/**
* 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.
*/
private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirm Delete");
......@@ -179,12 +225,18 @@ public class IncomeController {
return alert.showAndWait();
}
/**
* 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 {
FileHandling fileHandling = new FileHandling();
//Instantiate new incomeRegister
if (fileHandling.isEmpty(fileName)) {
incomeRegister = new IncomeRegister();
System.out.println("hey");
} else {
} else { //Load previous income register
try {
incomeRegister = fileHandling.readIncomeRegisterFromFile(fileName);
} catch (IOException e) {
......@@ -194,13 +246,25 @@ public class IncomeController {
return incomeRegister;
}
/**
* Saves the changes made to the income 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.
*/
public void saveDataToFile(String fileName) throws IOException {
FileHandling fileHandling = new FileHandling();
fileHandling.writeItemRegisterToFile(incomeRegister, fileName);
}
/**
* Switches scenes from the income scene to another, by loading a new FXML file and setting the scene to this location.
* The destination depends entirely on which button is pressed.
* @param event A button click on the buttons on the buttonbar or the next button
* @throws IOException If an error occurs with loading any of the FXML files.
*/
@FXML
public void switchScene(ActionEvent event) throws IOException {
//Always saving the data when switching scenes
saveDataToFile("Income");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == expenseBtn) {
......
......@@ -19,6 +19,10 @@ import no.ntnu.idatt1002.demo.data.Economics.ExpenseRegister;
import no.ntnu.idatt1002.demo.data.Economics.FileHandling;
import no.ntnu.idatt1002.demo.data.Economics.IncomeRegister;
/**
* Class that acts as both a main menu and monthly budget overview that shows the monthly progress of a users account.
* The main menu act as a hub that branches to numerous other windows, such as adding expenses or looking into food recipes.
*/
public class MainMenuController {
@FXML
......@@ -49,24 +53,36 @@ public class MainMenuController {
private Label balanceLbl;
/**
* Initializes various classes that relates to income and expense, in order to present the overview that depends on the
* income (money inflow) and expense (money outflow).
* Sets the progress bar, budget month, balance label, date and how much of the monthly budget has been spent.
* @throws IOException Upon errors with file reading/writing.
*/
@FXML
public void initialize() throws IOException {
//Instantiate the income- controller and register
IncomeController incomeController = new IncomeController();
IncomeRegister incomeRegister = incomeController.loadIncomeDataFromFile("Income");
//Instantiate the expense- controller and register
ExpensesController expensesController = new ExpensesController();
ExpenseRegister expenseRegister = expensesController.loadExpenseDataFromFile("Expense");
double incomeSum = incomeRegister.getTotalSum();
double expenseSum = expenseRegister.getTotalSum();
//Set progress
progressbar.setProgress(expenseSum/incomeSum);
progressMarker.setTranslateX(-275 + progressbar.getProgress());
//progressMarker.setTranslateX(-275 + progressbar.getProgress());
//Displaying month
budgetMonth.setText("BUDGET " + (LocalDate.EPOCH.getMonth()));
double balance = incomeSum - expenseSum;
//Set balance
balanceLbl.setText("Balance: " + (balance));
//Displaying how much of the monthly budget has been spent.
today.setText("Used " + expenseSum + " out of " + incomeSum + " this month");
if (balance < 0) {
......@@ -77,9 +93,14 @@ public class MainMenuController {
//date.restrict
}
/**
* Switches scenes from the main menu scene to another, by loading a new FXML file and setting the scene to this location.
* The destination depends entirely on which button is pressed.
* @param event A button click.
* @throws IOException If an error occurs with loading any of the FXML files.
*/
@FXML
public void switchScene(ActionEvent event) throws IOException {
//saveDataToFile("Income");
FXMLLoader loader = new FXMLLoader();
if (event.getSource() == addExpenseBtn) {
loader.setLocation(SceneController.class.getResource("/view/Expenses.fxml"));
......
......@@ -5,3 +5,7 @@ budgetAmount=500.0
budgetCategory=FOOD
budgetDescription=
budgetAmount=67.0
budgetCategory=CLOTHES
budgetDescription=
......@@ -8,8 +8,3 @@ amount=100.0
isRecurring=Recurring
category=OTHER
date=2023-03-27
amount=10000.0
isRecurring=Not recurring
category=FOOD
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment