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 3323d86..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,16 +403,17 @@ 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; current.close(); } /** * 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", @@ -445,7 +446,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", @@ -481,7 +483,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 5679911..375d129 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,11 +18,14 @@ 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.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; @@ -31,6 +36,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; @@ -187,13 +193,25 @@ 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 @@ -247,6 +265,52 @@ public class DashBoardController { addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton)); addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2)); 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"); + 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. + */ + 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(); + } } /** @@ -410,7 +474,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. */ @@ -576,47 +640,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 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..b7835a1 100644 --- a/src/Client/src/main/resources/stylesheets/dashboardStyle.css +++ b/src/Client/src/main/resources/stylesheets/dashboardStyle.css @@ -81,5 +81,16 @@ -fx-font-size: 14px; } +.toolTipButton { + -fx-background-color: transparent; + -fx-padding: 0 0 0 0; +} + +.tooltip { + -fx-background-color: #d0f2d3; + -fx-text-fill: #364c38; + -fx-font-size: 14px; +} +