Merge branch 'add_savedCO2_property' into 'master'
Add co2 saved property tables and tests See merge request cse1105/2018-2019/oopp-group-43/template!58
This commit is contained in:
@@ -201,10 +201,6 @@ public class CalculatorController {
|
||||
|
||||
addSliderListenerGoodsServices(goodsSlider, goodsLabel);
|
||||
addSliderListenerGoodsServices(servicesSlider, servicesLabel);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -471,19 +467,27 @@ public class CalculatorController {
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
if (localProduceCheckbox.isSelected()) {
|
||||
controller.localProduce.setSelected(true);
|
||||
localProduceCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"local_produce", true);
|
||||
}
|
||||
if (bikeCheckbox.isSelected()) {
|
||||
controller.bike.setSelected(true);
|
||||
bikeCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike", true);
|
||||
}
|
||||
if (temperatureCheckbox.isSelected()) {
|
||||
controller.loweringTemp.setSelected(true);
|
||||
temperatureCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"temperature", true);
|
||||
}
|
||||
if (solarPanelsCheckbox.isSelected()) {
|
||||
controller.solarPanels.setSelected(true);
|
||||
solarPanelsCheckbox.setSelected(true);
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels", true);
|
||||
}
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
|
||||
@@ -40,21 +40,7 @@ public class DashBoardController {
|
||||
public static ObservableList<Friend> data = FXCollections.observableArrayList();
|
||||
public ObservableList<Friend> friendLeaderData = FXCollections.observableArrayList();
|
||||
public ObservableList<Friend> globalLeaderData = FXCollections.observableArrayList();
|
||||
|
||||
//these need to be public because they are used by the calculatorController
|
||||
//suppressing the checkstyle warnings because the fields have to be public
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
public CheckBox localProduce;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
public CheckBox loweringTemp;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
public CheckBox bike;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
public CheckBox solarPanels;
|
||||
public ObservableList<Friend> developmentData = FXCollections.observableArrayList();
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
@@ -84,12 +70,14 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private AnchorPane menuBar;
|
||||
@FXML
|
||||
private Button addNewActivityButton;
|
||||
@FXML
|
||||
private Button calculateFootPrintButton;
|
||||
@FXML
|
||||
private Label footprintLabel;
|
||||
@FXML
|
||||
private Label firstFootprintLabel;
|
||||
@FXML
|
||||
private Label differenceLabel;
|
||||
@FXML
|
||||
private Button addFriendButton;
|
||||
@FXML
|
||||
private TableView<Friend> friendsTable;
|
||||
@@ -104,6 +92,12 @@ public class DashBoardController {
|
||||
@FXML
|
||||
private TableColumn<Friend, Float> globalScore;
|
||||
@FXML
|
||||
private TableView<Friend> developmentLeaderboard;
|
||||
@FXML
|
||||
private TableColumn<Friend, String> developmentUser;
|
||||
@FXML
|
||||
private TableColumn<Friend, Float> developmentScore;
|
||||
@FXML
|
||||
private TableView<Friend> friendLeaderboard;
|
||||
@FXML
|
||||
private TableColumn<Friend, String> friendUser;
|
||||
@@ -159,6 +153,17 @@ public class DashBoardController {
|
||||
private Label fruits;
|
||||
@FXML
|
||||
private Label snacks;
|
||||
@FXML
|
||||
private CheckBox localProduce;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
private CheckBox loweringTemp;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
private CheckBox bike;
|
||||
@SuppressWarnings("CheckStyle")
|
||||
@FXML
|
||||
private CheckBox solarPanels;
|
||||
|
||||
/**
|
||||
* Loads the the necessary things before anything else.
|
||||
@@ -177,6 +182,8 @@ public class DashBoardController {
|
||||
scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
globalScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
developmentUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
developmentScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
friendUser.setCellValueFactory(new PropertyValueFactory<>("Friend"));
|
||||
friendScore.setCellValueFactory(new PropertyValueFactory<>("Score"));
|
||||
if (pieChart != null) {
|
||||
@@ -226,6 +233,31 @@ public class DashBoardController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the scores of users.
|
||||
* @param users the list of users
|
||||
*/
|
||||
public void sortDiffScores(List<String> users) throws InterruptedException {
|
||||
for (int i = 0; i < users.size(); i++) {
|
||||
for (int j = 0; j < users.size(); j++) {
|
||||
Float firstDiff = userService.getFirstFootprint(users.get(i)) - userService
|
||||
.getFootprint(users.get(i));
|
||||
Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService
|
||||
.getFootprint(users.get(j));
|
||||
if (i < j && firstDiff < secondDiff) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
users.set(j, temp);
|
||||
}
|
||||
if (i > j && firstDiff > secondDiff) {
|
||||
String temp = users.get(i);
|
||||
users.set(i, users.get(j));
|
||||
users.set(j, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a fade transition for switching between the different panes.
|
||||
* @param node the node on which the transition needs to act
|
||||
@@ -291,7 +323,18 @@ public class DashBoardController {
|
||||
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
|
||||
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
|
||||
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
|
||||
localProduce.setSelected(true);
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("local_produce")) {
|
||||
localProduce.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("bike")) {
|
||||
bike.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("temperature")) {
|
||||
loweringTemp.setSelected(true);
|
||||
}
|
||||
if (userService.getExtraInputs(userService.currentUser.getName()).get("solar_panels")) {
|
||||
solarPanels.setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,6 +345,11 @@ public class DashBoardController {
|
||||
System.out.println(userService.currentUser.getName());
|
||||
System.out.println(userService.getFootprint(userService.currentUser.getName()));
|
||||
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
|
||||
firstFootprintLabel.setText("" + userService
|
||||
.getFirstFootprint(userService.currentUser.getName()));
|
||||
Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService
|
||||
.getFootprint(userService.currentUser.getName());
|
||||
differenceLabel.setText( "" + diff);
|
||||
usernameLabel.setText("" + userService.currentUser.getName());
|
||||
addFadeTransition(userPane);
|
||||
System.out.println("display user");
|
||||
@@ -316,13 +364,14 @@ public class DashBoardController {
|
||||
* Displays the friends pane.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void displayFriends(ActionEvent event) {
|
||||
public void displayFriends(ActionEvent event) throws InterruptedException {
|
||||
addFadeTransition(friendsPane);
|
||||
System.out.println("display friends");
|
||||
dashboardPane.setVisible(false);
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
friendsPane.setVisible(true);
|
||||
updateFriends();
|
||||
}
|
||||
|
||||
//sets the slide in transition for startup
|
||||
@@ -363,32 +412,59 @@ public class DashBoardController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaderboard is updaating.
|
||||
* Leaderboard is updating.
|
||||
* @throws InterruptedException throws exception
|
||||
*/
|
||||
public void updateLeaderboard() throws InterruptedException {
|
||||
friendLeaderboard.getItems().clear();
|
||||
globalLeaderboard.getItems().clear();
|
||||
//global leaderboard
|
||||
globalLeaderData.removeAll();
|
||||
List<String> userList = userService.getAllUsers();
|
||||
//global leaderboard
|
||||
globalLeaderboard.getItems().clear();
|
||||
globalLeaderData.removeAll();
|
||||
sortScores(userList);
|
||||
//development leaderboard
|
||||
developmentLeaderboard.getItems().clear();
|
||||
developmentData.removeAll();
|
||||
sortDiffScores(userList);
|
||||
for (int j = 0; j < userList.size(); j++) {
|
||||
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j)));
|
||||
Friend diffUser = new Friend(userList.get(j), userService
|
||||
.getFirstFootprint(userList.get(j))
|
||||
- userService.getFootprint(userList.get(j)));
|
||||
globalLeaderData.add(user);
|
||||
developmentData.add(diffUser);
|
||||
}
|
||||
globalLeaderboard.setItems(globalLeaderData);
|
||||
// friend leaderboard
|
||||
friendLeaderData.removeAll();
|
||||
String name = userService.currentUser.getName();
|
||||
List<String> friendList = userService.getFriendNames(name);
|
||||
friendList.add(name);
|
||||
developmentLeaderboard.setItems(developmentData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Friends tables are updating.
|
||||
* @throws InterruptedException throws exception
|
||||
*/
|
||||
public void updateFriends() throws InterruptedException {
|
||||
List<String> wholeList = userService.getFriendNames(userService.currentUser.getName());
|
||||
wholeList.add(userService.currentUser.getName());
|
||||
//friend list
|
||||
friendsTable.getItems().clear();
|
||||
data.removeAll();
|
||||
List<String> friendList = userService.getFriendNames(userService.currentUser.getName());
|
||||
sortScores(friendList);
|
||||
//friends leaderboard
|
||||
friendLeaderboard.getItems().clear();
|
||||
friendLeaderData.removeAll();
|
||||
sortDiffScores(wholeList);
|
||||
for (int i = 0; i < friendList.size(); i++) {
|
||||
Friend friend = new Friend(friendList.get(i),
|
||||
userService.getFootprint(friendList.get(i)));
|
||||
friendLeaderData.add(friend);
|
||||
Friend user = new Friend(friendList.get(i), userService
|
||||
.getFootprint(friendList.get(i)));
|
||||
data.add(user);
|
||||
}
|
||||
for (int j = 0; j < wholeList.size(); j++) {
|
||||
Friend diffUser = new Friend(wholeList.get(j),
|
||||
userService.getFirstFootprint(wholeList.get(j))
|
||||
- userService.getFootprint(wholeList.get(j)));
|
||||
friendLeaderData.add(diffUser);
|
||||
}
|
||||
friendsTable.setItems(data);
|
||||
friendLeaderboard.setItems(friendLeaderData);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import greenify.client.Friend;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -17,9 +16,6 @@ public class FriendController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
@FXML
|
||||
private Button addButton;
|
||||
@FXML
|
||||
@@ -55,12 +51,8 @@ public class FriendController {
|
||||
}
|
||||
//add friend to the current user
|
||||
userService.addFriend(userService.currentUser.getName(), userNameText.getText());
|
||||
Friend friend = new Friend(userNameText.getText(),
|
||||
userService.getFootprint(userNameText.getText()));
|
||||
DashBoardController.data.add(friend);
|
||||
//close the register window after the user has entered all the credentials
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
controller.updateLeaderboard();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.KeyValue;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.PasswordField;
|
||||
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;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -26,6 +43,123 @@ public class RegisterWindowController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
//navigation panes
|
||||
@FXML
|
||||
private AnchorPane getStartedPane;
|
||||
@FXML
|
||||
private AnchorPane travelPane;
|
||||
@FXML
|
||||
private AnchorPane homePane;
|
||||
@FXML
|
||||
private ScrollPane foodPane;
|
||||
@FXML
|
||||
private AnchorPane shoppingPane;
|
||||
|
||||
//'get started' pane
|
||||
@FXML
|
||||
private Slider peopleInHouseholdSlider;
|
||||
@FXML
|
||||
private Label peopleInHouseHoldLabel;
|
||||
@FXML
|
||||
private Slider annualIncomeSlider;
|
||||
@FXML
|
||||
private Label annualIncomeLabel;
|
||||
@FXML
|
||||
private Button saveButton;
|
||||
|
||||
//travel pane
|
||||
@FXML
|
||||
private TextField publicTransitField;
|
||||
@FXML
|
||||
private TextField airplaneTravelField;
|
||||
@FXML
|
||||
private TextField carTravelGasolineField;
|
||||
@FXML
|
||||
private Slider carTravelGasolineSlider;
|
||||
@FXML
|
||||
private Label carTravelGasolineLabel;
|
||||
@FXML
|
||||
private TextField carTravelDieselField;
|
||||
@FXML
|
||||
private Slider carTravelDieselSlider;
|
||||
@FXML
|
||||
private Label carTravelDieselLabel;
|
||||
@FXML
|
||||
private TextField carTravelElectricField;
|
||||
@FXML
|
||||
private Slider carTravelElectricSlider;
|
||||
@FXML
|
||||
private Label carTravelElectricLabel;
|
||||
|
||||
//home pane
|
||||
@FXML
|
||||
private TextField electricityField;
|
||||
@FXML
|
||||
private Slider cleanEnergyPurchasedSlider;
|
||||
@FXML
|
||||
private Label cleanEnergyPurchasedLabel;
|
||||
@FXML
|
||||
private TextField naturalGasField;
|
||||
@FXML
|
||||
private TextField heatingOilField;
|
||||
@FXML
|
||||
private TextField livingSpaceField;
|
||||
@FXML
|
||||
private Slider waterUsageSlider;
|
||||
@FXML
|
||||
private Label waterUsageLabel;
|
||||
|
||||
//food pane
|
||||
@FXML
|
||||
private Slider meatFishEggsSlider;
|
||||
@FXML
|
||||
private Label meatFishEggsLabel;
|
||||
@FXML
|
||||
private Slider grainsBakedGoodsSlider;
|
||||
@FXML
|
||||
private Label grainsBakedGoodsLabel;
|
||||
@FXML
|
||||
private Slider dairySlider;
|
||||
@FXML
|
||||
private Label dairyLabel;
|
||||
@FXML
|
||||
private Slider fruitsVegetablesSlider;
|
||||
@FXML
|
||||
private Label fruitsVegetablesLabel;
|
||||
@FXML
|
||||
private Slider snacksDrinksSlider;
|
||||
@FXML
|
||||
private Label snacksDrinksLabel;
|
||||
|
||||
//shopping pane
|
||||
@FXML
|
||||
private Text goodsField;
|
||||
@FXML
|
||||
private Text servicesField;
|
||||
@FXML
|
||||
private Slider goodsSlider;
|
||||
@FXML
|
||||
private Label goodsLabel;
|
||||
@FXML
|
||||
private Slider servicesSlider;
|
||||
@FXML
|
||||
private Label servicesLabel;
|
||||
|
||||
//extra pane
|
||||
@FXML
|
||||
private AnchorPane extraPane;
|
||||
@FXML
|
||||
private CheckBox localProduceCheckbox;
|
||||
@FXML
|
||||
private CheckBox bikeCheckbox;
|
||||
@FXML
|
||||
private CheckBox temperatureCheckbox;
|
||||
@FXML
|
||||
private CheckBox solarPanelsCheckbox;
|
||||
|
||||
@FXML
|
||||
private TextField userNameText;
|
||||
@FXML
|
||||
@@ -42,14 +176,10 @@ public class RegisterWindowController {
|
||||
* @throws InterruptedException exception when interrupted
|
||||
*/
|
||||
public void initialize() throws InterruptedException {
|
||||
// PathTransition pathTransUName = new PathTransition(Duration.millis(1100),
|
||||
// uNamePathLine, userNameText);
|
||||
// pathTransUName.play();
|
||||
addSlideAnimation(1100, userNameText, -300);
|
||||
addSlideAnimation(1100, passwordField, 300);
|
||||
TimeUnit.MILLISECONDS.sleep(300);
|
||||
addSlideAnimation(1100, passwordField2, -420);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +200,7 @@ public class RegisterWindowController {
|
||||
* @param event the click of the sign up button
|
||||
*/
|
||||
@FXML
|
||||
public void handleSignUpButton(ActionEvent event) {
|
||||
public void handleSignUpButton(ActionEvent event) throws IOException {
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
Window owner = signUpButton.getScene().getWindow();
|
||||
//check if the username field is empty
|
||||
@@ -99,9 +229,353 @@ public class RegisterWindowController {
|
||||
|
||||
//register the user with the provided username and password
|
||||
userService.registerUser(userNameText.getText(), passwordField.getText());
|
||||
|
||||
//close the register window after the user has entered all the credentials
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
|
||||
Parent calc = Application.load(this.getClass().getClassLoader()
|
||||
.getResource("fxml/FirstCalculator.fxml"));
|
||||
Scene scene = new Scene(calc);
|
||||
scene.getStylesheets().add(getClass().getClassLoader()
|
||||
.getResource("stylesheets/calculatorStyle.css").toExternalForm());
|
||||
Stage calcStage = new Stage();
|
||||
|
||||
calcStage.setScene(scene);
|
||||
calcStage.setTitle("Calculate CO2 footprint - " + userService.currentUser.getName());
|
||||
calcStage.show();
|
||||
|
||||
peopleInHouseholdSlider.setSnapToTicks(true);
|
||||
//add listener to slider for amount of people in household
|
||||
peopleInHouseholdSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
peopleInHouseHoldLabel.setText("" + newValue.intValue());
|
||||
}
|
||||
});
|
||||
|
||||
//add listener to slider for annual income
|
||||
annualIncomeSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
annualIncomeLabel.setText("" + (newValue.intValue() * 1000));
|
||||
}
|
||||
});
|
||||
|
||||
addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg");
|
||||
addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge");
|
||||
|
||||
cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
cleanEnergyPurchasedLabel.setText(newValue.intValue() + " %");
|
||||
}
|
||||
});
|
||||
|
||||
waterUsageSlider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
waterUsageLabel.setText(newValue.intValue() + "% of similar households");
|
||||
}
|
||||
});
|
||||
|
||||
addSliderListenerDailyServing(meatFishEggsSlider, meatFishEggsLabel);
|
||||
addSliderListenerDailyServing(grainsBakedGoodsSlider, grainsBakedGoodsLabel);
|
||||
addSliderListenerDailyServing(dairySlider, dairyLabel);
|
||||
addSliderListenerDailyServing(fruitsVegetablesSlider, fruitsVegetablesLabel);
|
||||
addSliderListenerDailyServing(snacksDrinksSlider, snacksDrinksLabel);
|
||||
|
||||
addSliderListenerGoodsServices(goodsSlider, goodsLabel);
|
||||
addSliderListenerGoodsServices(servicesSlider, servicesLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds the listener to the given slider and displays it's output on a given label.
|
||||
* @param slider the slider to attach the listener to.
|
||||
* @param label the label to display the slider output on.
|
||||
*/
|
||||
private void addSliderListenerCarUsage(Slider slider, Label label, String unit) {
|
||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
label.setText(newValue.intValue() + unit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addSliderListenerDailyServing(Slider slider, Label label) {
|
||||
DecimalFormat df = new DecimalFormat("0.0");
|
||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
label.setText(df.format(newValue.doubleValue()) + " daily servings per person");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addSliderListenerGoodsServices(Slider slider, Label label) {
|
||||
slider.valueProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable,
|
||||
Number oldValue, Number newValue) {
|
||||
label.setText(newValue.intValue() + "€ / month");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addSlideInAnimation(Node node) {
|
||||
Timeline timeline = new Timeline();
|
||||
KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT);
|
||||
KeyFrame keyFrame = new KeyFrame(Duration.millis(600), keyValue);
|
||||
timeline.getKeyFrames().add(keyFrame);
|
||||
timeline.play();
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'get started' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayGetStarted(ActionEvent event) {
|
||||
getStartedPane.setVisible(true);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'travel' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayTravel(ActionEvent event) {
|
||||
addSlideInAnimation(travelPane);
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(true);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'home' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayHome(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(true);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'food' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayFood(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(true);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'shopping' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayShopping(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(true);
|
||||
extraPane.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* displays the 'Extra' section of the calculator.
|
||||
* Activated when the designated button (navigation button) is clicked
|
||||
* @param event the click of the designated button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void displayExtra(ActionEvent event) {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
extraPane.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The method saves the calculation.
|
||||
* @param event user clicks to button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void saveCalc(ActionEvent event) throws InterruptedException {
|
||||
getStartedPane.setVisible(false);
|
||||
travelPane.setVisible(false);
|
||||
homePane.setVisible(false);
|
||||
foodPane.setVisible(false);
|
||||
shoppingPane.setVisible(false);
|
||||
if (!annualIncomeLabel.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(), "input_income",
|
||||
annualIncomeLabel.getText());
|
||||
}
|
||||
if (!peopleInHouseHoldLabel.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(), "input_size",
|
||||
peopleInHouseHoldLabel.getText());
|
||||
}
|
||||
if (!publicTransitField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_publictrans",
|
||||
publicTransitField.getText());
|
||||
}
|
||||
if (!airplaneTravelField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_airtotal",
|
||||
airplaneTravelField.getText());
|
||||
}
|
||||
if (!carTravelGasolineField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles1",
|
||||
carTravelGasolineField.getText());
|
||||
}
|
||||
if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg1",
|
||||
carTravelGasolineLabel.getText().replace(" mpg", ""));
|
||||
}
|
||||
if (!carTravelDieselField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles2",
|
||||
carTravelDieselField.getText());
|
||||
}
|
||||
if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg2",
|
||||
carTravelDieselLabel.getText().replace(" mpg", ""));
|
||||
}
|
||||
if (!carTravelElectricField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_miles3",
|
||||
carTravelElectricField.getText());
|
||||
}
|
||||
if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_transportation_mpg3",
|
||||
carTravelElectricLabel.getText().replace(" mpge", ""));
|
||||
}
|
||||
if (!electricityField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"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().replace(" %", ""));
|
||||
}
|
||||
if (!naturalGasField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_naturalgas_dollars",
|
||||
naturalGasField.getText());
|
||||
}
|
||||
if (!heatingOilField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_heatingoil_dollars",
|
||||
heatingOilField.getText());
|
||||
}
|
||||
if (!livingSpaceField.getText().equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_squarefeet",
|
||||
livingSpaceField.getText());
|
||||
}
|
||||
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_housing_watersewage",
|
||||
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().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!grainsBakedGoodsLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("4.4")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_cereals",
|
||||
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().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!fruitsVegetablesLabel.getText()
|
||||
.replace(" daily servings per person", "").equals("3.9")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_food_fruitvegetables",
|
||||
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().replace(" daily servings per person", ""));
|
||||
}
|
||||
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_goods_total",
|
||||
goodsLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
|
||||
userService.updateInput(userService.currentUser.getName(),
|
||||
"input_footprint_shopping_services_total",
|
||||
servicesLabel.getText().replace("€ / month", ""));
|
||||
}
|
||||
if (localProduceCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"local_produce", true);
|
||||
}
|
||||
if (bikeCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike", true);
|
||||
}
|
||||
if (temperatureCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"temperature", true);
|
||||
}
|
||||
if (solarPanelsCheckbox.isSelected()) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels", true);
|
||||
}
|
||||
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,26 @@ public class UserService {
|
||||
.encode().toUri(), String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the extra input of the user.
|
||||
* @param name name of the user
|
||||
* @param inputName name of the input
|
||||
* @param value value of the input
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateExtraInput(String name, String inputName, Boolean value) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
|
||||
.queryParam("name", name)
|
||||
.queryParam("inputName", inputName)
|
||||
.queryParam("value",value);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||
.encode().toUri(), String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the footprint of the user.
|
||||
* @param name name of the user
|
||||
@@ -120,6 +140,23 @@ public class UserService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first footprint of the user.
|
||||
* @param name name of the user
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
public Float getFirstFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
return footprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the footprint of the user.
|
||||
* @param name name of the user
|
||||
@@ -138,6 +175,25 @@ public class UserService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the first footprint of the user.
|
||||
* @param name name of the user
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Float saveFirstFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/saveFirstFootprint")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float result = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the friend list of the user.
|
||||
* @param name name of the user
|
||||
@@ -191,6 +247,23 @@ public class UserService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the footprint inputs of the user.
|
||||
* @param name the username of the current user.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Map<String, Boolean> getExtraInputs(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
|
||||
.queryParam("name", name);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), Map.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of all users.
|
||||
*/
|
||||
|
||||
632
src/Client/src/main/resources/fxml/FirstCalculator.fxml
Normal file
632
src/Client/src/main/resources/fxml/FirstCalculator.fxml
Normal file
@@ -0,0 +1,632 @@
|
||||
<?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?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
|
||||
<children>
|
||||
<AnchorPane fx:id="calculatorTabs" prefHeight="92.0" prefWidth="820.0" style="-fx-background-color: #677069;">
|
||||
<children>
|
||||
<Button fx:id="calculatorGetStartedButton" contentDisplay="TOP" layoutX="147.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayGetStarted" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Get started" textFill="#d4ddd6" AnchorPane.leftAnchor="147.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/cloud.png" />
|
||||
<!--image credits:-->
|
||||
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
|
||||
<!--from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorTravelButton" contentDisplay="TOP" layoutX="232.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayTravel" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Travel" textFill="#d4ddd6" AnchorPane.leftAnchor="232.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<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
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorHomeButton" contentDisplay="TOP" layoutX="317.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayHome" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Home" textFill="#d4ddd6" AnchorPane.leftAnchor="317.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/home.png" />
|
||||
<!--image credits:
|
||||
made by Smashicons https://www.flaticon.com/authors/smashicons
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorFoodButton" contentDisplay="TOP" layoutX="402.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayFood" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Food" textFill="#d4ddd6" AnchorPane.leftAnchor="402.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/coffee-cup.png" />
|
||||
<!--image credits:
|
||||
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="calculatorShoppingButton" contentDisplay="TOP" layoutX="487.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayShopping" prefHeight="81.0" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Shopping" textFill="#d4ddd6" AnchorPane.leftAnchor="487.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/shopping-cart.png" />
|
||||
<!--image credits:
|
||||
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
|
||||
from https://www.flaticon.com/
|
||||
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
|
||||
-->
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" onAction="#saveCalc" text="Save">
|
||||
<font>
|
||||
<Font size="17.0" />
|
||||
</font></Button>
|
||||
<Button fx:id="calculatorExtraButton" contentDisplay="TOP" layoutX="497.0" layoutY="5.0" mnemonicParsing="false" onAction="#displayExtra" prefHeight="81.0" prefWidth="79.0" style="-fx-padding: 0px 0px 0px 0px;" styleClass="navButton" text="Extra" textFill="#d4ddd6" AnchorPane.leftAnchor="572.0">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="16.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/icons8-potted-plant-100.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane fx:id="getStartedPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" AnchorPane.leftAnchor="0.0">
|
||||
<children>
|
||||
<Text layoutX="224.0" layoutY="96.0" strokeType="OUTSIDE" strokeWidth="0.0" text="1. How many people live in your household?">
|
||||
<font>
|
||||
<Font size="19.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Slider fx:id="peopleInHouseholdSlider" blockIncrement="1.0" layoutX="260.0" layoutY="147.0" majorTickUnit="1.0" max="6.0" min="1.0" minorTickCount="0" prefHeight="38.0" prefWidth="300.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" styleClass="slidertje" />
|
||||
<Label fx:id="peopleInHouseHoldLabel" alignment="CENTER" contentDisplay="CENTER" layoutX="612.0" layoutY="70.0" prefHeight="38.0" prefWidth="44.0" text="0">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font></Label>
|
||||
<Text layoutX="207.0" layoutY="254.0" strokeType="OUTSIDE" strokeWidth="0.0" text="2. What is your gross annual household income?">
|
||||
<font>
|
||||
<Font size="19.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Slider fx:id="annualIncomeSlider" layoutX="224.0" layoutY="302.0" majorTickUnit="10.0" minorTickCount="0" prefHeight="38.0" prefWidth="388.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Text fill="#757575" layoutX="373.0" layoutY="277.0" strokeType="OUTSIDE" strokeWidth="0.0" text="in 1000 euros">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="annualIncomeLabel" layoutX="634.0" layoutY="232.0" prefHeight="30.0" prefWidth="150.0" text="0">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</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="147.0" layoutY="14.0" stroke="#545b54" />
|
||||
</children></AnchorPane>
|
||||
<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>
|
||||
<AnchorPane prefHeight="505.0" prefWidth="497.0">
|
||||
<children>
|
||||
<Text fill="#505050" layoutX="14.0" layoutY="27.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Gasoline">
|
||||
<font>
|
||||
<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" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="38.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="carTravelGasolineSlider" layoutX="14.0" layoutY="122.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="77.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="carTravelGasolineLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="239.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="carTravelDieselLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpg">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="carTravelDieselSlider" layoutX="14.0" layoutY="285.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="200.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<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>
|
||||
</TextField>
|
||||
<Text fill="#505050" layoutX="14.0" layoutY="189.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Diesel">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#505050" layoutX="14.0" layoutY="354.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Electric">
|
||||
<font>
|
||||
<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" text="0">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="419.0" layoutY="365.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="49.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="carTravelElectricSlider" layoutX="14.0" layoutY="450.0" majorTickUnit="15.0" max="115.0" min="10.0" minorTickCount="0" prefHeight="14.0" prefWidth="453.0" showTickLabels="true" showTickMarks="true" />
|
||||
<HBox alignment="CENTER" layoutX="204.0" layoutY="404.0" prefHeight="31.0" prefWidth="89.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="carTravelElectricLabel" alignment="TOP_CENTER" contentDisplay="CENTER" text="0 mpge">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content></ScrollPane>
|
||||
<Text layoutX="300.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How do you get around?">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font></Text>
|
||||
<Text fill="#727272" layoutX="370.0" layoutY="103.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Car travel">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="355.0" layoutY="374.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Public Transit">
|
||||
<font>
|
||||
<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" text="0">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font></TextField>
|
||||
<Text fill="#727272" layoutX="350.0" layoutY="476.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Airplane travel">
|
||||
<font>
|
||||
<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" text="0">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font></TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="398.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="659.0" layoutY="499.0" prefHeight="31.0" prefWidth="62.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="mi/year" wrappingWidth="63.0">
|
||||
<font>
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Text>
|
||||
</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="232.0" layoutY="14.0" stroke="#545b54" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<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>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="177.0" layoutY="85.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Electricity">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<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>
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="616.0" layoutY="105.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="€/year" wrappingWidth="41.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
<HBox.margin>
|
||||
<Insets left="3.0" />
|
||||
</HBox.margin>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="waterUsageSlider" blockIncrement="100.0" layoutX="177.0" layoutY="509.0" majorTickUnit="100.0" max="300.0" minorTickCount="0" prefHeight="24.0" prefWidth="499.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Slider fx:id="cleanEnergyPurchasedSlider" blockIncrement="25.0" layoutX="177.0" layoutY="188.0" minorTickCount="0" prefHeight="24.0" prefWidth="499.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Text fill="#6f6f6f" layoutX="238.0" layoutY="165.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Percent purchased from clean energy program:">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<HBox alignment="CENTER" layoutX="553.0" layoutY="146.0" prefHeight="27.0" prefWidth="55.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="cleanEnergyPurchasedLabel" text="0 %">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Button layoutX="400.0" layoutY="547.0" mnemonicParsing="false" onAction="#displayFood" styleClass="nextButton" text="Next" />
|
||||
<Text fill="#727272" layoutX="177.0" layoutY="255.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Natural gas">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="616.0" layoutY="262.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="€/year" wrappingWidth="41.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
<HBox.margin>
|
||||
<Insets left="3.0" />
|
||||
</HBox.margin>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<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>
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="616.0" layoutY="325.0" prefHeight="31.0" prefWidth="54.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="€/year" wrappingWidth="41.0">
|
||||
<font>
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
<HBox.margin>
|
||||
<Insets left="3.0" />
|
||||
</HBox.margin>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<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>
|
||||
</TextField>
|
||||
<Text fill="#727272" layoutX="177.0" layoutY="316.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Heating oil & other fuels">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="177.0" layoutY="383.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Living space area">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<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>
|
||||
</TextField>
|
||||
<HBox alignment="CENTER_LEFT" layoutX="616.0" layoutY="390.0" prefHeight="31.0" prefWidth="0.0" styleClass="km-yearBox">
|
||||
<children>
|
||||
<Text layoutY="3.0" strokeType="OUTSIDE" strokeWidth="0.0" text="m²" textAlignment="CENTER" wrappingWidth="41.0">
|
||||
<font>
|
||||
<Font size="19.0" />
|
||||
</font>
|
||||
<HBox.margin>
|
||||
<Insets left="3.0" />
|
||||
</HBox.margin>
|
||||
</Text>
|
||||
</children>
|
||||
</HBox>
|
||||
<Text fill="#727272" layoutX="177.0" layoutY="454.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Water usage">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<HBox alignment="CENTER" layoutX="298.0" layoutY="459.0" prefHeight="27.0" prefWidth="258.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="waterUsageLabel" text="0% of similar households">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Line endX="79.0" layoutX="317.0" layoutY="14.0" stroke="#545b54" />
|
||||
</children></AnchorPane>
|
||||
<ScrollPane fx:id="foodPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<content>
|
||||
<AnchorPane prefHeight="1000.0" prefWidth="817.0">
|
||||
<children>
|
||||
<Text layoutX="146.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much does the average person in your household eat?">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="146.0" layoutY="117.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Meat, fish, eggs">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Slider fx:id="meatFishEggsSlider" blockIncrement="2.5" layoutX="146.0" layoutY="205.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="149.0" prefHeight="31.0" prefWidth="220.0" styleClass="km-indicator">
|
||||
<children>
|
||||
<Label fx:id="meatFishEggsLabel" text="2.6 daily servings per person">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Text fill="#727272" layoutX="519.0" layoutY="115.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 2,6">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="519.0" layoutY="276.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 4,4">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</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">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="grainsBakedGoodsSlider" blockIncrement="4.5" layoutX="146.0" layoutY="366.0" majorTickUnit="4.5" max="13.5" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Text fill="#727272" layoutX="146.0" layoutY="278.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Grains & baked goods">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="146.0" layoutY="439.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Dairy">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<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">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Text fill="#727272" layoutX="519.0" layoutY="437.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 2,4">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="524.0" layoutY="776.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 3,7">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</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">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="snacksDrinksSlider" blockIncrement="3.7" layoutX="151.0" layoutY="866.0" majorTickUnit="3.7" max="11.0" minorTickCount="0" prefHeight="24.0" prefWidth="517.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Text fill="#727272" layoutX="151.0" layoutY="778.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Snacks, drinks etc.">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="151.0" layoutY="617.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Fruits & vegetables">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<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">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Text fill="#727272" layoutX="524.0" layoutY="615.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 3,9">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button layoutX="378.0" layoutY="926.0" mnemonicParsing="false" onAction="#displayShopping" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="402.0" layoutY="7.0" stroke="#545b54" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<AnchorPane fx:id="shoppingPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<Text layoutX="185.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="How much do you spend on each of the following?">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="133.0" layoutY="119.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Goods">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="133.0" layoutY="310.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Services">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="518.0" layoutY="117.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 1.520 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Text fill="#727272" layoutX="518.0" layoutY="309.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Average: 3.428 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<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="1520 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</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="3428 € / month">
|
||||
<font>
|
||||
<Font size="15.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</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" />
|
||||
<Button layoutX="383.0" layoutY="547.0" mnemonicParsing="false" onAction="#displayExtra" styleClass="nextButton" text="Next" />
|
||||
<Line endX="79.0" layoutX="487.0" layoutY="7.0" stroke="#545b54" />
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="extraPane" layoutY="92.0" prefHeight="611.0" prefWidth="820.0" visible="false">
|
||||
<children>
|
||||
<Text layoutX="199.0" layoutY="36.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Have you done any extra activities to save CO2?">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<CheckBox fx:id="localProduceCheckbox" layoutX="233.0" layoutY="189.0" mnemonicParsing="false" styleClass="extraCheckBox" text="Buying local produce" textFill="#727272">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</CheckBox>
|
||||
<CheckBox fx:id="bikeCheckbox" layoutX="233.0" layoutY="235.0" mnemonicParsing="false" styleClass="extraCheckBox" text="Using your bike instead of your car" textFill="#727272">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</CheckBox>
|
||||
<CheckBox fx:id="temperatureCheckbox" layoutX="233.0" layoutY="281.0" mnemonicParsing="false" styleClass="extraCheckBox" text="Lowering the temperature of your home" textFill="#727272">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</CheckBox>
|
||||
<CheckBox fx:id="solarPanelsCheckbox" layoutX="233.0" layoutY="327.0" mnemonicParsing="false" styleClass="extraCheckBox" text="Installing solar panels" textFill="#727272">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</CheckBox>
|
||||
<Line endX="79.0" layoutX="572.0" layoutY="7.0" stroke="#545b54" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -15,7 +15,7 @@
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
@@ -73,8 +73,8 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label fx:id="income" layoutX="207.0" layoutY="28.0" styleClass="activityField" text=" " textAlignment="CENTER" />
|
||||
<Label fx:id="peopleNumber" layoutX="204.0" layoutY="82.0" styleClass="activityField" text=" " textAlignment="CENTER" />
|
||||
<Label fx:id="peopleNumber" layoutX="207.0" layoutY="28.0" styleClass="activityField" text=" " textAlignment="CENTER" />
|
||||
<Label fx:id="income" layoutX="204.0" layoutY="82.0" styleClass="activityField" text=" " textAlignment="CENTER" />
|
||||
</children>
|
||||
</Pane>
|
||||
<Label alignment="CENTER" layoutX="20.0" layoutY="275.0" prefHeight="32.0" prefWidth="255.0" text="Home!" textAlignment="CENTER" textFill="#107222">
|
||||
@@ -296,7 +296,7 @@
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" layoutX="80.0" layoutY="250.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
|
||||
<children>
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Last CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
@@ -313,12 +313,50 @@
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" layoutX="80.0" layoutY="400.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
|
||||
<children>
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="First CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="firstFootprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="co2 footprint" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="tons CO2 / year" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
<PieChart fx:id="pieChart" layoutX="441.0" layoutY="300.0" prefHeight="352.0" prefWidth="363.0" />
|
||||
<ImageView fitHeight="163.0" fitWidth="200.0" layoutX="550.0" layoutY="47.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../icons/butterfly.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
<VBox alignment="CENTER" layoutX="80.0" layoutY="550.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
|
||||
<children>
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Development" textAlignment="CENTER" wrappingWidth="161.79296875">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="differenceLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="239.0" text="co2 footprint difference" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="41.0" prefWidth="162.0" text="tons CO2 / year" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="703.0" prefWidth="820.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
@@ -366,10 +404,10 @@
|
||||
<TableColumn fx:id="globalScore" prefWidth="124.0" text="Score" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<TableView fx:id="friendLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||
<TableView fx:id="developmentLeaderboard" layoutX="302.0" layoutY="220.0" prefHeight="333.0" prefWidth="200.0">
|
||||
<columns>
|
||||
<TableColumn fx:id="friendUser" prefWidth="75.0" text="User" />
|
||||
<TableColumn fx:id="friendScore" prefWidth="124.0" text="Score" />
|
||||
<TableColumn fx:id="developmentUser" prefWidth="75.0" text="User" />
|
||||
<TableColumn fx:id="developmentScore" prefWidth="124.0" text="Score" />
|
||||
</columns>
|
||||
</TableView>
|
||||
<Label layoutX="69.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Global Leaderboard" textAlignment="CENTER" textFill="#5f1616">
|
||||
@@ -377,7 +415,7 @@
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Label layoutX="315.0" layoutY="177.0" prefHeight="46.0" prefWidth="187.0" text="Friends Leaderboard" textAlignment="CENTER" textFill="#5e1515">
|
||||
<Label layoutX="279.0" layoutY="177.0" prefHeight="46.0" prefWidth="266.0" text="Development Leaderboard" textAlignment="CENTER" textFill="#5e1515">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
@@ -391,7 +429,12 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="130.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
|
||||
<Text layoutX="117.0" layoutY="155.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Friend List">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TableView fx:id="friendsTable" layoutX="60.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
|
||||
<columns>
|
||||
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
|
||||
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
|
||||
@@ -400,6 +443,20 @@
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
<Text layoutX="315.0" layoutY="155.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Friend Leaderboard">
|
||||
<font>
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<TableView fx:id="friendLeaderboard" layoutX="300.0" layoutY="170.0" prefHeight="426.0" prefWidth="216.0" style="-fx-background-color: #e1fcd9;">
|
||||
<columns>
|
||||
<TableColumn fx:id="friendUser" prefWidth="107.0" text="Friend" />
|
||||
<TableColumn fx:id="friendScore" prefWidth="108.0" text="Score" />
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
||||
</columnResizePolicy>
|
||||
</TableView>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
|
||||
@@ -56,6 +56,16 @@ public class UserServiceTest {
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstFootprint() throws Exception {
|
||||
Float estimate = new Float(5);
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFootprint() throws Exception {
|
||||
Float estimate = new Float(5);
|
||||
@@ -66,6 +76,16 @@ public class UserServiceTest {
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFirstFootprint() throws Exception {
|
||||
Float estimate = new Float(5);
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/saveFirstFootprint?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFriendNamesTest() throws Exception {
|
||||
List<String> estimate = new ArrayList<String>();
|
||||
@@ -99,12 +119,29 @@ public class UserServiceTest {
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraInputsTest() throws Exception {
|
||||
Map<String, Boolean> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", true);
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, Boolean> result = userService.getExtraInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setInputTest() throws Exception {
|
||||
userService.updateInput("Eric", "input_size", "5");
|
||||
Mockito.verify(userService).updateInput("Eric", "input_size", "5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setExtraInputTest() throws Exception {
|
||||
userService.updateExtraInput("Eric", "solar_panels", true);
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFriendTest() throws Exception {
|
||||
userService.addFriend("Eric", "Ceren");
|
||||
|
||||
@@ -180,4 +180,17 @@ public class InputValidator {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets extra values.
|
||||
* @return the map of default values
|
||||
*/
|
||||
public static Map<String, Boolean> getExtraValues() {
|
||||
Map<String, Boolean> map = new HashMap<String, Boolean>() { };
|
||||
map.put("local_produce", false);
|
||||
map.put("bike", false);
|
||||
map.put("temperature", false);
|
||||
map.put("solar_panels", false);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,15 @@ public class User {
|
||||
@NotNull
|
||||
private Float footPrint = 0.0f;
|
||||
|
||||
@NotNull
|
||||
private Float firstFootprint = 0.0f;
|
||||
|
||||
@ElementCollection
|
||||
private Map<String, String> footPrintInputs = new HashMap<>();
|
||||
|
||||
@ElementCollection
|
||||
private Map<String, Boolean> extraInputs = new HashMap<>();
|
||||
|
||||
@ManyToMany
|
||||
private List<User> friends;
|
||||
|
||||
@@ -57,6 +63,7 @@ public class User {
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.setFootPrintInputs(InputValidator.getDefaultValues());
|
||||
this.setExtraInputs(InputValidator.getExtraValues());
|
||||
this.friends = new ArrayList<User>();
|
||||
}
|
||||
|
||||
@@ -124,6 +131,22 @@ public class User {
|
||||
this.footPrint = footPrint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the first footPrint of user.
|
||||
* @return the footprint of the user
|
||||
*/
|
||||
public Float getFirstFootprint() {
|
||||
return firstFootprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the footprint of a user.
|
||||
* @param firstFootprint footprint of a user
|
||||
*/
|
||||
public void setFirstFootprint(Float firstFootprint) {
|
||||
this.firstFootprint = firstFootprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the footprint inputs of the user.
|
||||
* @return footprint inputs of the user
|
||||
@@ -140,6 +163,22 @@ public class User {
|
||||
this.footPrintInputs = footPrintInputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the extra inputs of the user.
|
||||
* @return extra inputs of the user
|
||||
*/
|
||||
public Map<String, Boolean> getExtraInputs() {
|
||||
return extraInputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the extra inputs of the user.
|
||||
* @param extraInputs footprint inputs of the user
|
||||
*/
|
||||
public void setExtraInputs(Map<String, Boolean> extraInputs) {
|
||||
this.extraInputs = extraInputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the friends of the user.
|
||||
* @return friends list of the user
|
||||
|
||||
@@ -53,6 +53,20 @@ public class UserController {
|
||||
userService.setInput(name, inputName, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method sets extra input for a user.
|
||||
* @param name name of the user
|
||||
* @param inputName name of the input of the user
|
||||
* @param value value of the input
|
||||
*/
|
||||
@RequestMapping("/setExtraInput")
|
||||
public void setExtraInput(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "inputName") String inputName,
|
||||
@RequestParam(value = "value") Boolean value) {
|
||||
userService.setExtraInput(name, inputName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets input for a user.
|
||||
* @param name name of the user
|
||||
@@ -84,6 +98,27 @@ public class UserController {
|
||||
return footprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method saves first footprint for a user.
|
||||
* @param name name of the user
|
||||
*/
|
||||
@RequestMapping("/saveFirstFootprint")
|
||||
public Float saveFirstFootprint(@RequestParam(value = "name") String name) {
|
||||
Float footprint = userService.saveFirstFootprint(name);
|
||||
return footprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets first footprint for a user.
|
||||
* @param name name of the user
|
||||
*/
|
||||
@RequestMapping("/getFirst")
|
||||
public Float getFirstFootprint(@RequestParam(value = "name") String name) {
|
||||
System.out.println("hello");
|
||||
Float footprint = userService.getFirstFootprint(name);
|
||||
return footprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets friend list for a user.
|
||||
* @param name name of the user
|
||||
@@ -111,6 +146,14 @@ public class UserController {
|
||||
return userService.getInputMap(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the extra inputs map of the user.
|
||||
*/
|
||||
@RequestMapping("/getExtraInputs")
|
||||
public Map<String, Boolean> getExtraInputs(@RequestParam(value = "name") String name) {
|
||||
return userService.getExtraInputMap(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds friend for a user.
|
||||
* @param name name of the user
|
||||
|
||||
@@ -72,7 +72,21 @@ public class CalculatorService {
|
||||
* @return the footprint of the user
|
||||
*/
|
||||
public Float calculateFootprint(User user) {
|
||||
return invokeExternalService(user.getFootPrintInputs());
|
||||
Float footprint = invokeExternalService(user.getFootPrintInputs());
|
||||
addExtras(user);
|
||||
return footprint;
|
||||
}
|
||||
|
||||
public void addExtras(User user) {
|
||||
if (user.getExtraInputs().get("local_produce")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
} else if (user.getExtraInputs().get("bike")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
} else if (user.getExtraInputs().get("temperature")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
} else if (user.getExtraInputs().get("solar_panels")) {
|
||||
user.setFootPrint(user.getFootPrint() - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,22 @@ public class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets extra input for a user.
|
||||
* @param name name of the user
|
||||
* @param inputName name of the input of the user
|
||||
* @param value value of the input
|
||||
*/
|
||||
public void setExtraInput(String name, String inputName, Boolean value) {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user == null) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
} else {
|
||||
user.getExtraInputs().put(inputName, value);
|
||||
userRepository.save(user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the input value of an input.
|
||||
* @param name of the user
|
||||
@@ -125,6 +141,16 @@ public class UserService {
|
||||
return user.getFootPrintInputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the map of extra inputs.
|
||||
* @param name of the user
|
||||
* @return extra input map
|
||||
*/
|
||||
public Map<String, Boolean> getExtraInputMap(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
return user.getExtraInputs();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method saves the footprint of a user.
|
||||
* @param name name of the user
|
||||
@@ -137,6 +163,18 @@ public class UserService {
|
||||
return user.getFootPrint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method saves the first footprint of a user.
|
||||
* @param name name of the user
|
||||
* @return footprint of the user
|
||||
*/
|
||||
public Float saveFirstFootprint(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
user.setFirstFootprint(calculatorService.calculateFootprint(user));
|
||||
userRepository.save(user);
|
||||
return user.getFootPrint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the footprint of a user.
|
||||
* @param name name of the user
|
||||
@@ -147,6 +185,16 @@ public class UserService {
|
||||
return user.getFootPrint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the first footprint of a user.
|
||||
* @param name name of the user
|
||||
* @return first footprint of the user
|
||||
*/
|
||||
public Float getFirstFootprint(String name) {
|
||||
User user = userRepository.findByName(name);
|
||||
return user.getFirstFootprint();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the friends of a user.
|
||||
* @param name name of the user
|
||||
|
||||
@@ -78,6 +78,25 @@ public class UserControllerTest {
|
||||
assertEquals("7", arg3Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setExtraInputTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<Boolean> arg3Captor = ArgumentCaptor.forClass(Boolean.class);
|
||||
mvc.perform(get("/setExtraInput")
|
||||
.param("name", "ceren")
|
||||
.param("inputName", "input_size")
|
||||
.param("value", "true")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1))
|
||||
.setExtraInput(arg1Captor.capture(), arg2Captor.capture(), arg3Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
assertEquals("input_size", arg2Captor.getValue());
|
||||
assertEquals(true, arg3Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFriendTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
@@ -107,6 +126,19 @@ public class UserControllerTest {
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraInputMapTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/getExtraInputs")
|
||||
.param("name", "ceren")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1))
|
||||
.getExtraInputMap(arg1Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllUsersTest() throws Exception {
|
||||
mvc.perform(get("/getAllUsers")
|
||||
@@ -115,6 +147,18 @@ public class UserControllerTest {
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFriendNamesTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/getFriends")
|
||||
.param("name", "ceren")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1)).getFriends(arg1Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInputTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
@@ -141,4 +185,40 @@ public class UserControllerTest {
|
||||
verify(userService, times(1)).getFootprint(arg1Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstFootprintTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/getFirst")
|
||||
.param("name", "ceren")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1)).getFirstFootprint(arg1Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFootprintTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/saveFootprint")
|
||||
.param("name", "ceren")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1)).saveFootprint(arg1Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFirstFootprintTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/saveFirstFootprint")
|
||||
.param("name", "ceren")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1)).saveFirstFootprint(arg1Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,29 @@ public class CalculatorServiceTest {
|
||||
Assert.assertEquals(new Float(19.259982), footPrint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addExtrasTest() throws URISyntaxException {
|
||||
User user = new User(1L,"greenify", "password");
|
||||
Map<String,Boolean> map = new HashMap<String, Boolean>() {{
|
||||
put("local_produce", false);
|
||||
put("bike", false);
|
||||
put("temperature", false);
|
||||
put("solar_panels", false);
|
||||
}};
|
||||
user.setExtraInputs(map);
|
||||
user.setFootPrint(50f);
|
||||
Map<String,Boolean> secondMap = new HashMap<String, Boolean>() {{
|
||||
put("local_produce", true);
|
||||
put("bike", true);
|
||||
put("temperature", true);
|
||||
put("solar_panels", true);
|
||||
}};
|
||||
user.setExtraInputs(secondMap);
|
||||
calculatorService.addExtras(user);
|
||||
mockServer.verify();
|
||||
Assert.assertEquals(new Float(48f), user.getFootPrint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeExternalServiceTest() {
|
||||
CalculatorService service = new CalculatorService();
|
||||
|
||||
@@ -92,11 +92,26 @@ public class UserServiceTest {
|
||||
.get("input_footprint_shopping_food_dairy_default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setExtraInputTest() {
|
||||
User alex = new User(1L, "alex", "password");
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
userService.setExtraInput("alex", "solar_panels", true);
|
||||
assertEquals(true, alex.getExtraInputs()
|
||||
.get("solar_panels"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setInputNullTest() {
|
||||
assertThrows(ApplicationException.class, () -> userService.setInput(null, "hello", "5.5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setExtraInputNullTest() {
|
||||
assertThrows(ApplicationException.class, () -> userService.setExtraInput(null, "hello", true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setInputApplicationTestItem() {
|
||||
assertThrows(ApplicationException.class, () -> userService
|
||||
@@ -149,6 +164,17 @@ public class UserServiceTest {
|
||||
.getInputMap("alex"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraInputMapTest() {
|
||||
Map<String, Boolean> map = new HashMap<>();
|
||||
User alex = new User(1L, "alex", "password");
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
alex.setExtraInputs(map);
|
||||
assertEquals(map, userService
|
||||
.getExtraInputMap("alex"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInputExceptionTest() {
|
||||
assertThrows(ApplicationException.class, () -> userService.getInput("alex", "hello"));
|
||||
@@ -163,6 +189,15 @@ public class UserServiceTest {
|
||||
Assertions.assertEquals(15F, userService.getFootprint("alex"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstFootprintTest() {
|
||||
User alex = new User(1L, "alex", "password");
|
||||
alex.setFirstFootprint(15F);
|
||||
when(userRepository.findByName(alex.getName()))
|
||||
.thenReturn(alex);
|
||||
Assertions.assertEquals(15F, userService.getFirstFootprint("alex"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFootprintTest() {
|
||||
User alex = new User(1L, "alex", "password");
|
||||
@@ -174,6 +209,17 @@ public class UserServiceTest {
|
||||
Assertions.assertEquals(15f, userService.saveFootprint("alex"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveFirstFootprintTest() {
|
||||
User lola = new User(1L, "lola", "password");
|
||||
when(userRepository.findByName(lola.getName()))
|
||||
.thenReturn(lola);
|
||||
when(calculatorService.calculateFootprint(lola))
|
||||
.thenReturn(0f);
|
||||
userService.saveFirstFootprint("lola");
|
||||
Assertions.assertEquals(0f, userService.saveFirstFootprint("lola"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFriendsTest() {
|
||||
User alex = new User(1L, "alex", "password");
|
||||
|
||||
Reference in New Issue
Block a user