From 5bdfe7eef109f15549e05f154e025680a4d52642 Mon Sep 17 00:00:00 2001 From: Harry Linrui XU <xulr0820@hotmail.com> Date: Tue, 18 Apr 2023 08:21:56 +0200 Subject: [PATCH] Override inherited methods in BudgetController --- .../demo/controller/BudgetController.java | 65 ++++--------------- 1 file changed, 11 insertions(+), 54 deletions(-) diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java index ada81e37..87acb2d5 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/BudgetController.java @@ -30,6 +30,7 @@ import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory; import java.io.IOException; import java.util.Optional; +import org.apache.commons.compress.compressors.zstandard.ZstdUtils; /** * Controller for budget scene in the application. This controller manages all actions that relates to the budget tableview (add, edit and delete), the switching @@ -38,7 +39,7 @@ import java.util.Optional; * @author Anders Emil Bergan * @since 24.3.2023 */ -public class BudgetController implements FinanceController { +public class BudgetController extends FinanceController { private GeneralBudget general; @@ -122,7 +123,7 @@ public class BudgetController implements FinanceController { formatDatePicker(); } - private ObservableList<PieChart.Data> createBudgetPieChart() throws IllegalArgumentException { // + public ObservableList<PieChart.Data> createPieChart() throws IllegalArgumentException { // ObservableList<PieChart.Data> budgetData = FXCollections.observableArrayList(); List<ExpenseCategory> chosenCategories = general.getChosenBudgetCategories(); @@ -144,14 +145,16 @@ public class BudgetController implements FinanceController { ); }*/ - private void refreshPieChart() { - this.budgetPieChart.setData(createBudgetPieChart()); + @Override + public void refreshPieChart() { + this.budgetPieChart.setData(createPieChart()); } /** * Method for disabling the date picker, yet having its opacity at max. */ - private void formatDatePicker() { + @Override + public void formatDatePicker() { date.setValue(LocalDate.now()); date.setDisable(true); date.setStyle("-fx-opacity: 1"); @@ -251,26 +254,13 @@ public class BudgetController implements FinanceController { * 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(){ this.budgetList.setAll(general.getBudgetItems()); //Refreshing the sum of the amounts of the budget //this.sum.setText(String.valueOf(general.totalSum())); } - /** - * 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(String title, String header, String content) { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION); - alert.setTitle("Confirm Delete"); - alert.setHeaderText("Delete Confirmation"); - alert.setContentText("Are you sure you would like to delete the selected entry?"); - - return alert.showAndWait(); - } - /** * Saves the changes made to the tableview by writing the information to a file. * @@ -281,44 +271,11 @@ public class BudgetController implements FinanceController { FileHandlingBudget.writeGeneralBudgetToFile("Budget", general); } - /** - * Displays an alert box of type error, informing of a custom error. - */ - private void showErrorDialogBox(String title, String header, String content) { - Alert alert = new Alert(AlertType.ERROR); - alert.setTitle(title); - alert.setHeaderText(header); - alert.setContentText(content); - alert.showAndWait(); - } - - /** - * 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 { - //Instantiate new budget - if (FileHandlingBudget.isEmpty(fileName)) { - general = new GeneralBudget(1000); - //throws new IOException("Not valid budget") - } else { //Load previous budget - try { - general = FileHandlingBudget.readGeneralBudgetFromFile(fileName); - } catch (IOException e) { - showErrorDialogBox("File error", "Error in reading from fil", "An error occurred" - + "when reading GeneralBudget from the file"); - } - } - return general; - } - /** * Switches scene, by loading a new FXML file and setting the scene to this location. * @param event A button click on the return to main menu button */ - @FXML + @Override public void switchScene(ActionEvent event) { FXMLLoader loader = new FXMLLoader(); try { @@ -326,11 +283,11 @@ public class BudgetController implements FinanceController { //Adds unused categories to the table general.addUnusedCategories(); //Always saving the data when switching scenes - saveDataToFile(); loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml")); } else if (event.getSource() == backBtn) { loader.setLocation(getClass().getResource("/view/dualList.fxml")); } + saveDataToFile(); Parent root = loader.load(); Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); Scene scene = new Scene(root); -- GitLab