Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2023_9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kluge Svendsrud
idatt1002_2023_9
Commits
577b2c7d
Commit
577b2c7d
authored
1 year ago
by
Harry Linrui XU
Browse files
Options
Downloads
Patches
Plain Diff
Made entries double-clickable when choosing budget
parent
ac064e62
No related branches found
No related tags found
1 merge request
!51
Added javadoc to all methods
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/ntnu/idatt1002/demo/controller/SelectBudgetController.java
+55
-9
55 additions, 9 deletions
...tnu/idatt1002/demo/controller/SelectBudgetController.java
with
55 additions
and
9 deletions
src/main/java/no/ntnu/idatt1002/demo/controller/SelectBudgetController.java
+
55
−
9
View file @
577b2c7d
...
...
@@ -4,16 +4,21 @@ import java.io.IOException;
import
javafx.collections.FXCollections
;
import
javafx.collections.ObservableList
;
import
javafx.event.ActionEvent
;
import
javafx.event.Event
;
import
javafx.fxml.FXML
;
import
javafx.scene.Node
;
import
javafx.scene.control.Alert
;
import
javafx.scene.control.Alert.AlertType
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.Label
;
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.FileHandlingBudgetArchive
;
import
no.ntnu.idatt1002.demo.data.Budget.FileHandlingSelectedBudget
;
import
no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory
;
/**
* Class for selecting a budget from the archive.
...
...
@@ -34,10 +39,14 @@ public class SelectBudgetController {
private
BudgetRegister
budgetRegister
;
private
ObservableList
<
String
>
budgetList
;
/**
* Initializes the view when it is loaded. Prepares the view by adding event filters,
* instantiating the budget register and setting the list view.
* @throws IOException
*/
@FXML
public
void
initialize
()
throws
IOException
{
//Prevent users from choosing nothing
okBtn
.
addEventFilter
(
ActionEvent
.
ACTION
,
event
->
{
if
(
budgetListView
.
getSelectionModel
().
getSelectedItem
()
==
null
)
{
...
...
@@ -46,6 +55,7 @@ public class SelectBudgetController {
}
});
//Load budget register from file.
try
{
if
(
FileHandlingBudgetArchive
.
isBudgetRegisterEmpty
(
"budgets/Archive"
))
{
budgetRegister
=
new
BudgetRegister
();
...
...
@@ -56,32 +66,68 @@ public class SelectBudgetController {
ioe
.
printStackTrace
();
}
System
.
out
.
println
(
"budget register is: "
+
budgetRegister
);
budgetList
=
FXCollections
.
observableList
(
budgetRegister
.
getBudgetNames
());
ObservableList
<
String
>
budgetList
=
FXCollections
.
observableList
(
budgetRegister
.
getBudgetNames
());
budgetListView
.
setItems
(
budgetList
);
//Double clicking the entry also chooses it
budgetListView
.
setOnMouseClicked
(
mouseEvent
->
{
if
(
mouseEvent
.
getButton
().
equals
(
MouseButton
.
PRIMARY
)){
if
(
mouseEvent
.
getClickCount
()
==
2
){
System
.
out
.
println
(
"Double clicked"
);
selectBudget
(
mouseEvent
);
}
}
});
}
/**
* Selects the budget in the budget list view and stores this value as
* the currently selected budget.
* @param event Double mouseclick or a click on the ok button.
*/
@FXML
public
void
selectBudget
(
ActionEvent
event
)
throws
IOException
{
String
name
=
budgetListView
.
getSelectionModel
().
getSelectedItem
();
FileHandlingSelectedBudget
.
updateSelectedBudget
(
name
,
"budgets/SelectedBudget"
);
public
void
selectBudget
(
Event
event
)
{
try
{
String
name
=
budgetListView
.
getSelectionModel
().
getSelectedItem
();
FileHandlingSelectedBudget
.
updateSelectedBudget
(
name
,
"budgets/SelectedBudget"
);
}
catch
(
IOException
ioe
)
{
showErrorDialogBox
(
ioe
.
getMessage
(),
ioe
.
getMessage
(),
ioe
.
getMessage
());
}
final
Node
source
=
(
Node
)
event
.
getSource
();
((
Stage
)
source
.
getScene
().
getWindow
()).
close
();
}
/**
* Closes the dialog box and clears the currently selected budget.
* @param event Button press on cancel button
*/
@FXML
public
void
exitWindow
(
ActionEvent
event
)
throws
IOException
{
FileHandlingSelectedBudget
.
clearSelectedBudget
(
"budgets/SelectedBudget"
);
public
void
exitWindow
(
ActionEvent
event
)
{
try
{
FileHandlingSelectedBudget
.
clearSelectedBudget
(
"budgets/SelectedBudget"
);
}
catch
(
IOException
ioe
)
{
showErrorDialogBox
(
ioe
.
getMessage
(),
ioe
.
getMessage
(),
ioe
.
getMessage
());
}
final
Node
source
=
(
Node
)
event
.
getSource
();
((
Stage
)
source
.
getScene
().
getWindow
()).
close
();
}
/**
* Displays an error message dialog box with a customizable title, header and content.
* @param title The dialog title.
* @param header The dialog header.
* @param content The dialog content.
*/
public
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
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment