diff --git a/src/Client/src/main/java/greenify/client/Friend.java b/src/Client/src/main/java/greenify/client/Friend.java index 5612f79..d0e65e5 100644 --- a/src/Client/src/main/java/greenify/client/Friend.java +++ b/src/Client/src/main/java/greenify/client/Friend.java @@ -1,16 +1,17 @@ package greenify.client; +import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleFloatProperty; import javafx.beans.property.SimpleStringProperty; public class Friend { private SimpleStringProperty friend; - private SimpleFloatProperty score; + private SimpleDoubleProperty score; - public Friend(String friend, Float friendScore) { + public Friend(String friend, Double friendScore) { this.friend = new SimpleStringProperty(friend); - this.score = new SimpleFloatProperty(friendScore); + this.score = new SimpleDoubleProperty(friendScore); } @@ -22,11 +23,11 @@ public class Friend { this.friend = new SimpleStringProperty(name); } - public Float getScore() { + public Double getScore() { return score.get(); } - public void setScore(Float score) { - this.score = new SimpleFloatProperty(score); + public void setScore(Double score) { + this.score = new SimpleDoubleProperty(score); } } diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 12b095a..daf7176 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -55,7 +55,7 @@ public class Hints { + "utensils and napkins, it saves plastic and paper."); this.hints.add("It takes about 66 days to form a new habit, keep going!"); this.hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for " - + "the environment to refill than to buy a new one every time it's empty."); + + "the environment to refill than to buy a new one every time it's empty."); this.hints.add("Recycle glass bottles!" + " A glass bottle made in our time will take more than 4,000 years" + " to decompose."); @@ -75,3 +75,4 @@ public class Hints { } } + diff --git a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java index f96b126..9961f48 100644 --- a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java +++ b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java @@ -16,7 +16,6 @@ import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Alert; import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.Slider; @@ -34,7 +33,6 @@ import java.text.DecimalFormat; @Controller public class CalculatorController { - private static UserController.AlertHelper AlertHelper; @Autowired UserService userService; @@ -146,15 +144,6 @@ public class CalculatorController { //extra pane @FXML private AnchorPane extraPane; - @FXML - private CheckBox localProduceCheckbox; - @FXML - private CheckBox bikeCheckbox; - @FXML - private CheckBox temperatureCheckbox; - @FXML - private CheckBox solarPanelsCheckbox; - /** * initializes the window, performs some actions before loading all other things. @@ -372,7 +361,6 @@ public class CalculatorController { foodPane.setVisible(false); shoppingPane.setVisible(false); extraPane.setVisible(true); - } /** @@ -407,42 +395,15 @@ public class CalculatorController { "input_footprint_shopping_services_total", servicesLabel.getText().replace("€ / month", "")); } - checkCheckBoxes(); Float footprint = userService.saveFootprint(userService.currentUser.getName()); Window owner = saveButton.getScene().getWindow(); Stage current = (Stage) owner; current.close(); controller.updateLeaderboard(); - CalculatorController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, + UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Footprint saved!", "Your footprint is saved!"); } - /** - * Checks the check boxes. - */ - public void checkCheckBoxes() { - if (localProduceCheckbox.isSelected()) { - localProduceCheckbox.setSelected(true); - userService.updateExtraInput(userService.currentUser.getName(), - "local_produce", true); - } - if (bikeCheckbox.isSelected()) { - bikeCheckbox.setSelected(true); - userService.updateExtraInput(userService.currentUser.getName(), - "bike", true); - } - if (temperatureCheckbox.isSelected()) { - temperatureCheckbox.setSelected(true); - userService.updateExtraInput(userService.currentUser.getName(), - "temperature", true); - } - if (solarPanelsCheckbox.isSelected()) { - solarPanelsCheckbox.setSelected(true); - userService.updateExtraInput(userService.currentUser.getName(), - "solar_panels", true); - } - } - /** * Checks the food labels. */ @@ -477,7 +438,7 @@ public class CalculatorController { } /** - * Checks the housing labels. + * Checks the house labels. */ public void checkHousingLabels() { if (!electricityField.getText().equals("0")) { @@ -531,30 +492,30 @@ public class CalculatorController { "input_footprint_transportation_miles1", carTravelGasolineField.getText()); } - if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) { + if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_mpg1", - carTravelGasolineLabel.getText().replace(" mpg", "")); + carTravelGasolineLabel.getText().replace(" km/L", "")); } if (!carTravelDieselField.getText().equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_miles2", carTravelDieselField.getText()); } - if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) { + if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_mpg2", - carTravelDieselLabel.getText().replace(" mpg", "")); + carTravelDieselLabel.getText().replace(" km/L", "")); } if (!carTravelElectricField.getText().equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_miles3", carTravelElectricField.getText()); } - if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) { + if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_mpg3", - carTravelElectricLabel.getText().replace(" mpge", "")); + carTravelElectricLabel.getText().replace(" km/Le", "")); } } } \ No newline at end of file diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index ad65941..fe09235 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -17,7 +17,6 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.chart.PieChart; import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; @@ -168,16 +167,16 @@ public class DashBoardController { @FXML private ImageView achiev1image; @FXML - private CheckBox localProduce; - @FXML - private CheckBox loweringTemp; - @FXML - private CheckBox bike; - @FXML - private CheckBox solarPanels; - @FXML private Label hintText; @FXML + private Label solarPanels; + @FXML + private Label localProduce; + @FXML + private Label bike; + @FXML + private Label loweringTemp; + @FXML private Button refreshHintsButton; /** @@ -249,8 +248,8 @@ public class DashBoardController { public void sortScores(List users) throws InterruptedException { for (int i = 0; i < users.size(); i++) { for (int j = 0; j < users.size(); j++) { - Float firstScore = userService.getFootprint(users.get(i)); - Float secondScore = userService.getFootprint(users.get(j)); + Double firstScore = userService.getFootprint(users.get(i)); + Double secondScore = userService.getFootprint(users.get(j)); if (i > j && firstScore < secondScore) { String temp = users.get(i); users.set(i, users.get(j)); @@ -272,9 +271,9 @@ public class DashBoardController { public void sortDiffScores(List 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 + Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService .getFootprint(users.get(i)); - Float secondDiff = userService.getFirstFootprint(users.get(j)) - userService + Double secondDiff = userService.getFirstFootprint(users.get(j)) - userService .getFootprint(users.get(j)); if (i < j && firstDiff < secondDiff) { String temp = users.get(i); @@ -356,18 +355,11 @@ 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")); - 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); - } + Map extraMap = userService.getExtraInputs(userService.currentUser.getName()); + localProduce.setText(extraMap.get("local_produce")); + bike.setText(extraMap.get("bike")); + solarPanels.setText(extraMap.get("solar_panels")); + loweringTemp.setText(extraMap.get("temperature")); } /** @@ -380,9 +372,9 @@ public class DashBoardController { footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName())); firstFootprintLabel.setText("" + userService .getFirstFootprint(userService.currentUser.getName())); - Float diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService + Double diff = userService.getFirstFootprint(userService.currentUser.getName()) - userService .getFootprint(userService.currentUser.getName()); - differenceLabel.setText( "" + diff); + differenceLabel.setText( "" + Math.round(diff * 10) / 10.0); usernameLabel.setText("" + userService.currentUser.getName()); addFadeTransition(userPane); System.out.println("display user"); @@ -390,7 +382,6 @@ public class DashBoardController { userPane.setVisible(true); activitiesPane.setVisible(false); friendsPane.setVisible(false); - } /** @@ -526,9 +517,9 @@ public class DashBoardController { 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))); + double diff = Math.round((userService.getFirstFootprint(userList.get(j)) + - userService.getFootprint(userList.get(j))) * 10) / 10.0; + Friend diffUser = new Friend(userList.get(j), diff); globalLeaderData.add(user); developmentData.add(diffUser); } @@ -558,9 +549,9 @@ public class DashBoardController { 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))); + double diff = Math.round((userService.getFirstFootprint(wholeList.get(j)) + - userService.getFootprint(wholeList.get(j))) * 10) / 10.0; + Friend diffUser = new Friend(wholeList.get(j), diff); friendLeaderData.add(diffUser); } friendsTable.setItems(data); @@ -642,6 +633,4 @@ public class DashBoardController { button.setOnMouseExited(e -> scaleDown.playFromStart()); } } - } - diff --git a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java index 63d1d03..e14e30f 100644 --- a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java +++ b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java @@ -8,20 +8,28 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Slider; import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; +import javafx.stage.Window; import javafx.util.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @Controller public class ExtraActivityController { - @Autowired UserService userService; + @Autowired + CalculatorController calculatorController; + + @Autowired + DashBoardController controller; + @FXML private AnchorPane veganMealPane; @FXML @@ -59,6 +67,8 @@ public class ExtraActivityController { private Slider solarPanelsSlider; @FXML private Label solarPanelsLabel; + @FXML + private Button saveButton; /** * initializes the sliders and labels before loading. @@ -78,7 +88,6 @@ public class ExtraActivityController { displayBikeButton.setSkin(new TranslateButtonSkin(displayBikeButton)); displayTemperatureButton.setSkin(new TranslateButtonSkin(displayTemperatureButton)); displaySolarPanelButton.setSkin(new TranslateButtonSkin(displaySolarPanelButton)); - } /** @@ -150,6 +159,43 @@ public class ExtraActivityController { solarPanelPane.setVisible(true); } + /** + * The method updates the values + */ + @SuppressWarnings("Duplicates") + public void save(ActionEvent event) throws InterruptedException { + Window owner = saveButton.getScene().getWindow(); + Float footprint = userService.saveFootprint(userService.currentUser.getName()); + controller.updateLeaderboard(); + Stage current = (Stage) owner; + current.close(); + UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Activities are added!", + "Your new activities are added!"); + } + + /** + * The method updates the values of extras. + * @param event user clicks to button + */ + @SuppressWarnings("Duplicates") + public void updateExtras(ActionEvent event) throws InterruptedException { + if (!bikeLabel.getText().replace(" km", "").equals("0")) { + userService.updateExtraInput(userService.currentUser.getName(), + "bike", + bikeLabel.getText().replace(" km", "")); + } + if (!solarPanelsLabel.getText().equals("0")) { + userService.updateExtraInput(userService.currentUser.getName(), + "solar_panels", + solarPanelsLabel.getText()); + } + if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) { + userService.updateExtraInput(userService.currentUser.getName(), + "bike", + temperatureLabel.getText().replace(" Degrees", "")); + } + } + public class TranslateButtonSkin extends ButtonSkin { /** * button skin that sets a translate animation on entering and exiting the button. diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index 93833dd..5073101 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -1,9 +1,14 @@ package greenify.client.controller; -import com.sun.javafx.scene.control.skin.ButtonSkin; import greenify.client.Application; import greenify.client.rest.UserService; -import javafx.animation.*; +import javafx.animation.FadeTransition; +import javafx.animation.Interpolator; +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.ParallelTransition; +import javafx.animation.Timeline; +import javafx.animation.TranslateTransition; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; @@ -13,7 +18,6 @@ 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; @@ -36,12 +40,11 @@ import java.util.concurrent.TimeUnit; */ @Controller public class RegisterWindowController { - @Autowired UserService userService; @Autowired - DashBoardController controller; + ExtraActivityController extraActivityController; //navigation panes @FXML @@ -148,15 +151,6 @@ public class RegisterWindowController { //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 @@ -177,7 +171,6 @@ public class RegisterWindowController { addSlideAnimation(1100, passwordField, 300); TimeUnit.MILLISECONDS.sleep(300); addSlideAnimation(1100, passwordField2, -420); - signUpButton.setSkin(new SignUpButtonSkin(signUpButton)); } /** @@ -267,9 +260,9 @@ public class RegisterWindowController { } }); - addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " mpg"); - addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " mpg"); - addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " mpge"); + addSliderListenerCarUsage(carTravelGasolineSlider, carTravelGasolineLabel, " km/L"); + addSliderListenerCarUsage(carTravelDieselSlider, carTravelDieselLabel, " km/L"); + addSliderListenerCarUsage(carTravelElectricSlider, carTravelElectricLabel, " km/Le"); cleanEnergyPurchasedSlider.valueProperty().addListener(new ChangeListener() { @Override @@ -312,6 +305,7 @@ public class RegisterWindowController { }); } + @SuppressWarnings("Duplicates") private void addSliderListenerDailyServing(Slider slider, Label label) { DecimalFormat df = new DecimalFormat("0.0"); slider.valueProperty().addListener(new ChangeListener() { @@ -333,6 +327,23 @@ public class RegisterWindowController { }); } + /** + * adds a fade transition to the given node. + * @param node the node to add the transition to + */ + public void addFadeTransAnimation(Node node) { + FadeTransition fade = new FadeTransition(Duration.millis(350), node); + fade.setFromValue(0); + fade.setToValue(1.0); + TranslateTransition trans = new TranslateTransition(Duration.millis(350), node); + trans.setFromY(800); + trans.setToY(0); + ParallelTransition par = new ParallelTransition(); + par.setNode(travelPane); + par.getChildren().addAll(fade, trans); + par.play(); + } + private void addSlideInAnimation(Node node) { Timeline timeline = new Timeline(); KeyValue keyValue = new KeyValue(node.translateXProperty(), 0, Interpolator.EASE_OUT); @@ -348,6 +359,7 @@ public class RegisterWindowController { */ @SuppressWarnings("Duplicates") public void displayGetStarted(ActionEvent event) { + addFadeTransAnimation(getStartedPane); getStartedPane.setVisible(true); travelPane.setVisible(false); homePane.setVisible(false); @@ -363,7 +375,7 @@ public class RegisterWindowController { */ @SuppressWarnings("Duplicates") public void displayTravel(ActionEvent event) { - addSlideInAnimation(travelPane); + addFadeTransAnimation(travelPane); getStartedPane.setVisible(false); travelPane.setVisible(true); homePane.setVisible(false); @@ -380,6 +392,7 @@ public class RegisterWindowController { */ @SuppressWarnings("Duplicates") public void displayHome(ActionEvent event) { + addFadeTransAnimation(homePane); getStartedPane.setVisible(false); travelPane.setVisible(false); homePane.setVisible(true); @@ -395,6 +408,7 @@ public class RegisterWindowController { */ @SuppressWarnings("Duplicates") public void displayFood(ActionEvent event) { + addFadeTransAnimation(foodPane); getStartedPane.setVisible(false); travelPane.setVisible(false); homePane.setVisible(false); @@ -410,6 +424,7 @@ public class RegisterWindowController { */ @SuppressWarnings("Duplicates") public void displayShopping(ActionEvent event) { + addFadeTransAnimation(shoppingPane); getStartedPane.setVisible(false); travelPane.setVisible(false); homePane.setVisible(false); @@ -424,7 +439,10 @@ public class RegisterWindowController { * @param event the click of the designated button */ @SuppressWarnings("Duplicates") - public void displayExtra(ActionEvent event) { + public void displayExtra(ActionEvent event) throws IOException { + addFadeTransAnimation(extraPane); + extraPane.getChildren().setAll((Node) Application.load(this.getClass() + .getClassLoader().getResource("fxml/extraActivities.fxml"))); getStartedPane.setVisible(false); travelPane.setVisible(false); homePane.setVisible(false); @@ -466,27 +484,13 @@ public class RegisterWindowController { "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(); + UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, + owner, "Footprint saved!", "Your footprint is saved!"); } /** @@ -577,57 +581,30 @@ public class RegisterWindowController { "input_footprint_transportation_miles1", carTravelGasolineField.getText()); } - if (!carTravelGasolineLabel.getText().replace(" mpg", "").equals("0")) { + if (!carTravelGasolineLabel.getText().replace(" km/L", "").equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_mpg1", - carTravelGasolineLabel.getText().replace(" mpg", "")); + carTravelGasolineLabel.getText().replace(" km/L", "")); } if (!carTravelDieselField.getText().equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_miles2", carTravelDieselField.getText()); } - if (!carTravelDieselLabel.getText().replace(" mpg", "").equals("0")) { + if (!carTravelDieselLabel.getText().replace(" km/L", "").equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_mpg2", - carTravelDieselLabel.getText().replace(" mpg", "")); + carTravelDieselLabel.getText().replace(" km/L", "")); } if (!carTravelElectricField.getText().equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_miles3", carTravelElectricField.getText()); } - if (!carTravelElectricLabel.getText().replace(" mpge", "").equals("0")) { + if (!carTravelElectricLabel.getText().replace(" km/Le", "").equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_mpg3", - carTravelElectricLabel.getText().replace(" mpge", "")); + carTravelElectricLabel.getText().replace(" km/Le", "")); } } - - @SuppressWarnings("Duplicates") - private class SignUpButtonSkin extends ButtonSkin { - /** - * button skin for the 'add activity' buttons. - * adds scale animations on entering, clicking and extiting the button - * @param button the button to set the skin of - */ - private SignUpButtonSkin(Button button) { - super(button); - - //transition to scale up on hover - final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(85)); - //add the node and the position to scale to - scaleUp.setNode(button); - scaleUp.setToX(1.1); - scaleUp.setToY(1.1); - //play the transition when hovered over the button - button.setOnMouseEntered(e -> scaleUp.playFromStart()); - - final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(85)); - scaleDown.setNode(button); - scaleDown.setToX(1.0); - scaleDown.setToY(1.0); - button.setOnMouseExited(e -> scaleDown.playFromStart()); - } - } -} +} \ No newline at end of file diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index c808c15..89160be 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -1,10 +1,7 @@ package greenify.client.controller; -import com.sun.javafx.scene.control.skin.ButtonSkin; import greenify.client.Application; import greenify.client.rest.UserService; -import javafx.animation.FillTransition; -import javafx.animation.ScaleTransition; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; @@ -13,10 +10,8 @@ import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; -import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.stage.Window; -import javafx.util.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -40,11 +35,6 @@ public class UserController { @FXML private Button signUpButton; - public void initialize() { - loginButton.setSkin(new LoginButtonSkin(loginButton)); - signUpButton.setSkin(new LoginButtonSkin(signUpButton)); - } - /** * Handles when the user clicks on the login button. * it checks if the username and password fields are filled @@ -145,39 +135,11 @@ public class UserController { Parent registerWindow = Application.load(this.getClass().getClassLoader() .getResource("fxml/RegisterWindow.fxml")); Scene registerScene = new Scene(registerWindow); - registerScene.getStylesheets().add(Application.class.getClassLoader() - .getResource("stylesheets/registerWindowStyle.css").toExternalForm()); Stage registerStage = new Stage(); registerStage.setScene(registerScene); registerStage.setTitle("Enter register credentials"); registerStage.show(); } - @SuppressWarnings("Duplicates") - private class LoginButtonSkin extends ButtonSkin { - /** - * button skin for the 'add activity' buttons. - * adds scale animations on entering, clicking and extiting the button - * @param button the button to set the skin of - */ - private LoginButtonSkin(Button button) { - super(button); - - //transition to scale up on hover - final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(85)); - //add the node and the position to scale to - scaleUp.setNode(button); - scaleUp.setToX(1.1); - scaleUp.setToY(1.1); - //play the transition when hovered over the button - button.setOnMouseEntered(e -> scaleUp.playFromStart()); - - final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(85)); - scaleDown.setNode(button); - scaleDown.setToX(1.0); - scaleDown.setToY(1.0); - button.setOnMouseExited(e -> scaleDown.playFromStart()); - } - } - } + diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index bb19bf5..699137e 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -109,13 +109,13 @@ public class UserService { * @param value value of the input */ @SuppressWarnings("Duplicates") - public void updateExtraInput(String name, String inputName, Boolean value) { + public void updateExtraInput(String name, String inputName, String 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); + .queryParam("value", value); new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); ResponseEntity authenticateResponse = this.restTemplate.getForEntity(builder.build() @@ -128,15 +128,16 @@ public class UserService { * @return returns the footprint score */ @SuppressWarnings("Duplicates") - public Float getFootprint(String name) { + public double getFootprint(String name) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint") .queryParam("name", name); new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); - Float result = this.restTemplate.getForObject(builder + Float footprint = this.restTemplate.getForObject(builder .build().encode().toUri(), Float.class); + double result = Math.round(footprint * 10) / 10.0; return result; } @@ -145,7 +146,7 @@ public class UserService { * @param name name of the user * @return returns the footprint score */ - public Float getFirstFootprint(String name) { + public double getFirstFootprint(String name) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst") @@ -154,7 +155,8 @@ public class UserService { System.out.println(builder.build().encode().toUri()); Float footprint = this.restTemplate.getForObject(builder .build().encode().toUri(), Float.class); - return footprint; + double result = Math.round(footprint * 10) / 10.0; + return result; } /** @@ -270,14 +272,14 @@ public class UserService { * @param name the username of the current user. */ @SuppressWarnings("Duplicates") - public Map getExtraInputs(String name) { + public Map 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 result = this.restTemplate.getForObject(builder.build() + Map result = this.restTemplate.getForObject(builder.build() .encode().toUri(), Map.class); return result; } @@ -313,4 +315,4 @@ public class UserService { .build().encode().toUri(), List.class); return result; } -} +} \ No newline at end of file diff --git a/src/Client/src/main/resources/fxml/FirstCalculator.fxml b/src/Client/src/main/resources/fxml/FirstCalculator.fxml index 3304516..2fea111 100644 --- a/src/Client/src/main/resources/fxml/FirstCalculator.fxml +++ b/src/Client/src/main/resources/fxml/FirstCalculator.fxml @@ -1,26 +1,13 @@ - - - - - - - - - - - - - - + diff --git a/src/Client/src/main/resources/fxml/RegisterWindow.fxml b/src/Client/src/main/resources/fxml/RegisterWindow.fxml index 6c82691..5764438 100644 --- a/src/Client/src/main/resources/fxml/RegisterWindow.fxml +++ b/src/Client/src/main/resources/fxml/RegisterWindow.fxml @@ -1,6 +1,5 @@ - @@ -25,7 +24,7 @@ - - +