Skip to content
Snippets Groups Projects
Commit f48bb608 authored by Harry Linrui Xu's avatar Harry Linrui Xu
Browse files

Merge branch 'button-popup' into 'master'

Added information popup to edit and delete buttons and fixed positioning of adding ingredients

See merge request !55
parents dcf16057 c997035c
Branches improving-test-coverage
No related tags found
1 merge request!55Added information popup to edit and delete buttons and fixed positioning of adding ingredients
Pipeline #220145 failed with stages
in 2 minutes and 10 seconds
......@@ -14,6 +14,7 @@ import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.PieChart.Data;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.text.Text;
import javafx.stage.Modality;
......@@ -242,6 +243,10 @@ public class BudgetController extends FinanceController {
item = budgetTableView.getSelectionModel().getSelectedItem();
//Binds the selected item to another item which is defined in the budgetcontroller
budgetController.setBudget(item);
} else if (event.getSource().equals(editBtn) && budgetTableView.getSelectionModel().getSelectedItem() == null) {
showInformationDialog("No entry selected", "Please select the entry you wish"
+ " to edit", "Click on the entry you wish to edit, then press the edit button");
return;
} else {
return;
}
......@@ -276,6 +281,8 @@ public class BudgetController extends FinanceController {
BudgetItem item = budgetTableView.getSelectionModel().getSelectedItem();
//Exits the method if nothing is selected
if (item == null) {
showInformationDialog("No entry selected", "Please select the entry you wish"
+ " to edit", "Click on the entry you wish to edit, then press the edit button");
return;
}
//Brings up a confirmation popup
......@@ -291,6 +298,22 @@ public class BudgetController extends FinanceController {
}
}
/**
* Displays an information dialog.
* @param title The dialog box title.
* @param header The dialog box header.
* @param content The dialog box content.
*/
private void showInformationDialog(String title, String header, String content) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(content);
alert.show();
}
/**
* 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.
......@@ -349,12 +372,16 @@ public class BudgetController extends FinanceController {
//Always saving the data when switching to main menu
saveDataToFile();
} else if (event.getSource() == continueBtn) {
Optional<ButtonType> isConfirmed = showConfirmationDialog("Finish setup"
, "By pressing OK you will complete the budget setup?",""
+ "Have you done all the changes you wished to make?");
if (isConfirmed.isPresent() && isConfirmed.get() == ButtonType.OK) {
loader.setLocation(getClass().getResource("/view/dualList.fxml"));
} else return;
//Adds unused categories to the table
general.addUnusedCategories();
updateBudgetRegister(FileHandlingSelectedBudget
.readSelectedBudget("budgets/SelectedBudget"));
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
//Always saving the data when switching to main menu
saveDataToFile();
......
......@@ -6,12 +6,14 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Rectangle2D;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.Stage;
import no.ntnu.idatt1002.demo.data.recipes.*;
......@@ -88,7 +90,7 @@ public class SuggestRecipesController implements Initializable {
* @throws IOException If the method is unable to set the location based on the provided path of the dialog pane.
*/
@FXML
private void addIngredient() throws IOException {
private void addIngredient(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/AddIngredient.fxml"));
DialogPane addIngredientPane = loader.load();
......@@ -97,6 +99,11 @@ public class SuggestRecipesController implements Initializable {
dialog.setDialogPane(addIngredientPane);
dialog.setTitle("Add ingredient to fridge");
//Position popup left, allowing for quick comparison between fridge and add list
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
dialog.setX((bounds.getWidth() - dialog.getWidth()) /3);
dialog.setY((bounds.getWidth() - dialog.getWidth()) /2);
Optional<ButtonType> clickedButton = dialog.showAndWait();
if (clickedButton.isPresent() && clickedButton.get() == ButtonType.CLOSE) {
......
......@@ -8,26 +8,13 @@ import java.io.FileWriter;
import java.io.IOException;
//Set titler på hvert vindu - kan gjøres i switch scene
//capsing av titler og font sizing
//HS vindu litt lit venster slik at kjøleskap og søk funker
//Popup for edit og delete button
//Close program properly
//close button i first menu
//remove printstackstraces
//En delete funksjon i select old budget
//Endre pakkenavn
//Public vs private metoder må sjekkes
//confirmation for når returnBtn som returner til start. "Are you sure you want to go back. Changes will not be saved"
// FIKSE TRY CATCHES I ALLE METODENE!!!!!!!!!!
//Bytte oversikt på dualList til Monthly ....
//System.out.println(System.getProperty("user.dir") + path); =
//C:\Users\xulr0\IdeaProjects\skoleProsjekter\idatt1002\idatt1002_2023_9src/main/resources/
//(System.getProperty("user.dir") + "/" + path) =
//(path) =
//(src/main/resources)
/**
* Class that handles the reading and writing to the budget archive file,
......
package no.ntnu.idatt1002.demo.data.Budget;
import javafx.scene.control.ProgressBar;
/**
* Class that represents the main menu category progress bars. Each bar
* is associated with a corresponding expense category.
*
* @author Anders Emil Bergan.
* @since 17.04.2023.
*/
public class MMBI {
private ProgressBar progressBar;
private BudgetItem budgetItem;
/**
* Constructor for creating a MMBI.
* @param item The budget item.
* @param bar The progress bar.
*/
public MMBI(BudgetItem item, ProgressBar bar){
this.budgetItem = item;
this.progressBar = bar;
}
/**
* Gets the budget item.
* @return the budget item.
*/
public BudgetItem getBudgetItem(){
return budgetItem;
}
/**
* Sets the budget item to the argument value.
* @param item The value to which the budget item will be set.
*/
public void setBudgetItem(BudgetItem item){
this.budgetItem = item;
}
/**
* Gets the progress bar.
* @return the progress bar.
*/
public ProgressBar getBar(){
return progressBar;
}
/**
* Sets the progress bar to the argument value.
* @param bar The value to which the progress bar will be set.
*/
public void setProgressBar(ProgressBar bar){
this.progressBar = bar;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<DialogPane id="dialog-pane" expanded="true" prefHeight="555.0" prefWidth="614.0" stylesheets="@../style.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.AddIngredientController">
<DialogPane id="dialog-pane" expanded="true" prefHeight="555.0" prefWidth="614.0" stylesheets="@../style.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.AddIngredientController">
<content>
<AnchorPane prefHeight="400.0" prefWidth="600.0">
<padding>
......@@ -74,7 +82,7 @@
<children>
<Pane prefHeight="100.0" prefWidth="543.0">
<children>
<Label layoutX="19.0" layoutY="30.0" prefWidth="516.0" styleClass="head-line" stylesheets="@../style.css" text="Add ingredients to Fridge">
<Label layoutX="121.0" layoutY="28.0" prefWidth="516.0" styleClass="head-line" stylesheets="@../style.css" text="Add ingredients">
<font>
<Font size="30.0" />
</font>
......
......@@ -128,7 +128,7 @@
<center>
<Pane BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="filter" layoutX="134.0" layoutY="2.0" prefWidth="150.0" promptText="Show">
<ComboBox fx:id="filter" disable="true" layoutX="134.0" layoutY="2.0" opacity="0.0" prefWidth="150.0" promptText="Show">
<opaqueInsets>
<Insets />
</opaqueInsets>
......
......@@ -117,7 +117,7 @@
<center>
<Pane BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="filter" layoutX="74.0" layoutY="19.0" prefWidth="150.0" promptText="Show">
<ComboBox fx:id="filter" disable="true" layoutX="74.0" layoutY="19.0" opacity="0.0" prefWidth="150.0" promptText="Show">
<opaqueInsets>
<Insets />
</opaqueInsets>
......
......@@ -181,7 +181,7 @@
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="42.0" prefWidth="106.0" GridPane.columnIndex="1">
<children>
<ComboBox fx:id="filter" prefHeight="25.0" prefWidth="80.0" promptText="Show">
<ComboBox fx:id="filter" disable="true" opacity="0.0" prefHeight="25.0" prefWidth="80.0" promptText="Show">
<opaqueInsets>
<Insets />
</opaqueInsets>
......
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