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; +} +