Skip to content
Snippets Groups Projects
MainMenu.java 3.72 KiB
Newer Older
package no.ntnu.idatt1002.demo.controller;

import java.io.IOException;
import java.time.LocalDate;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.FileHandlingBudget;
import no.ntnu.idatt1002.demo.data.Budget.GeneralBudget;

public class MainMenu {

  @FXML
  private ProgressBar bookBar;

  @FXML
  private Label bookLbl;

  @FXML
  private Button budgetBtn;

  @FXML
  private ProgressBar clothesBar;

  @FXML
  private Label clothesLbl;

  @FXML
  private DatePicker date;

  @FXML
  private Button expenseBtn;

  @FXML
  private ProgressBar foodBar;

  @FXML
  private Button foodBtn;

  @FXML
  private Label foodLbl;

  @FXML
  private Button incomeBtn;

  @FXML
  private ProgressBar mainBar;

  @FXML
  private ProgressBar otherBar;

  @FXML
  private Label otherLbl;

  @FXML
  private Button returnBtn;

  @FXML
  private Label title;

  GeneralBudget generalBudget;

  @FXML
  public void initialize() {
    /*general = loadBudgetDataFromFile("Budget");
    budgetList = FXCollections.observableArrayList(general.getBudgetItems());
    budgetTableView.setItems(budgetList);*/

    title.setText("BUDGET" + LocalDate.EPOCH);
    date.setValue(LocalDate.now());

  }

/*
  /**
   * 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)) {
      general = new GeneralBudget(31, 1000);
    } else { //Load previous budget
      try {
        general = fileHandlingBudget.readGeneralBudgetFromFile(fileName);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return general;
  }

  /**
   * Saves the changes made to the budget 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 {
    FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
    fileHandlingBudget.writeGeneralBudgetToFile(fileName, general);
  }
*/
  @FXML
  private void switchScene(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader();
    if (event.getSource() == foodBtn) {
      System.out.println("Food button pressed");
    } else if (event.getSource() == expenseBtn) {
      loader.setLocation(SceneController.class.getResource("/view/Expenses.fxml"));
    }  else if (event.getSource() == incomeBtn) {
      loader.setLocation(SceneController.class.getResource("/view/Income.fxml"));
    } else if (event.getSource() == budgetBtn) {
      loader.setLocation(SceneController.class.getResource("/view/BudgetNew.fxml"));
    } else if (event.getSource() == returnBtn) {
      loader.setLocation(SceneController.class.getResource("/view/FirstMenu.fxml"));
    }
    Parent root = loader.load();
    Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }
}