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

Created controller for selecting budget (listview) + added method for switching to main menu

parent 9e493022
No related branches found
No related tags found
1 merge request!43Merging frontend-testing into master
......@@ -20,6 +20,7 @@ import javafx.stage.Modality;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.FileHandlingBudget;
import no.ntnu.idatt1002.demo.data.Economics.Expense;
import no.ntnu.idatt1002.demo.data.Economics.Income;
public class SceneController {
......@@ -69,7 +70,7 @@ public class SceneController {
dialog.showAndWait();
try {
if (FileHandlingBudget.readCurrentFile("CurrentFile") != null) {
if (FileHandlingBudget.readCurrentFile() != null) {
switchNext(event);
}
} catch (IOException ioe) {
......@@ -77,8 +78,7 @@ public class SceneController {
}
}
private void switchNext(ActionEvent event) {
try {
private void switchNext(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(SceneController.class.getResource("/view/dualList.fxml"));
Parent root = loader.load();
......@@ -86,9 +86,6 @@ public class SceneController {
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch(IOException ioe) {
showErrorDialogBox("", "", "");
}
}
private void showErrorDialogBox(String title, String header, String content) {
Alert alert = new Alert(AlertType.ERROR);
......@@ -100,7 +97,38 @@ public class SceneController {
}
public void switchMainMenu(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/MainMenuNew.fxml"));
FXMLLoader loader = new FXMLLoader();
loader.setLocation(SceneController.class.getResource("/view/SelectBudget.fxml"));
String dialogTitle = "Select budget";
// Load the FXML file for your dialog box
Dialog<Income> dialog = new Dialog<>();
try {
// Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) {
showErrorDialogBox("Loading error", "Error in loading dialog box", "Could not load"
+ "the AddIncome window");
}
//Sets the title of the dialog box
dialog.setTitle(dialogTitle);
// Show the Dialog and wait for the user to close it
dialog.showAndWait();
try {
if (FileHandlingBudget.readCurrentFile() != null) {
switchChosenBudget(event);
}
} catch(IOException ioe) {
showErrorDialogBox("Loading error", "Could not switch to main menu", "");
}
}
private void switchChosenBudget(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(SceneController.class.getResource("/view/MainMenuNew.fxml"));
Parent root = loader.load();
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
......
package no.ntnu.idatt1002.demo.controller;
import java.io.IOException;
import java.util.Collection;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.Budget.BudgetRegister;
import no.ntnu.idatt1002.demo.data.Budget.FileHandlingBudget;
import no.ntnu.idatt1002.demo.data.Budget.GeneralBudget;
public class SelectBudgetController {
@FXML
private ListView<String> budgetListView;
private BudgetRegister budgetRegister;
private ObservableList<String> budgetList;
@FXML
public void initialize() throws IOException {
budgetRegister = FileHandlingBudget.readBudgetArchive("");
System.out.println(budgetRegister);
System.out.println(budgetRegister.getBudgetNames().size());
System.out.println("this is budgetRegisr: " + budgetRegister);
budgetList = FXCollections.observableList(budgetRegister.getBudgetNames());
budgetListView.setItems(budgetList);
budgetListView.setOnMouseClicked(mouseEvent-> {
if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
if(mouseEvent.getClickCount() == 2){
System.out.println("Double clicked");
}
}
});
}
@FXML
public void selectBudget(ActionEvent event) throws IOException {
String name = budgetListView.getSelectionModel().getSelectedItem();
System.out.println(name);
FileHandlingBudget.updateCurrentFile(name);
final Node source = (Node) event.getSource();
((Stage) source.getScene().getWindow()).close();
}
@FXML
public void exitWindow(ActionEvent event) throws IOException {
FileHandlingBudget.updateCurrentFile("");
final Node source = (Node) event.getSource();
((Stage) source.getScene().getWindow()).close();
}
}
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