Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tasty Pages
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SE2 Projekt
Tasty Pages
Commits
9e08c410
Commit
9e08c410
authored
1 year ago
by
Karsch Lukas
Browse files
Options
Downloads
Patches
Plain Diff
included nutrition table files
parent
ee4fbeb7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/mi/hdm/controllers/components/NutritionTableController.java
+92
-0
92 additions, 0 deletions
.../hdm/controllers/components/NutritionTableController.java
src/main/resources/fxml/components/nutrition-table.fxml
+140
-0
140 additions, 0 deletions
src/main/resources/fxml/components/nutrition-table.fxml
with
232 additions
and
0 deletions
src/main/java/mi/hdm/controllers/components/NutritionTableController.java
0 → 100644
+
92
−
0
View file @
9e08c410
package
mi.hdm.controllers.components
;
import
javafx.fxml.FXML
;
import
javafx.scene.control.ProgressBar
;
import
javafx.scene.paint.Color
;
import
javafx.scene.text.Text
;
import
mi.hdm.recipes.Nutrition
;
import
mi.hdm.recipes.NutritionTable
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
java.math.BigDecimal
;
import
java.util.Map
;
public
class
NutritionTableController
{
private
final
static
Logger
log
=
LogManager
.
getLogger
(
NutritionTableController
.
class
);
private
final
NutritionTable
nutritionTable
;
private
final
String
text
;
@FXML
private
ProgressBar
caloriesProgressBar
;
@FXML
private
ProgressBar
carbsProgressBar
;
@FXML
private
ProgressBar
fatProgressbar
;
@FXML
private
ProgressBar
proteinProgressBar
;
@FXML
private
ProgressBar
fibersProgressBar
;
@FXML
private
ProgressBar
saltProgressBar
;
@FXML
private
Text
caloriesPercentage
;
@FXML
private
Text
carbsPercentage
;
@FXML
private
Text
fatPercentage
;
@FXML
private
Text
proteinPercentage
;
@FXML
private
Text
fiberPercentage
;
@FXML
private
Text
saltPercentage
;
@FXML
private
Text
description
;
public
NutritionTableController
(
NutritionTable
nutritionTable
,
String
text
)
{
this
.
nutritionTable
=
nutritionTable
;
this
.
text
=
text
;
}
@FXML
public
void
initialize
()
{
description
.
setText
(
text
);
drawNutritionTable
();
}
private
void
drawNutritionTable
()
{
log
.
debug
(
"Drawing nutrition table for meal plan."
);
final
Map
<
Nutrition
,
BigDecimal
>
weeklyNutrition
=
nutritionTable
.
getTable
();
//calculate percentage of weekly recommended dosage
double
cals
=
weeklyNutrition
.
get
(
Nutrition
.
CALORIES
).
doubleValue
()
/
(
NutritionTable
.
CALORIES_DAILY
*
7
);
double
carbs
=
weeklyNutrition
.
get
(
Nutrition
.
CARBS
).
doubleValue
()
/
(
NutritionTable
.
CARBS_DAILY
*
7
);
double
fat
=
weeklyNutrition
.
get
(
Nutrition
.
FAT
).
doubleValue
()
/
(
NutritionTable
.
FAT_DAILY
*
7
);
double
protein
=
weeklyNutrition
.
get
(
Nutrition
.
PROTEINS
).
doubleValue
()
/
(
NutritionTable
.
DAILY_PROTEIN
*
7
);
double
fiber
=
weeklyNutrition
.
get
(
Nutrition
.
FIBERS
).
doubleValue
()
/
(
NutritionTable
.
DAILY_FIBER
*
7
);
double
salt
=
weeklyNutrition
.
get
(
Nutrition
.
SALT
).
doubleValue
()
/
(
NutritionTable
.
DAILY_SALT
*
7
);
//update gui
setPercentage
(
caloriesProgressBar
,
caloriesPercentage
,
cals
);
setPercentage
(
carbsProgressBar
,
carbsPercentage
,
carbs
);
setPercentage
(
fatProgressbar
,
fatPercentage
,
fat
);
setPercentage
(
proteinProgressBar
,
proteinPercentage
,
protein
);
setPercentage
(
fibersProgressBar
,
fiberPercentage
,
fiber
);
setPercentage
(
saltProgressBar
,
saltPercentage
,
salt
);
}
private
void
setPercentage
(
ProgressBar
progressBar
,
Text
textObject
,
double
value
)
{
log
.
debug
(
"Setting percentage for {}"
,
textObject
.
getId
());
progressBar
.
setProgress
(
value
);
textObject
.
setText
(
Math
.
round
(
value
*
100
)
+
"%"
);
//set text color for percentages
if
(
value
>
0.9
)
{
if
(
value
>
1
)
{
textObject
.
setFill
(
Color
.
valueOf
(
"#D91C1C"
));
//red
}
textObject
.
setFill
(
Color
.
valueOf
(
"#ff8a0d"
));
//orange
}
else
{
textObject
.
setFill
(
Color
.
valueOf
(
"#000000"
));
//default: black
}
}
}
This diff is collapsed.
Click to expand it.
src/main/resources/fxml/components/nutrition-table.fxml
0 → 100644
+
140
−
0
View file @
9e08c410
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<VBox
xmlns=
"http://javafx.com/javafx"
xmlns:fx=
"http://javafx.com/fxml"
fx:controller=
"mi.hdm.controllers.components.NutritionTableController"
prefHeight=
"250.0"
prefWidth=
"500.0"
>
<VBox>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Nutrition"
>
<font>
<Font
name=
"Arial Bold"
size=
"25.0"
/>
</font>
</Text>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Your nutrition score..."
fx:id=
"description"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<HBox
alignment=
"CENTER_LEFT"
prefHeight=
"57.0"
prefWidth=
"872.0"
spacing=
"5.0"
>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Calories"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<ProgressBar
fx:id=
"caloriesProgressBar"
prefHeight=
"24.0"
prefWidth=
"631.0"
progress=
"0.0"
style=
"-fx-background-color: #d9d9d9; -fx-background-radius: 5; -fx-control-inner-background: a; -fx-accent: #d91c1c;"
>
<HBox.margin>
<Insets
left=
"70.0"
/>
</HBox.margin>
</ProgressBar>
<Text
fx:id=
"caloriesPercentage"
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"0%"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
</HBox>
<HBox
alignment=
"CENTER_LEFT"
prefHeight=
"53.0"
prefWidth=
"872.0"
spacing=
"5.0"
>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Carbs"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<ProgressBar
fx:id=
"carbsProgressBar"
prefHeight=
"24.0"
prefWidth=
"631.0"
progress=
"0.0"
style=
"-fx-background-color: #d9d9d9; -fx-control-inner-background: a; -fx-background-radius: 5; -fx-accent: #d91c1c;"
>
<HBox.margin>
<Insets
left=
"70.0"
/>
</HBox.margin>
</ProgressBar>
<Text
fx:id=
"carbsPercentage"
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"0%"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
</HBox>
<HBox
alignment=
"CENTER_LEFT"
prefHeight=
"57.0"
prefWidth=
"872.0"
spacing=
"5.0"
>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Fat"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<ProgressBar
fx:id=
"fatProgressbar"
prefHeight=
"24.0"
prefWidth=
"631.0"
progress=
"0.0"
style=
"-fx-background-color: #d9d9d9; -fx-background-radius: 5; -fx-control-inner-background: a; -fx-accent: #d91c1c;"
>
<HBox.margin>
<Insets
left=
"70.0"
/>
</HBox.margin>
</ProgressBar>
<Text
fx:id=
"fatPercentage"
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"0%"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
</HBox>
<HBox
alignment=
"CENTER_LEFT"
prefHeight=
"53.0"
prefWidth=
"872.0"
spacing=
"5.0"
>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Protein"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<ProgressBar
fx:id=
"proteinProgressBar"
prefHeight=
"24.0"
prefWidth=
"631.0"
progress=
"0.0"
style=
"-fx-background-color: #d9d9d9; -fx-control-inner-background: a; -fx-background-radius: 5; -fx-accent: #d91c1c;"
>
<HBox.margin>
<Insets
left=
"70.0"
/>
</HBox.margin>
</ProgressBar>
<Text
fx:id=
"proteinPercentage"
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"0%"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
</HBox>
<HBox
alignment=
"CENTER_LEFT"
prefHeight=
"53.0"
prefWidth=
"872.0"
spacing=
"5.0"
>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Fibers"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<ProgressBar
fx:id=
"fibersProgressBar"
prefHeight=
"24.0"
prefWidth=
"631.0"
progress=
"0.0"
style=
"-fx-background-color: #d9d9d9; -fx-control-inner-background: a; -fx-background-radius: 5; -fx-accent: #d91c1c;"
>
<HBox.margin>
<Insets
left=
"70.0"
/>
</HBox.margin>
</ProgressBar>
<Text
fx:id=
"fiberPercentage"
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"0%"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
</HBox>
<HBox
alignment=
"CENTER_LEFT"
prefHeight=
"53.0"
prefWidth=
"872.0"
spacing=
"5.0"
>
<Text
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"Salt"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
<ProgressBar
fx:id=
"saltProgressBar"
prefHeight=
"24.0"
prefWidth=
"631.0"
progress=
"0.0"
style=
"-fx-background-color:#d9d9d9; -fx-control-inner-background: a; -fx-background-radius: 5; -fx-accent: #d91c1c;"
>
<HBox.margin>
<Insets
left=
"70.0"
/>
</HBox.margin>
</ProgressBar>
<Text
fx:id=
"saltPercentage"
fill=
"#1e1e1e"
strokeType=
"OUTSIDE"
strokeWidth=
"0.0"
text=
"0%"
wrappingWidth=
"83.47006416320801"
>
<font>
<Font
name=
"Arial"
size=
"17.0"
/>
</font>
</Text>
</HBox>
</VBox>
</VBox>
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