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

"Added context menus to income and expenses"

parent 6674f11b
No related branches found
No related tags found
5 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.,!31Added input validation to tableviews
...@@ -113,6 +113,19 @@ public class IncomeExpenseController implements FinanceController { ...@@ -113,6 +113,19 @@ public class IncomeExpenseController implements FinanceController {
@FXML @FXML
private Label title; private Label title;
@FXML
private MenuItem editIncomeMenu;
@FXML
private MenuItem deleteIncomeMenu;
@FXML
private MenuItem editExpenseMenu;
@FXML
private MenuItem deleteExpenseMenu;
private IncomeRegister incomeRegister; private IncomeRegister incomeRegister;
private ExpenseRegister expenseRegister; private ExpenseRegister expenseRegister;
...@@ -232,23 +245,32 @@ public class IncomeExpenseController implements FinanceController { ...@@ -232,23 +245,32 @@ public class IncomeExpenseController implements FinanceController {
* @param event A button click on the edit button. * @param event A button click on the edit button.
*/ */
@Override @Override
public void handleEditBtn(javafx.event.ActionEvent event) { public void handleEditBtn(javafx.event.ActionEvent event) {
System.out.println(event.getSource());
Income chosenIncome = incomeTableView.getSelectionModel().getSelectedItem(); Income chosenIncome = incomeTableView.getSelectionModel().getSelectedItem();
Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem(); Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem();
if (event.getSource() == editBtn) { System.out.println(chosenIncome);
if (chosenIncome!= null) { System.out.println(chosenExpense);
if (chosenIncome != null) {
if (event.getSource() == editBtn || event.getSource() == editIncomeMenu) {
handleEditIncome(chosenIncome); handleEditIncome(chosenIncome);
} else if (chosenExpense != null) { System.out.println(1);
handleEditExpense(chosenExpense); } else if (event.getSource() == deleteIncomeMenu) {
} else return;
} else if (event.getSource() == deleteBtn) {
if (chosenIncome != null) {
handleDeleteIncome(chosenIncome); handleDeleteIncome(chosenIncome);
} else if (chosenExpense != null) { System.out.println(2);
} else return;
} else if (chosenExpense != null) {
if (event.getSource() == editBtn || event.getSource() == editExpenseMenu) {
handleEditExpense(chosenExpense);
System.out.println(3);
} else if (event.getSource() == deleteExpenseMenu) {
handleDeleteExpense(chosenExpense); handleDeleteExpense(chosenExpense);
System.out.println(4);
} else return; } else return;
} } else return;
//Updates the tableview and pie chart using the register //Updates the tableview and pie chart using the register
refreshTableView(); refreshTableView();
refreshPieCharts(); refreshPieCharts();
......
...@@ -2,8 +2,15 @@ ...@@ -2,8 +2,15 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?> <?import javafx.scene.Cursor?>
<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?> <?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
<?import javafx.scene.image.Image?> <?import javafx.scene.image.Image?>
...@@ -13,17 +20,15 @@ ...@@ -13,17 +20,15 @@
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?> <?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.IncomeController"> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="695.0" prefWidth="1130.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.IncomeExpenseController">
<children> <children>
<ImageView fitHeight="400.0" fitWidth="600.0" pickOnBounds="true"> <ImageView fitHeight="695.0" fitWidth="1130.0" pickOnBounds="true">
<image> <image>
<Image url="@../Images/backgroundMini.jpg" /> <Image url="@../Images/backgroundMini.jpg" />
</image> </image>
...@@ -31,72 +36,78 @@ ...@@ -31,72 +36,78 @@
<Cursor fx:constant="DEFAULT" /> <Cursor fx:constant="DEFAULT" />
</cursor> </cursor>
</ImageView> </ImageView>
<BorderPane prefHeight="400.0" prefWidth="600.0"> <VBox prefHeight="695.0" prefWidth="1100.0">
<top> <children>
<HBox BorderPane.alignment="CENTER"> <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="143.0" prefWidth="1100.0">
<children> <right>
<Button fx:id="returnBtn" mnemonicParsing="false" onAction="#switchScene" text="Return "> <Pane BorderPane.alignment="CENTER">
<opaqueInsets> <children>
<Insets left="100.0" /> <Label fx:id="daysLeftLbl" layoutX="27.0" layoutY="83.0" text="Days left: 31">
</opaqueInsets> <font>
<HBox.margin> <Font name="Lucida Console" size="14.0" />
<Insets left="10.0" top="10.0" /> </font>
</HBox.margin> </Label>
</Button> <DatePicker fx:id="date" layoutX="-4.0" layoutY="55.0" prefWidth="175.0" />
<Region prefHeight="70.0" prefWidth="141.0" /> </children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Income" textAlignment="CENTER" wrappingWidth="174.6796875"> </Pane>
<HBox.margin> </right>
<Insets /> <left>
</HBox.margin> <Pane prefWidth="175.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="returnBtn" alignment="CENTER" layoutX="-2.0" layoutY="58.0" mnemonicParsing="false" onAction="#returnToMainMenu" text="Return to Main Menu">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Button>
</children>
</Pane>
</left>
<center>
<Label fx:id="title" text="INCOME AND EXPENSES" textAlignment="CENTER" BorderPane.alignment="CENTER">
<font> <font>
<Font size="48.0" /> <Font name="Lucida Console" size="48.0" />
</font> </font>
</Text> </Label>
</children> </center>
<opaqueInsets> <VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> <Insets left="15.0" />
</opaqueInsets> </VBox.margin>
</HBox> </BorderPane>
</top> <BorderPane prefHeight="64.0" prefWidth="1100.0">
<center> <left>
<GridPane BorderPane.alignment="CENTER"> <HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="40.0" left="40.0" right="40.0" />
</BorderPane.margin>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" maxWidth="485.3333231608073" minWidth="10.0" prefWidth="427.33335367838544" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="111.33333333333331" minWidth="10.0" prefWidth="92.66664632161456" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="65.33334064483643" minHeight="10.0" prefHeight="65.33334064483643" vgrow="SOMETIMES" />
<RowConstraints maxHeight="298.66665744781494" minHeight="10.0" prefHeight="214.00004069010413" vgrow="SOMETIMES" />
<RowConstraints maxHeight="298.66665744781494" minHeight="10.0" prefHeight="29.999959309895814" vgrow="SOMETIMES" />
<RowConstraints maxHeight="298.66665744781494" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<HBox alignment="BOTTOM_LEFT" prefWidth="410.0" spacing="5.0">
<children> <children>
<Button fx:id="addBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleAddButton" text="Add" textAlignment="CENTER"> <MenuButton mnemonicParsing="false" prefHeight="25.0" prefWidth="50.0">
<items>
<MenuItem fx:id="addIncome" mnemonicParsing="false" onAction="#handleAddBtn" text="Income" />
<MenuItem fx:id="addExpense" mnemonicParsing="false" onAction="#handleAddBtn" text="Expense" />
</items>
<graphic> <graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="30.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
<Image url="@../Images/add_image.png" /> <Image url="@../Images/add.png" />
</image> </image>
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </MenuButton>
<Button fx:id="editBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleEditButton" text="Edit" textAlignment="CENTER"> <Button fx:id="editBtn" mnemonicParsing="false" onAction="#handleEditBtn" prefHeight="25.0" prefWidth="60.0">
<font>
<Font name="Lucida Console" size="12.0" />
</font>
<graphic> <graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="30.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
<Image url="@../Images/edit.png" /> <Image url="@../Images/edit.png" />
</image> </image>
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="deleteBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" textAlignment="CENTER"> <Button fx:id="deleteBtn" mnemonicParsing="false" onAction="#handleDeleteBtn" prefHeight="25.0" prefWidth="60.0">
<font>
<Font name="Lucida Console" size="12.0" />
</font>
<graphic> <graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="30.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
<Image url="@../Images/delete.png" /> <Image url="@../Images/delete.png" />
</image> </image>
...@@ -104,86 +115,143 @@ ...@@ -104,86 +115,143 @@
</graphic> </graphic>
</Button> </Button>
</children> </children>
<opaqueInsets> <BorderPane.margin>
<Insets /> <Insets left="30.0" />
</opaqueInsets> </BorderPane.margin>
<padding>
<Insets bottom="5.0" />
</padding>
</HBox> </HBox>
<VBox alignment="BOTTOM_LEFT" prefHeight="200.0" prefWidth="100.0" spacing="5.0" GridPane.columnIndex="1"> </left>
<right>
<Pane BorderPane.alignment="CENTER">
<children> <children>
<ComboBox fx:id="show" prefWidth="150.0" promptText="Show "> <ProgressBar fx:id="budgetProgress" prefWidth="200.0" progress="0.0" />
</children>
</Pane>
</right>
<opaqueInsets>
<Insets />
</opaqueInsets>
<VBox.margin>
<Insets left="10.0" right="15.0" />
</VBox.margin>
<center>
<Pane BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="filter" layoutX="134.0" layoutY="2.0" prefWidth="150.0" promptText="Show">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</ComboBox> </ComboBox>
</children> </children>
</Pane>
</center>
</BorderPane>
<GridPane prefHeight="473.0" prefWidth="1055.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="5.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="4.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox maxWidth="490.0" prefHeight="215.0" prefWidth="490.0" GridPane.rowIndex="1">
<children>
<TableView fx:id="incomeTableView" maxHeight="175.0" prefHeight="175.0" prefWidth="264.0">
<columns>
<TableColumn fx:id="inDateCol" prefWidth="75.0" text="Date" />
<TableColumn fx:id="inAmountCol" prefWidth="75.0" text="Amount" />
<TableColumn fx:id="inCategoryCol" prefWidth="75.0" text="Category" />
<TableColumn fx:id="inDescriptionCol" prefWidth="75.0" text="Description" />
<TableColumn fx:id="inRecurringCol" prefWidth="75.0" text="Recurring" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="handleDeleteIncome" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete " />
</items>
</ContextMenu>
</contextMenu>
</TableView>
<Label text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
</VBox> </VBox>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="3"> <Pane GridPane.columnIndex="1" GridPane.rowIndex="1">
<children> <children>
<Button disable="true" mnemonicParsing="false" text="Income" /> <PieChart fx:id="incomePieChart" layoutX="4.0" layoutY="-41.0" legendSide="RIGHT" maxHeight="244.0" maxWidth="512.0" prefHeight="244.0" prefWidth="350.0" title="Income" />
<Button fx:id="budgetBtn" mnemonicParsing="false" onAction="#switchScene" text="Budget" />
<Button fx:id="expenseBtn" mnemonicParsing="false" onAction="#switchScene" text="Expenses" />
<Button mnemonicParsing="false" onAction="#switchScene" text="Next">
<HBox.margin>
<Insets left="170.0" />
</HBox.margin>
</Button>
</children> </children>
<padding> </Pane>
<Insets top="10.0" /> <Pane GridPane.columnIndex="1" GridPane.rowIndex="3">
</padding> <children>
</HBox> <PieChart fx:id="expensePieChart" layoutX="-2.0" layoutY="-37.0" legendSide="RIGHT" maxHeight="261.0" maxWidth="519.0" prefHeight="237.0" prefWidth="350.0" title="Expenses" />
<TableView fx:id="incomeTableView" prefHeight="260.0" prefWidth="485.0" GridPane.columnSpan="2" GridPane.rowIndex="1"> </children>
<columns> </Pane>
<TableColumn fx:id="dateColumn" prefWidth="75.0" text="Date" /> <Pane prefHeight="20.0" prefWidth="1046.0">
<TableColumn fx:id="amountColumn" prefWidth="75.0" text="Amount" /> <children>
<TableColumn fx:id="categoryColumn" prefWidth="75.0" text="Category" /> <Text layoutY="16.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Income" textAlignment="CENTER">
<TableColumn fx:id="descriptionColumn" prefWidth="75.0" text="Description" /> <font>
<TableColumn fx:id="recurringColumn" prefWidth="75.0" text="Recurring" /> <Font name="Lucida Console" size="14.0" />
</columns> </font>
<columnResizePolicy> </Text>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> </children>
</columnResizePolicy> </Pane>
</TableView> <VBox GridPane.rowIndex="3">
<StackPane GridPane.rowIndex="2"> <children>
<TableView fx:id="expenseTableView" maxHeight="175.0" maxWidth="490.0" prefHeight="172.0" prefWidth="264.0">
<columns>
<TableColumn fx:id="expDateCol" prefWidth="75.0" text="Date" />
<TableColumn fx:id="expAmountCol" prefWidth="75.0" text="Amount" />
<TableColumn fx:id="expCategoryCol" prefWidth="75.0" text="Category" />
<TableColumn fx:id="expDescriptionCol" prefWidth="75.0" text="Description" />
<TableColumn fx:id="expRecurringCol" prefWidth="75.0" text="Recurring" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="handleDeleteExpense" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" />
</items>
</ContextMenu>
</contextMenu>
</TableView>
<Label text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
</VBox>
<Pane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
<children> <children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#f8f8f8" height="18.0" stroke="#d9cccc" strokeType="INSIDE" width="209.0" StackPane.alignment="CENTER_LEFT" /> <Text layoutY="14.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Expenses" textAlignment="CENTER">
<HBox prefHeight="18.0" prefWidth="517.0"> <font>
<children> <Font name="Lucida Console" size="14.0" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Sum: "> </font>
<HBox.margin> </Text>
<Insets left="2.0" />
</HBox.margin>
</Text>
<Region prefHeight="18.0" prefWidth="74.0" />
<Text fx:id="sum" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />
</children>
</HBox>
</children> </children>
</StackPane> </Pane>
</children> </children>
<padding>
<Insets left="10.0" />
</padding>
<VBox.margin>
<Insets left="30.0" right="30.0" />
</VBox.margin>
</GridPane> </GridPane>
</center> </children>
<opaqueInsets> </VBox>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
<left>
<Region prefHeight="330.0" prefWidth="1.0" BorderPane.alignment="CENTER" />
</left>
<right>
<Region prefHeight="357.0" prefWidth="0.0" BorderPane.alignment="CENTER" />
</right>
<bottom>
<Region prefHeight="0.0" prefWidth="600.0" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane>
</children> </children>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
</AnchorPane> </AnchorPane>
...@@ -173,7 +173,8 @@ ...@@ -173,7 +173,8 @@
<contextMenu> <contextMenu>
<ContextMenu> <ContextMenu>
<items> <items>
<MenuItem mnemonicParsing="false" text="Unspecified Action" /> <MenuItem fx:id="editIncomeMenu" mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="deleteIncomeMenu" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete " />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
...@@ -220,7 +221,8 @@ ...@@ -220,7 +221,8 @@
<contextMenu> <contextMenu>
<ContextMenu> <ContextMenu>
<items> <items>
<MenuItem mnemonicParsing="false" text="Unspecified Action" /> <MenuItem fx:id="editExpenseMenu" mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="deleteExpenseMenu" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" />
</items> </items>
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
......
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