From 31def99398b79c1b1615d2d05fc0f2b19c34cfd9 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 8 Apr 2019 12:55:32 +0200 Subject: [PATCH 1/5] ADD::added buttons to apply tooltips to for the activities because you can't apply tooltips to imageviews, I added the achievement images to buttons to which you can add tooltips --- .../controller/DashBoardController.java | 18 +++- .../src/main/resources/fxml/dashboard.fxml | 99 ++++++++++++------- .../resources/stylesheets/dashboardStyle.css | 5 + 3 files changed, 80 insertions(+), 42 deletions(-) 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 b82e788..463c537 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -16,10 +16,7 @@ import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.chart.PieChart; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; +import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; @@ -187,13 +184,24 @@ public class DashBoardController { @FXML private Label loweringTemp; @FXML - private Button refreshHintsButton; + private Button achiev1Tip; + @FXML + private Button achiev2Tip; + @FXML + private Button achiev3Tip; + @FXML + private Button achiev4Tip; + @FXML + private Button achiev5Tip; + @FXML + private Button achiev6Tip; /** * Loads the the necessary things before anything else. * @throws InterruptedException exception if interrupted */ public void initialize() throws InterruptedException { + hintText.setWrapText(true); hintText.setText(hints.randomHint()); //set the dashboardPane to visible diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml index a686159..98d7c34 100644 --- a/src/Client/src/main/resources/fxml/dashboard.fxml +++ b/src/Client/src/main/resources/fxml/dashboard.fxml @@ -16,6 +16,7 @@ + @@ -77,7 +78,7 @@ - + @@ -399,7 +400,7 @@ - + diff --git a/src/Client/src/main/resources/stylesheets/dashboardStyle.css b/src/Client/src/main/resources/stylesheets/dashboardStyle.css index a7eefaa..4a74ac6 100644 --- a/src/Client/src/main/resources/stylesheets/dashboardStyle.css +++ b/src/Client/src/main/resources/stylesheets/dashboardStyle.css @@ -81,5 +81,10 @@ -fx-font-size: 14px; } +.toolTipButton { + -fx-background-color: transparent; + -fx-padding: 0 0 0 0; +} + From 9e37421d6debfd1bf02c12b43a6ee2f75542e050 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 8 Apr 2019 13:08:20 +0200 Subject: [PATCH 2/5] ADD::added tooltip texts to all achievements --- .../client/controller/DashBoardController.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 463c537..7089d54 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -202,6 +202,7 @@ public class DashBoardController { */ public void initialize() throws InterruptedException { + hintText.setWrapText(true); hintText.setText(hints.randomHint()); //set the dashboardPane to visible @@ -256,6 +257,22 @@ public class DashBoardController { addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2)); addRandomHints(); + + addToolTip(achiev1Tip, "Starting off \n You did your first green activity!"); + addToolTip(achiev2Tip, "Social Butterfly \n You added three friends"); + addToolTip(achiev3Tip, "Green Saver \n You saved * of CO2"); + addToolTip(achiev4Tip, "Animal Friend \n You have eaten 10 vegetarian meals"); + addToolTip(achiev5Tip, "Tom Dumoulin \n You have biked * km"); + addToolTip(achiev6Tip, "Let it shine \n You installed solar panels"); + } + + /** + * adds a tooltip to the button. + * @param button the button to add the tooltip to. + * @param message the message to be displayed in the tooltip. + */ + public void addToolTip(Button button, String message) { + button.setTooltip(new Tooltip(message)); } /** From 18a0973af47a38de9da11416605bf43dd12d4561 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 8 Apr 2019 14:00:21 +0200 Subject: [PATCH 3/5] EDIT::added style to tooltips and reduced delay between hovering over the achievement and the tooltip appearing EDIT::fixed some checkstyle warnings --- .../src/main/java/greenify/client/Friend.java | 1 - .../controller/CalculatorController.java | 2 +- .../controller/DashBoardController.java | 59 +++++++++++++++---- .../controller/ExtraActivityController.java | 3 +- .../resources/stylesheets/dashboardStyle.css | 6 ++ 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Friend.java b/src/Client/src/main/java/greenify/client/Friend.java index d0e65e5..b0282f3 100644 --- a/src/Client/src/main/java/greenify/client/Friend.java +++ b/src/Client/src/main/java/greenify/client/Friend.java @@ -1,7 +1,6 @@ package greenify.client; import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleFloatProperty; import javafx.beans.property.SimpleStringProperty; public class Friend { 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 39c92fb..e297d53 100644 --- a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java +++ b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java @@ -397,11 +397,11 @@ public class CalculatorController { } Float footprint = userService.saveFootprint(userService.currentUser.getName()); Window owner = saveButton.getScene().getWindow(); - Stage current = (Stage) owner; controller.updateLeaderboard(); controller.updateAchievements(); UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Footprint saved!", "Your footprint is saved!"); + Stage current = (Stage) owner; current.close(); } 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 7089d54..3425b49 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -6,8 +6,10 @@ import greenify.client.Friend; import greenify.client.Hints; import greenify.client.rest.UserService; import javafx.animation.FadeTransition; +import javafx.animation.KeyFrame; import javafx.animation.PathTransition; import javafx.animation.ScaleTransition; +import javafx.animation.Timeline; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; @@ -16,7 +18,12 @@ import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.chart.PieChart; -import javafx.scene.control.*; + +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.Tooltip; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; @@ -28,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import java.io.IOException; +import java.lang.reflect.Field; import java.util.List; import java.util.Map; import java.util.Objects; @@ -258,6 +266,9 @@ public class DashBoardController { addRandomHints(); + Tooltip tooltip = new Tooltip("tip"); + hackTooltipStartTiming(tooltip); + addToolTip(achiev1Tip, "Starting off \n You did your first green activity!"); addToolTip(achiev2Tip, "Social Butterfly \n You added three friends"); addToolTip(achiev3Tip, "Green Saver \n You saved * of CO2"); @@ -271,10 +282,37 @@ public class DashBoardController { * @param button the button to add the tooltip to. * @param message the message to be displayed in the tooltip. */ - public void addToolTip(Button button, String message) { + private void addToolTip(Button button, String message) { button.setTooltip(new Tooltip(message)); } + /** + * changes the delay time between hovering over something with a tooltip and when the + * tooltip is displayed. + * @param tooltip the tooltip to change the delay of + */ + private static void hackTooltipStartTiming(Tooltip tooltip) { + + try { + Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR"); + fieldBehavior.setAccessible(true); + Object objBehavior = fieldBehavior.get(tooltip); + + Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer"); + fieldTimer.setAccessible(true); + Timeline objTimer = (Timeline) fieldTimer.get(objBehavior); + + objTimer.getKeyFrames().clear(); + objTimer.getKeyFrames().add(new KeyFrame(new Duration(150))); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + e.getMessage(); + } catch (IllegalAccessException e) { + e.getMessage(); + e.printStackTrace(); + } + } + /** * Sorts the scores of users. * @param users the list of users @@ -389,7 +427,8 @@ 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")); - Map extraMap = userService.getExtraInputs(userService.currentUser.getName()); + Map extraMap = userService.getExtraInputs(userService.currentUser + .getName()); localProduce.setText(extraMap.get("local_produce")); bike.setText(extraMap.get("bike")); solarPanels.setText(extraMap.get("solar_panels")); @@ -433,7 +472,7 @@ public class DashBoardController { } /** - * Logs out the user + * Logs out the user. * @param event the event (clicking the button) * @throws IOException if the Application doesn't load. */ @@ -597,32 +636,32 @@ public class DashBoardController { */ public void updateAchievements() { Map achievements = userService.getAchievements(userService.currentUser.getName()); - if((Boolean)achievements.get("Starting off")) { + if ((Boolean)achievements.get("Starting off")) { achieve1.setOpacity(1); } else { achieve1.setOpacity(0.3); } - if((Boolean)achievements.get("Social butterfly")) { + if ((Boolean)achievements.get("Social butterfly")) { achieve2.setOpacity(1); } else { achieve2.setOpacity(0.3); } - if((Boolean)achievements.get("Green saver")) { + if ((Boolean)achievements.get("Green saver")) { achieve3.setOpacity(1); } else { achieve3.setOpacity(0.3); } - if((Boolean)achievements.get("Animal friend")) { + if ((Boolean)achievements.get("Animal friend")) { achieve4.setOpacity(1); } else { achieve4.setOpacity(0.3); } - if((Boolean)achievements.get("Tom Dumoulin")) { + if ((Boolean)achievements.get("Tom Dumoulin")) { achieve5.setOpacity(1); } else { achieve5.setOpacity(0.3); } - if((Boolean)achievements.get("Let it shine")) { + if ((Boolean)achievements.get("Let it shine")) { achieve6.setOpacity(1); } else { achieve6.setOpacity(0.3); 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 f84dff5..67b1fdb 100644 --- a/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java +++ b/src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java @@ -229,7 +229,8 @@ public class ExtraActivityController { controller.updateAchievements(); Stage current = (Stage) owner; current.close(); - UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Activities are added!", + UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, + "Activities are added!", "Your new activities are added!"); } diff --git a/src/Client/src/main/resources/stylesheets/dashboardStyle.css b/src/Client/src/main/resources/stylesheets/dashboardStyle.css index 4a74ac6..b7835a1 100644 --- a/src/Client/src/main/resources/stylesheets/dashboardStyle.css +++ b/src/Client/src/main/resources/stylesheets/dashboardStyle.css @@ -86,5 +86,11 @@ -fx-padding: 0 0 0 0; } +.tooltip { + -fx-background-color: #d0f2d3; + -fx-text-fill: #364c38; + -fx-font-size: 14px; +} + From 79fd69503c7916d761cdc9491493be238c0698aa Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 8 Apr 2019 14:17:06 +0200 Subject: [PATCH 4/5] FIX::fixed complieJava build failing --- .../client/controller/CalculatorController.java | 9 ++++++--- .../client/controller/DashBoardController.java | 13 +++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) 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 e297d53..f52c842 100644 --- a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java +++ b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java @@ -408,7 +408,8 @@ public class CalculatorController { /** * Checks the food labels. */ - public void checkFoodLabels() { + @SuppressWarnings("Duplicates") + private void checkFoodLabels() { if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_shopping_food_meatfisheggs", @@ -441,7 +442,8 @@ public class CalculatorController { /** * Checks the house labels. */ - public void checkHousingLabels() { + @SuppressWarnings("Duplicates") + private void checkHousingLabels() { if (!electricityField.getText().equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_housing_electricity_dollars", @@ -477,7 +479,8 @@ public class CalculatorController { /** * Checks the transport labels. */ - public void checkTransportLabels() { + @SuppressWarnings("Duplicates") + private void checkTransportLabels() { if (!publicTransitField.getText().equals("0")) { userService.updateInput(userService.currentUser.getName(), "input_footprint_transportation_publictrans", 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 3425b49..136f3d9 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -25,6 +25,7 @@ import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.Tooltip; import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.effect.ColorAdjust; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.shape.Line; @@ -636,47 +637,55 @@ public class DashBoardController { */ public void updateAchievements() { Map achievements = userService.getAchievements(userService.currentUser.getName()); + ColorAdjust desaturate = new ColorAdjust(); + desaturate.setSaturation(-0.75); if ((Boolean)achievements.get("Starting off")) { achieve1.setOpacity(1); } else { + achieve1.setEffect(desaturate); achieve1.setOpacity(0.3); } if ((Boolean)achievements.get("Social butterfly")) { achieve2.setOpacity(1); } else { + achieve2.setEffect(desaturate); achieve2.setOpacity(0.3); } if ((Boolean)achievements.get("Green saver")) { achieve3.setOpacity(1); } else { + achieve3.setEffect(desaturate); achieve3.setOpacity(0.3); } if ((Boolean)achievements.get("Animal friend")) { achieve4.setOpacity(1); } else { + achieve4.setEffect(desaturate); achieve4.setOpacity(0.3); } if ((Boolean)achievements.get("Tom Dumoulin")) { achieve5.setOpacity(1); } else { + achieve5.setEffect(desaturate); achieve5.setOpacity(0.3); } if ((Boolean)achievements.get("Let it shine")) { achieve6.setOpacity(1); } else { + achieve6.setEffect(desaturate); achieve6.setOpacity(0.3); } } //class for the animations on the navigation buttons - public class MyButtonSkin extends ButtonSkin { + private class MyButtonSkin extends ButtonSkin { /** * adds a skin and scale animation to a button. * the scale transition is for hovering over it so it then scales up * and scales down when you stop hovering over it. * @param button the button to add the animation to */ - public MyButtonSkin(Button button) { + private MyButtonSkin(Button button) { //inherit the button properties super(button); //transition to scale up on hover From 6ba21c331d2e3dbf1317f30b8134d6587ccd92c2 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 8 Apr 2019 14:21:20 +0200 Subject: [PATCH 5/5] FIX::fixed compileJava build failing the last merge undid the change of this line, this should fix it --- .../java/greenify/client/controller/CalculatorController.java | 1 - 1 file changed, 1 deletion(-) 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 94091fa..3aa8270 100644 --- a/src/Client/src/main/java/greenify/client/controller/CalculatorController.java +++ b/src/Client/src/main/java/greenify/client/controller/CalculatorController.java @@ -403,7 +403,6 @@ public class CalculatorController { Window owner = saveButton.getScene().getWindow(); controller.updateLeaderboard(); controller.updateAchievements(); - Stage current = (Stage) owner; UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Footprint saved!", "Your footprint is saved!"); Stage current = (Stage) owner;