Fix calculator bugs
This commit is contained in:
@@ -6,11 +6,11 @@ import javafx.beans.property.SimpleStringProperty;
|
||||
public class Friend {
|
||||
|
||||
private SimpleStringProperty friend;
|
||||
private SimpleFloatProperty friendScore;
|
||||
private SimpleFloatProperty score;
|
||||
|
||||
public Friend(String friend, Float friendScore) {
|
||||
this.friend = new SimpleStringProperty(friend);
|
||||
this.friendScore = new SimpleFloatProperty(friendScore);
|
||||
this.score = new SimpleFloatProperty(friendScore);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ public class Friend {
|
||||
this.friend = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
public Float getFriendScore() {
|
||||
return friendScore.get();
|
||||
public Float getScore() {
|
||||
return score.get();
|
||||
}
|
||||
|
||||
public void setScore(Float score) {
|
||||
this.friendScore = new SimpleFloatProperty(score);
|
||||
this.score = new SimpleFloatProperty(score);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
@@ -29,6 +30,9 @@ public class CalculatorController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
//navigation panes
|
||||
@FXML
|
||||
private AnchorPane getStartedPane;
|
||||
@@ -119,6 +123,10 @@ public class CalculatorController {
|
||||
|
||||
//shopping pane
|
||||
@FXML
|
||||
private Text goodsField;
|
||||
@FXML
|
||||
private Text servicesField;
|
||||
@FXML
|
||||
private Slider goodsSlider;
|
||||
@FXML
|
||||
private Label goodsLabel;
|
||||
@@ -303,8 +311,7 @@ public class CalculatorController {
|
||||
* The method saves the calculation.
|
||||
* @param event user clicks to button
|
||||
*/
|
||||
public void saveCalc(ActionEvent event) {
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
public void saveCalc(ActionEvent event) throws InterruptedException {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
@@ -336,7 +343,7 @@ public class CalculatorController {
|
||||
if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText());
|
||||
carTravelGasolineLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
@@ -346,36 +353,36 @@ public class CalculatorController {
|
||||
if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText());
|
||||
carTravelDieselLabel.getText().replace(" km/L", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText());
|
||||
carTravelElectricLabel.getText().replace(" km/Le", ""));
|
||||
}
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_electricity_dollars",
|
||||
"input_footprint_housing_electricity_dollars",
|
||||
electricityField.getText());
|
||||
}
|
||||
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_gco2_per_kwh",
|
||||
cleanEnergyPurchasedLabel.getText());
|
||||
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
|
||||
}
|
||||
if (!naturalGasField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_naturalgas_dollars",
|
||||
"input_footprint_housing_naturalgas_dollars",
|
||||
naturalGasField.getText());
|
||||
}
|
||||
if (!heatingOilField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_heatingoil_dollars",
|
||||
"input_footprint_housing_heatingoil_dollars",
|
||||
heatingOilField.getText());
|
||||
}
|
||||
if (!livingSpaceField.getText().equals("0")) {
|
||||
@@ -386,44 +393,49 @@ public class CalculatorController {
|
||||
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_watersewage",
|
||||
waterUsageLabel.getText());
|
||||
waterUsageLabel.getText().replace("% of similar households", ""));
|
||||
}
|
||||
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_meatfisheggs",
|
||||
meatFishEggsLabel.getText());
|
||||
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText().replace(" daily servings per person", "").equals("4.4")) {
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
grainsBakedGoodsLabel.getText());
|
||||
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_dairy",
|
||||
dairyLabel.getText());
|
||||
dairyLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText().replace(" daily servings per person", "").equals("3.9")) {
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
fruitsVegetablesLabel.getText());
|
||||
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_otherfood",
|
||||
snacksDrinksLabel.getText());
|
||||
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
snacksDrinksLabel.getText());
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
snacksDrinksLabel.getText());
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
@@ -50,9 +43,9 @@
|
||||
<Image url="@../icons/world.png" />
|
||||
<!--image credits:
|
||||
made by prettycons https://www.flaticon.com/authors/prettycons
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
@@ -108,7 +101,7 @@
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" onAction="#saveCalculation" text="Save">
|
||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" onAction="#saveCalc" mnemonicParsing="false" text="Save">
|
||||
<font>
|
||||
<Font size="17.0" />
|
||||
</font></Button>
|
||||
@@ -146,9 +139,8 @@
|
||||
</opaqueInsets>
|
||||
</Label>
|
||||
<Button fx:id="getStartedNextButton" layoutX="383.0" layoutY="406.0" mnemonicParsing="false" onAction="#displayTravel" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="188.0" layoutY="14.0" stroke="#38573e" />
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="travelPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<AnchorPane fx:id="travelPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<ScrollPane layoutX="158.0" layoutY="109.0" prefHeight="215.0" prefWidth="499.0">
|
||||
<content>
|
||||
@@ -159,7 +151,7 @@
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="carTravelGasolineField" layoutX="14.0" layoutY="38.0" prefHeight="31.0" prefWidth="405.0" promptText="16.400">
|
||||
<TextField fx:id="carTravelGasolineField" layoutX="14.0" layoutY="38.0" prefHeight="31.0" prefWidth="405.0" promptText="16.400" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -202,7 +194,7 @@
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<TextField fx:id="carTravelDieselField" layoutX="14.0" layoutY="200.0" prefHeight="31.0" prefWidth="405.0" promptText="15.400">
|
||||
<TextField fx:id="carTravelDieselField" layoutX="14.0" layoutY="200.0" prefHeight="31.0" prefWidth="405.0" promptText="15.400" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -217,7 +209,7 @@
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="carTravelElectricField" layoutX="14.0" layoutY="365.0" prefHeight="31.0" prefWidth="405.0" promptText="14.900">
|
||||
<TextField fx:id="carTravelElectricField" layoutX="14.0" layoutY="365.0" prefHeight="31.0" prefWidth="405.0" promptText="14.900" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -258,7 +250,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="publicTransitField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="394.0" prefHeight="31.0" prefWidth="499.0" promptText="0">
|
||||
<TextField fx:id="publicTransitField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="394.0" prefHeight="31.0" prefWidth="499.0" promptText="0" text="0">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font></TextField>
|
||||
@@ -267,7 +259,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField fx:id="airplaneTravelField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="495.0" prefHeight="31.0" prefWidth="499.0" promptText="0">
|
||||
<TextField fx:id="airplaneTravelField" alignment="CENTER_RIGHT" layoutX="158.0" layoutY="495.0" prefHeight="31.0" prefWidth="499.0" promptText="0" text="0">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font></TextField>
|
||||
@@ -290,10 +282,9 @@
|
||||
</children>
|
||||
</HBox>
|
||||
<Button fx:id="travelNextButton" layoutX="383.0" layoutY="559.0" mnemonicParsing="false" onAction="#displayHome" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="273.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="homePane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<AnchorPane fx:id="homePane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<Text layoutX="245.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you use in your home?">
|
||||
<font>
|
||||
@@ -305,7 +296,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField layoutX="177.0" layoutY="105.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570">
|
||||
<TextField fx:id="electricityField" layoutX="177.0" layoutY="105.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -356,7 +347,7 @@
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<TextField layoutX="177.0" layoutY="262.0" prefHeight="31.0" prefWidth="434.0" promptText="2,000">
|
||||
<TextField fx:id="naturalGasField" layoutX="177.0" layoutY="262.0" prefHeight="31.0" prefWidth="434.0" promptText="2,000" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -373,7 +364,7 @@
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<TextField layoutX="177.0" layoutY="325.0" prefHeight="31.0" prefWidth="434.0" promptText="3,100">
|
||||
<TextField fx:id="heatingOilField" layoutX="177.0" layoutY="325.0" prefHeight="31.0" prefWidth="434.0" promptText="3,100" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -388,7 +379,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TextField layoutX="177.0" layoutY="390.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570">
|
||||
<TextField fx:id="livingSpaceField" layoutX="177.0" layoutY="390.0" prefHeight="31.0" prefWidth="434.0" promptText="1,570" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -419,9 +410,8 @@
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Line endX="79.0" layoutX="358.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children></AnchorPane>
|
||||
<ScrollPane fx:id="foodPane" layoutY="92.0" pannable="true" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<ScrollPane fx:id="foodPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<content>
|
||||
<AnchorPane prefHeight="1000.0" prefWidth="817.0">
|
||||
<children>
|
||||
@@ -457,7 +447,7 @@
|
||||
</Text>
|
||||
<HBox alignment="CENTER" layoutX="299.0" layoutY="310.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="grainsBakedGoodsLabel" text="4,4 daily servings per person">
|
||||
<Label fx:id="grainsBakedGoodsLabel" text="4.4 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -478,7 +468,7 @@
|
||||
<Slider fx:id="dairySlider" blockIncrement="2.5" layoutX="146.0" layoutY="527.0" majorTickUnit="2.5" max="7.5" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="299.0" layoutY="471.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="dairyLabel" text="2,4 daily servings per person">
|
||||
<Label fx:id="dairyLabel" text="2.4 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -497,7 +487,7 @@
|
||||
</Text>
|
||||
<HBox alignment="CENTER" layoutX="304.0" layoutY="810.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="snacksDrinksLabel" text="3,7 daily servings per person">
|
||||
<Label fx:id="snacksDrinksLabel" text="3.7 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -518,7 +508,7 @@
|
||||
<Slider fx:id="fruitsVegetablesSlider" blockIncrement="3.9" layoutX="151.0" layoutY="705.0" majorTickUnit="3.9" max="11.6" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="304.0" layoutY="649.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="fruitsVegetablesLabel" text="3,9 daily servings per person">
|
||||
<Label fx:id="fruitsVegetablesLabel" text="3.9 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -531,12 +521,11 @@
|
||||
</font>
|
||||
</Text>
|
||||
<Button layoutX="378.0" layoutY="926.0" mnemonicParsing="false" onAction="#displayShopping" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="443.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<AnchorPane fx:id="shoppingPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<Text layoutX="133.0" layoutY="50.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you spend on each of the following?">
|
||||
<font>
|
||||
@@ -566,7 +555,7 @@
|
||||
<Slider fx:id="goodsSlider" blockIncrement="1520.0" layoutX="133.0" layoutY="209.0" majorTickUnit="1520.0" max="4560.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="335.0" layoutY="145.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="goodsLabel" text="1.520 € / month">
|
||||
<Label fx:id="goodsLabel" text="1520 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -575,7 +564,7 @@
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" layoutX="335.0" layoutY="348.0" prefHeight="31.0" prefWidth="150.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="servicesLabel" text="3.428 € / month">
|
||||
<Label fx:id="servicesLabel" text="3428 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
@@ -583,7 +572,8 @@
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="servicesSlider" blockIncrement="3428.0" layoutX="133.0" layoutY="418.0" majorTickUnit="3428.0" max="10284.0" minorTickCount="0" prefHeight="24.0" prefWidth="554.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Line endX="79.0" layoutX="528.0" layoutY="7.0" stroke="#38573e" />
|
||||
</children></AnchorPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user